Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @author Intektor
- */
- public class GuiMagazineTable extends GuiContainer {
- private static final ResourceLocation texture = new ResourceLocation(CounterGuns.MODID, "textures/gui/magazine_table.png");
- List<MagazineRegistry.MagazineRegistryEntry> magazinesToChoose = new ArrayList<>();
- int currentMagazineChosenID;
- final int buttonLeft = 0, buttonRight = 1;
- public GuiMagazineTable(Container inventorySlotsIn) {
- super(inventorySlotsIn);
- }
- @Override
- public void initGui() {
- super.initGui();
- buttonList.clear();
- int i = (this.width - this.xSize) / 2;
- int j = (this.height - this.ySize) / 2;
- buttonList.add(new GuiButton(buttonLeft, i + 24 - 11, j + 5, 10, 20, "<"));
- buttonList.add(new GuiButton(buttonRight, i + 24 + 17, j + 5, 10, 20, ">"));
- buttonList.get(buttonLeft).visible = false;
- buttonList.get(buttonRight).visible = false;
- prevStackIn0 = null;
- }
- @Override
- public void updateScreen() {
- ItemStack stack = inventorySlots.getInventory().get(0);
- if (!ItemStackHelper.areItemStacksCompletelyIdentical(prevStackIn0, stack)) {
- prevStackIn0 = stack;
- if (stack != null && stack.getItem() instanceof ItemGunStandardBullet) {
- ItemGunStandardBullet gun = (ItemGunStandardBullet) stack.getItem();
- magazinesToChoose = MagazineRegistry.INSTANCE.findMagazines(gun.matchingCaliber());
- currentMagazineChosenID = 0;
- CounterGuns.network.sendToServer(new ChangeMagazineTypeGuiMagazineMessageToServer(0));
- } else {
- CounterGuns.network.sendToServer(new ChangeMagazineTypeGuiMagazineMessageToServer(-1));
- }
- buttonList.get(buttonLeft).visible = stack != null && stack.getItem() instanceof ItemGun;
- buttonList.get(buttonRight).visible = stack != null && stack.getItem() instanceof ItemGun;
- }
- super.updateScreen();
- }
- @Override
- protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
- GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
- this.mc.getTextureManager().bindTexture(texture);
- int i = (this.width - this.xSize) / 2;
- int j = (this.height - this.ySize) / 2;
- this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);
- }
- ItemStack prevStackIn0;
- @Override
- protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
- ItemStack stack = inventorySlots.getInventory().get(0);
- int i = (this.width - this.xSize) / 2;
- int j = (this.height - this.ySize) / 2;
- if (stack == null) {
- int x = 24;
- int y = 34 - 16 * 2;
- CGRenderHelper.renderVirtualSlot(new ItemStack(CounterGuns.desert_eagle), x, y);
- CGRenderHelper.renderVirtualSlot(new ItemStack(CounterGuns.m_0_223), x, y + 16);
- } else {
- if (stack.getItem() instanceof ItemGun) {
- if (!magazinesToChoose.isEmpty() && currentMagazineChosenID < magazinesToChoose.size()) {
- MagazineRegistry.MagazineRegistryEntry chosen = magazinesToChoose.get(currentMagazineChosenID);
- VirtualSlotRenderer renderer2 = new VirtualSlotRenderer(width, height);
- renderer2.addStack(new ItemStack(chosen.magazine), false, true, 24, 7, null);
- renderer2.render(mouseX, mouseY, i, j);
- int x = 52;
- int y = 35 + 18;
- VirtualSlotRenderer renderer = new VirtualSlotRenderer(width, height);
- for (ItemStack craft : chosen.crafting) {
- renderer.addStack(craft, true, true, x, y, null);
- x += 18;
- }
- renderer.render(mouseX, mouseY, i, j);
- }
- } else if (stack.getItem() instanceof ItemMagazine) {
- ItemMagazine mag = (ItemMagazine) stack.getItem();
- VirtualSlotRenderer renderer = new VirtualSlotRenderer(width, height);
- int x = 52;
- int y = 35 + 18;
- for (ItemStack craft : MagazineRegistry.INSTANCE.getEntryForMagazine(mag).refillItems) {
- renderer.addStack(craft, true, true, x, y, null);
- x += 18;
- }
- renderer.render(mouseX, mouseY, i, j);
- }
- }
- }
- public boolean isPointInRegion(int x, int y, int width, int height, int pX, int pY) {
- return pX >= x && pX <= x + width && pY >= y && pY <= y + height;
- }
- @Override
- protected void actionPerformed(GuiButton button) throws IOException {
- switch (button.id) {
- case buttonLeft:
- if (currentMagazineChosenID > 0) {
- currentMagazineChosenID--;
- CounterGuns.network.sendToServer(new ChangeMagazineTypeGuiMagazineMessageToServer(currentMagazineChosenID));
- }
- break;
- case buttonRight:
- if (currentMagazineChosenID < magazinesToChoose.size() - 1) {
- currentMagazineChosenID++;
- CounterGuns.network.sendToServer(new ChangeMagazineTypeGuiMagazineMessageToServer(currentMagazineChosenID));
- }
- break;
- }
- }
- @Override
- public void onGuiClosed() {
- super.onGuiClosed();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement