Implement ability presets

This commit is contained in:
abel1502 2025-05-17 12:47:09 +03:00
parent 853b6576ad
commit e59f8b441d
No known key found for this signature in database
GPG Key ID: 076926596A536338
5 changed files with 868 additions and 822 deletions

View File

@ -0,0 +1,32 @@
package com.hbm.handler.ability;
import java.util.HashMap;
// All abilities available on a given tool
public class AvailableAbilities {
private HashMap<IBaseAbility, Integer> abilities = new HashMap<IBaseAbility, Integer>();
AvailableAbilities() {}
AvailableAbilities addAbility(IBaseAbility ability, int level) {
if (level < 0 || level >= ability.levels()) {
throw new IllegalArgumentException("Illegal level " + level + " for ability " + ability.getName());
}
abilities.put(ability, level);
return this;
}
AvailableAbilities removeAbility(IBaseAbility ability) {
abilities.remove(ability);
return this;
}
boolean supportsAbility(IBaseAbility ability) {
return abilities.containsKey(ability);
}
int maxLevel(IBaseAbility ability) {
return abilities.getOrDefault(ability, -1);
}
}

View File

@ -29,9 +29,8 @@ public interface IToolAreaAbility extends IBaseAbility {
// (neither for the original block nor for the extras)
boolean onDig(int level, World world, int x, int y, int z, EntityPlayer player, IItemWithAbility tool);
public static enum AreaAbility {
// region handlers
None(new IToolAreaAbility() {
public static final IToolAreaAbility NONE = new IToolAreaAbility() {
@Override
public String getName() {
// TODO: null? empty? otherwise i18n
@ -42,9 +41,9 @@ public interface IToolAreaAbility extends IBaseAbility {
public boolean onDig(int level, World world, int x, int y, int z, EntityPlayer player, IItemWithAbility tool) {
return false;
}
}),
};
Recursion(new IToolAreaAbility() {
public static final IToolAreaAbility RECURSION = new IToolAreaAbility() {
@Override
public String getName() {
return "tool.ability.recursion";
@ -165,9 +164,9 @@ public interface IToolAreaAbility extends IBaseAbility {
return false;
}
}),
};
Hammer(new IToolAreaAbility() {
public static final IToolAreaAbility HAMMER = new IToolAreaAbility() {
@Override
public String getName() {
return "tool.ability.hammer";
@ -208,9 +207,9 @@ public interface IToolAreaAbility extends IBaseAbility {
return false;
}
}),
};
Explosion(new IToolAreaAbility() {
public static final IToolAreaAbility EXPLOSION = new IToolAreaAbility() {
@Override
public String getName() {
return "tool.ability.explosion";
@ -248,13 +247,6 @@ public interface IToolAreaAbility extends IBaseAbility {
return true;
}
});
// endregion handlers
public IToolAreaAbility handler;
AreaAbility(IToolAreaAbility handler) {
this.handler = handler;
}
};
// endregion handlers
}

View File

@ -41,9 +41,8 @@ public interface IToolHarvestAbility extends IBaseAbility {
}
}
public static enum HarvestAbility {
// region handlers
None(new IToolHarvestAbility() {
public static final IToolHarvestAbility NONE = new IToolHarvestAbility() {
@Override
public String getName() {
// TODO: null? empty? otherwise i18n
@ -54,9 +53,9 @@ public interface IToolHarvestAbility extends IBaseAbility {
public boolean skipDefaultDrops(int level) {
return false;
}
}),
};
Silk(new IToolHarvestAbility() {
public static final IToolHarvestAbility SILK = new IToolHarvestAbility() {
@Override
public String getName() {
return "tool.ability.silktouch";
@ -86,9 +85,9 @@ public interface IToolHarvestAbility extends IBaseAbility {
ItemStack stack = player.getHeldItem();
EnchantmentUtil.removeEnchantment(stack, Enchantment.silkTouch);
}
}),
};
Luck(new IToolHarvestAbility() {
public static final IToolHarvestAbility LUCK = new IToolHarvestAbility() {
@Override
public String getName() {
return "tool.ability.luck";
@ -130,9 +129,9 @@ public interface IToolHarvestAbility extends IBaseAbility {
ItemStack stack = player.getHeldItem();
EnchantmentUtil.removeEnchantment(stack, Enchantment.fortune);
}
}),
};
Smelter(new IToolHarvestAbility() {
public static final IToolHarvestAbility SMELTER = new IToolHarvestAbility() {
@Override
public String getName() {
return "tool.ability.smelter";
@ -173,9 +172,9 @@ public interface IToolHarvestAbility extends IBaseAbility {
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, stack.copy()));
}
}
}),
};
Shredder(new IToolHarvestAbility() {
public static final IToolHarvestAbility SHREDDER = new IToolHarvestAbility() {
@Override
public String getName() {
return "tool.ability.shredder";
@ -205,9 +204,9 @@ public interface IToolHarvestAbility extends IBaseAbility {
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, result.copy()));
}
}
}),
};
Centrifuge(new IToolHarvestAbility() {
public static final IToolHarvestAbility CENTRIFUGE = new IToolHarvestAbility() {
@Override
public String getName() {
return "tool.ability.centrifuge";
@ -241,9 +240,9 @@ public interface IToolHarvestAbility extends IBaseAbility {
}
}
}
}),
};
Crystallizer(new IToolHarvestAbility() {
public static final IToolHarvestAbility CRYSTALLIZER = new IToolHarvestAbility() {
@Override
public String getName() {
return "tool.ability.crystallizer";
@ -273,9 +272,9 @@ public interface IToolHarvestAbility extends IBaseAbility {
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, result.output.copy()));
}
}
}),
};
Mercury(new IToolHarvestAbility() {
public static final IToolHarvestAbility MERCURY = new IToolHarvestAbility() {
@Override
public String getName() {
return "tool.ability.mercury";
@ -309,13 +308,6 @@ public interface IToolHarvestAbility extends IBaseAbility {
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, new ItemStack(ModItems.ingot_mercury, mercury)));
}
}
});
};
// endregion handlers
public IToolHarvestAbility handler;
HarvestAbility(IToolHarvestAbility handler) {
this.handler = handler;
}
}
}

View File

@ -37,9 +37,8 @@ import net.minecraft.world.World;
public interface IWeaponAbility extends IBaseAbility {
void onHit(int level, World world, EntityPlayer player, Entity victim, IItemWithAbility tool);
public static enum WeaponAbility {
// region handlers
None(new IWeaponAbility() {
public static final IWeaponAbility NONE = new IWeaponAbility() {
@Override
public String getName() {
// TODO: null? empty? otherwise i18n
@ -48,9 +47,9 @@ public interface IWeaponAbility extends IBaseAbility {
@Override
public void onHit(int level, World world, EntityPlayer player, Entity victim, IItemWithAbility tool) {}
}),
};
Radiation(new IWeaponAbility() {
public static final IWeaponAbility RADIATION = new IWeaponAbility() {
@Override
public String getName() {
return "weapon.ability.radiation";
@ -73,9 +72,9 @@ public interface IWeaponAbility extends IBaseAbility {
if(victim instanceof EntityLivingBase)
ContaminationUtil.contaminate((EntityLivingBase)victim, HazardType.RADIATION, ContaminationType.CREATIVE, radAtLevel[level]);
}
}),
};
Vampire(new IWeaponAbility() {
public static final IWeaponAbility VAMPIRE = new IWeaponAbility() {
@Override
public String getName() {
return "weapon.ability.vampire";
@ -105,9 +104,9 @@ public interface IWeaponAbility extends IBaseAbility {
player.heal(amount);
}
}
}),
};
Stun(new IWeaponAbility() {
public static final IWeaponAbility STUN = new IWeaponAbility() {
@Override
public String getName() {
return "weapon.ability.stun";
@ -136,9 +135,9 @@ public interface IWeaponAbility extends IBaseAbility {
living.addPotionEffect(new PotionEffect(Potion.weakness.id, duration * 20, 4));
}
}
}),
};
Blend(new IWeaponAbility() {
public static final IWeaponAbility BLEND = new IWeaponAbility() {
@Override
public String getName() {
return "weapon.ability.blender";
@ -178,9 +177,9 @@ public interface IWeaponAbility extends IBaseAbility {
}
}
}
}),
};
Phosphorus(new IWeaponAbility() {
public static final IWeaponAbility PHOSPHORUS = new IWeaponAbility() {
@Override
public String getName() {
return "weapon.ability.phosphorus";
@ -208,9 +207,9 @@ public interface IWeaponAbility extends IBaseAbility {
living.addPotionEffect(new PotionEffect(HbmPotion.phosphorus.id, duration * 20, 4));
}
}
}),
};
Fire(new IWeaponAbility() {
public static final IWeaponAbility FIRE = new IWeaponAbility() {
@Override
public String getName() {
return "weapon.ability.fire";
@ -234,9 +233,9 @@ public interface IWeaponAbility extends IBaseAbility {
victim.setFire(durationAtLevel[level]);
}
}
}),
};
Chainsaw(new IWeaponAbility() {
public static final IWeaponAbility CHAINSAW = new IWeaponAbility() {
@Override
public String getName() {
return "weapon.ability.chainsaw";
@ -283,9 +282,9 @@ public interface IWeaponAbility extends IBaseAbility {
}
}
}
}),
};
Beheader(new IWeaponAbility() {
public static final IWeaponAbility BEHEADER = new IWeaponAbility() {
@Override
public String getName() {
return "weapon.ability.beheader";
@ -324,9 +323,9 @@ public interface IWeaponAbility extends IBaseAbility {
}
}
}
}),
};
Bobble(new IWeaponAbility() {
public static final IWeaponAbility BOBBLE = new IWeaponAbility() {
@Override
public String getName() {
return "weapon.ability.bobble";
@ -347,13 +346,6 @@ public interface IWeaponAbility extends IBaseAbility {
mob.entityDropItem(new ItemStack(ModBlocks.bobblehead, 1, world.rand.nextInt(BobbleType.values().length - 1) + 1), 0.0F);
}
}
});
};
// endregion handlers
public IWeaponAbility handler;
WeaponAbility(IWeaponAbility handler) {
this.handler = handler;
}
}
}

