Jump to content

[SOLVED] Weird behaviour of items while in expanded gui


SkylordJoel

Recommended Posts

Hi,

For my protocol block, the gui is 256x256. When I open it, the items in the top two rows of the inventory work fine. However, the bottom two rows will throw out an item if you click on any of the items in the slots. Is there a way to avoid this?

PS: I have identical code in other blocks without the expanded GUI, and they all work fine.

 

Thanks,

SkylordJoel

 

SOLUTION:

Have this as your constructor:

    public GUIWhatever(InventoryPlayer par1InventoryPlayer, TileEntityWhatever tile_entity) {

        super(new WhateverProtocol(par1InventoryPlayer, tile_entity));

        this.inventory = tile_entity;

       

        this.xSize = customSize;

        this.ySize = customSize;

    }

Link to comment
Share on other sites

By the way this is 1.6.4 and some positions are not calculated yet:

package cr0s.WarpDrive.client.gui;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;

import uedevkit.gui.GuiSimpleBase;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import cr0s.WarpDrive.WarpDrive;
import cr0s.WarpDrive.WarpDriveConfig;
import cr0s.WarpDrive.client.ClientProxy;
import cr0s.WarpDrive.common.container.ContainerProtocol;
import cr0s.WarpDrive.tile.TileEntityProtocol;

@SideOnly(Side.CLIENT)
public class GUIProtocol extends GuiSimpleBase { 
	/*TODO
	 * List of stuff:
	 * dim_getP - done
	 * dim_setP - done
	 * dim_getN - done
	 * dim_setN - done
	 * setMode - done
	 * setDistance - done
	 * setDirection - done
	 * getAttachedPlayers - done
	 * summon
	 * summonAll - done
	 * getX - done
	 * getY - done
	 * getZ - done
	 * energyRemaining For Core
	 * doJump - done
	 * getShipSize - done
	 * setBeaconFrequency - unused
	 * getDx - done
	 * getDz - dome
	 * setCoreFrequency - more like ship name, done	
	 * isInSpace - done
	 * isInHyperspace - done
	 * setTargetJumpgate*/

	int xSize = 256;
	int ySize = 256;
   
	private static final ResourceLocation furnaceGuiTextures = new ResourceLocation(WarpDrive.modid + ":textures/gui/" + "guiWarpInterface_alternate.png");//ClientProxy.warpInterfaceGui/*"textures/gui/container/furnace.png"*/);
    private TileEntityProtocol furnaceInventory;
    
    private GuiTextField front;
    private GuiTextField back;
    private GuiTextField left;
    private GuiTextField right;
    private GuiTextField up;
    private GuiTextField down;
    
    private GuiTextField distance;
    
    private GuiTextField mode;
    
    private GuiTextField direction;
    
    private GuiTextField shipName;
    //private GuiTextField beaconInput; UNUSED
    
    private char[] allowedChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
    private char[] modeChars = { '0'/*jump/long jump*/, '1'/*To hyperspace*/, '2'/*jumpgate*//*, '3'/*jump to different dimensions*/ };
    private char[] directionChars = { '0'/*up*/, '1'/*down*/, '2'/*left*/, '3'/*right*/, '4'/*forward*/, '5'/*back*/ };

    public GUIProtocol(InventoryPlayer par1InventoryPlayer, TileEntityProtocol tile_entity) {
        super(new ContainerProtocol(par1InventoryPlayer, tile_entity));
        this.furnaceInventory = tile_entity;
    }
    
    int grey = 4210752;
    
    int sizex = -14;//10-24
    int sizey = -12;
    
    int dimensionx = -25;
    int dimensiony = 132;
    
    int blocksx;
    int blocksy;
    
    int coord0x;
    int coord0y;
    
    int pixelsPerWord = 10;
    
