use of gregtech.api.gui.ModularUI in project GregTech by GregTechCE.
the class NetworkHandler method init.
public static void init() {
channel = NetworkRegistry.INSTANCE.newEventDrivenChannel(GTValues.MODID);
channel.register(new NetworkHandler());
PacketEncoder<PacketUIWidgetUpdate> widgetUpdateEncoder = (packet, buf) -> {
buf.writeVarInt(packet.updateData.readableBytes());
buf.writeBytes(packet.updateData);
buf.writeVarInt(packet.windowId);
buf.writeVarInt(packet.widgetId);
};
PacketDecoder<PacketUIWidgetUpdate> widgetUpdateDecoder = (buf) -> {
ByteBuf directSliceBuffer = buf.readBytes(buf.readVarInt());
ByteBuf copiedDataBuffer = Unpooled.copiedBuffer(directSliceBuffer);
directSliceBuffer.release();
return new PacketUIWidgetUpdate(buf.readVarInt(), buf.readVarInt(), new PacketBuffer(copiedDataBuffer));
};
registerPacket(1, PacketUIOpen.class, new PacketCodec<>((packet, buf) -> {
buf.writeVarInt(packet.serializedHolder.readableBytes());
buf.writeBytes(packet.serializedHolder);
buf.writeVarInt(packet.uiFactoryId);
buf.writeVarInt(packet.windowId);
buf.writeVarInt(packet.initialWidgetUpdates.size());
for (PacketUIWidgetUpdate widgetUpdate : packet.initialWidgetUpdates) {
widgetUpdateEncoder.encode(widgetUpdate, buf);
}
}, (buf) -> {
ByteBuf directSliceBuffer = buf.readBytes(buf.readVarInt());
ByteBuf copiedDataBuffer = Unpooled.copiedBuffer(directSliceBuffer);
directSliceBuffer.release();
int uiFactoryId = buf.readVarInt();
int windowId = buf.readVarInt();
ArrayList<PacketUIWidgetUpdate> initialWidgetUpdates = new ArrayList<>();
int initialWidgetUpdatesCount = buf.readVarInt();
for (int i = 0; i < initialWidgetUpdatesCount; i++) {
initialWidgetUpdates.add(widgetUpdateDecoder.decode(buf));
}
return new PacketUIOpen(uiFactoryId, new PacketBuffer(copiedDataBuffer), windowId, initialWidgetUpdates);
}));
registerPacket(2, PacketUIWidgetUpdate.class, new PacketCodec<>((packet, buf) -> {
buf.writeVarInt(packet.updateData.readableBytes());
buf.writeBytes(packet.updateData);
buf.writeVarInt(packet.windowId);
buf.writeVarInt(packet.widgetId);
}, (buf) -> {
ByteBuf directSliceBuffer = buf.readBytes(buf.readVarInt());
ByteBuf copiedDataBuffer = Unpooled.copiedBuffer(directSliceBuffer);
directSliceBuffer.release();
return new PacketUIWidgetUpdate(buf.readVarInt(), buf.readVarInt(), new PacketBuffer(copiedDataBuffer));
}));
registerPacket(3, PacketUIClientAction.class, new PacketCodec<>((packet, buf) -> {
buf.writeVarInt(packet.updateData.readableBytes());
buf.writeBytes(packet.updateData);
buf.writeVarInt(packet.windowId);
buf.writeVarInt(packet.widgetId);
}, (buf) -> {
ByteBuf directSliceBuffer = buf.readBytes(buf.readVarInt());
ByteBuf copiedDataBuffer = Unpooled.copiedBuffer(directSliceBuffer);
directSliceBuffer.release();
return new PacketUIClientAction(buf.readVarInt(), buf.readVarInt(), new PacketBuffer(copiedDataBuffer));
}));
registerPacket(4, PacketBlockParticle.class, new PacketCodec<>((packet, buf) -> {
buf.writeBlockPos(packet.blockPos);
buf.writeFloat((float) packet.entityPos.x);
buf.writeFloat((float) packet.entityPos.y);
buf.writeFloat((float) packet.entityPos.z);
buf.writeVarInt(packet.particlesAmount);
}, (buf) -> new PacketBlockParticle(buf.readBlockPos(), new Vector3(buf.readFloat(), buf.readFloat(), buf.readFloat()), buf.readVarInt())));
registerPacket(5, PacketClipboard.class, new PacketCodec<>((packet, buf) -> {
buf.writeString(packet.text);
}, (buf) -> new PacketClipboard(buf.readString(32767))));
registerServerExecutor(PacketUIClientAction.class, (packet, handler) -> {
Container openContainer = handler.player.openContainer;
if (openContainer instanceof ModularUIContainer && openContainer.windowId == packet.windowId) {
ModularUI modularUI = ((ModularUIContainer) openContainer).getModularUI();
PacketBuffer buffer = packet.updateData;
modularUI.guiWidgets.get(packet.widgetId).handleClientAction(buffer.readVarInt(), buffer);
}
});
if (FMLCommonHandler.instance().getSide().isClient()) {
initClient();
}
}
use of gregtech.api.gui.ModularUI in project GregTech by GregTechCE.
the class MetaTileEntityChest method createUI.
@Override
protected ModularUI createUI(EntityPlayer entityPlayer) {
Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, Math.max(176, 14 + rowSize * 18), 18 + 18 * amountOfRows + 94).label(5, 5, getMetaFullName());
builder.widget(new SortingButtonWidget(111, 4, 60, 10, "gregtech.gui.sort", (info) -> sortInventorySlotContents(inventory)));
for (int y = 0; y < amountOfRows; y++) {
for (int x = 0; x < rowSize; x++) {
int index = y * rowSize + x;
builder.slot(inventory, index, 7 + x * 18, 18 + y * 18, GuiTextures.SLOT);
}
}
int startX = (Math.max(176, 14 + rowSize * 18) - 162) / 2;
builder.bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT, startX, 18 + 18 * amountOfRows + 12);
if (!getWorld().isRemote) {
builder.bindOpenListener(() -> onContainerOpen(entityPlayer));
builder.bindCloseListener(() -> onContainerClose(entityPlayer));
}
return builder.build(getHolder(), entityPlayer);
}
use of gregtech.api.gui.ModularUI in project GregTech by GregTechCE.
the class MetaTileEntityLockedSafe method createUI.
@Override
protected ModularUI createUI(EntityPlayer entityPlayer) {
DoubleSupplier supplier = () -> 0.2 + (unlockProgress / (MAX_UNLOCK_PROGRESS * 1.0)) * 0.8;
ModularUI.Builder builder = ModularUI.defaultBuilder().widget(new ProgressWidget(supplier, 5, 5, 166, 74, GuiTextures.PROGRESS_BAR_UNLOCK, MoveType.VERTICAL_INVERTED)).bindPlayerInventory(entityPlayer.inventory);
ServerWidgetGroup lockedGroup = new ServerWidgetGroup(() -> !isSafeUnlocked && unlockProgress < 0);
lockedGroup.addWidget(new LabelWidget(5, 20, "gregtech.machine.locked_safe.malfunctioning"));
lockedGroup.addWidget(new LabelWidget(5, 30, "gregtech.machine.locked_safe.requirements"));
lockedGroup.addWidget(new SlotWidget(unlockInventory, 0, 70, 40, false, true).setBackgroundTexture(GuiTextures.SLOT));
lockedGroup.addWidget(new SlotWidget(unlockInventory, 1, 70 + 18, 40, false, true).setBackgroundTexture(GuiTextures.SLOT));
lockedGroup.addWidget(new SlotWidget(unlockComponents, 0, 70, 58, false, false));
lockedGroup.addWidget(new SlotWidget(unlockComponents, 1, 70 + 18, 58, false, false));
ServerWidgetGroup unlockedGroup = new ServerWidgetGroup(() -> isSafeUnlocked);
for (int row = 0; row < 3; row++) {
for (int col = 0; col < 9; col++) {
unlockedGroup.addWidget(new SlotWidget(safeLootInventory, col + row * 9, 8 + col * 18, 15 + row * 18, true, false));
}
}
return builder.widget(unlockedGroup).widget(lockedGroup).build(getHolder(), entityPlayer);
}
use of gregtech.api.gui.ModularUI in project GregTech by GregTechCE.
the class GTUtility method findPlayersUsing.
public static List<EntityPlayerMP> findPlayersUsing(MetaTileEntity metaTileEntity, double radius) {
ArrayList<EntityPlayerMP> result = new ArrayList<>();
AxisAlignedBB box = new AxisAlignedBB(metaTileEntity.getPos()).expand(radius, radius, radius).expand(-radius, -radius, -radius);
List<EntityPlayerMP> entities = metaTileEntity.getWorld().getEntitiesWithinAABB(EntityPlayerMP.class, box);
for (EntityPlayerMP player : entities) {
if (player.openContainer instanceof ModularUIContainer) {
ModularUI modularUI = ((ModularUIContainer) player.openContainer).getModularUI();
if (modularUI.holder instanceof MetaTileEntityHolder && ((MetaTileEntityHolder) modularUI.holder).getMetaTileEntity() == metaTileEntity) {
result.add(player);
}
}
}
return result;
}
use of gregtech.api.gui.ModularUI in project GregTech by GregTechCE.
the class MetaTileEntityItemCollector method createUI.
@Override
protected ModularUI createUI(EntityPlayer entityPlayer) {
int rowSize = (int) Math.sqrt(exportItems.getSlots());
Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 176, 45 + rowSize * 18 + 105 + 82).label(10, 5, getMetaFullName());
builder.widget(new ClickButtonWidget(10, 20, 20, 20, "-1", data -> adjustSuckingRange(-1)));
builder.widget(new ClickButtonWidget(146, 20, 20, 20, "+1", data -> adjustSuckingRange(+1)));
builder.widget(new ImageWidget(30, 20, 116, 20, GuiTextures.DISPLAY));
builder.widget(new SimpleTextWidget(88, 30, "gregtech.machine.item_collector.gui.collect_range", 0xFFFFFF, () -> Integer.toString(itemSuckingRange)));
for (int y = 0; y < rowSize; y++) {
for (int x = 0; x < rowSize; x++) {
int index = y * rowSize + x;
builder.widget(new SlotWidget(exportItems, index, 89 - rowSize * 9 + x * 18, 45 + y * 18, true, false).setBackgroundTexture(GuiTextures.SLOT));
}
}
this.itemFilter.initUI(45 + rowSize * 18 + 5, builder::widget);
builder.bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT, 7, 45 + rowSize * 18 + 105);
return builder.build(getHolder(), entityPlayer);
}
Aggregations