Jump to content

Nomnomab

Members
  • Posts

    21
  • Joined

  • Last visited

Everything posted by Nomnomab

  1. Ah, thanks I'll try that, and yeah I meant getActualState sorry haha. Been a bit tired recently
  2. Like, the getActiveState from a block and the "server data" is the tile entity's nonremote data I guess. Not even sure how to go about this haha @diesieben07
  3. Ok, code is changed correctly for that part. Also, the data seems to save and load properly if I check with !worldIn.isRemote. Am I able to just set the Active State from the Server data? @draganz @diesieben07
  4. First off, I am setting the tile entitie's data here: @Override public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { System.out.print("BlockMultiTanningRack set in world.\n"); // set this data getTileEntity(worldIn, pos).setIsMaster(true); // grab direction EnumFacing enumFacing = BlockPistonBase.getFacingFromEntity(pos, placer); // grab positions BlockPos right = getDirectionalOffset(pos, enumFacing.getIndex(), 1, 0, 0); BlockPos topLeft = getDirectionalOffset(pos, enumFacing.getIndex(), 0, 1, 0); BlockPos topRight = getDirectionalOffset(pos, enumFacing.getIndex(), 1, 1, 0); // set blocks worldIn.setBlockState(pos, state.withProperty(FACING, enumFacing).withProperty(PIECE, Enum4Piece.BOTTOMLEFT)); worldIn.setBlockState(right, ModBlocks.TANNING_RACK.getDefaultState().withProperty(FACING, enumFacing).withProperty(PIECE, Enum4Piece.BOTTOMRIGHT)); worldIn.setBlockState(topLeft, ModBlocks.TANNING_RACK.getDefaultState().withProperty(FACING, enumFacing).withProperty(PIECE, Enum4Piece.TOPLEFT)); worldIn.setBlockState(topRight, ModBlocks.TANNING_RACK.getDefaultState().withProperty(FACING, enumFacing).withProperty(PIECE, Enum4Piece.TOPRIGHT)); // set tiles Tile4PieceVerticalBlock rightEntity = (Tile4PieceVerticalBlock)createTileEntity(worldIn, state); Tile4PieceVerticalBlock topLeftEntity = (Tile4PieceVerticalBlock)createTileEntity(worldIn, state); Tile4PieceVerticalBlock topRightEntity = (Tile4PieceVerticalBlock)createTileEntity(worldIn, state); // set masters rightEntity.setMasterPos(pos.getX(), pos.getY(), pos.getZ()); topLeftEntity.setMasterPos(pos.getX(), pos.getY(), pos.getZ()); topRightEntity.setMasterPos(pos.getX(), pos.getY(), pos.getZ()); // set tile in world worldIn.setTileEntity(right, rightEntity); worldIn.setTileEntity(topLeft, topLeftEntity); worldIn.setTileEntity(topRight, topRightEntity); super.onBlockPlacedBy(worldIn, pos, state, placer, stack); } And then debugging here: @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { TileEntity tile = worldIn.getTileEntity(pos); if(tile != null && tile instanceof Tile4PieceVerticalBlock) { Tile4PieceVerticalBlock tileTanningRack = (Tile4PieceVerticalBlock)tile; playerIn.addChatMessage(new TextComponentString("Master = " + tileTanningRack.isMaster() + ", Slave = " + tileTanningRack.hasMaster())); } return super.onBlockActivated(worldIn, pos, state, playerIn, hand, heldItem, side, hitX, hitY, hitZ); }
  5. Considering when I debug before I reload the world, it contains the data I set. But then when I reload the world and then debug, the data is completely reset. (I debug through onBlockActivated btw to do quick checks)
  6. Ok so, I can successfully set data on my TileEntity for my ModelTanningRack, but for some reason if I reload the world, the data is not loaded up at all and only reset. My TileEntity: public class Tile4PieceVerticalBlock extends TileEntity implements ITickable { private boolean isMaster, hasMaster; private int masterX, masterY, masterZ; // reset info when master is gone public void reset(){ masterX = masterY = masterZ = 0; isMaster = hasMaster = false; } // check that the master exists public boolean checkForMaster(){ TileEntity tile = worldObj.getTileEntity(getMasterPos()); return (tile != null && (tile instanceof Tile4PieceVerticalBlock)); } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { System.out.println("WRITE:" + getMasterPos() + "\n"); compound.setInteger("masterX", masterX); compound.setInteger("masterY", masterY); compound.setInteger("masterZ", masterZ); compound.setBoolean("isMaster", isMaster); compound.setBoolean("hasMaster", hasMaster); super.writeToNBT(compound); // if(hasMaster() && isMaster()){ // masterWriteToNBT(compound); // } return compound; } @Override public void readFromNBT(NBTTagCompound compound) { this.masterX = compound.getInteger("masterX"); this.masterY = compound.getInteger("masterY"); this.masterZ = compound.getInteger("masterZ"); this.isMaster = compound.getBoolean("isMaster"); this.hasMaster = compound.getBoolean("hasMaster"); super.readFromNBT(compound); System.out.println("READ:" + getMasterPos() + "\n"); // if(hasMaster() && isMaster()){ // masterReadToNBT(compound); // } } public boolean hasMaster(){ return hasMaster; } public boolean isMaster(){ return isMaster; } public int getMasterX(){ return masterX; } public int getMasterY(){ return masterY; } public int getMasterZ(){ return masterZ; } public BlockPos getMasterPos(){ return new BlockPos(getMasterX(), getMasterY(), getMasterZ()); } public void setHasMaster(boolean bool){ hasMaster = bool; } public void setIsMaster(boolean bool){ isMaster = bool; hasMaster = bool; } public void setMasterPos(int x, int y, int z){ masterX = x; masterY = y; masterZ = z; setHasMaster(true); } public int xCoord(){ return pos.getX(); } public int yCoord(){ return pos.getY(); } public int zCoord(){ return pos.getZ(); } @Override public void update() { } } Any ideas? (I could very well be missing something)
  7. Were you syncing the data to the client? Yep, just could never find the right way to set the state to the Block. Since I kept getting NullPointers for the block state. I do that for one of my structures. A 3x3 millstone. Ah sweet, currently making the base classes for this so that I can do it as large as I need Hopefully it doesn't explode too much
  8. Haha yeah Let us know how it turns out
  9. Ah ok, then yeah, it should be fine for you. Unless it doesn't act like a door, then you might have to do a bit of a rewrite
  10. Maybe? Depends on what you are trying to do
  11. Tried that, although only tried to use data from the TileEntity to set the state there. Should I use placement instead in the "group" of multiblocks? Like parent is x,y,z and child is using that parent's position to determine the state? What would you recommend
  12. Quick question then, do TileEntities support loading of BlockStates to a Block it is housed in? Trying to make this as painless as possible to load up states over 16. I can share what I've done once I make sure it doesn't blow up in my face anymore
  13. Trying to accomplish the same thing with a model two blocks wide and two blocks tall. Currently using 4 split model pieces and then using BlockStates to change the piece out. Still trying to work it out though haha
  14. I have a new issue haha, although not sure what to do about it. Currently trying to save to my block a PART integer: private int part; And then when it gets read, it will set the Block's PART data: public static final PropertyInteger PART = PropertyInteger.create("part", 0, 3); To the correct part. Currently it is throwing a NullPointer exception for grabbing the state from the block: getWorld().setBlockState(pos, getWorld().getBlockState(pos).withProperty(BlockTanningRack.FACING, EnumFacing.NORTH).withProperty(BlockTanningRack.PART, part)); Probably doing something really bad here, haha. Any ideas? Btw, I am trying to save my data and load it to a state since in the future I will have larger than 16 states for a multiblock, so I want to understand how to do this part of it
  15. Well, basically nothing happens other than if I spam right click on the block, the item will flicker for a split second (it has a custom renderer to display the held item). Not sure what's going on. Also, is this method supposed to be calling 4 times at once?
  16. When I tried using Block#onBlockActivated, I was able to successfully use the item on the block, which took the item from the inventory and put it into the block. This works great, but once I implemented a way to take the item with a hand with no item being held, it never took the item out of the inventory even though the adding section of the method was firing. @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { // do something if (!worldIn.isRemote) { System.out.print("Call\n"); EnumFacing enumFacing = state.getValue(FACING); EnumPart enumPart = state.getValue(PART); TileEntityTanningRack tile = getTileEntity(worldIn, pos); if (state.getValue(PART) != EnumPart.LEFT) { BlockPos newPos = getDirectionOffset(enumFacing, EnumPart.LEFT, enumPart, pos); worldIn.getBlockState(newPos).getBlock().onBlockActivated(worldIn, newPos, worldIn.getBlockState(newPos), playerIn, hand, heldItem, side, hitX, hitY, hitZ); tile.markDirty(); return true; } IItemHandler itemHandler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side); boolean flag = false; if(heldItem != null){ if(ModItems.ItemValidForTanningRack(heldItem.getItem())){ if(itemHandler.getStackInSlot(0) == null){ // remove item from player ItemStack itemStack = heldItem.splitStack(1); itemHandler.insertItem(0, itemStack, false); flag = true; }else if(!flag && itemHandler.getStackInSlot(0) != null){ // give player the item ItemStack itemStack = itemHandler.extractItem(0, 1, false); if(!playerIn.inventory.addItemStackToInventory(itemStack)){ // fail itemHandler.insertItem(0, itemStack, false); tile.markDirty(); return false; } } }else{ if(itemHandler.getStackInSlot(0) == null) return false; // give player the item ItemStack itemStack = itemHandler.extractItem(0, 1, false); if(!playerIn.inventory.addItemStackToInventory(itemStack)){ // fail itemHandler.insertItem(0, itemStack, false); tile.markDirty(); return false; } } tile.markDirty(); return true; } else if(!flag && heldItem == null){ if(itemHandler.getStackInSlot(0) == null) return false; // give player the item ItemStack itemStack = itemHandler.extractItem(0, 1, false); if(!playerIn.inventory.addItemStackToInventory(itemStack)){ // fail itemHandler.insertItem(0, itemStack, false); return false; } } } System.out.print("USED\n"); return false; }
  17. Heyo everyone, got a quick question here. Is onBlockActivated() in a Block class, an alright place to store the events that happen when a user right clicks with an item onto it? Or should I be using an Item's onItemUse() instead? Keep in mind I am trying to do custom events for items like Leather, which I am unsure if you can add custom events to vanilla items. Any help is great! Thanks
×
×
  • Create New...

Important Information

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