aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/kubatech/api/utils/ItemID.java78
-rw-r--r--src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_ExtremeExterminationChamber.java69
2 files changed, 124 insertions, 23 deletions
diff --git a/src/main/java/kubatech/api/utils/ItemID.java b/src/main/java/kubatech/api/utils/ItemID.java
new file mode 100644
index 0000000000..199af7ebd0
--- /dev/null
+++ b/src/main/java/kubatech/api/utils/ItemID.java
@@ -0,0 +1,78 @@
+package kubatech.api.utils;
+
+import java.util.Objects;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+
+public class ItemID {
+ private final Item item;
+ private final int count;
+ private final int meta;
+ private final NBTTagCompound tag;
+ private final boolean ignorecount;
+ private final boolean ignoremeta;
+ private final boolean ignorenbt;
+
+ public static ItemID create(ItemStack stack) {
+ return new ItemID(stack, true, true, true, true); // ignore count by default
+ }
+
+ public static ItemID create(ItemStack stack, boolean ignorecount) {
+ return new ItemID(stack, ignorecount, false, false, true);
+ }
+
+ public static ItemID create(ItemStack stack, boolean ignorecount, boolean ignoremeta) {
+ return new ItemID(stack, ignorecount, ignoremeta, false, true);
+ }
+
+ public static ItemID create(ItemStack stack, boolean ignorecount, boolean ignoremeta, boolean ignorenbt) {
+ return new ItemID(stack, ignorecount, ignoremeta, ignorenbt, true);
+ }
+
+ public static ItemID create_NoCopy(ItemStack stack) {
+ return new ItemID(stack, true, false, false, false); // ignore count by default
+ }
+
+ public static ItemID create_NoCopy(ItemStack stack, boolean ignorecount) {
+ return new ItemID(stack, ignorecount, false, false, false);
+ }
+
+ public static ItemID create_NoCopy(ItemStack stack, boolean ignorecount, boolean ignoremeta) {
+ return new ItemID(stack, ignorecount, ignoremeta, false, false);
+ }
+
+ public static ItemID create_NoCopy(ItemStack stack, boolean ignorecount, boolean ignoremeta, boolean ignorenbt) {
+ return new ItemID(stack, ignorecount, ignoremeta, ignorenbt, false);
+ }
+
+ private ItemID(ItemStack stack, boolean ignorecount, boolean ignoremeta, boolean ignorenbt, boolean createcopy) {
+ this.ignorecount = ignorecount;
+ this.ignoremeta = ignoremeta;
+ this.ignorenbt = ignorenbt;
+ item = stack.getItem();
+ count = ignorecount ? 0 : stack.stackSize;
+ meta = ignoremeta ? 0 : stack.getItemDamage();
+ tag = ignorenbt ? null : (createcopy ? (NBTTagCompound) stack.stackTagCompound.copy() : stack.stackTagCompound);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(item, count, meta, tag);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) return false;
+ if (obj == this) return true;
+ if (obj instanceof ItemID) return obj.hashCode() == this.hashCode();
+ if (obj instanceof ItemStack) {
+ if (!item.equals(((ItemStack) obj).getItem())) return false;
+ if (!ignorecount) if (count != ((ItemStack) obj).stackSize) return false;
+ if (!ignoremeta) if (meta != ((ItemStack) obj).getItemDamage()) return false;
+ if (!ignorenbt) if (!tag.equals(((ItemStack) obj).stackTagCompound)) return false;
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_ExtremeExterminationChamber.java b/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_ExtremeExterminationChamber.java
index 6eda8055be..394500b0bb 100644
--- a/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_ExtremeExterminationChamber.java
+++ b/src/main/java/kubatech/tileentity/gregtech/multiblock/GT_MetaTileEntity_ExtremeExterminationChamber.java
@@ -61,6 +61,7 @@ import kubatech.api.LoaderReference;
import kubatech.api.network.CustomTileEntityPacket;
import kubatech.api.tileentity.CustomTileEntityPacketHandler;
import kubatech.api.utils.FastRandom;
+import kubatech.api.utils.ItemID;
import kubatech.api.utils.ReflectionHelper;
import kubatech.client.effect.EntityRenderer;
import kubatech.loaders.MobRecipeLoader;
@@ -199,8 +200,8 @@ public class GT_MetaTileEntity_ExtremeExterminationChamber
.addInfo(Author)
.addInfo("Spawns and Exterminates monsters for you")
.addInfo("Base energy usage: 2,000 EU/t")
- .addInfo("Recipe time is based on mob health")
- .addInfo("You have to put weapon in ULV Input Bus")
+ .addInfo("Recipe time is based on mob health and the weapon")
+ .addInfo("You have to put a weapon in ULV Input Bus (optional)")
.addInfo("Also produces 120 Liquid XP per operation")
.addInfo("If the mob spawns infernal")
.addInfo("it will drain 8 times more power")
@@ -216,6 +217,7 @@ public class GT_MetaTileEntity_ExtremeExterminationChamber
.addOtherStructurePart("Borosilicate Glass", "All walls without corners")
.addStructureInfo("The glass tier limits the Energy Input tier")
.addOtherStructurePart("Steel Frame Box", "All vertical corners (except top and bottom)")
+ .addOtherStructurePart("Diamond spikes", "Inside second layer")
.addOutputBus("Any casing", 1)
.addOtherStructurePart(
"1x ULV " + StatCollector.translateToLocal("GT5U.MBTT.InputBus"), "Any casing", 1)
@@ -415,6 +417,15 @@ public class GT_MetaTileEntity_ExtremeExterminationChamber
private CustomTileEntityPacket mobPacket = null;
+ private static class WeaponCache {
+ ItemStack stack = null;
+ ItemID id = null;
+ int looting = 0;
+ double attackdamage = 0;
+ }
+
+ private final WeaponCache weaponCache = new WeaponCache();
+
@Override
public boolean checkRecipe(ItemStack aStack) {
if (getBaseMetaTileEntity().isClientSide()) return false;
@@ -438,34 +449,46 @@ public class GT_MetaTileEntity_ExtremeExterminationChamber
this.mOutputFluids = new FluidStack[] {FluidRegistry.getFluidStack("xpjuice", 5000)};
this.mOutputItems = recipe.generateOutputs(rand, this, 3, 0);
} else {
+ double attackDamage = 9d; // damage from spikes
GT_MetaTileEntity_Hatch_InputBus inputbus = this.mInputBusses.get(0);
- if (inputbus == null || !isValidMetaTileEntity(inputbus)) return false;
- ItemStack lootingholder = inputbus.getStackInSlot(0);
- if (lootingholder == null || !Enchantment.looting.canApply(lootingholder)) return false;
- double attackDamage = 3;
-
- try {
- //noinspection unchecked
- attackDamage += ((Multimap<String, AttributeModifier>) lootingholder.getAttributeModifiers())
- .get(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName()).stream()
- .mapToDouble(attr -> attr.getAmount()
- + (double) EnchantmentHelper.func_152377_a(
- lootingholder, EnumCreatureAttribute.UNDEFINED))
- .sum();
- } catch (Exception ex) {
- ex.printStackTrace();
+ if (inputbus == null || !isValidMetaTileEntity(inputbus)) {
+ weaponCache.stack = null;
+ return false;
+ }
+ weaponCheck:
+ {
+ ItemStack lootingholder = inputbus.getStackInSlot(0);
+ if (weaponCache.id.equals(lootingholder)) break weaponCheck;
+ if (lootingholder == null || !Enchantment.looting.canApply(lootingholder)) {
+ weaponCache.stack = null;
+ break weaponCheck;
+ }
+ try {
+ //noinspection unchecked
+ weaponCache.attackdamage = ((Multimap<String, AttributeModifier>)
+ lootingholder.getAttributeModifiers())
+ .get(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName()).stream()
+ .mapToDouble(attr -> attr.getAmount()
+ + (double) EnchantmentHelper.func_152377_a(
+ lootingholder, EnumCreatureAttribute.UNDEFINED))
+ .sum();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ weaponCache.stack = lootingholder;
+ weaponCache.looting =
+ EnchantmentHelper.getEnchantmentLevel(Enchantment.looting.effectId, lootingholder);
+ weaponCache.id = ItemID.create_NoCopy(lootingholder, true, true);
}
+ if (weaponCache.stack != null) attackDamage += weaponCache.attackdamage;
this.mOutputItems = recipe.generateOutputs(
- rand,
- this,
- attackDamage,
- EnchantmentHelper.getEnchantmentLevel(Enchantment.looting.effectId, lootingholder));
+ rand, this, attackDamage, weaponCache.stack != null ? weaponCache.looting : 0);
int eut = this.mEUt;
calculatePerfectOverclockedNessMulti(this.mEUt, this.mMaxProgresstime, 2, getMaxInputVoltage());
- if (lootingholder.isItemStackDamageable()) {
+ if (weaponCache.stack != null && weaponCache.stack.isItemStackDamageable()) {
do {
- if (lootingholder.attemptDamageItem(1, rand)) {
+ if (weaponCache.stack.attemptDamageItem(1, rand)) {
inputbus.setInventorySlotContents(0, null);
break;
}