View File

@ -0,0 +1,38 @@
package com.hbm.handler.ability;
public class ToolPreset {
public IToolAreaAbility areaAbility = IToolAreaAbility.NONE;
public int areaAbilityLevel = 0;
public IToolHarvestAbility harvestAbility = IToolHarvestAbility.NONE;
public int harvestAbilityLevel = 0;
public ToolPreset() {}
public ToolPreset(IToolAreaAbility areaAbility, IToolHarvestAbility harvestAbility) {
this.areaAbility = areaAbility;
this.harvestAbility = harvestAbility;
}
public ToolPreset(IToolAreaAbility areaAbility, int areaAbilityLevel, IToolHarvestAbility harvestAbility, int harvestAbilityLevel) {
this.areaAbility = areaAbility;
this.areaAbilityLevel = areaAbilityLevel;
this.harvestAbility = harvestAbility;
this.harvestAbilityLevel = harvestAbilityLevel;
}
public String getMessage() {
String areaPart = areaAbility.getFullName(areaAbilityLevel);
String harvestPart = harvestAbility.getFullName(harvestAbilityLevel);
if (harvestPart.isEmpty() && areaPart.isEmpty())
return "[Tool ability deactivated]";
if (harvestPart.isEmpty())
return "[Enabled " + areaPart + "]";
if (areaPart.isEmpty())
return "[Enabled " + harvestPart + "]";
return "[Enabled " + areaPart + " + " + harvestPart + "]";
}
}