use of gregtech.api.items.behavior.MonitorPluginBaseBehavior in project GregTech by GregTechCEu.
the class MetaTileEntityMonitorScreen method readFromNBT.
@Override
public void readFromNBT(NBTTagCompound data) {
super.readFromNBT(data);
this.frameColor = data.hasKey("color") ? data.getInteger("color") : 0XFF00Ff00;
this.scale = data.hasKey("scale") ? data.getFloat("scale") : 1;
this.slot = data.hasKey("slot") ? data.getInteger("slot") : 0;
this.mode = CoverDigitalInterface.MODE.VALUES[data.hasKey("mode") ? data.getByte("mode") : 0];
this.inventory.deserializeNBT(data.getCompoundTag("Inventory"));
if (data.hasKey("coverPos") && data.hasKey("coverSide")) {
BlockPos pos = NBTUtil.getPosFromTag(data.getCompoundTag("coverPos"));
EnumFacing side = EnumFacing.byIndex(data.getByte("coverSide"));
this.coverPos = new BlockPosFace(pos, side);
} else {
this.coverPos = null;
}
MonitorPluginBaseBehavior behavior = MonitorPluginBaseBehavior.getBehavior(this.inventory.getStackInSlot(0));
if (behavior == null) {
unloadPlugin();
} else {
loadPlugin(behavior);
}
}
use of gregtech.api.items.behavior.MonitorPluginBaseBehavior in project GregTech by GregTechCEu.
the class MetaTileEntityMonitorScreen method initializeInventory.
@Override
protected void initializeInventory() {
super.initializeInventory();
this.inventory = new ItemStackHandler() {
@Override
public int getSlotLimit(int slot) {
return 1;
}
@Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack) {
MonitorPluginBaseBehavior behavior = MonitorPluginBaseBehavior.getBehavior(stack);
return behavior != null;
}
@Nonnull
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
if (!getWorld().isRemote && !getStackInSlot(slot).isEmpty() && !simulate) {
unloadPlugin();
writeCustomData(GregtechDataCodes.UPDATE_PLUGIN_ITEM, packetBuffer -> {
packetBuffer.writeItemStack(ItemStack.EMPTY);
});
}
return super.extractItem(slot, amount, simulate);
}
};
this.itemInventory = this.inventory;
}
use of gregtech.api.items.behavior.MonitorPluginBaseBehavior in project GregTech by GregTechCEu.
the class MetaTileEntityMonitorScreen method createUI.
@Override
protected ModularUI createUI(EntityPlayer entityPlayer) {
MultiblockControllerBase controller = this.getController();
if (controller instanceof MetaTileEntityCentralMonitor && ((MetaTileEntityCentralMonitor) controller).isActive()) {
int width = 330;
int height = 260;
ToggleButtonWidget[] buttons = new ToggleButtonWidget[5];
buttons[0] = new ToggleButtonWidget(width - 135, 25, 20, 20, GuiTextures.BUTTON_FLUID, () -> this.mode == CoverDigitalInterface.MODE.FLUID, (isPressed) -> {
if (isPressed)
setMode(CoverDigitalInterface.MODE.FLUID);
}).setTooltipText("metaitem.cover.digital.mode.fluid");
buttons[1] = new ToggleButtonWidget(width - 115, 25, 20, 20, GuiTextures.BUTTON_ITEM, () -> this.mode == CoverDigitalInterface.MODE.ITEM, (isPressed) -> {
if (isPressed)
setMode(CoverDigitalInterface.MODE.ITEM);
}).setTooltipText("metaitem.cover.digital.mode.item");
buttons[2] = new ToggleButtonWidget(width - 95, 25, 20, 20, GuiTextures.BUTTON_ENERGY, () -> this.mode == CoverDigitalInterface.MODE.ENERGY, (isPressed) -> {
if (isPressed)
setMode(CoverDigitalInterface.MODE.ENERGY);
}).setTooltipText("metaitem.cover.digital.mode.energy");
buttons[3] = new ToggleButtonWidget(width - 75, 25, 20, 20, GuiTextures.BUTTON_MACHINE, () -> this.mode == CoverDigitalInterface.MODE.MACHINE, (isPressed) -> {
if (isPressed)
setMode(CoverDigitalInterface.MODE.MACHINE);
}).setTooltipText("metaitem.cover.digital.mode.machine");
buttons[4] = new ToggleButtonWidget(width - 35, 25, 20, 20, GuiTextures.BUTTON_INTERFACE, () -> this.mode == CoverDigitalInterface.MODE.PROXY, (isPressed) -> {
if (isPressed)
setMode(CoverDigitalInterface.MODE.PROXY);
}).setTooltipText("metaitem.cover.digital.mode.proxy");
List<CoverDigitalInterface> covers = new ArrayList<>();
((MetaTileEntityCentralMonitor) controller).getAllCovers().forEach(coverPos -> covers.add(getCoverFromPosSide(coverPos)));
WidgetPluginConfig pluginWidget = new WidgetPluginConfig();
WidgetPluginConfig mainGroup = new WidgetPluginConfig().setSize(width, height);
mainGroup.widget(new LabelWidget(15, 55, "monitor.gui.title.scale", 0xFFFFFFFF)).widget(new ClickButtonWidget(50, 50, 20, 20, "-1", (data) -> setConfig(this.slot, ((float) Math.round((scale - (data.isShiftClick ? 1.0f : 0.1f)) * 10) / 10), this.frameColor))).widget(new ClickButtonWidget(130, 50, 20, 20, "+1", (data) -> setConfig(this.slot, ((float) Math.round((scale + (data.isShiftClick ? 1.0f : 0.1f)) * 10) / 10), this.frameColor))).widget(new ImageWidget(70, 50, 60, 20, GuiTextures.DISPLAY)).widget(new SimpleTextWidget(100, 60, "", 16777215, () -> Float.toString(scale))).widget(new LabelWidget(15, 85, "monitor.gui.title.argb", 0xFFFFFFFF)).widget(new WidgetARGB(50, 80, 20, this.frameColor, (color) -> setConfig(this.slot, this.scale, color))).widget(new LabelWidget(15, 110, "monitor.gui.title.slot", 0xFFFFFFFF)).widget(new ClickButtonWidget(50, 105, 20, 20, "-1", (data) -> setConfig(this.slot - 1, this.scale, this.frameColor))).widget(new ClickButtonWidget(130, 105, 20, 20, "+1", (data) -> setConfig(this.slot + 1, this.scale, this.frameColor))).widget(new ImageWidget(70, 105, 60, 20, GuiTextures.DISPLAY)).widget(new SimpleTextWidget(100, 115, "", 16777215, () -> Integer.toString(slot))).widget(new LabelWidget(15, 135, "monitor.gui.title.plugin", 0xFFFFFFFF)).widget(new SlotWidget(inventory, 0, 50, 130, true, true).setBackgroundTexture(GuiTextures.SLOT).setChangeListener(() -> {
if (this.getWorld() != null && !this.getWorld().isRemote) {
MonitorPluginBaseBehavior behavior = MonitorPluginBaseBehavior.getBehavior(inventory.getStackInSlot(0));
if (behavior == null) {
unloadPlugin();
} else {
loadPlugin(behavior);
}
writeCustomData(GregtechDataCodes.UPDATE_PLUGIN_ITEM, packetBuffer -> packetBuffer.writeItemStack(inventory.getStackInSlot(0)));
}
})).widget(new ClickButtonWidget(80, 130, 40, 20, "monitor.gui.title.config", (data) -> {
if (plugin != null && mainGroup.isVisible()) {
plugin.customUI(pluginWidget, this.getHolder(), entityPlayer);
mainGroup.setVisible(false);
}
}) {
@Override
protected void triggerButton() {
super.triggerButton();
if (plugin != null && mainGroup.isVisible()) {
plugin.customUI(pluginWidget, getHolder(), entityPlayer);
mainGroup.setVisible(false);
}
}
}).widget(new WidgetCoverList(width - 140, 50, 120, 11, covers, getCoverFromPosSide(this.coverPos), (coverPos) -> {
if (coverPos == null) {
this.setMode(null, this.mode);
} else {
this.setMode(new BlockPosFace(coverPos.coverHolder.getPos(), coverPos.attachedSide));
}
})).widget(buttons[0]).widget(buttons[1]).widget(buttons[2]).widget(buttons[3]).widget(buttons[4]).bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT, 15, 170);
return ModularUI.builder(GuiTextures.BOXED_BACKGROUND, width, height).widget(pluginWidget).widget(mainGroup).widget(new WidgetMonitorScreen(330, 0, 150, this)).widget(new LabelWidget(15, 13, "gregtech.machine.monitor_screen.name", 0XFFFFFFFF)).widget(new ClickButtonWidget(15, 25, 40, 20, "monitor.gui.title.back", data -> {
if (mainGroup.isVisible() && ((MetaTileEntityCentralMonitor) controller).isActive() && controller.isValid()) {
MetaTileEntityUIFactory.INSTANCE.openUI(controller.getHolder(), (EntityPlayerMP) entityPlayer);
} else if (!mainGroup.isVisible()) {
pluginWidget.removePluginWidget();
mainGroup.setVisible(true);
if (plugin != null) {
plugin.markAsDirty();
}
}
}) {
@Override
protected void triggerButton() {
super.triggerButton();
if (!mainGroup.isVisible()) {
pluginWidget.removePluginWidget();
mainGroup.setVisible(true);
if (plugin != null) {
plugin.markAsDirty();
}
}
}
}).bindCloseListener(() -> {
if (plugin != null) {
plugin.markAsDirty();
}
}).build(this.getHolder(), entityPlayer);
}
return null;
}
use of gregtech.api.items.behavior.MonitorPluginBaseBehavior in project GregTech by GregTechCEu.
the class MetaTileEntityMonitorScreen method receiveCustomData.
@Override
public void receiveCustomData(int dataId, PacketBuffer buf) {
super.receiveCustomData(dataId, buf);
if (dataId == GregtechDataCodes.UPDATE_ALL) {
readSync(buf);
} else if (dataId == GregtechDataCodes.UPDATE_PLUGIN_DATA) {
// plugin
if (plugin != null) {
plugin.readPluginData(buf.readVarInt(), buf);
}
} else if (dataId == GregtechDataCodes.UPDATE_PLUGIN_ITEM) {
try {
ItemStack itemStack = buf.readItemStack();
MonitorPluginBaseBehavior behavior = MonitorPluginBaseBehavior.getBehavior(itemStack);
if (behavior == null) {
unloadPlugin();
} else {
this.inventory.setStackInSlot(0, itemStack);
loadPlugin(behavior);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of gregtech.api.items.behavior.MonitorPluginBaseBehavior in project GregTech by GregTechCEu.
the class MetaTileEntityMonitorScreen method receiveInitialSyncData.
@Override
public void receiveInitialSyncData(PacketBuffer buf) {
super.receiveInitialSyncData(buf);
readSync(buf);
try {
ItemStack itemStack = buf.readItemStack();
MonitorPluginBaseBehavior behavior = MonitorPluginBaseBehavior.getBehavior(itemStack);
if (behavior == null) {
unloadPlugin();
} else {
this.inventory.setStackInSlot(0, itemStack);
loadPlugin(behavior);
plugin.receiveInitialSyncData(buf);
}
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations