Jump to content

[1.6.4] Custom GUI with dynamic mapping *help*


hugo_the_dwarf

Recommended Posts

The title makes it sound a bit confusing, I'm trying to make a special block for my Mod that when acquired and placed will allow the player to "build" a base.

I'm still learning and have a slim grasp on TileEntities, Containers, and NBT so I'm more or less mucking around hoping things work.

 

Anyways What I want is that when you right-click the block you can set "locations" that will be 'filled' when run (and enough resources)

 

right now I have the TileEntity, GUI, Container and the GUI opening. But after you set the locations for blocks to be placed you can't see it ever again (also I'm having trouble figuring out how to save it via NBT)

 

So what works:

  • Gui opens
  • Gui buttons work
  • Gui text displays information
  • Locations can be set with Gui
  • Locations can be cleared (all of them) with Gui
  • TileEntity can place blocks using Locations

 

What I want to work (or get working/do)

  • Gui shows list/map of locations that can be clicked for removal/editing
  • Block information can be stored with a location, and picked by player (use wood planks for 123,45,-200. But use cobble at 122,44,-200)
  • Needs to have blocks in storage to use them and decrease the stacks (I can probably figure this one out, if I can get it to use it's inventory)
  • Saves list and loads it so persists through client/server close, reopen
  • Turns into an Entity with same Gui so it can be attacked(bit out my league but if know how or tutorials would be appreciated)

 

But the main thing is I want a map that is basically a cut out matrix based on the Y value. That can be clicked to make changes to the locations.

 

Code:

public class GuiBaseBuilder extends GuiContainer
{
public static final ResourceLocation texture = 
		new ResourceLocation(Main.MODID.toLowerCase(), "textures/gui/blankGui.png");

private TileEntityBaseBuilder bb;
private int cw = 15; //control Width
private int ch = 15; //control Height
private int x = 0;
private int y = 0;
private int z = 0;

public GuiBaseBuilder(Container par1Container) 
{
	super(par1Container);
}

public GuiBaseBuilder(InventoryPlayer invPlayer, TileEntityBaseBuilder entity) 
{
	super(new ContainerBaseBuilder(invPlayer, entity));
	xSize = 176;
	ySize = 165;
	bb = entity;
}	

@Override
protected void drawGuiContainerBackgroundLayer(float f, int i, int j) 
{
	int posX = (this.width) / 2;//middle of the GUI image
	int posY = (this.height) / 2;//middle of the GUI image
	int xBuffer = 29;//just my own margin for drawing buttons

	GL11.glColor4f(1F, 1F, 1F, 1F);
	Minecraft.getMinecraft().renderEngine.bindTexture(texture);
	drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);

	this.buttonList.clear();
	//Start with main control buttons		
	this.buttonList.add(new GuiButton(0, posX + xBuffer - 60, posY - 80, 60, 20, "Start/Stop")); //right now does nothing, as it was hit and miss
	this.buttonList.add(new GuiButton(1, posX + xBuffer, posY - 80, 25, 20, "Add")); //Adds the location based on x,y,z
	this.buttonList.add(new GuiButton(8, posX + xBuffer + 25, posY - 80, 25, 20, "Clear")); //Clears all the locations

	//Location controls
	this.buttonList.add(new GuiButton(2, posX + xBuffer, posY - 50, cw, ch, "<"));//X left
	this.buttonList.add(new GuiButton(3, posX + xBuffer + cw, posY - 50, cw, ch, ">"));//X right

	this.buttonList.add(new GuiButton(6, posX + xBuffer, posY - 35, cw, ch, "Y+"));//Y up
	this.buttonList.add(new GuiButton(7, posX + xBuffer + cw, posY - 35, cw, ch, "Y-"));//Y down

	this.buttonList.add(new GuiButton(4, posX + xBuffer, posY - 20, cw, ch, "^"));//Z up confusing should be 'forward'
	this.buttonList.add(new GuiButton(5, posX + xBuffer + cw, posY - 20, cw, ch, "v"));//Z down confusing should be 'back'

	//Visual information on location
	this.drawString(fontRenderer, "X: "+(x+bb.xCoord)+" offSet: "+x, posX + xBuffer - 90, posY - 38, 0xFFFFFF);
	this.drawString(fontRenderer, "Y: "+(y+bb.yCoord)+" offSet: "+y, posX + xBuffer - 90, posY - 28, 0xFFFFFF);
	this.drawString(fontRenderer, "Z: "+(z+bb.zCoord)+" offSet: "+z, posX + xBuffer - 90, posY - 18, 0xFFFFFF);
}

...snip...

}

Custom methods and update are at the bottom

public class TileEntityBaseBuilder extends TileEntity implements IInventory
{

private ItemStack[] inventory = new ItemStack[9];
private ArrayList<Vector3f> locations = new ArrayList<Vector3f>();
private int CD_TIME = 35;
private int cd = CD_TIME;
private boolean onOff = false;

@Override
public void closeChest(){}

@Override
public void writeToNBT(NBTTagCompound par1nbtTagCompound) 
{
	super.writeToNBT(par1nbtTagCompound);

	NBTTagList list = new NBTTagList();

	for(int i = 0; i < getSizeInventory(); i++) 
	{
		  ItemStack itemstack = getStackInSlot(i);
		  if(itemstack != null) 
		  {
			  NBTTagCompound item = new NBTTagCompound();
			  
			  item.setByte("SlotBaseBuild", (byte) i);
			  itemstack.writeToNBT(item);
			  
			  list.appendTag(item);
		  }
		}
	par1nbtTagCompound.setTag("ItemsBaseBuild", list);
}

@Override
public void readFromNBT(NBTTagCompound par1nbtTagCompound) 
{
	super.readFromNBT(par1nbtTagCompound);

	NBTTagList list = par1nbtTagCompound.getTagList("ItemsBaseBuild");

	  for(int i = 0; i < list.tagCount(); i++) {
	        NBTTagCompound item = (NBTTagCompound) list.tagAt(i);
	        int slot = item.getByte("SlotBaseBuild");

	        if(slot >= 0 && slot < getSizeInventory()) {
	          setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(item));
	        }
	  }
}

@Override
public ItemStack decrStackSize(int slot, int count) 
{
	ItemStack itemstack = getStackInSlot(slot);

	if(itemstack != null) 
	{
		if(itemstack.stackSize <= count) 
		{
			setInventorySlotContents(slot, null);
		} 
		else 
		{
			itemstack = itemstack.splitStack(count);
			onInventoryChanged();
		}
	}
	return itemstack;
}

@Override
public String getInvName() 
{
	return "BaseBuilder";
}

@Override
public int getInventoryStackLimit() 
{
	return 64;
}

@Override
public int getSizeInventory() 
{
	return inventory.length;
}

@Override
public ItemStack getStackInSlot(int i) 
{
	return inventory[i];
}

@Override
public ItemStack getStackInSlotOnClosing(int slot) 
{
	ItemStack itemstack = getStackInSlot(slot);
	setInventorySlotContents(slot, null);
	return itemstack;
}

@Override
public boolean isInvNameLocalized() 
{
	return true;
}

@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) 
{
	return true;
}

@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) 
{
	return entityplayer.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <= 64;
}

@Override
public void openChest(){}

@Override
public void setInventorySlotContents(int i, ItemStack itemstack) 
{
	inventory[i] = itemstack;

	if(itemstack != null && itemstack.stackSize > getInventoryStackLimit()) 
	{
		itemstack.stackSize = getInventoryStackLimit();
	}
	onInventoryChanged();
}

@Override
public boolean canUpdate() 
{
	return true;
}

@Override
public void updateEntity() 
{
	if (cd == 0 /*&& onOff*/)
	{
		cd = CD_TIME;
		for(Vector3f v : locations)			
		{			
			getWorldObj().setBlock((int)v.x, (int)v.y, (int)v.z, Block.blockClay.blockID);				
		}
		//switchOnOff();
	}
	else cd--;
}

public void switchOnOff()
{
	onOff = !onOff;
	if(onOff)System.out.println("on");
	else System.out.println("off");
	System.out.println(onOff);
}

public void clearList()
{
	locations.clear();
}

public void addLocation(float i, float j, float k)
{
	if (i + xCoord == xCoord && j + yCoord == yCoord && k + zCoord == zCoord)return;
	Vector3f location = new Vector3f(i + xCoord, j + yCoord, k + zCoord);
	if (locations.size() > 0)
	{
		for (int l = 0;l < locations.size();l++)
		{
			if (locations.get(l).equals(location))
			{
				System.out.println("Same Location Found, replacing");
				locations.set(l, location);
				System.out.println("replaced: "+ location);
				return;
			}				
		}			
	}
	locations.add(location);
	System.out.println("Location added");
	System.out.println(location);
}

Link to comment
Share on other sites

OK so in your writeToNBT() and readFromNBT() you aren't reading or writing the locations so that will not be saved if they are unloaded.

 

Secondly GUIs are client side only so you need a packet send a packet to the client saying what the locations are so you can show then on the GUI.

 

Also, I can't see the rest of your GUI class, but from what I can see you are doing the TileEntity stuff client side. If you could add the rest of your GuiBaseBuilder it would help.

Link to comment
Share on other sites

Ok, so I guess I can try to muck around with NBTTagCompunds and see if I can mash a Vector3f in them, might have to make my own Class thinking on it if I want to store a Block ID:Meta with a location aswell (so if I make a new class for that what would I have to Extend/Implement?)

 

Oh? Packets are something that are still a mystery to me I had *assumed* since the GUI class gets passed and instance of the TileEntity that it was being altered in realtime, I know my tests allow me to use commands and make changes in the TileEntity from the GUI so somehow my wrong way is partially working (hit and miss)

 

And here is the entire GUI class, the stuff I snipped out before was two methods, I don't even know if I need the Mouse Clicked method, I was looking at someones GUI tutorial trying to find how to add buttons and use them.

 

 

All of the GuiClass excluding imports*

public class GuiBaseBuilder extends GuiContainer
{
public static final ResourceLocation texture = 
		new ResourceLocation(Main.MODID.toLowerCase(), "textures/gui/blankGui.png");

private TileEntityBaseBuilder bb;
private int cw = 15; //control Width
private int ch = 15; //control Height
private int x = 0;
private int y = 0;
private int z = 0;

public GuiBaseBuilder(Container par1Container) 
{
	super(par1Container);
}

public GuiBaseBuilder(InventoryPlayer invPlayer, TileEntityBaseBuilder entity) 
{
	super(new ContainerBaseBuilder(invPlayer, entity));
	xSize = 176;
	ySize = 165;
	bb = entity;
}	

@Override
protected void drawGuiContainerBackgroundLayer(float f, int i, int j) 
{
	int posX = (this.width) / 2;//middle of the GUI image
	int posY = (this.height) / 2;//middle of the GUI image
	int xBuffer = 29;//just my own margin for drawing buttons

	GL11.glColor4f(1F, 1F, 1F, 1F);
	Minecraft.getMinecraft().renderEngine.bindTexture(texture);
	drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);

	this.buttonList.clear();
	//Start with main control buttons		
	this.buttonList.add(new GuiButton(0, posX + xBuffer - 60, posY - 80, 60, 20, "Start/Stop")); //right now does nothing, as it was hit and miss
	this.buttonList.add(new GuiButton(1, posX + xBuffer, posY - 80, 25, 20, "Add")); //Adds the location based on x,y,z
	this.buttonList.add(new GuiButton(8, posX + xBuffer + 25, posY - 80, 25, 20, "Clear")); //Clears all the locations

	//Location controls
	this.buttonList.add(new GuiButton(2, posX + xBuffer, posY - 50, cw, ch, "<"));//X left
	this.buttonList.add(new GuiButton(3, posX + xBuffer + cw, posY - 50, cw, ch, ">"));//X right

	this.buttonList.add(new GuiButton(6, posX + xBuffer, posY - 35, cw, ch, "Y+"));//Y up
	this.buttonList.add(new GuiButton(7, posX + xBuffer + cw, posY - 35, cw, ch, "Y-"));//Y down

	this.buttonList.add(new GuiButton(4, posX + xBuffer, posY - 20, cw, ch, "^"));//Z up confusing should be 'forward'
	this.buttonList.add(new GuiButton(5, posX + xBuffer + cw, posY - 20, cw, ch, "v"));//Z down confusing should be 'back'

	//Visual information on location
	this.drawString(fontRenderer, "X: "+(x+bb.xCoord)+" offSet: "+x, posX + xBuffer - 90, posY - 38, 0xFFFFFF);
	this.drawString(fontRenderer, "Y: "+(y+bb.yCoord)+" offSet: "+y, posX + xBuffer - 90, posY - 28, 0xFFFFFF);
	this.drawString(fontRenderer, "Z: "+(z+bb.zCoord)+" offSet: "+z, posX + xBuffer - 90, posY - 18, 0xFFFFFF);
}

@Override
protected void mouseClicked(int par1, int par2, int par3) 
{
	super.mouseClicked(par1, par2, par3);
}

