Search in sources :

Example 1 with IGuiItem

use of mekanism.common.item.interfaces.IGuiItem in project Mekanism by mekanism.

the class PacketGuiButtonPress method handle.

@Override
public void handle(NetworkEvent.Context context) {
    ServerPlayerEntity player = context.getSender();
    if (player == null) {
        return;
    }
    if (type == Type.ENTITY) {
        Entity entity = player.level.getEntity(entityID);
        if (entity != null) {
            INamedContainerProvider provider = entityButton.getProvider(entity);
            if (provider != null) {
                // Ensure valid data
                NetworkHooks.openGui(player, provider, buf -> buf.writeVarInt(entityID));
            }
        }
    } else if (type == Type.TILE) {
        TileEntityMekanism tile = WorldUtils.getTileEntity(TileEntityMekanism.class, player.level, tilePosition);
        if (tile != null) {
            INamedContainerProvider provider = tileButton.getProvider(tile, extra);
            if (provider != null) {
                // Ensure valid data
                NetworkHooks.openGui(player, provider, buf -> {
                    buf.writeBlockPos(tilePosition);
                    buf.writeVarInt(extra);
                });
            }
        }
    } else if (type == Type.ITEM) {
        ItemStack stack = player.getItemInHand(hand);
        if (stack.getItem() instanceof IGuiItem) {
            INamedContainerProvider provider = itemButton.getProvider(stack, hand);
            if (provider != null) {
                NetworkHooks.openGui(player, provider, buf -> {
                    buf.writeEnum(hand);
                    buf.writeItem(stack);
                });
            }
        }
    }
}
Also used : TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) TileEntityInductionCasing(mekanism.common.tile.multiblock.TileEntityInductionCasing) IGuiItem(mekanism.common.item.interfaces.IGuiItem) Entity(net.minecraft.entity.Entity) Attribute(mekanism.common.block.attribute.Attribute) BiFunction(java.util.function.BiFunction) INamedContainerProvider(net.minecraft.inventory.container.INamedContainerProvider) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) BlockPos(net.minecraft.util.math.BlockPos) Function(java.util.function.Function) ItemStack(net.minecraft.item.ItemStack) Block(net.minecraft.block.Block) WorldUtils(mekanism.common.util.WorldUtils) NetworkHooks(net.minecraftforge.fml.network.NetworkHooks) MekanismContainerTypes(mekanism.common.registries.MekanismContainerTypes) MekanismLang(mekanism.common.MekanismLang) TileEntity(net.minecraft.tileentity.TileEntity) Hand(net.minecraft.util.Hand) IMekanismPacket(mekanism.common.network.IMekanismPacket) TileEntityBoilerCasing(mekanism.common.tile.multiblock.TileEntityBoilerCasing) AttributeGui(mekanism.common.block.attribute.AttributeGui) PacketBuffer(net.minecraft.network.PacketBuffer) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) IGuiItem(mekanism.common.item.interfaces.IGuiItem) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) INamedContainerProvider(net.minecraft.inventory.container.INamedContainerProvider) ItemStack(net.minecraft.item.ItemStack)

Aggregations

BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1 MekanismLang (mekanism.common.MekanismLang)1 Attribute (mekanism.common.block.attribute.Attribute)1 AttributeGui (mekanism.common.block.attribute.AttributeGui)1 IGuiItem (mekanism.common.item.interfaces.IGuiItem)1 IMekanismPacket (mekanism.common.network.IMekanismPacket)1 MekanismContainerTypes (mekanism.common.registries.MekanismContainerTypes)1 TileEntityMekanism (mekanism.common.tile.base.TileEntityMekanism)1 TileEntityBoilerCasing (mekanism.common.tile.multiblock.TileEntityBoilerCasing)1 TileEntityInductionCasing (mekanism.common.tile.multiblock.TileEntityInductionCasing)1 WorldUtils (mekanism.common.util.WorldUtils)1 Block (net.minecraft.block.Block)1 Entity (net.minecraft.entity.Entity)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 INamedContainerProvider (net.minecraft.inventory.container.INamedContainerProvider)1 ItemStack (net.minecraft.item.ItemStack)1 PacketBuffer (net.minecraft.network.PacketBuffer)1 TileEntity (net.minecraft.tileentity.TileEntity)1 Hand (net.minecraft.util.Hand)1