    String size0 = "Amount of blocks from Core to be moved: ";
    
    
    /**
     * Draw the foreground layer for the GuiContainer (everything in front of the items)
     */
    protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
        String s = this.furnaceInventory.isInvNameLocalized() ? this.furnaceInventory.getInvName() : I18n.getString(this.furnaceInventory.getInvName());
        this.fontRenderer.drawString(s, this.xSize / 2 - this.fontRenderer.getStringWidth(s) / 2, 6, 4210752);
        this.fontRenderer.drawString(I18n.getString("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
        
        String size1 = furnaceInventory.getFront() + ", Right: " + furnaceInventory.getRight() + ", Up: " + furnaceInventory.getUp();
	    String size2 = "Back: " + furnaceInventory.getBack() + ", Left: " + furnaceInventory.getLeft() + ", Down: " + furnaceInventory.getDown();

	    String dimension = furnaceInventory.currentDimension();
	    
	    String blocks = "Ship Size: " + String.valueOf(furnaceInventory.getShipSize());
	    
	    String coord0 = "Coordinates: ";
	    String coord1 = "X: " + String.valueOf(furnaceInventory.getCoreX());
	    String coord2 = "Y: " + String.valueOf(furnaceInventory.getCoreY());
	    String coord3 = "Z: " + String.valueOf(furnaceInventory.getCoreZ());
	    
	    String coord4 = "Destination Coordinates: ";
	    String coord5 = "X: " + String.valueOf(furnaceInventory.getDestX());
	    //String coord6 = "Y: " + String.valueOf(furnaceInventory.getDestY());
	    String coord7 = "Z: " + String.valueOf(furnaceInventory.getDestZ());
        
        write(size0, sizex, sizey, grey); //Title
        write(size1, sizex, sizey + pixelsPerWord, grey); //setP
        write(size2, sizex, sizey + (2 * pixelsPerWord), grey); //setN
        
        write(dimension, dimensionx, dimensiony, grey);
        
        write(coord0, coord0x, coord0y, grey);
        write(coord1, coord0x + pixelsPerWord, coord0y, grey);
        write(coord2, coord0x + 2 * (pixelsPerWord), coord0y, grey);
        write(coord3, coord0x + 3 * (pixelsPerWord), coord0y, grey);
        
        write(coord4, coord0x + 5 * (pixelsPerWord), coord0y, grey);
        write(coord5, coord0x + 6 * (pixelsPerWord), coord0y, grey);
        write(coord7, coord0x + 7 * (pixelsPerWord), coord0y, grey);
        
        write(blocks, blocksx, blocksy, grey);
        
        front.drawTextBox();
        back.drawTextBox();
        left.drawTextBox();
        right.drawTextBox();
        up.drawTextBox();
        down.drawTextBox();
        
        distance.drawTextBox();
        
        mode.drawTextBox();
        
        direction.drawTextBox();
        
        shipName.drawTextBox();
        
        //beaconInput.drawTextBox(); UNUSED
    }

    /**
     * Draw the background layer for the GuiContainer (everything behind the items)
     */
    protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) {
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.getTextureManager().bindTexture(furnaceGuiTextures);
        int k = (this.width - this.xSize) / 2;
        int l = (this.height - this.ySize) / 2;
        this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
        
        int i1;
        
        //FLAME - DON'T NEED
        /*if (this.furnaceInventory.isBurning())
        {
            i1 = this.furnaceInventory.getBurnTimeRemainingScaled(12);
            this.drawTexturedModalRect(k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 2);
        }*/
        
        //GIANT ARROW - DON'T NEED
        /*i1 = this.furnaceInventory.getCookProgressScaled(24);
        this.drawTexturedModalRect(k + 79, l + 34, 176, 14, i1 + 1, 16);*/
    }
    