@Override
protected void actionPerformed(GuiButton button) 
{		
	switch (button.id)
	{
	case 0:
		bb.switchOnOff();
		break;
	case 1:
		bb.addLocation(x, y, z);
		break;
	case 2:
		x--;
		break;
	case 3:
		x++;
		break;
	case 4:
		z--;
		break;
	case 5:
		z++;
		break;
	case 6:
		y++;
		break;
	case 7:
		y--;
		break;
	case 8:
		bb.clearList();
		break;
	}
}

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

    • Hey today I was trying to play in 1.21 modpack that I made on fabric (my version of fabric is in 0.16.0) with this list of mods : - Entity Model Features (by traben_0) - Entity Texture Features (by traben_0) - Advanced Chat (by Wesley8081) - Ambient Environment (by Jaredlll08) - Ambient Souds 6 (by CreativeMD) - Animatica (by FoundationGames) - Armor Statues (by Fuzs) - Auto HUD (by Crendgrim) - Bad Packets (by badasintended) - Balm (by BlayTheNinth) - Better Beds (by Motschen) - Better Chunk Loading (by someaddon) - Better Compatibility Checker (by Gaz-) - Better FPS [Render Distance] (by someaddon) - Better Ping Display (by Quintinity) - Better Statistics Screen (by TheCSDev) - Better Armor HUD (by efekos) - Better F3 ( by cominixo) - Blur + (by Motschen) - Bobby (by Johni0702) - Cat Jam (by shmove) - Catalogue (by MrCrayfish) - Chat Heads (by dzwdz) - Cherished Worlds (by TheIllusiveC4) - Chunk Sending (by someaddon) - Chunks Fade In (by kerudion) - Chunky (by pop4959) - Cloth Config (by shedaniel) - Clumps (by Jaredlll08) - Cobweb (CrystalSpider) - Collective (by Serilum) - Configured (by MrCrayfish) - Connectivity (by someaddon) - Continuity (by Pepper_Bell) - Creative Core (by CreativeMD) - Cupboard (by someaddon) - Cut Through (by Fuzs) - Dark Loading Screen (by Neecko5b84) - Debugify (by XanderIsDev) - Double Doors (by Serilum) - Dynamic FPS (by juliand665) - Dynamic Lights (by Tschipcraft) - Easy Anvils (by Fuzs) - Easy Magic (by Fuzs) - Easy Shulker Boxes (by Fuzs) - Eating Animation (by theone-ss) - Enhanced Attack Indicator (by Mineash) - Enhanced Block Entities (by FoundationGames) - Enhanced Visuals (by CreativeMD) - Entity Culling (by tr7zw) - Environmental Water (by AgentMindStorm) - Essential (by SparkUniverse_) - Extra Thicc Packets (by JaselUmena) - Fabric (by modmuss50) - Fabric Language Kotlin (by modmuss50) - Falling Leaves (by RandomMcSomethin) - Fancy Block Particles (by Hantonik) - Fancy Health Bar (by efekos) - Farsight (by someaddon) - Fast IP Ping (by Fallen_Breath) - Ferrite Core (by  malte0811) - Fish On The Line (by Serilum) - Fix GPU Memory Leak  (by someaddon) - Forge Config API Port (by Fuzs) - FPS Reducer (by bre2el) - Freecam (by hashalite) - Fzzy Config (by fzzyhmstrs) - Get It Together (by bl4ckscor3) - Global Packs (by JTK222) - Harvest With Ease (by CrystalSpider) - Ichuntil Util (by iChun) - Immediately Fast (by RaphilMC) - Immersive UI (by SSKirillSS) - Indium (by comp500) - Inventory HUD+ (by dmitrylovin) - Iris Shaders (by coderbot) - Item Physic Full (by CreativeMD) - Jade (by Snownee) - Journey Map (by techbrew) - Just Enough Breeding (by Christofmeg) - Just Enough Items (by mezz) - Just Enough Professions (by Mrbysco) - Language Reload (by Jerozgen) - Leaves Be Gone (by Fuzs) - Let Me Despawn (by frikinjay) - Let Sleeping Dogs Lie (by iChun) - Lithium (by JellySquid) - Loading Backgrounds (by Lupin) - Mineblock's Repeated Utilities (by itsmineblock11) - Menulogue (by MrCrayfish) - Mob Plaques (by Fuzs) - Mod Menu (by Prospector) - Model Gap Fix (by MehVahdJukaar) - Mouse Tweaks (by YaLTeR) - Nether Portal Fix (by BlayTheNinth) - Nicer Skies (by ztereohype) - Noisium (by Steveplays28) - Not Enough Animations (by tr7zw) - Opti GUI (by opekope2) - Packet Fixer (by TonimatasDEV) - Particle Core (by fzzyhmstrs) - Passive Shields (by Serilum) - Pick Up Notifier (by Fuzs) - Ping Wheel (by LukenSkyne) - Puzzle (by Motschen) - Puzzles LIB (by Fuzs) - Reese's Sodium Options (by FlashyReese) - Resource Pack Overrides (by Fuzs) - Server Country Flags (by khajiitos) - Server Performance (by someaddon) - Skin Layer 3D (by tr7zw) - Sodium (by JellySquid) - Sodium Extra (by FlashyReese) - Sodium Shadowy Path Blocks (by Rynnavinx) - Sound Physics Remastered (by henkelmax) - Sounds (by itsmineblock11) - Spark (by lucko) - Stack Refill (by Serilum) - Structure Essentials (by someaddon) - TCD Commons API (by TheCSDev) - Text Placeholder API (by Patbox) - Villager Names (by Serilum) - Visual Overhaul (by Motschen) - Visual Workbench (by Fuzs) - Visuality (by PinkGoosik) - Wakes (by Goby56) - Wavey Capes (by tr7zw) - YDM'S Weapon Master  (by YourDailyModderx) - Yet Another Config LIB (by XanderIsDev) - Zoomify (by XanderIsDev) And When I load it it work, I can create a world and even let him open forever at least I didn't move cause if so the game just crash and tell me this message :   Encountered an unexpected exception net.minecraft.class_148: Ticking entity at net.minecraft.server.MinecraftServer.method_3813(MinecraftServer.java:1025) at net.minecraft.server.MinecraftServer.method_3748(MinecraftServer.java:912) at net.minecraft.class_1132.method_3748(class_1132.java:114) at net.minecraft.server.MinecraftServer.method_29741(MinecraftServer.java:697) at net.minecraft.server.MinecraftServer.method_29739(MinecraftServer.java:281) at java.base/java.lang.Thread.run(Thread.java:1583) Caused by: java.lang.NullPointerException: Cannot invoke "net.minecraft.class_4706.isEmpty()" because "tickets" is null at net.minecraft.class_3204.canNoneExpire(class_3204.java:1034) at net.minecraft.class_3204.handler$dln000$lithium$unregisterExpiringTicket(class_3204.java:1075) at net.minecraft.class_3204.method_17645(class_3204.java:172) at net.minecraft.class_3204.method_17292(class_3204.java:194) at net.minecraft.class_3215.method_17300(class_3215.java:443) at com.betterchunkloading.chunk.PlayerChunkData.checkPrediction(PlayerChunkData.java:406) at com.betterchunkloading.chunk.PlayerChunkData.checkDirection(PlayerChunkData.java:353) at com.betterchunkloading.chunk.PlayerChunkData.trackPlayerMovement(PlayerChunkData.java:177) at com.betterchunkloading.chunk.PlayerChunkData.onChunkChanged(PlayerChunkData.java:130) at com.betterchunkloading.event.EventHandler.onPlayerTick(EventHandler.java:200) at net.minecraft.class_3222.handler$zed000$betterchunkloading$onPlayerTick(class_3222.java:2618) at net.minecraft.class_3222.method_5773(class_3222.java:564) at net.minecraft.class_3218.mixinextras$bridge$method_5773$202(class_3218.java) at net.minecraft.class_3218.wrapOperation$eei000$puzzleslib$tickNonPassenger(class_3218.java:7797) at net.minecraft.class_3218.method_18762(class_3218.java:770) at net.minecraft.class_1937.method_18472(class_1937.java:498) at net.minecraft.class_3218.method_31420(class_3218.java:408) at net.minecraft.class_5574.method_31791(class_5574.java:54) at net.minecraft.class_3218.method_18765(class_3218.java:372) at net.minecraft.server.MinecraftServer.method_3813(MinecraftServer.java:1021) ... 5 more Sorry guys if it obvious but actually I'm an old player of Minecraft but I'm new in modding so yup. But Thanks everyone by advance to help me with this.
    • These forums are for Minecraft Forge, not Fabric. You would probably be better served posting this question wherever fabric support is given, most likely their discord server.
    • Add the new latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here
    • Update: I tried to reproduce the bug and found out that if I place a flare on a block and then dismantle it with the pickarang (Quark), the flare gets no NBT Tag after getting assigned an empty one through the offhand.
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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