Jump to content

hugo_the_dwarf

Members
  • Posts

    334
  • Joined

  • Last visited

Everything posted by hugo_the_dwarf

  1. 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); }
  2. I have this special Item I want in my Mod called a "Emblem of Repair" and by having it on you will slowly repair everything damaged in your inventory. However I want it to be upgraded by feeding it an item (test item is Iron Ingots) I was looking at how Bows work and tried to mimic that in the item (near the bottom of the class) What happens is if I do right-click and hold it will consume a ingot however it never really did (visually it works, but in the background it doesn't aka if I simply right-click the ingot reappears and the changes are undone) so How do I make this 'work' correctly? Also I'm new to modding MC (but not to modding or java in general) Any help or advice or explanation would be helpful (Also I read the before you post a topic and should I use Gist or the spoiler+code combo below? apparently spoilers don't open) https://gist.github.com/anonymous/fd0bbdff2adf90bc1851
×
×
  • Create New...

Important Information

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