From 86edf93e4bdf56ed4974d0c06eca5de309ca4f9a Mon Sep 17 00:00:00 2001 From: Alkalus Date: Tue, 14 Apr 2020 23:12:54 +0100 Subject: + Added a way to register blocks that will cause MachineUpdates when placed. (Useful for non-GT blocks used in Multis) $ Fixed Industrial Cutting Machine defaulting to slicing mode. $ Fixed reInit() on recipe maps causing absurd crashes. (Doesn't seem to break anything at the moment not doing it, so.. I won't) --- .../common/helpers/MachineUpdateHandler.java | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/Java/gtPlusPlus/xmod/gregtech/common/helpers/MachineUpdateHandler.java (limited to 'src/Java/gtPlusPlus/xmod/gregtech/common/helpers') diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/MachineUpdateHandler.java b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/MachineUpdateHandler.java new file mode 100644 index 0000000000..0b52560e0d --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/helpers/MachineUpdateHandler.java @@ -0,0 +1,42 @@ +package gtPlusPlus.xmod.gregtech.common.helpers; + +import java.util.HashMap; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import gregtech.api.GregTech_API; +import net.minecraft.block.Block; +import net.minecraftforge.event.world.BlockEvent; + +public class MachineUpdateHandler { + + private static final HashMap mBlockCache = new HashMap(); + + public static void registerBlockToCauseMachineUpdate(String aUnlocalName, Block aBlock) { + mBlockCache.put(aUnlocalName, aBlock); + } + + @SubscribeEvent + public void onBlockEvent(BlockEvent event) { + Block aBlock = event.block; + String aUnlocalName = aBlock != null ? aBlock.getUnlocalizedName() : "NULL"; + boolean aDoUpdate = false; + if (aBlock != null && aUnlocalName != null && !aUnlocalName.equals("NULL")) { + for (String aCachedName : mBlockCache.keySet()) { + if (aCachedName.equals(aUnlocalName)) { + aDoUpdate = true; + break; + } + else { + if (aBlock == mBlockCache.get(aCachedName)) { + aDoUpdate = true; + break; + } + } + } + if (aDoUpdate) { + GregTech_API.causeMachineUpdate(event.world, event.x, event.y, event.z); + } + } + } + +} -- cgit