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);
});
}
}
}
}
Aggregations