Example usage for net.minecraftforge.fml.common.network IGuiHandler IGuiHandler

List of usage examples for net.minecraftforge.fml.common.network IGuiHandler IGuiHandler

Introduction

In this page you can find the example usage for net.minecraftforge.fml.common.network IGuiHandler IGuiHandler.

Prototype

IGuiHandler

Source Link

Usage

From source file:com.elytradev.thermionics.Thermionics.java

License:Open Source License

@EventHandler
public void onPreInit(FMLPreInitializationEvent e) {
    //Skip for now; we have no keys yet
    //CONFIG = new Configuration(e.getSuggestedConfigurationFile());
    //CONFIG.save();

    LOG = e.getModLog();/*w  w  w.j ava  2 s. c o m*/
    //LOG = LogManager.getLogger(Thermionics.MODID);

    CapabilityManager.INSTANCE.register(IHeatStorage.class, new DefaultHeatStorageSerializer(),
            HeatStorage::new);
    CapabilityManager.INSTANCE.register(IRotaryPowerSupply.class, new DefaultRotaryPowerSerializer(),
            RotaryPowerSupply::new);
    CapabilityManager.INSTANCE.register(IRotaryPowerConsumer.class, new DefaultRotaryConsumerSerializer(),
            RotaryPowerConsumer::new);
    CapabilityManager.INSTANCE.register(IWeaponSkillInfo.class, new DefaultWeaponSkillInfoSerializer(),
            WeaponSkillInfo::new);

    proxy.preInit();

    CONTEXT = NetworkContext.forChannel("tmxfx");
    CONTEXT.register(SpawnParticleEmitterMessage.class);

    if (Loader.isModLoaded("probedataprovider")) {
        ProbeDataSupport.init();
    }

    MinecraftForge.EVENT_BUS.register(this);
    MinecraftForge.EVENT_BUS.register(proxy);

    /* (See https://mcforge.readthedocs.io/en/latest/events/intro/ for docs on static event handlers)
     * Because the registry events are forced on us, we might as well delegate to the former ObjectHolder classes
     * so they can flow in a more Enum-y way.
     */
    MinecraftForge.EVENT_BUS.register(ThermionicsBlocks.class);
    MinecraftForge.EVENT_BUS.register(ThermionicsItems.class);
    MinecraftForge.EVENT_BUS.register(ThermionicsRecipes.class);

    NetworkRegistry.INSTANCE.registerGuiHandler(this, new IGuiHandler() {
        @Override
        public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
            TileEntity te = world.getTileEntity(new BlockPos(x, y, z));

            if (te != null && (te instanceof IContainerInventoryHolder)) {
                ConcreteContainer container = EnumGui.forId(id).createContainer(player.inventory,
                        ((IContainerInventoryHolder) te).getContainerInventory(), te);
                container.validate();
                return container;
            }

            System.out.println("NULL SERVER ELEMENT.");
            return null; //For now!
        }

        @Override
        public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
            TileEntity te = world.getTileEntity(new BlockPos(x, y, z));
            ConcreteContainer container = null;
            if (te != null && (te instanceof IContainerInventoryHolder)) {
                container = EnumGui.forId(id).createContainer(player.inventory,
                        ((IContainerInventoryHolder) te).getContainerInventory(), te);
            }

            return new ConcreteGui(container);
        }

    });

    MinecraftForge.EVENT_BUS.register(this);
    BigExplosionHandler.instance().init();
}