From 305ecbe6c89761084333389b2c57247eb3ecc32e Mon Sep 17 00:00:00 2001 From: Jakub <53441451+kuba6000@users.noreply.github.com> Date: Tue, 27 Aug 2024 09:54:53 +0200 Subject: [PATCH] Add KingSlime NEI drops as IMobInforProvider (-0.8s from first pack load) (#122) * Add KingSlime drops provider (-0.8s) * Fix * Update dependencies.gradle * Update dependencies.gradle * update --------- Co-authored-by: Martin Robertz --- .gitignore | 1 + dependencies.gradle | 5 +- settings.gradle | 2 +- .../tconstruct/armor/TinkerArmorEvents.java | 45 +++++- .../tconstruct/tools/TinkerToolEvents.java | 153 +++++++++++++++++- .../tconstruct/world/TinkerWorldEvents.java | 37 ++++- .../world/entity/KingBlueSlime.java | 52 +++++- .../tconstruct/world/entity/MetalSlime.java | 1 + .../tconstruct/world/entity/SlimeBase.java | 21 ++- .../resources/assets/tinker/lang/en_US.lang | 5 + 10 files changed, 310 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 40fb5e4a..e4380dee 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ whitelist.json *.iws src/main/resources/mixins.*.json *.bat +layout.json diff --git a/dependencies.gradle b/dependencies.gradle index a9df64e5..5d39a72d 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,10 +1,10 @@ // Add your dependencies here dependencies { - compileOnlyApi('com.github.GTNewHorizons:Angelica:1.0.0-beta2:api') + compileOnlyApi('com.github.GTNewHorizons:Angelica:1.0.0-beta4:api') api("com.github.GTNewHorizons:Mantle:0.4.1:dev") api("com.github.GTNewHorizons:ForgeMultipart:1.5.0:dev") - implementation("com.github.GTNewHorizons:NotEnoughItems:2.6.19-GTNH:dev") + implementation("com.github.GTNewHorizons:NotEnoughItems:2.6.26-GTNH:dev") compileOnlyApi("curse.maven:cofh-core-69162:2388751") compileOnly("com.github.GTNewHorizons:inventory-tweaks:1.6.2:api") compileOnly("com.github.GTNewHorizons:waila:1.8.1:api") @@ -15,4 +15,5 @@ dependencies { compileOnly("curse.maven:dynamic-sword-skills-226360:2495462") compileOnly("curse.maven:notenoughkeys-224614:2276280") compileOnly("thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev") + compileOnly("com.github.GTNewHorizons:Mobs-Info:0.4.2-GTNH:dev") } diff --git a/settings.gradle b/settings.gradle index 54797868..242692e5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,7 +17,7 @@ pluginManagement { } plugins { - id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.25' + id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.26' } diff --git a/src/main/java/tconstruct/armor/TinkerArmorEvents.java b/src/main/java/tconstruct/armor/TinkerArmorEvents.java index 3b93a7c1..ba5bf958 100644 --- a/src/main/java/tconstruct/armor/TinkerArmorEvents.java +++ b/src/main/java/tconstruct/armor/TinkerArmorEvents.java @@ -1,7 +1,10 @@ package tconstruct.armor; +import java.util.ArrayList; import java.util.Locale; +import javax.annotation.Nonnull; + import net.minecraft.entity.boss.EntityDragon; import net.minecraft.entity.boss.IBossDisplayData; import net.minecraft.entity.item.EntityItem; @@ -16,6 +19,11 @@ import net.minecraftforge.event.entity.living.LivingDropsEvent; import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent; import net.minecraftforge.event.entity.living.LivingFallEvent; +import com.kuba6000.mobsinfo.api.IMobExtraInfoProvider; +import com.kuba6000.mobsinfo.api.MobDrop; +import com.kuba6000.mobsinfo.api.MobRecipe; + +import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import tconstruct.TConstruct; import tconstruct.armor.items.TravelWings; @@ -24,10 +32,12 @@ import tconstruct.library.modifier.IModifyable; import tconstruct.util.config.PHConstruct; import tconstruct.util.network.ArmourGuiSyncPacket; -public class TinkerArmorEvents { +@Optional.Interface(iface = "com.kuba6000.mobsinfo.api.IMobExtraInfoProvider", modid = "mobsinfo") +public class TinkerArmorEvents implements IMobExtraInfoProvider { @SubscribeEvent public void onLivingDrop(LivingDropsEvent event) { + // ANY CHANGE MADE IN HERE MUST ALSO BE MADE IN provideDropsInformation! if (event.entityLiving == null) return; if (!event.entityLiving.worldObj.getGameRules().getGameRuleBooleanValue("doMobLoot")) return; @@ -65,6 +75,39 @@ public class TinkerArmorEvents { } } + @Optional.Method(modid = "mobsinfo") + @Override + public void provideExtraDropsInformation(@Nonnull String entityString, @Nonnull ArrayList drops, + @Nonnull MobRecipe recipe) { + if (recipe.entity instanceof IMob) { + MobDrop drop = new MobDrop( + new ItemStack(TinkerArmor.heartCanister, 1, 1), + MobDrop.DropType.Normal, + 50, + null, + null, + false, + false); + drops.add(drop); + } + + if (recipe.entity instanceof IBossDisplayData) { + String entityName = recipe.entity.getClass().getSimpleName().toLowerCase(); + for (String name : PHConstruct.heartDropBlacklist) + if (name.toLowerCase(Locale.US).equals(entityName)) return; + + MobDrop drop = new MobDrop( + new ItemStack(TinkerArmor.heartCanister, recipe.entity instanceof EntityDragon ? 5 : 1, 3), + MobDrop.DropType.Normal, + 10000, + null, + null, + false, + false); + drops.add(drop); + } + } + /* Abilities */ @SubscribeEvent public void armorMineSpeed(net.minecraftforge.event.entity.player.PlayerEvent.BreakSpeed event) { diff --git a/src/main/java/tconstruct/tools/TinkerToolEvents.java b/src/main/java/tconstruct/tools/TinkerToolEvents.java index bb74fce2..d4777601 100644 --- a/src/main/java/tconstruct/tools/TinkerToolEvents.java +++ b/src/main/java/tconstruct/tools/TinkerToolEvents.java @@ -1,8 +1,13 @@ package tconstruct.tools; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import javax.annotation.Nonnull; + import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.monster.EntityCreeper; import net.minecraft.entity.monster.EntitySkeleton; @@ -14,17 +19,27 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.DamageSource; +import net.minecraft.util.StatCollector; import net.minecraft.util.Vec3; import net.minecraft.world.EnumDifficulty; +import net.minecraft.world.World; import net.minecraftforge.event.entity.living.LivingAttackEvent; import net.minecraftforge.event.entity.living.LivingDropsEvent; import net.minecraftforge.event.entity.player.PlayerDropsEvent; import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary.OreRegisterEvent; +import com.kuba6000.mobsinfo.api.IChanceModifier; +import com.kuba6000.mobsinfo.api.IMobExtraInfoProvider; +import com.kuba6000.mobsinfo.api.MobDrop; +import com.kuba6000.mobsinfo.api.MobRecipe; +import com.kuba6000.mobsinfo.loader.extras.Translations; + +import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.eventhandler.Event.Result; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.PlayerEvent.ItemCraftedEvent; +import io.netty.buffer.ByteBuf; import tconstruct.TConstruct; import tconstruct.armor.player.TPlayerStats; import tconstruct.library.TConstructRegistry; @@ -41,7 +56,8 @@ import tconstruct.util.ItemHelper; import tconstruct.util.config.PHConstruct; import tconstruct.util.network.MovementUpdatePacket; -public class TinkerToolEvents { +@Optional.Interface(iface = "com.kuba6000.mobsinfo.api.IMobExtraInfoProvider", modid = "mobsinfo") +public class TinkerToolEvents implements IMobExtraInfoProvider { @SubscribeEvent public void onCrafting(ItemCraftedEvent event) { @@ -280,6 +296,7 @@ public class TinkerToolEvents { @SubscribeEvent public void onLivingDrop(LivingDropsEvent event) { + // ANY CHANGE MADE IN HERE MUST ALSO BE MADE IN provideDropsInformation! if (event.entityLiving == null) return; if (event.recentlyHit) { @@ -371,6 +388,140 @@ public class TinkerToolEvents { } } + @Optional.Method(modid = "mobsinfo") + @Override + public void provideExtraDropsInformation(@Nonnull String entityString, @Nonnull ArrayList drops, + @Nonnull MobRecipe recipe) { + if (recipe.entity instanceof EntitySkeleton) { + + MobDrop drop = new MobDrop( + new ItemStack(Items.skull, 1, ((EntitySkeleton) recipe.entity).getSkeletonType()), + MobDrop.DropType.Normal, + 0, + null, + null, + false, + false); + drop.variableChance = true; + drop.chanceModifiers.add(new BeheadingModifier(10d, 20d)); + drops.add(drop); + + if (((EntitySkeleton) recipe.entity).getSkeletonType() == 1) { + MobDrop drop2 = new MobDrop( + new ItemStack(TinkerTools.materials, 1, 8), + MobDrop.DropType.Normal, + 2000, + null, + null, + true, + false); + drops.add(drop2); + } + + } + + if (recipe.entity.getClass() == EntityZombie.class) { + MobDrop drop = new MobDrop( + new ItemStack(Items.skull, 1, 2), + MobDrop.DropType.Normal, + 0, + null, + null, + false, + false); + drop.variableChance = true; + drop.chanceModifiers.add(new BeheadingModifier(10d, 20d)); + drops.add(drop); + + MobDrop drop2 = new MobDrop( + new ItemStack(TinkerTools.materials, 1, 2), + MobDrop.DropType.Normal, + 0, + null, + null, + true, + false); + drop2.variableChance = true; + drop2.chanceModifiers.addAll( + Arrays.asList( + new IChanceModifier.NormalChance(10d), + new IChanceModifier.DropsOnlyUsing(TinkerTools.cleaver))); + drops.add(drop2); + } + + if (recipe.entity.getClass() == EntityCreeper.class) { + MobDrop drop = new MobDrop( + new ItemStack(Items.skull, 1, 4), + MobDrop.DropType.Normal, + 0, + null, + null, + false, + false); + drop.variableChance = true; + drop.chanceModifiers.add(new BeheadingModifier(5d, 10d)); + drops.add(drop); + } + } + + private static class BeheadingModifier implements IChanceModifier { + + double m1, m2; + + @SuppressWarnings("unused") + BeheadingModifier() { + // Constructor is called via reflection in IChanceModifier.loadFromByteBuf() + } + + BeheadingModifier(double m1, double m2) { + this.m1 = m1; + this.m2 = m2; + } + + @Override + public String getDescription() { + throw new UnsupportedOperationException(); + } + + @Override + public void applyTooltip(List currentTooltip) { + currentTooltip.addAll( + Arrays.asList( + Translations.BASE_CHANCE.get(0d), + StatCollector.translateToLocalFormatted( + "tconstruct.mobsinfocompat.tinkers_construct_beheading", + m1), + StatCollector.translateToLocalFormatted( + "tconstruct.mobsinfocompat.tinkers_construct_beheading_1", + m2))); + } + + @Override + public double apply(double chance, @Nonnull World world, @Nonnull List drops, Entity attacker, + EntityLiving victim) { + if (!(attacker instanceof EntityPlayer)) return 0d; + ItemStack stack = ((EntityPlayer) attacker).getCurrentEquippedItem(); + if (stack != null && stack.hasTagCompound() && stack.getItem() instanceof ToolCore) { + int beheading = stack.getTagCompound().getCompoundTag("InfiTool").getInteger("Beheading"); + if (stack.getItem() == TinkerTools.cleaver) beheading += 2; + return m1 * beheading; + } + return 0d; + } + + @Override + public void writeToByteBuf(ByteBuf byteBuf) { + byteBuf.writeDouble(m1); + byteBuf.writeDouble(m2); + } + + @Override + public void readFromByteBuf(ByteBuf byteBuf) { + m1 = byteBuf.readDouble(); + m2 = byteBuf.readDouble(); + } + } + @SubscribeEvent public void registerOre(OreRegisterEvent evt) { diff --git a/src/main/java/tconstruct/world/TinkerWorldEvents.java b/src/main/java/tconstruct/world/TinkerWorldEvents.java index dc1c9b25..dbe7964d 100644 --- a/src/main/java/tconstruct/world/TinkerWorldEvents.java +++ b/src/main/java/tconstruct/world/TinkerWorldEvents.java @@ -1,5 +1,9 @@ package tconstruct.world; +import java.util.ArrayList; + +import javax.annotation.Nonnull; + import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; @@ -20,6 +24,12 @@ import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.living.LivingSpawnEvent; import net.minecraftforge.event.entity.player.BonemealEvent; +import com.kuba6000.mobsinfo.api.ConstructableItemStack; +import com.kuba6000.mobsinfo.api.IMobExtraInfoProvider; +import com.kuba6000.mobsinfo.api.MobDrop; +import com.kuba6000.mobsinfo.api.MobRecipe; + +import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.eventhandler.Event; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import tconstruct.TConstruct; @@ -27,7 +37,8 @@ import tconstruct.tools.TinkerTools; import tconstruct.util.ItemHelper; import tconstruct.util.config.PHConstruct; -public class TinkerWorldEvents { +@Optional.Interface(iface = "com.kuba6000.mobsinfo.api.IMobExtraInfoProvider", modid = "mobsinfo") +public class TinkerWorldEvents implements IMobExtraInfoProvider { @SubscribeEvent public void onLivingSpawn(LivingSpawnEvent.SpecialSpawn event) { @@ -102,6 +113,7 @@ public class TinkerWorldEvents { @SubscribeEvent public void onLivingDrop(LivingDropsEvent event) { + // ANY CHANGE MADE IN HERE MUST ALSO BE MADE IN provideExtraDropsInformation! if (event.entityLiving == null) return; if (event.entityLiving.getClass() == EntityGhast.class) { @@ -116,4 +128,27 @@ public class TinkerWorldEvents { } } } + + @Optional.Method(modid = "mobsinfo") + @Override + public void provideExtraDropsInformation(@Nonnull String entityString, @Nonnull ArrayList drops, + @Nonnull MobRecipe recipe) { + if (recipe.entity.getClass() == EntityGhast.class) { + if (PHConstruct.uhcGhastDrops) { + for (MobDrop drop : drops) { + if (drop.stack.getItem() == Items.ghast_tear) { + drop.stack = new ItemStack(Items.gold_ingot); + drop.reconstructableStack = new ConstructableItemStack(drop.stack); + } + } + } else { + for (MobDrop drop : drops) { + if (drop.stack.getItem() == Items.ghast_tear) { + drop.chance += 10000; + drop.clampChance(); + } + } + } + } + } } diff --git a/src/main/java/tconstruct/world/entity/KingBlueSlime.java b/src/main/java/tconstruct/world/entity/KingBlueSlime.java index ef489687..b8cb56f2 100644 --- a/src/main/java/tconstruct/world/entity/KingBlueSlime.java +++ b/src/main/java/tconstruct/world/entity/KingBlueSlime.java @@ -1,11 +1,18 @@ package tconstruct.world.entity; +import java.util.ArrayList; + +import javax.annotation.Nonnull; + import net.minecraft.entity.boss.IBossDisplayData; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.StatCollector; import net.minecraft.world.World; +import com.kuba6000.mobsinfo.api.MobDrop; + +import cpw.mods.fml.common.Optional; import tconstruct.armor.TinkerArmor; import tconstruct.library.TConstructRegistry; import tconstruct.library.crafting.ToolBuilder; @@ -78,6 +85,7 @@ public class KingBlueSlime extends SlimeBase implements IBossDisplayData { @Override protected void dropFewItems(boolean par1, int par2) { + // ANY CHANGE MADE IN HERE MUST ALSO BE MADE IN provideDropsInformation! super.dropFewItems(par1, par2); ToolCore tool = getValidTool(); @@ -111,11 +119,45 @@ public class KingBlueSlime extends SlimeBase implements IBossDisplayData { } } + @Optional.Method(modid = "mobsinfo") + @Override + public void provideDropsInformation(@Nonnull ArrayList drops) { + super.provideDropsInformation(drops); + double chance = 1d / TConstructRegistry.tools.size(); + int validtools = 0; + for (ToolCore tool : TConstructRegistry.tools) { + final ItemStack headStack = new ItemStack(tool.getHeadItem(), 1, 17); + final ItemStack handleStack = new ItemStack(tool.getHandleItem(), 1, 17); + final ItemStack accessoryStack = tool.getAccessoryItem() != null + ? new ItemStack(tool.getAccessoryItem(), 1, 17) + : null; + final ItemStack extraStack = tool.getExtraItem() != null ? new ItemStack(tool.getExtraItem(), 1, 17) : null; + + String loc = "tool." + tool.getToolName().toLowerCase() + ".kingslime"; // special localization the same way + // as + // materials + String name; + if (StatCollector.canTranslate(loc)) name = StatCollector.translateToLocal(loc); + else name = StatCollector.translateToLocal("tool.kingslimeprefix") + " " + tool.getLocalizedToolName(); + + ItemStack toolStack = ToolBuilder.instance + .buildTool(headStack, handleStack, accessoryStack, extraStack, name); + + if (toolStack != null) { + NBTTagCompound tags = toolStack.getTagCompound().getCompoundTag("InfiTool"); + tags.setInteger("Attack", 5 + tool.getDamageVsEntity(null)); + tags.setInteger("TotalDurability", 2500); + tags.setInteger("BaseDurability", 2500); + tags.setInteger("MiningSpeed", 1400); + validtools++; + drops.add(MobDrop.create(toolStack).withChance(chance)); + } + } + drops.add( + MobDrop.create(new ItemStack(TinkerArmor.heartCanister, 1, 1)).withChance((chance / 5d) * validtools)); + } + ToolCore getValidTool() { - ToolCore tool = TConstructRegistry.tools.get(rand.nextInt(TConstructRegistry.tools.size())); - /* - * if (tool.getExtraItem() != null) tool = getValidTool(); - */ - return tool; + return TConstructRegistry.tools.get(rand.nextInt(TConstructRegistry.tools.size())); } } diff --git a/src/main/java/tconstruct/world/entity/MetalSlime.java b/src/main/java/tconstruct/world/entity/MetalSlime.java index c5b1f5fb..70ea5958 100644 --- a/src/main/java/tconstruct/world/entity/MetalSlime.java +++ b/src/main/java/tconstruct/world/entity/MetalSlime.java @@ -4,6 +4,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.DamageSource; import net.minecraft.world.World; +// unused? public class MetalSlime extends BlueSlime { public MetalSlime(World world) { diff --git a/src/main/java/tconstruct/world/entity/SlimeBase.java b/src/main/java/tconstruct/world/entity/SlimeBase.java index cc2aff60..26e5e40f 100644 --- a/src/main/java/tconstruct/world/entity/SlimeBase.java +++ b/src/main/java/tconstruct/world/entity/SlimeBase.java @@ -1,5 +1,9 @@ package tconstruct.world.entity; +import java.util.ArrayList; + +import javax.annotation.Nonnull; + import net.minecraft.entity.EntityLiving; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.boss.IBossDisplayData; @@ -16,9 +20,14 @@ import net.minecraft.world.EnumSkyBlock; import net.minecraft.world.World; import net.minecraftforge.common.ForgeHooks; +import com.kuba6000.mobsinfo.api.IMobInfoProvider; +import com.kuba6000.mobsinfo.api.MobDrop; + +import cpw.mods.fml.common.Optional; import tconstruct.world.TinkerWorld; -public abstract class SlimeBase extends EntityLiving implements IMob { +@Optional.Interface(iface = "com.kuba6000.mobsinfo.api.IMobInfoProvider", modid = "mobsinfo") +public abstract class SlimeBase extends EntityLiving implements IMob, IMobInfoProvider { public float sizeOffset; public float sizeFactor; @@ -280,6 +289,7 @@ public abstract class SlimeBase extends EntityLiving implements IMob { // Drops items depending on slime size @Override protected void dropFewItems(boolean par1, int par2) { + // ANY CHANGE MADE IN HERE MUST ALSO BE MADE IN provideDropsInformation! int size = this.getSlimeSize(); Item j = this.getDropItem(); @@ -296,6 +306,15 @@ public abstract class SlimeBase extends EntityLiving implements IMob { } } + @Optional.Method(modid = "mobsinfo") + @Override + public void provideDropsInformation(@Nonnull ArrayList drops) { + Item j = this.getDropItem(); + if (j != null) { + drops.add(MobDrop.create(j).withChance(MobDrop.getChanceBasedOnFromTo(0, 9) * 0.5d).withLooting()); + } + } + @Override protected void fall(float distance) { // we call the event for proper behaviour with other stuff diff --git a/src/main/resources/assets/tinker/lang/en_US.lang b/src/main/resources/assets/tinker/lang/en_US.lang index 272262ea..818c7b03 100644 --- a/src/main/resources/assets/tinker/lang/en_US.lang +++ b/src/main/resources/assets/tinker/lang/en_US.lang @@ -1124,3 +1124,8 @@ fluid.molten.unstableIngots=Molten Unstable Ingots fluid.molten.bedrockiumIngots=Molten Bedrockium Ingots item.iguana.tcon.clayBucket.Quartz.name=Molten Quartz Clay Bucket + +#mobsinfo compat +tconstruct.mobsinfocompat.tinkers_construct_beheading=Each level of beheading on your weapon gives additional %.2f%% +tconstruct.mobsinfocompat.tinkers_construct_beheading_1=If you are using a Cleaver, it gives another %.2f%% +