    @Override
    public void initGui() {
    	super.initGui();
    	buttonList.clear();
    	
    	Keyboard.enableRepeatEvents(true);
	    
	    //int biX = 0; UNUSED
	    //int biY = 0; UNUSED
    	
	    int frontX = 0; //TODO
	    int frontY = 0;
	    
	    int diX = 0;
	    int diY = 0;
	    
	    int dirX = 0;
	    int dirY = 0;
	    
	    int moX = 0;
	    int moY = 0;
	    
	    int sNX = 58;
	    int sNY = -33;
	    
	    int inputLength = 30;
	    int inputWidth = 20;
	    
	    //applyBasicAttributes(beaconInput); UNUSED
	    
	    shipName = new GuiTextField(this.fontRenderer, sNX, sNY, inputLength * 2, inputWidth);
	    shipName.setMaxStringLength(10);
	    
	    direction = new GuiTextField(this.fontRenderer, dirX, dirY, inputLength, inputWidth);
	    direction.setMaxStringLength(1);
	    
	    mode = new GuiTextField(this.fontRenderer, moX, moY, inputLength, inputWidth);
	    mode.setMaxStringLength(1);

	    distance = new GuiTextField(this.fontRenderer, diX, diY, inputLength, inputWidth);
	    distance.setMaxStringLength(3);
	    
    	front = new GuiTextField(this.fontRenderer, frontX, frontY, inputLength, inputWidth);
    	front.setMaxStringLength(3);
    	
    	back = new GuiTextField(this.fontRenderer, frontX, frontY + pixelsPerWord, inputLength, inputWidth);
    	back.setMaxStringLength(3);
    	
    	left = new GuiTextField(this.fontRenderer, frontX, frontY + (2 * pixelsPerWord), inputLength, inputWidth);
    	left.setMaxStringLength(3);
    	
    	right = new GuiTextField(this.fontRenderer, frontX, frontY + (3 * pixelsPerWord), inputLength, inputWidth);
    	right.setMaxStringLength(3);
    	
    	up = new GuiTextField(this.fontRenderer, frontX, frontY + (4 * pixelsPerWord), inputLength, inputWidth);
    	up.setMaxStringLength(3);
    	
    	down = new GuiTextField(this.fontRenderer, frontX, frontY + (5 * pixelsPerWord), inputLength, inputWidth);
    	down.setMaxStringLength(3);
    	
	    applyBasicAttributes(front);
	    applyBasicAttributes(back);
	    applyBasicAttributes(right);
	    applyBasicAttributes(left);
	    applyBasicAttributes(up);
	    applyBasicAttributes(down);
	    
	    applyBasicAttributes(distance);
	    
	    applyBasicAttributes(mode);
	    
	    applyBasicAttributes(direction);
	    
	    applyBasicAttributes(shipName);
    	
    	//beaconInput = new GuiTextField(this.fontRenderer, biX, biY, inputLength, inputWidth); UNUSED
    	//beaconInput.setMaxStringLength(2); UNUSED
    	
    	/**/buttonList.add(new GuiButton(0/*button number, maybe for mod, else gui*/, guiLeft - 26/*Location in relation to left in pixels*/, guiTop + 177/*Location in relation to top in pixels*/, 30/*Length in pixels*/, 20/*Height in pixels*/, "Jump"/*Text on button*/));
    	/**/buttonList.add(new GuiButton(1/*button number, maybe for mod, else gui*/, guiLeft - 26/*Location in relation to left in pixels*/, guiTop + 157/*Location in relation to top in pixels*/, 60/*Length in pixels*/, 20/*Height in pixels*/, "Summon All"/*Text on button*/));
    	buttonList.add(new GuiButton(2, guiLeft + 4/*217: -40*/, guiTop + 177/*227: -45*/, 30, 20, "Wiki"));
    }
    
    public void applyBasicAttributes(GuiTextField field) {
    	//if(field != null) {
	    	field.setEnableBackgroundDrawing(true);
	    	field.setFocused(false);
	    	field.setCanLoseFocus(true);
    	//}
	}

