aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/MachineUpdateHandler.java
blob: 8263243474b44a9eecc178344210447af9093fd1 (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
package gtPlusPlus.xmod.gregtech.common.helpers;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import gregtech.api.GregTech_API;
import java.util.HashMap;
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);
            }
        }
    }
}