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 <[email protected]>
This commit is contained in:
JakubandMartin Robertz authored and GitHub committed 2024-08-27 09:54:53 +02:00
1 parent 691a6ef32b
commit 305ecbe6c8
10 files changed
+310 -12

No files matched your search

@@ -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<MobDrop> 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) {
@@ -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<MobDrop> 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<String> 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<ItemStack> 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) {
@@ -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<MobDrop> 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();
}
}
}
}
}
}
@@ -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<MobDrop> 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()));
}
}
@@ -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) {
@@ -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<MobDrop> 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