	@Override
    protected void keyTyped(char par1, int par2) {
		if(anyTextBoxFocused()) {
			if(par1 != 27) {
				if(shipName.textboxKeyTyped(par1, par2)) {
					shipName();
				}

				if(isValidChar(par1)) {
			//super.keyTyped(par1, par2);
					if(front.textboxKeyTyped(par1, par2)) {
						simpleTextPacket("WarpDrive_F", this.front, 4);
					} else if(back.textboxKeyTyped(par1, par2)) {
						simpleTextPacket("WarpDrive_B", this.back, 4);
					} else if(left.textboxKeyTyped(par1, par2)) {
						simpleTextPacket("WarpDrive_L", this.left, 4);
					} else if(right.textboxKeyTyped(par1, par2)) {
						simpleTextPacket("WarpDrive_R", this.right, 4);
					} else if(up.textboxKeyTyped(par1, par2)) {
						simpleTextPacket("WarpDrive_U", this.up, 4);
					} else if(down.textboxKeyTyped(par1, par2)) {
						simpleTextPacket("WarpDrive_D", this.down, 4);
					} else if(distance.textboxKeyTyped(par1, par2)) {
						simpleTextPacket("WarpDrive_Dis", this.distance, 4);
					} else if(isValidModeChar(par1)) {
						if(mode.textboxKeyTyped(par1, par2)) {
							modeTextPacket("WarpDrive_M", this.mode, 4);
						} else if(isValidDirectionChar(par1)) {
							if(direction.textboxKeyTyped(par1, par2)) {
								directionTextPacket("WarpDrive_Dir", this.direction, 4);
							}
						}
			//} else if(beaconInput.textboxKeyTyped(par1, par2)) {UNUSED
				//simpleTextPacket("WarpDrive_Protocol", this.beaconInput.getText().getBytes())); UNUSED
					}
				} else {
					super.keyTyped(par1, par2);
				}
			}
		} else if (par1 == 27) {
			mc.thePlayer.closeScreen();
		}
	}

    public boolean anyTextBoxFocused() {
		return front.isFocused() || back.isFocused() || left.isFocused() || right.isFocused() || up.isFocused() || down.isFocused() || distance.isFocused() || mode.isFocused() || direction.isFocused() || shipName.isFocused();
	}

	public void shipName() {
		ByteArrayOutputStream bos = new ByteArrayOutputStream(shipName.getText().length());
		DataOutputStream output = new DataOutputStream(bos);

		try {
			String f = shipName.getText();

			output.writeUTF(f);
		} catch(Exception e) {
			e.printStackTrace();
		}

		Packet250CustomPayload packet = new Packet250CustomPayload();
		packet.channel = "WarpDrive_SN";
		packet.data = bos.toByteArray();
		packet.length = bos.size();

		this.mc.thePlayer.sendQueue.addToSendQueue(packet);
	}

	public void directionTextPacket(String channel, GuiTextField field, int bytes) {
		ByteArrayOutputStream bos = new ByteArrayOutputStream(bytes);
		DataOutputStream output = new DataOutputStream(bos);

		try {
			String f = field.getText();
			int fI = Integer.parseInt(f);

			output.writeInt(fI);
		} catch(Exception e) {
			e.printStackTrace();
		}

		Packet250CustomPayload packet = new Packet250CustomPayload();
		packet.channel = channel;
		packet.data = bos.toByteArray();
		packet.length = bos.size();

		this.mc.thePlayer.sendQueue.addToSendQueue(packet);
	}

	private boolean isValidDirectionChar(char par1) {
    	for(int x = 0; x <= this.directionChars.length; x++) {
    		if(par1 == this.directionChars[x]) {
    			return true;
    		}
    	}
		return false;
	}

	private boolean isValidModeChar(char par1) {
    	for(int x = 0; x <= this.modeChars.length; x++) {
    		if(par1 == this.modeChars[x]) {
    			return true;
    		}
    	}
    	return false;
    }

