Draco18s Posted June 17, 2013 Posted June 17, 2013 I know about ChestGenHooks, but I don't want to add items to chests. I want to add them to dispensers (actually a custom block, but it uses the Dispenser's TE). If ChestGenHooks can do this, I haven't figured out how. Additionally, I can't seem to get the block to be oriented the way I want...it's weird: world.setBlock(x, y, z, TrapsBase.TrapBlock.blockID, 1, 3); //metadata 1 means it should point up Doing that in worldgen doesn't make it point up, it points south...which is metadata 3...and it doesn't matter what direction I tell it to face, it always faces south. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
ObsequiousNewt Posted June 17, 2013 Posted June 17, 2013 ((TileEntityMyDispenser) world.getBlockTileEntity(x,y,z)).addItem(stack); Oddly enough, addItem(ItemStack) is defined by TileEntityDispenser. Feel free to replace with setInventorySlotContents() or whatever. As for the orientation: getIcon() code? Quote BEWARE OF GOD --- Co-author of Pentachoron Labs' SBFP Tech.
Draco18s Posted June 17, 2013 Author Posted June 17, 2013 ((TileEntityMyDispenser) world.getBlockTileEntity(x,y,z)).addItem(stack); Oddly enough, addItem(ItemStack) is defined by TileEntityDispenser. Feel free to replace with setInventorySlotContents() or whatever. world.getBlockTileEntity(x,y,z) returns null: world.setBlock((int)c.xCoord, (int)c.yCoord-1, (int)c.zCoord, TrapsBase.arrowSlot.blockID, 1, 3); TileEntityDispenser dis = (TileEntityDispenser)world.getBlockTileEntity((int)c.xCoord, (int)c.yCoord, (int)c.zCoord); if(dis != null) { addTrapItem(dis); } else { System.out.print("Boo."); //this runs } Yes, that's the right TE. public TileEntity createNewTileEntity(World par1World) { return new TileEntityDispenser(); } As for the orientation: getIcon() code? getIcon won't help you. I'm using a custom renderer and yes I checked that it wasn't just rendering wrong. It was still shooting arrows in the incorrect direction. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
ObsequiousNewt Posted June 18, 2013 Posted June 18, 2013 ((TileEntityMyDispenser) world.getBlockTileEntity(x,y,z)).addItem(stack); Oddly enough, addItem(ItemStack) is defined by TileEntityDispenser. Feel free to replace with setInventorySlotContents() or whatever. world.getBlockTileEntity(x,y,z) returns null: world.setBlock((int)c.xCoord, (int)c.yCoord-1, (int)c.zCoord, TrapsBase.arrowSlot.blockID, 1, 3); TileEntityDispenser dis = (TileEntityDispenser)world.getBlockTileEntity((int)c.xCoord, (int)c.yCoord, (int)c.zCoord); if(dis != null) { addTrapItem(dis); } else { System.out.print("Boo."); //this runs } Yes, that's the right TE. Perhaps you might try removing the "-1"? Or adding one in the next line? public TileEntity createNewTileEntity(World par1World) { return new TileEntityDispenser(); } As for the orientation: getIcon() code? getIcon won't help you. I'm using a custom renderer and yes I checked that it wasn't just rendering wrong. It was still shooting arrows in the incorrect direction. If you're sure, then I don't know. Quote BEWARE OF GOD --- Co-author of Pentachoron Labs' SBFP Tech.
Draco18s Posted June 18, 2013 Author Posted June 18, 2013 Perhaps you might try removing the "-1"? Or adding one in the next line? Frakking hell. Thanks for spotting that. >..x The -1 should actually be on another line entirely. If you're sure, then I don't know. public Icon getIcon(int par1, int par2) { if(par2 <= 1) return verticalFront; return blockIcon; } All it does it determine which overlay to use. The four horizontal facings have one icon (four "holes") the vertical one has another (two "holes"). The renderer is a tad bit more complex. package draco18s.traps.client; import net.minecraft.block.Block; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.world.IBlockAccess; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import draco18s.traps.TrapsBase; public class RenderArrowTrap implements ISimpleBlockRenderingHandler { private int renderType; public RenderArrowTrap(int r) { renderType = r; } @Override public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) { renderer.renderBlockAsItem(TrapsBase.pseudoAT, 3, 1.0F); } public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { int l = world.getBlockMetadata(x, y, z); l = l & 7; int i = x; int j = y; int k = z; int xm = 0; int zm = 0; switch(l) { case 0: case 2: case 3: xm = 1; break; case 1: case 4: case 5: zm = 1; break; } int meta = 0; int wid1 = world.getBlockId(x+xm, y, z+zm); int wid2 = world.getBlockId(x-xm, y, z-zm); int wid = 0; if(wid1 != block.blockID && Block.blocksList[wid1] != null && Block.blocksList[wid1].isOpaqueCube()) { wid = wid1; meta = world.getBlockMetadata(x+xm, y, z+zm); } else if(wid2 != block.blockID && Block.blocksList[wid2] != null && Block.blocksList[wid2].isOpaqueCube()) { wid = wid2; meta = world.getBlockMetadata(x-xm, y, z-zm); } else { if(l <= 1) { wid1 = world.getBlockId(x+zm, y, z+xm); wid2 = world.getBlockId(x-zm, y, z-xm); if(wid1 != block.blockID && Block.blocksList[wid1] != null && Block.blocksList[wid1].isOpaqueCube()) { wid = wid1; meta = world.getBlockMetadata(x+zm, y, z+xm); } else if(wid2 != block.blockID && Block.blocksList[wid2] != null && Block.blocksList[wid2].isOpaqueCube()) { wid = wid2; meta = world.getBlockMetadata(x-zm, y, z-xm); } else { wid = Block.stoneBrick.blockID; } } else { wid = Block.stoneBrick.blockID; } } Icon camo = Block.blocksList[wid].getIcon(l, meta); Icon furnace = Block.furnaceIdle.getIcon(2,3); Icon top = Block.furnaceIdle.getIcon(1,0); Icon self = block.getIcon(0, l); renderer.renderBlockUsingTexture(Block.stone, x, y, z, camo); switch(l) { case 0: renderer.renderFaceYNeg(Block.blocksList[wid], (double)x, (double)y, (double)z, self); renderer.renderFaceYPos(Block.blocksList[wid], (double)x, (double)y, (double)z, top); break; case 1: renderer.renderFaceYPos(Block.blocksList[wid], (double)x, (double)y, (double)z, self); renderer.renderFaceYNeg(Block.blocksList[wid], (double)x, (double)y, (double)z, top); break; case 2: renderer.renderFaceZNeg(Block.blocksList[wid], (double)x, (double)y, (double)z, self); renderer.renderFaceZPos(Block.blocksList[wid], (double)x, (double)y, (double)z, furnace); renderer.renderFaceYPos(Block.blocksList[wid], (double)x, (double)y, (double)z, top); renderer.renderFaceYNeg(Block.blocksList[wid], (double)x, (double)y, (double)z, top); break; case 3: renderer.renderFaceZPos(Block.blocksList[wid], (double)x, (double)y, (double)z, self); renderer.renderFaceZNeg(Block.blocksList[wid], (double)x, (double)y, (double)z, furnace); renderer.renderFaceYPos(Block.blocksList[wid], (double)x, (double)y, (double)z, top); renderer.renderFaceYNeg(Block.blocksList[wid], (double)x, (double)y, (double)z, top); break; case 4: renderer.renderFaceXNeg(Block.blocksList[wid], (double)x, (double)y, (double)z, self); renderer.renderFaceXPos(Block.blocksList[wid], (double)x, (double)y, (double)z, furnace); renderer.renderFaceYPos(Block.blocksList[wid], (double)x, (double)y, (double)z, top); renderer.renderFaceYNeg(Block.blocksList[wid], (double)x, (double)y, (double)z, top); break; case 5: renderer.renderFaceXPos(Block.blocksList[wid], (double)x, (double)y, (double)z, self); renderer.renderFaceXNeg(Block.blocksList[wid], (double)x, (double)y, (double)z, furnace); renderer.renderFaceYPos(Block.blocksList[wid], (double)x, (double)y, (double)z, top); renderer.renderFaceYNeg(Block.blocksList[wid], (double)x, (double)y, (double)z, top); break; } return true; } @Override public boolean shouldRender3DInInventory() { return true; } @Override public int getRenderId() { return renderType; } } But feel free. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
Draco18s Posted June 18, 2013 Author Posted June 18, 2013 You'll never believe what fixed it. world.setBlockMetadataWithNotify((int)c.xCoord, (int)c.yCoord-1, (int)c.zCoord, 1, 3); Had to forcibly set the metadata after creating the block. Because dispensers do this: public void onBlockAdded(World par1World, int par2, int par3, int par4) { super.onBlockAdded(par1World, par2, par3, par4); this.setDispenserDefaultDirection(par1World, par2, par3, par4); } Even the vanilla dispenser has this "problem." Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
ObsequiousNewt Posted June 18, 2013 Posted June 18, 2013 You'll never believe what fixed it. world.setBlockMetadataWithNotify((int)c.xCoord, (int)c.yCoord-1, (int)c.zCoord, 1, 3); Had to forcibly set the metadata after creating the block. Because dispensers do this: public void onBlockAdded(World par1World, int par2, int par3, int par4) { super.onBlockAdded(par1World, par2, par3, par4); this.setDispenserDefaultDirection(par1World, par2, par3, par4); } Even the vanilla dispenser has this "problem." Lolz. Well, I'm glad I solved at least half of your problem Quote BEWARE OF GOD --- Co-author of Pentachoron Labs' SBFP Tech.
Recommended Posts
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.