mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
Implement ability presets
This commit is contained in:
parent
853b6576ad
commit
e59f8b441d
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -29,9 +29,8 @@ public interface IToolAreaAbility extends IBaseAbility {
|
|||||||
// (neither for the original block nor for the extras)
|
// (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);
|
boolean onDig(int level, World world, int x, int y, int z, EntityPlayer player, IItemWithAbility tool);
|
||||||
|
|
||||||
public static enum AreaAbility {
|
|
||||||
// region handlers
|
// region handlers
|
||||||
None(new IToolAreaAbility() {
|
public static final IToolAreaAbility NONE = new IToolAreaAbility() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
// TODO: null? empty? otherwise i18n
|
// 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) {
|
public boolean onDig(int level, World world, int x, int y, int z, EntityPlayer player, IItemWithAbility tool) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}),
|
};
|
||||||
|
|
||||||
Recursion(new IToolAreaAbility() {
|
public static final IToolAreaAbility RECURSION = new IToolAreaAbility() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "tool.ability.recursion";
|
return "tool.ability.recursion";
|
||||||
@ -165,9 +164,9 @@ public interface IToolAreaAbility extends IBaseAbility {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}),
|
};
|
||||||
|
|
||||||
Hammer(new IToolAreaAbility() {
|
public static final IToolAreaAbility HAMMER = new IToolAreaAbility() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "tool.ability.hammer";
|
return "tool.ability.hammer";
|
||||||
@ -208,9 +207,9 @@ public interface IToolAreaAbility extends IBaseAbility {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}),
|
};
|
||||||
|
|
||||||
Explosion(new IToolAreaAbility() {
|
public static final IToolAreaAbility EXPLOSION = new IToolAreaAbility() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "tool.ability.explosion";
|
return "tool.ability.explosion";
|
||||||
@ -248,13 +247,6 @@ public interface IToolAreaAbility extends IBaseAbility {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
// endregion handlers
|
|
||||||
|
|
||||||
public IToolAreaAbility handler;
|
|
||||||
|
|
||||||
AreaAbility(IToolAreaAbility handler) {
|
|
||||||
this.handler = handler;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
// endregion handlers
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,9 +41,8 @@ public interface IToolHarvestAbility extends IBaseAbility {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static enum HarvestAbility {
|
|
||||||
// region handlers
|
// region handlers
|
||||||
None(new IToolHarvestAbility() {
|
public static final IToolHarvestAbility NONE = new IToolHarvestAbility() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
// TODO: null? empty? otherwise i18n
|
// TODO: null? empty? otherwise i18n
|
||||||
@ -54,9 +53,9 @@ public interface IToolHarvestAbility extends IBaseAbility {
|
|||||||
public boolean skipDefaultDrops(int level) {
|
public boolean skipDefaultDrops(int level) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}),
|
};
|
||||||
|
|
||||||
Silk(new IToolHarvestAbility() {
|
public static final IToolHarvestAbility SILK = new IToolHarvestAbility() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "tool.ability.silktouch";
|
return "tool.ability.silktouch";
|
||||||
@ -86,9 +85,9 @@ public interface IToolHarvestAbility extends IBaseAbility {
|
|||||||
ItemStack stack = player.getHeldItem();
|
ItemStack stack = player.getHeldItem();
|
||||||
EnchantmentUtil.removeEnchantment(stack, Enchantment.silkTouch);
|
EnchantmentUtil.removeEnchantment(stack, Enchantment.silkTouch);
|
||||||
}
|
}
|
||||||
}),
|
};
|
||||||
|
|
||||||
Luck(new IToolHarvestAbility() {
|
public static final IToolHarvestAbility LUCK = new IToolHarvestAbility() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "tool.ability.luck";
|
return "tool.ability.luck";
|
||||||
@ -130,9 +129,9 @@ public interface IToolHarvestAbility extends IBaseAbility {
|
|||||||
ItemStack stack = player.getHeldItem();
|
ItemStack stack = player.getHeldItem();
|
||||||
EnchantmentUtil.removeEnchantment(stack, Enchantment.fortune);
|
EnchantmentUtil.removeEnchantment(stack, Enchantment.fortune);
|
||||||
}
|
}
|
||||||
}),
|
};
|
||||||
|
|
||||||
Smelter(new IToolHarvestAbility() {
|
public static final IToolHarvestAbility SMELTER = new IToolHarvestAbility() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "tool.ability.smelter";
|
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()));
|
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
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "tool.ability.shredder";
|
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()));
|
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
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "tool.ability.centrifuge";
|
return "tool.ability.centrifuge";
|
||||||
@ -241,9 +240,9 @@ public interface IToolHarvestAbility extends IBaseAbility {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
};
|
||||||
|
|
||||||
Crystallizer(new IToolHarvestAbility() {
|
public static final IToolHarvestAbility CRYSTALLIZER = new IToolHarvestAbility() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "tool.ability.crystallizer";
|
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()));
|
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
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "tool.ability.mercury";
|
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)));
|
world.spawnEntityInWorld(new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, new ItemStack(ModItems.ingot_mercury, mercury)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
// endregion handlers
|
// endregion handlers
|
||||||
|
|
||||||
public IToolHarvestAbility handler;
|
|
||||||
|
|
||||||
HarvestAbility(IToolHarvestAbility handler) {
|
|
||||||
this.handler = handler;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,9 +37,8 @@ import net.minecraft.world.World;
|
|||||||
public interface IWeaponAbility extends IBaseAbility {
|
public interface IWeaponAbility extends IBaseAbility {
|
||||||
void onHit(int level, World world, EntityPlayer player, Entity victim, IItemWithAbility tool);
|
void onHit(int level, World world, EntityPlayer player, Entity victim, IItemWithAbility tool);
|
||||||
|
|
||||||
public static enum WeaponAbility {
|
|
||||||
// region handlers
|
// region handlers
|
||||||
None(new IWeaponAbility() {
|
public static final IWeaponAbility NONE = new IWeaponAbility() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
// TODO: null? empty? otherwise i18n
|
// TODO: null? empty? otherwise i18n
|
||||||
@ -48,9 +47,9 @@ public interface IWeaponAbility extends IBaseAbility {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, IItemWithAbility tool) {}
|
public void onHit(int level, World world, EntityPlayer player, Entity victim, IItemWithAbility tool) {}
|
||||||
}),
|
};
|
||||||
|
|
||||||
Radiation(new IWeaponAbility() {
|
public static final IWeaponAbility RADIATION = new IWeaponAbility() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "weapon.ability.radiation";
|
return "weapon.ability.radiation";
|
||||||
@ -73,9 +72,9 @@ public interface IWeaponAbility extends IBaseAbility {
|
|||||||
if(victim instanceof EntityLivingBase)
|
if(victim instanceof EntityLivingBase)
|
||||||
ContaminationUtil.contaminate((EntityLivingBase)victim, HazardType.RADIATION, ContaminationType.CREATIVE, radAtLevel[level]);
|
ContaminationUtil.contaminate((EntityLivingBase)victim, HazardType.RADIATION, ContaminationType.CREATIVE, radAtLevel[level]);
|
||||||
}
|
}
|
||||||
}),
|
};
|
||||||
|
|
||||||
Vampire(new IWeaponAbility() {
|
public static final IWeaponAbility VAMPIRE = new IWeaponAbility() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "weapon.ability.vampire";
|
return "weapon.ability.vampire";
|
||||||
@ -105,9 +104,9 @@ public interface IWeaponAbility extends IBaseAbility {
|
|||||||
player.heal(amount);
|
player.heal(amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
};
|
||||||
|
|
||||||
Stun(new IWeaponAbility() {
|
public static final IWeaponAbility STUN = new IWeaponAbility() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "weapon.ability.stun";
|
return "weapon.ability.stun";
|
||||||
@ -136,9 +135,9 @@ public interface IWeaponAbility extends IBaseAbility {
|
|||||||
living.addPotionEffect(new PotionEffect(Potion.weakness.id, duration * 20, 4));
|
living.addPotionEffect(new PotionEffect(Potion.weakness.id, duration * 20, 4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
};
|
||||||
|
|
||||||
Blend(new IWeaponAbility() {
|
public static final IWeaponAbility BLEND = new IWeaponAbility() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "weapon.ability.blender";
|
return "weapon.ability.blender";
|
||||||
@ -178,9 +177,9 @@ public interface IWeaponAbility extends IBaseAbility {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
};
|
||||||
|
|
||||||
Phosphorus(new IWeaponAbility() {
|
public static final IWeaponAbility PHOSPHORUS = new IWeaponAbility() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "weapon.ability.phosphorus";
|
return "weapon.ability.phosphorus";
|
||||||
@ -208,9 +207,9 @@ public interface IWeaponAbility extends IBaseAbility {
|
|||||||
living.addPotionEffect(new PotionEffect(HbmPotion.phosphorus.id, duration * 20, 4));
|
living.addPotionEffect(new PotionEffect(HbmPotion.phosphorus.id, duration * 20, 4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
};
|
||||||
|
|
||||||
Fire(new IWeaponAbility() {
|
public static final IWeaponAbility FIRE = new IWeaponAbility() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "weapon.ability.fire";
|
return "weapon.ability.fire";
|
||||||
@ -234,9 +233,9 @@ public interface IWeaponAbility extends IBaseAbility {
|
|||||||
victim.setFire(durationAtLevel[level]);
|
victim.setFire(durationAtLevel[level]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
};
|
||||||
|
|
||||||
Chainsaw(new IWeaponAbility() {
|
public static final IWeaponAbility CHAINSAW = new IWeaponAbility() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "weapon.ability.chainsaw";
|
return "weapon.ability.chainsaw";
|
||||||
@ -283,9 +282,9 @@ public interface IWeaponAbility extends IBaseAbility {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
};
|
||||||
|
|
||||||
Beheader(new IWeaponAbility() {
|
public static final IWeaponAbility BEHEADER = new IWeaponAbility() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "weapon.ability.beheader";
|
return "weapon.ability.beheader";
|
||||||
@ -324,9 +323,9 @@ public interface IWeaponAbility extends IBaseAbility {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
};
|
||||||
|
|
||||||
Bobble(new IWeaponAbility() {
|
public static final IWeaponAbility BOBBLE = new IWeaponAbility() {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "weapon.ability.bobble";
|
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);
|
mob.entityDropItem(new ItemStack(ModBlocks.bobblehead, 1, world.rand.nextInt(BobbleType.values().length - 1) + 1), 0.0F);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
// endregion handlers
|
// endregion handlers
|
||||||
|
|
||||||
public IWeaponAbility handler;
|
|
||||||
|
|
||||||
WeaponAbility(IWeaponAbility handler) {
|
|
||||||
this.handler = handler;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
38
src/main/java/com/hbm/handler/ability/ToolPreset.java
Normal file
38
src/main/java/com/hbm/handler/ability/ToolPreset.java
Normal 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 + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user