Jump to content

tyker1

Members
  • Posts

    33
  • Joined

  • Last visited

Everything posted by tyker1

  1. yeah, tyvm, also figured it out by reading http://greyminecraftcoder.blogspot.de/2013/08/the-tessellator.html this page, and do i need to use tessellator's draw method at end or it's find just to define how to draw it? to be honest, i'm not going to create an icon for each direction, because the block i want it to rotate has 8 states and therefore i'll need 8*4=32 icons for them.... u know thats really quiet much
  2. i have looked vanilla block rendering code for piston, but got confused about the following codes: switch (i1) { case 0: this.uvRotateEast = 3; this.uvRotateWest = 3; this.uvRotateSouth = 3; this.uvRotateNorth = 3; this.setRenderBounds(0.0D, 0.25D, 0.0D, 1.0D, 1.0D, 1.0D); break; case 1: this.setRenderBounds(0.0D, 0.0D, 0.0D, 1.0D, 0.75D, 1.0D); break; case 2: this.uvRotateSouth = 1; this.uvRotateNorth = 2; this.setRenderBounds(0.0D, 0.0D, 0.25D, 1.0D, 1.0D, 1.0D); break; case 3: this.uvRotateSouth = 2; this.uvRotateNorth = 1; this.uvRotateTop = 3; this.uvRotateBottom = 3; this.setRenderBounds(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.75D); break; case 4: this.uvRotateEast = 1; this.uvRotateWest = 2; this.uvRotateTop = 2; this.uvRotateBottom = 1; this.setRenderBounds(0.25D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D); break; case 5: this.uvRotateEast = 2; this.uvRotateWest = 1; this.uvRotateTop = 1; this.uvRotateBottom = 2; this.setRenderBounds(0.0D, 0.0D, 0.0D, 0.75D, 1.0D, 1.0D); obviously its rotating the block, but what dose uvRorate mean? these magical number really confused me... maybe u can explain it for me? thx
  3. Hi, i'm a starter in MineCraft Modding, and have met a problem about Icon rotate. The Problem is that: i have a set of Icon(for block's top side) with an arrow, and i want the arrow(well the icon direction) always be the direction player is facing(when placed). I have figured out that i can get the direction player facing through: int direction = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; And also know i should use a ISimpleBlockRenderingHandler and its method: public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { } to do do rotate. but i'm not sure what should i write in this method? i.e. i get the top Icon as Variable topIcon, and the direction blockDirection, what's the next step i should do? thx a lot for your help
  4. Orz, omg i must be too sleepy to figure out that... what a small silly mistake i have made! Tyvm!
  5. Ok i got it fixed by changing: stack.writeToNBT(item); into this.items[i].writeToNBT(item); but i'm quiet confused, why its not working by using ItemStack stack = getStackInSlot(i); stack.writeToNBT(item); they do should work correctly , because getStackInSlot(i) just returned a reference from this.items, doesn't it?
  6. ah sry, it is for a tileentity, which implments "IInventory" and i wanted it to save items in it so they wont going to lost after server restart..but its not working, i mean, items in it are gone after i restart the server
  7. I'm new to minecraft modding, after watching some tutorials, i just started to create a new mod.. I created a inventory and try to store the items in it using NBT data, but its not working,(Items in it still gone after restart the server) cause code is quiet long, i only post the methods with NBTs public class TileEntityProcessorHolder extends TileEntity implements IInventory{ private ItemStack[] items; private int[] inPorts; private int[] outPorts; private int timer = 4; private boolean isOpened = false; private boolean isConnectedWithIO = false; private int itemleng; public TileEntityProcessorHolder() { items = new ItemStack[3]; } @Override public int getSizeInventory() { return items.length; } @Override public ItemStack getStackInSlot(int i) { return items[i]; } @Override public ItemStack decrStackSize(int i, int count) { ItemStack itemstack = this.getStackInSlot(i); if(itemstack != null) { setInventorySlotContents(i,null); } return itemstack; } @Override public ItemStack getStackInSlotOnClosing(int i) { ItemStack itemstack = items[i]; setInventorySlotContents(i, null); return itemstack; } @Override public void setInventorySlotContents(int i, ItemStack itemstack) { items[i] = itemstack; } @Override public String getInventoryName() { // TODO Auto-generated method stub return null; } @Override public boolean hasCustomInventoryName() { // TODO Auto-generated method stub return false; } @Override public int getInventoryStackLimit() { // Now That we can only have one chip in the Holder, the maximun Stack should be 1 return 1; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return player.getDistanceSq(xCoord + 0.5F, yCoord + 0.5F, zCoord + 0.5F) <= 64; } @Override public void openInventory() { isOpened = true; } @Override public void closeInventory() { isOpened = false; int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); Item chip = null; if (items[0] != null) { chip = items[0].getItem(); } if (chip != null) { worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, meta < 2 ? meta + 2 : meta, 2); } else { worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, meta > 1 ? meta - 2 : meta, 2); } worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord)); } @Override public boolean isItemValidForSlot(int i, ItemStack item) { if (i == 1) { return false; } return item.equals(IntegratedItems.itemFPGA); } @Override public void writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); // save Items NBTTagList mitems = new NBTTagList(); for (int i = 0; i < getSizeInventory(); ++i) { ItemStack stack = getStackInSlot(i); if (stack != null) { NBTTagCompound item = new NBTTagCompound(); item.setByte("Slot", (byte)i); stack.writeToNBT(compound); mitems.appendTag(item); } } compound.setTag("Items", mitems); mitems = compound.getTagList("Items", Constants.NBT.TAG_COMPOUND); System.out.println("Items founded = " + mitems.tagCount()); // save inPorts NBTTagList in = new NBTTagList(); for(int i = 0; i < inPorts.length; i += 3) { NBTTagCompound coord = new NBTTagCompound(); coord.setInteger("xCoord", inPorts[i]); coord.setInteger("yCoord", inPorts[i+1]); coord.setInteger("zCoord", inPorts[i+2]); in.appendTag(coord); } compound.setTag("InPorts", in); // save outPorts NBTTagList out = new NBTTagList(); for(int i = 0; i < outPorts.length; i += 3) { NBTTagCompound coord = new NBTTagCompound(); coord.setInteger("xCoord", outPorts[i]); coord.setInteger("yCoord", outPorts[i+1]); coord.setInteger("zCoord", outPorts[i+2]); out.appendTag(coord); } compound.setTag("OutPorts", out); } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); // load Items NBTTagList mitems = compound.getTagList("Items", Constants.NBT.TAG_COMPOUND); this.itemleng = mitems.tagCount(); for(int i = 0; i < mitems.tagCount(); ++i) { NBTTagCompound item = mitems.getCompoundTagAt(i); byte slot = item.getByte("Slot"); if ((slot >= 0) && (slot < this.getSizeInventory())) { this.setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(item)); } } // load inPorts NBTTagList in = compound.getTagList("InPorts", Constants.NBT.TAG_COMPOUND); ArrayList ports = new ArrayList<Integer>(); for (int i = 0; i < in.tagCount(); i++) { NBTTagCompound port = (NBTTagCompound)in.getCompoundTagAt(i); ports.add(port.getInteger("xCoord")); ports.add(port.getInteger("yCoord")); ports.add(port.getInteger("zCoord")); } inPorts = getArrayFromList(ports); // load outPorts ports.clear(); NBTTagList out = compound.getTagList("OutPorts", Constants.NBT.TAG_COMPOUND); for (int i = 0; i < in.tagCount(); i++) { NBTTagCompound port = (NBTTagCompound)in.getCompoundTagAt(i); ports.add(port.getInteger("xCoord")); ports.add(port.getInteger("yCoord")); ports.add(port.getInteger("zCoord")); } outPorts = getArrayFromList(ports); // update "isConnectedWithIO" isConnectedWithIO = (inPorts.length != 0) || (outPorts.length != 0); } @Override public void updateEntity() { if (timer == 0) { timer = 5; if (isOpened) { isConnectedWithIO = ScanPins(); } } timer = timer - 1; } private boolean ScanPins() { ArrayList in = new ArrayList<Integer>(); ArrayList out = new ArrayList<Integer>(); boolean pinFounded = false; for(int i = -BlockInfo.VALIABLE_RADIUS; i <= BlockInfo.VALIABLE_RADIUS; ++i) for(int j = -BlockInfo.VALIABLE_RADIUS; j<= BlockInfo.VALIABLE_RADIUS; ++j) { if (i == 0 && j == 0) { continue; } Block targetBlock = worldObj.getBlock(xCoord+i, yCoord, zCoord+j); if (targetBlock.equals(IntegratedBlocks.blockPin)) { pinFounded = true; if (((blockPin)targetBlock).isOutPut(worldObj.getBlockMetadata(xCoord+i, yCoord, zCoord+j))) { // TODO add coords to outPorts[] in.add(xCoord+i); in.add(yCoord); in.add(zCoord+j); } else { // TODO add coords to outPorts[] out.add(xCoord+i); out.add(yCoord); out.add(zCoord+j); } } } inPorts = getArrayFromList(in); outPorts = getArrayFromList(out); return pinFounded; } public void FormatChip() { ItemStack item = items[1]; System.out.println("Item found = " + this.itemleng); if (item != null && item.getItem().equals(IntegratedItems.itemFPGA)) { if(item.stackTagCompound != null) { item.stackTagCompound.setBoolean("formatted", true); item.stackTagCompound.setIntArray("outputs", outPorts); item.stackTagCompound.setIntArray("inputs", inPorts); } setInventorySlotContents(2, item); setInventorySlotContents(1, null); } } private int[] getArrayFromList(ArrayList<Integer> list) { int[] array = new int[list.size()]; for (int i = 0; i < array.length; ++i) array[i] = list.get(i); return array; } } PS: i can't find game data so i can't check whether the NBT datas have been saved correctly, but as far as i use "println" in writeToNBT, it seems i do have wrote all datas
×
×
  • Create New...

Important Information

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