blob: 2710f5dc7807f6c8675636f8dc117a6db0dcc44a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
package gtPlusPlus.xmod.gregtech.common.helpers;
import java.util.HashMap;
import net.minecraft.block.Block;
import net.minecraftforge.event.world.BlockEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import gregtech.api.GregTech_API;
public class MachineUpdateHandler {
private static final HashMap<String, Block> mBlockCache = new HashMap<String, Block>();
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);
}
}
}
}
|