Skip to content

Commit

Permalink
Adds Hardcore Ender Expansion support for diamond dolly (#34)
Browse files Browse the repository at this point in the history
* Adds Hardcore Ender Expansion support for diamond dolly

* Moves class check to static block
  • Loading branch information
querns authored Jul 13, 2024
1 parent fc36901 commit 98f2135
Showing 1 changed file with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
Expand Down Expand Up @@ -50,6 +52,9 @@ public class ItemBarrelMover extends Item {
protected static ArrayList<String> classExtensionsNames = new ArrayList<String>();
protected static HashMap<String, Class> classMap = new HashMap<String, Class>();

protected static ArrayList<String> spawnerClassExtensionsNames = new ArrayList<String>();
protected static Set<Class<?>> spawnerClasses = new HashSet<>();

protected Method tagCompoundWrite = Utils.ReflectionHelper.getMethod(
NBTTagCompound.class,
new String[] { "a", "func_74734_a", "write" },
Expand Down Expand Up @@ -121,6 +126,15 @@ protected enum DollyType {
classExtensions.add(null);
}
}

spawnerClassExtensionsNames.add("chylex.hee.tileentity.TileEntityCustomSpawner");
spawnerClasses.add(TileEntityMobSpawner.class);

for (String s : spawnerClassExtensionsNames) {
try {
spawnerClasses.add(Class.forName(s));
} catch (ClassNotFoundException ignored) {}
}
}

public ItemBarrelMover() {
Expand Down Expand Up @@ -523,7 +537,7 @@ private void fixIC2Orientation(TileEntity entity, EntityPlayer player, int targY
}

private boolean isTEMovable(TileEntity te) {
if (te instanceof TileEntityMobSpawner) return this.canPickSpawners();
if (tileIsASpawner(te)) return this.canPickSpawners();
if (te instanceof TileEntityBarrel) return true;
if (te instanceof TileEntityChest) return true;
if (isTileBlacklisted(te.getClass())) {
Expand All @@ -535,6 +549,16 @@ private boolean isTEMovable(TileEntity te) {
return false;
}

private static boolean tileIsASpawner(TileEntity te) {
for (Class<?> c : spawnerClasses) {
if (c != null && c.isInstance(te)) {
return true;
}
}

return false;
}

private boolean isTileBlacklisted(Class clazz) {
for (Class<? extends TileEntity> tileClass : BetterBarrels.BlacklistedTileEntityClasses) {
if (clazz == tileClass) {
Expand Down Expand Up @@ -621,7 +645,7 @@ protected boolean pickupContainer(ItemStack stack, EntityPlayer player, World wo
nbtTarget.setString("Block", GameData.getBlockRegistry().getNameForObject(storedBlock));
nbtTarget.setInteger("Meta", blockMeta);
nbtTarget.setString("TEClass", containerTE.getClass().getName());
nbtTarget.setBoolean("isSpawner", containerTE instanceof TileEntityMobSpawner);
nbtTarget.setBoolean("isSpawner", tileIsASpawner(containerTE));
nbtTarget.setTag("NBT", nbtContainer); // TODO: Check this, seems the nbt classes were streamlined somewhat

if (tagCompoundWrite != null) {
Expand Down

0 comments on commit 98f2135

Please sign in to comment.