-
[Solved][1.10] Get Meta from Block for ItemStack
I think I'm all set now. Thanks for pointing me in the right direction. This is what I ended up with: Excerpt Block selectedBlock = world.getBlockState(pos).getBlock(); int meta = selectedBlock.damageDropped(world.getBlockState(pos)); ItemStack blockStack = new ItemStack(world.getBlockState(pos).getBlock(), 1, meta); Full methods @Override public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { int = 0, yD = 0, zD = 0; switch (facing) { case WEST: = -1; break; case DOWN: yD = -1; break; case NORTH: zD = -1; break; case EAST: = 1; break; case UP: yD = 1; break; case SOUTH: zD = 1; break;} for (int i = 1; i <= (player.isSneaking() ? length / 2 : length); i++) { Block block = world.getBlockState(new BlockPos(pos.getX() + i * , pos.getY() + i * yD, pos.getZ() + i * zD)).getBlock(); if ((((block == Blocks.AIR) || (block == Blocks.WATER) || (block == Blocks.FLOWING_WATER) || (block == Blocks.LAVA) || (block == Blocks.FLOWING_LAVA))) && ((player.capabilities.isCreativeMode) || (RemoveItemFromInventory(player, world, pos)))) { stack.damageItem(1, player); world.setBlockState(new BlockPos(pos.getX() + i * , pos.getY()+ i * yD, pos.getZ() + i * zD), world.getBlockState(pos)); //if (block instanceof SecurityWall) ((SecurityWall)block).onBlockPlacedBy(world, pos.getX() + i * , pos.getY() + i * yD, pos.getZ() + i * zD, player, stack); } else break; } if ((facing == EnumFacing.UP) && (player.posX > pos.getX()) && (player.posX < pos.getX()+1) && (player.posZ > pos.getZ()) && (player.posZ < pos.getZ()+1) && (player.posY > pos.getY()) && (player.posX < pos.getY()+3)) player.posY += (player.isSneaking()) ? length / 2 : length; return EnumActionResult.SUCCESS; } private boolean RemoveItemFromInventory(EntityPlayer player, World world, BlockPos pos) { Block selectedBlock = world.getBlockState(pos).getBlock(); int meta = selectedBlock.damageDropped(world.getBlockState(pos)); ItemStack blockStack = new ItemStack(world.getBlockState(pos).getBlock(), 1, meta); int slot = player.inventory.getSlotFor(blockStack); if (slot != -1) { ItemStack stack = player.inventory.getStackInSlot(slot); if (--stack.stackSize == 0) player.inventory.removeStackFromSlot(slot); return true; } else return false; }
-
[Solved][1.10] Get Meta from Block for ItemStack
This is the code I had before public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xOff, float yOff, float zOff) { int = 0, yD = 0, zD = 0; switch (side){ case 0: yD = -1; break; case 2: zD = -1; break; case 4: = -1; break; case 1: yD = 1; break; case 3: zD = 1; break; case 5: = 1; break;} int len = (player.isSneaking()) ? sneakLength : length; Block block = world.getBlock(x, y, z); int meta = world.getBlockMetadata(x, y, z); for (int i = 1; i <= len; i++) { Block b = world.getBlock(x + i * , y + i * yD, z + i * zD); if ( ( ( (b == Blocks.air) || (b == Blocks.water) || (b == Blocks.flowing_water) || (b == Blocks.lava) || (b == Blocks.flowing_lava) ) ) && ( (player.capabilities.isCreativeMode) || (player.inventory.consumeInventoryItem(Item.getItemFromBlock(block))) ) ) { world.setBlock(x + i * , y + i * yD, z + i * zD, block); if (block instanceof SecurityWall) ((SecurityWall)block).onBlockPlacedBy( world, x + i * , y + i * yD, z + i * zD, player, stack); if (meta != 0) world.setBlockMetadataWithNotify(x + i * , y + i * yD, z + i * zD, meta, 0); stack.damageItem(1, player); } else { return true; } } if ((side == 1) && (player.posX > x) && (player.posX < x+1) && (player.posZ > z) && (player.posZ < z+1) && (player.posY > y) && (player.posX < y+1)) player.posY += (player.isSneaking()) ? sneakLength : length; return true; } } and this is the code now public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { int = 0, yD = 0, zD = 0; switch (facing) { case WEST: = -1; break; case DOWN: yD = -1; break; case NORTH: zD = -1; break; case EAST: = 1; break; case UP: yD = 1; break; case SOUTH: zD = 1; break;} for (int i = 1; i <= (player.isSneaking() ? length / 2 : length); i++) { Block block = world.getBlockState(new BlockPos(pos.getX() + i * , pos.getY() + i * yD, pos.getZ() + i * zD)).getBlock(); if ((((block == Blocks.AIR) || (block == Blocks.WATER) || (block == Blocks.FLOWING_WATER) || (block == Blocks.LAVA) || (block == Blocks.FLOWING_LAVA))) && ((player.capabilities.isCreativeMode) || (RemoveItemFromInventory(player, world.getBlockState(pos))))) { stack.damageItem(1, player); world.setBlockState(new BlockPos(pos.getX() + i * , pos.getY()+ i * yD, pos.getZ() + i * zD), world.getBlockState(pos)); //if (block instanceof SecurityWall) ((SecurityWall)block).onBlockPlacedBy(world, pos.getX() + i * , pos.getY() + i * yD, pos.getZ() + i * zD, player, stack); } else break; } if ((facing == EnumFacing.UP) && (player.posX > pos.getX()) && (player.posX < pos.getX()+1) && (player.posZ > pos.getZ()) && (player.posZ < pos.getZ()+1) && (player.posY > pos.getY()) && (player.posX < pos.getY()+3)) player.posY += (player.isSneaking()) ? length / 2 : length; return EnumActionResult.SUCCESS; } private boolean RemoveItemFromInventory(EntityPlayer player, IBlockState block) { int slot = player.inventory.getSlotFor(new ItemStack(block.getBlock())); if (slot == -1) return false; ItemStack stack = player.inventory.getStackInSlot(slot); --stack.stackSize; if (stack.stackSize == 0) player.inventory.removeStackFromSlot(slot); return true; }
-
[Solved][1.10] Get Meta from Block for ItemStack
I'm trying to update a mod from 1.7.10, I have an item that when you right click on a block it checks the players inventory for more of that block and adds them in a line. Its working fine for stone, white wool, etc, anything with a meta value of 0/default state. How can I create an item stack of colored wool, stained glass, etc from a block in the world, onItemUse? or how can I get the actual meta int?
-
[SOLVED][1.7.10] Can't Teleport to Overworld
I've got it working I followed everyone's suggestions and there was no noticeable change. I added a "if (dimension == 0) player.travelToDimension(dimension);" to double travel to dimension 0/overworld My code works and I don't know why... @Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { NBTTagCompound nbtTagCompound = stack.getTagCompound(); if (nbtTagCompound == null) { nbtTagCompound = new NBTTagCompound(); stack.setTagCompound(nbtTagCompound); } if (player.isSneaking()) { if (world.isRemote) { NameHeldStackGUI nameGui = new NameHeldStackGUI(); Minecraft.getMinecraft().displayGuiScreen(nameGui); } nbtTagCompound.setBoolean("bound", true); nbtTagCompound.setInteger("dimension", player.dimension); nbtTagCompound.setDouble("x", player.posX); nbtTagCompound.setDouble("y", player.posY); nbtTagCompound.setDouble("z", player.posZ); } else if (nbtTagCompound.getBoolean("bound")) { double x = nbtTagCompound.getDouble("x"); double y = nbtTagCompound.getDouble("y"); double z = nbtTagCompound.getDouble("z"); int dimension = nbtTagCompound.getInteger("dimension"); if (player.dimension != dimension)player.travelToDimension(dimension); if (dimension == 0) player.travelToDimension(dimension); player.setPositionAndUpdate(x, y, z); world.playSoundEffect(x, y, z, "mob.endermen.portal", 1.0F, 1.0F); if (player.isBurning()) player.extinguish(); player.heal(1.0f); stack.damageItem(1, player); } return stack; }
-
[SOLVED][1.7.10] Can't Teleport to Overworld
To reiterate Everything works except teleporting from the nether or end to overworld. Meaning I can set and retrieve the NBT data. Maybe I did the GUI wrong, it works in game though, all it does is use packets to give the item stack a display name. It actually does teleport me to the overworld but no blocks or chunks load, Steve just floats there falling slowly then jumping back up
-
[SOLVED][1.7.10] Can't Teleport to Overworld
World#isRemote is false on the server and true on the client. Oh lol. Said it backwards . But getting rid of !world.isRemote, should fix it. If only it was that easy:( I removed "(!world.isRemote) && " and there was no change.
-
[SOLVED][1.7.10] Can't Teleport to Overworld
I have an item that will let you travel to the last location you set on it. I can use the item to travel within any dimension, and from any dimension to any other except the overworld. When I travel from the end or nether to the overworld the world doesn't load, my Y position slowly decreases and then fluctuates up and down by a couple points where the ground should be but I cant move or use the item again. When I log out and back in again everything is like it worked fine. Any ideas on what I'm missing? @Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { NBTTagCompound nbtTagCompound = stack.getTagCompound(); if (nbtTagCompound == null) { nbtTagCompound = new NBTTagCompound(); stack.setTagCompound(nbtTagCompound); } if (player.isSneaking()) { if (!world.isRemote) { NameHeldStackGUI nameGui = new NameHeldStackGUI(); Minecraft.getMinecraft().displayGuiScreen(nameGui); } nbtTagCompound.setBoolean("bound", true); nbtTagCompound.setInteger("dimension", player.dimension); nbtTagCompound.setDouble("x", player.posX); nbtTagCompound.setDouble("y", player.posY); nbtTagCompound.setDouble("z", player.posZ); } else if ((!world.isRemote) && (nbtTagCompound.hasKey("bound")) && (nbtTagCompound.getBoolean("bound"))) { double x = nbtTagCompound.getDouble("x"); double y = nbtTagCompound.getDouble("y"); double z = nbtTagCompound.getDouble("z"); int dimension = nbtTagCompound.getInteger("dimension"); [b]if (player.dimension != dimension)player.travelToDimension(dimension);[/b] player.setPositionAndUpdate(x, y, z); world.playSoundEffect(x, y, z, "mob.endermen.portal", 1.0F, 1.0F); if (player.isBurning()) player.extinguish(); player.heal(1.0f); stack.damageItem(1, player); } return stack; }
-
[SOLVED] GUI to name ItemStack
I had never heard of packets in Minecraft before, so I did a search and found this http://www.minecraftforge.net/forum/index.php/topic,20135.0.html It was really easy to implement after I got in the right mindset. TLDR: I named my item stack using a gui plus packets
-
[SOLVED] GUI to name ItemStack
I have an item that teleports the player when they right click, and saves the location when they shift right click. I want to have the itemstack have a custom name, so the player can get the name when they scroll to the item, which I can set with setStackDisplayName... But how do I get the name string from the GUI? Item Class GUI Class
IPS spam blocked by CleanTalk.