Skip to content

Commit

Permalink
Moves class check to static block
Browse files Browse the repository at this point in the history
  • Loading branch information
querns committed Jul 13, 2024
1 parent fa1e0f0 commit d24c32f
Showing 1 changed file with 17 additions and 8 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 @@ -536,16 +550,11 @@ private boolean isTEMovable(TileEntity te) {
}

private static boolean tileIsASpawner(TileEntity te) {
if (te instanceof TileEntityMobSpawner) {
return true;
}

try {
Class<?> heeClass = Class.forName("chylex.hee.tileentity.TileEntityCustomSpawner");
if (heeClass.isInstance(te)) {
for (Class<?> c : spawnerClasses) {
if (c != null && c.isInstance(te)) {
return true;
}
} catch (ClassNotFoundException ignored) {}
}

return false;
}
Expand Down

0 comments on commit d24c32f

Please sign in to comment.