	public void modeTextPacket(String channel, GuiTextField field, int lengthOfBytesInField) {
		ByteArrayOutputStream bos = new ByteArrayOutputStream(lengthOfBytesInField);
		DataOutputStream output = new DataOutputStream(bos);

		try {
			String f = field.getText();
			int fI = Integer.parseInt(f);

			output.writeInt(fI);
		} catch(Exception e) {
			e.printStackTrace();
		}

		Packet250CustomPayload packet = new Packet250CustomPayload();
		packet.channel = channel;
		packet.data = bos.toByteArray();
		packet.length = bos.size();

		this.mc.thePlayer.sendQueue.addToSendQueue(packet);
	}

	public void simpleTextPacket(String channel, GuiTextField field, int lengthOfBytesInField) {
		ByteArrayOutputStream bos = new ByteArrayOutputStream(lengthOfBytesInField);
		DataOutputStream output = new DataOutputStream(bos);

		try {
			String f = field.getText();
			int fI = Integer.parseInt(f);

			output.writeInt(fI);
		} catch(Exception e) {
			e.printStackTrace();
		}

		Packet250CustomPayload packet = new Packet250CustomPayload();
		packet.channel = channel;
		packet.data = bos.toByteArray();
		packet.length = bos.size();

		this.mc.thePlayer.sendQueue.addToSendQueue(packet);
	}

	@Override
    protected void mouseClicked(int x, int y, int buttonClicked) {
    	super.mouseClicked(x, y, buttonClicked);
    	
    	this.front.mouseClicked(x, y, buttonClicked);
    	this.back.mouseClicked(x, y, buttonClicked);
    	this.left.mouseClicked(x, y, buttonClicked);
    	this.right.mouseClicked(x, y, buttonClicked);
    	this.up.mouseClicked(x, y, buttonClicked);
    	this.down.mouseClicked(x, y, buttonClicked);
    	
    	this.distance.mouseClicked(x, y, buttonClicked);
    	
    	this.mode.mouseClicked(x, y, buttonClicked);
    	
    	this.direction.mouseClicked(x, y, buttonClicked);
    	
    	this.shipName.mouseClicked(x, y, buttonClicked);
    	
    	//this.beaconInput.mouseClicked(x, y, buttonClicked); UNUSED
    }
    
    private boolean isValidChar(char par1) {
    	for(int x = 0; x <= this.allowedChars.length; x++) {
    		if(par1 == this.allowedChars[x]) {
    			return true;
    		}
    	}
    	return false;
    }
    
    @Override
    public void updateScreen() {
    	this.front.updateCursorCounter();
    	this.back.updateCursorCounter();
    	this.left.updateCursorCounter();
    	this.right.updateCursorCounter();
    	this.up.updateCursorCounter();
    	this.down.updateCursorCounter();
    	
    	this.distance.updateCursorCounter();
    	
    	this.mode.updateCursorCounter();
    	
    	this.direction.updateCursorCounter();
    	
    	this.shipName.updateCursorCounter();
    	
    	//this.beaconInput.updateCursorCounter(); UNUSED
    }
    
    @Override
    protected void actionPerformed(GuiButton button) {
    	switch(button.id) {
    		case 0:
    			furnaceInventory.doJump();
    			System.out.println(furnaceInventory.getCoreFrequency() + " jumped from coordinates " + String.valueOf(furnaceInventory.getCoreX()) + ", " + String.valueOf(furnaceInventory.getCoreY()) + ", " + String.valueOf(furnaceInventory.getCoreZ()));
    			break;
    		case 1:
    			furnaceInventory.setSummonAllFlag(true);
    			break;
    			//System.out.println("Clicked!");//ACTION PERFORMED ON BUTTON CLICK
    		case 2:
    			openURL("https://sites.google.com/site/spaceageminecraft/wiki/blocks/warp-interface");
    	}
    }
    
    @Override
    public void onGuiClosed() {
    	super.onGuiClosed();
    	Keyboard.enableRepeatEvents(false);
    }
    
