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,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