diff --git a/src/main/java/gregtech/GregTechMod.java b/src/main/java/gregtech/GregTechMod.java index c5663818a..d16e55421 100644 --- a/src/main/java/gregtech/GregTechMod.java +++ b/src/main/java/gregtech/GregTechMod.java @@ -20,7 +20,8 @@ + "required-after:codechickenlib@[3.2.3,);" + "after:forestry;" + "after:jei@[4.15.0,);" - + "after:crafttweaker@[4.1.20,);") + + "after:crafttweaker@[4.1.20,);" + + "after:groovyscript@[0.1.0,);") public class GregTechMod { // Hold this so that we can reference non-interface methods without diff --git a/src/main/java/gregtech/common/items/ToolItems.java b/src/main/java/gregtech/common/items/ToolItems.java index 50177c4f4..9ad6c1db3 100644 --- a/src/main/java/gregtech/common/items/ToolItems.java +++ b/src/main/java/gregtech/common/items/ToolItems.java @@ -8,6 +8,8 @@ import gregtech.core.sound.GTSoundEvents; import net.minecraft.client.Minecraft; import net.minecraft.enchantment.EnumEnchantmentType; +import net.minecraft.entity.monster.EntityGolem; +import net.minecraft.entity.monster.EntitySpider; import net.minecraft.init.SoundEvents; import net.minecraft.item.ItemStack; import net.minecraftforge.client.model.ModelLoader; @@ -86,7 +88,8 @@ public static void init() { .toolClasses(ToolClasses.SAW)); HARD_HAMMER = register(ItemGTTool.Builder.of(GTValues.MODID, "hammer") .toolStats(b -> b.blockBreaking().crafting().damagePerCraftingAction(2) - .attackDamage(1.0F).attackSpeed(-2.8F)) + .attackDamage(1.0F).attackSpeed(-2.8F) + .behaviors(new EntityDamageBehavior(2.0F, EntityGolem.class))) .oreDict(ToolOreDicts.craftingToolHammer) .sound(SoundEvents.BLOCK_ANVIL_LAND) .symbol('h') @@ -111,7 +114,7 @@ public static void init() { WRENCH = register(ItemGTTool.Builder.of(GTValues.MODID, "wrench") .toolStats(b -> b.blockBreaking().crafting().sneakBypassUse() .attackDamage(1.0F).attackSpeed(-2.8F) - .behaviors(new BlockRotatingBehavior())) + .behaviors(new BlockRotatingBehavior(), new EntityDamageBehavior(3.0F, EntityGolem.class))) .sound(GTSoundEvents.WRENCH_TOOL, true) .oreDict(ToolOreDicts.craftingToolWrench) .symbol('w') @@ -133,7 +136,8 @@ public static void init() { .toolClasses(ToolClasses.CROWBAR)); SCREWDRIVER = register(ItemGTTool.Builder.of(GTValues.MODID, "screwdriver") .toolStats(b -> b.crafting().damagePerCraftingAction(4).sneakBypassUse() - .attackDamage(-1.0F).attackSpeed(3.0F)) + .attackDamage(-1.0F).attackSpeed(3.0F) + .behaviors(new EntityDamageBehavior(3.0F, EntitySpider.class))) .sound(GTSoundEvents.SCREWDRIVER_TOOL) .oreDict(ToolOreDicts.craftingToolScrewdriver) .symbol('d') @@ -227,6 +231,7 @@ public static void init() { .toolStats(b -> b.blockBreaking().crafting().sneakBypassUse() .efficiencyMultiplier(2.0F) .attackDamage(1.0F).attackSpeed(-2.8F) + .behaviors(new BlockRotatingBehavior(), new EntityDamageBehavior(3.0F, EntityGolem.class)) .brokenStack(ToolHelper.SUPPLY_POWER_UNIT_LV)) .sound(GTSoundEvents.WRENCH_TOOL, true) .oreDict(ToolOreDicts.craftingToolWrench) @@ -236,6 +241,7 @@ public static void init() { .toolStats(b -> b.blockBreaking().crafting().sneakBypassUse() .efficiencyMultiplier(3.0F) .attackDamage(1.0F).attackSpeed(-2.8F) + .behaviors(new BlockRotatingBehavior(), new EntityDamageBehavior(3.0F, EntityGolem.class)) .brokenStack(ToolHelper.SUPPLY_POWER_UNIT_HV)) .sound(GTSoundEvents.WRENCH_TOOL, true) .oreDict(ToolOreDicts.craftingToolWrench) @@ -245,6 +251,7 @@ public static void init() { .toolStats(b -> b.blockBreaking().crafting().sneakBypassUse() .efficiencyMultiplier(4.0F) .attackDamage(1.0F).attackSpeed(-2.8F) + .behaviors(new BlockRotatingBehavior(), new EntityDamageBehavior(3.0F, EntityGolem.class)) .brokenStack(ToolHelper.SUPPLY_POWER_UNIT_IV)) .sound(GTSoundEvents.WRENCH_TOOL, true) .oreDict(ToolOreDicts.craftingToolWrench) @@ -260,6 +267,7 @@ public static void init() { SCREWDRIVER_LV = register(ItemGTTool.Builder.of(GTValues.MODID, "screwdriver_lv") .toolStats(b -> b.crafting().sneakBypassUse() .attackDamage(-1.0F).attackSpeed(3.0F) + .behaviors(new EntityDamageBehavior(3.0F, EntitySpider.class)) .brokenStack(ToolHelper.SUPPLY_POWER_UNIT_LV)) .sound(GTSoundEvents.SCREWDRIVER_TOOL) .oreDict(ToolOreDicts.craftingToolScrewdriver) diff --git a/src/main/java/gregtech/common/items/tool/EntityDamageBehavior.java b/src/main/java/gregtech/common/items/tool/EntityDamageBehavior.java new file mode 100644 index 000000000..7d07dc16b --- /dev/null +++ b/src/main/java/gregtech/common/items/tool/EntityDamageBehavior.java @@ -0,0 +1,70 @@ +package gregtech.common.items.tool; + +import gregtech.api.damagesources.DamageSources; +import gregtech.api.items.toolitem.behavior.IToolBehavior; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; +import net.minecraft.world.World; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.function.Function; + +/** + * Add to tools to have them deal bonus damage to specific mobs. + * Pass null for the mobType parameter to ignore the tooltip. + */ +public class EntityDamageBehavior implements IToolBehavior { + + private final List> shouldDoBonusList = new ArrayList<>(); + private final String mobType; + + public EntityDamageBehavior(float bonus, Class... entities) { + this(null, bonus, entities); + } + + public EntityDamageBehavior(Map, Float> entities) { + this(null, entities); + } + + public EntityDamageBehavior(String mobType, float bonus, Class... entities) { + this.mobType = mobType; + for (Class entity : entities) { + shouldDoBonusList.add(e -> entity.isAssignableFrom(e.getClass()) ? bonus : 0); + } + } + + public EntityDamageBehavior(String mobType, Map, Float> entities) { + this.mobType = mobType; + for (Map.Entry, Float> entry : entities.entrySet()) { + Class entity = entry.getKey(); + float bonus = entry.getValue(); + shouldDoBonusList.add(e -> entity.isAssignableFrom(e.getClass()) ? bonus : 0); + } + } + + @Override + public void hitEntity(@Nonnull ItemStack stack, @Nonnull EntityLivingBase target, @Nonnull EntityLivingBase attacker) { + float damageBonus = shouldDoBonusList.stream().map(func -> func.apply(target)).filter(f -> f > 0).findFirst().orElse(0f); + if (damageBonus != 0f) { + DamageSource source = attacker instanceof EntityPlayer + ? DamageSources.getPlayerDamage((EntityPlayer) attacker) + : DamageSources.getMobDamage(attacker); + target.attackEntityFrom(source, damageBonus); + } + } + + @Override + public void addInformation(@Nonnull ItemStack stack, @Nullable World world, @Nonnull List tooltip, @Nonnull ITooltipFlag flag) { + if (mobType != null && !mobType.isEmpty()) { + tooltip.add(I18n.format("item.gt.tool.behavior.damage_boost", I18n.format("item.gt.tool.behavior.damage_boost_" + mobType))); + } + } +} diff --git a/src/main/resources/assets/gregtech/lang/en_us.lang b/src/main/resources/assets/gregtech/lang/en_us.lang index 9f5ebad43..03a5a345a 100644 --- a/src/main/resources/assets/gregtech/lang/en_us.lang +++ b/src/main/resources/assets/gregtech/lang/en_us.lang @@ -903,6 +903,7 @@ item.gt.tool.behavior.rail_rotation=§eRailroad Engineer: §fRotates Rails item.gt.tool.behavior.crop_harvesting=§aHarvester: §fHarvests Crops item.gt.tool.behavior.plunger=§9Plumber: §fDrains Fluids item.gt.tool.behavior.block_rotation=§2Mechanic: §fRotates Blocks +item.gt.tool.behavior.damage_boost=§4Damage Boost: §fExtra damage against %s item.gt.tool.sword.name=%s Sword item.gt.tool.pickaxe.name=%s Pickaxe