    @Override
    public void drawScreen(int par1, int par2, float par3) {
    	super.drawScreen(par1, par2, par3);
    	this.front.drawTextBox();
    	this.back.drawTextBox();
    	this.left.drawTextBox();
    	this.right.drawTextBox();
    	this.up.drawTextBox();
    	this.down.drawTextBox();
    	
    	this.distance.drawTextBox();
    	
    	this.mode.drawTextBox();
    	
    	this.direction.drawTextBox();
    	
    	this.shipName.drawTextBox();
    }
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • So I saw that mixin is shipped as a library with forge, but is it available for 1.7.10 ?  
    • So I've read the EULA, and lets be straight...     If I split my modpack(of my mods, yeah I'm nuts) into several(many) individual mods(like just one boss) with minor additions(plus not working together), then have a complete/modpack version on patreon/onlyfans having each addon work together... Would people buy my idea?
    • German A1 – C1, TestDAF, Goethe B1, B2, C1, C2, valid GOETHE certificate German A1 – C1, TestDAF, Goethe B1, B2, C1, C2, valid GOETHE certificate(+27(838-80-8170
    • Done, it still crashed. New log https://paste.ee/p/kYv6e
    • I am migrating a mod from 1.16.5 to 1.20.2 The version for 1.16.5 can be found here https://github.com/beothorn/automataCraft For the block called automata_start, it uses TileEntities and has blockstates, model/block and textures on json files. This is currently working fine on 1.16.5 https://github.com/beothorn/automataCraft/tree/master/src/main/resources/assets/automata For 1.20.2 I migrated the logic from TileEntities to BlockEntity. The mod is working fine. All blocks and Items are working with the correct textures except for the textures for each state of the automata_start block. No changes where made to the json files. This is the branch I am working on (there were some refactorings, but all is basically the same): https://github.com/beothorn/automataCraft/tree/1_20/src/main/resources/assets/automata The only difference I can think that may be related is that i had to implement createBlockStateDefinition on the BaseEntityBlock: https://github.com/beothorn/automataCraft/blob/1_20/src/main/java/br/com/isageek/automata/automata/AutomataStartBlock.java#L43 This is driving me crazy. I know the jsons are being loaded as I put a breakpoint at `net.minecraft.client.resources.model.ModelBakery#loadModel` and I can see BlockModelDefinition.fromJsonElement being called with automata_start. I also printed the state from the arguments of the tick function call and they look correct (https://github.com/beothorn/automataCraft/blob/1_20/src/main/java/br/com/isageek/automata/automata/Ticker.java#L32 ): blockState Block{automata:automata_start}[state=loadreplaceables] In game, all I see is the no textures. I think it is weird it is not the "missing texture" texture so I think it may be related to the material, but I had no success tweaking it (https://github.com/beothorn/automataCraft/blob/1_20/src/main/java/br/com/isageek/automata/automata/AutomataStartBlock.java#L37).   public static final Property<AutomataStartState> state = EnumProperty.create("state", AutomataStartState.class); private final AtomicReference<RegistryObject<BlockEntityType<?>>> blockEntityType; private final Map<String, RegistryObject<Block>> registeredBlocks; public AutomataStartBlock( final AtomicReference<RegistryObject<BlockEntityType<?>>> blockEntityType, final Map<String, RegistryObject<Block>> registeredBlocks ) { super(BlockBehaviour.Properties.of().mapColor(MapColor.STONE).strength(1.5F, 6.0F)); this.blockEntityType = blockEntityType; this.registeredBlocks = registeredBlocks; this.registerDefaultState(this.getStateDefinition().any().setValue(state, AutomataStartState.LOAD_REPLACEABLES)); } @Override protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateBuilder) { stateBuilder.add(state); }     So my cry for help is, anyone has any ideas? Is there a way to easily debug this, for example somewhere where I can list the textures for a given state, or make sure this is loaded?   Thanks in advance for the hints
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.