aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/MachineUpdateHandler.java
blob: 0b52560e0d80d55771464095d55b160787d9fc17 (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
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<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);    			
    		}
    	}
    }
	
}