PizzaTime
Members-
Posts
3 -
Joined
-
Last visited
PizzaTime's Achievements
Tree Puncher (2/8)
1
Reputation
-
Figured it out. Made some changes in my TileEntity to store the booleans then sync them with my properties. Works now. @Override public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { this.readFromNBT(pkt.getNbtCompound()); world.notifyBlockUpdate(pos, world.getBlockState(pos).getBlock().getDefaultState(), world.getBlockState(pos).getActualState(world, pos), 2); } @Override public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) { TileEntityCapacitor te = (TileEntityCapacitor) world.getTileEntity(pos); return state.withProperty(CAN_EXTRACT_UP, te.canExtract(EnumFacing.UP)) .withProperty(CAN_EXTRACT_DOWN, te.canExtract(EnumFacing.DOWN)) .withProperty(CAN_EXTRACT_NORTH, te.canExtract(EnumFacing.NORTH)) .withProperty(CAN_EXTRACT_SOUTH, te.canExtract(EnumFacing.SOUTH)) .withProperty(CAN_EXTRACT_EAST, te.canExtract(EnumFacing.EAST)) .withProperty(CAN_EXTRACT_WEST, te.canExtract(EnumFacing.WEST)); } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); this.canExtractUP = compound.getBoolean("up"); this.canExtractDOWN = compound.getBoolean("down"); this.canExtractNORTH = compound.getBoolean("north"); this.canExtractSOUTH = compound.getBoolean("south"); this.canExtractEAST = compound.getBoolean("east"); this.canExtractWEST = compound.getBoolean("west"); } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); compound.setBoolean("up", this.canExtractUP); compound.setBoolean("down", this.canExtractDOWN); compound.setBoolean("north", this.canExtractNORTH); compound.setBoolean("south", this.canExtractSOUTH); compound.setBoolean("east", this.canExtractEAST); compound.setBoolean("west", this.canExtractWEST); return compound; }
-
I've managed to create 6 separate PropertyBool for each EnumFacing in my Block class. And made it so my TileEntity only extracts Forge Energy to other IEnergyStorages when these PropertyBools are true. Everything is working fine, I can configure the sides with my custom Wrench, but when I close out my game and come back to my world, none of the Bools get saved. Some of the IBlockState methods are copies of BlockFurnace. FACING and FILL_ENERGY saves and work fine. It always reverts back to: this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(FILL_ENERGY, 0).withProperty(CAN_EXTRACT_UP, true).withProperty(CAN_EXTRACT_DOWN, true).withProperty(CAN_EXTRACT_NORTH, true).withProperty(CAN_EXTRACT_SOUTH, true).withProperty(CAN_EXTRACT_EAST, true).withProperty(CAN_EXTRACT_WEST, true)); There is probably some way of saving IBlockStates that I don't know about. I have registered the TileEntity: GameRegistry.registerTileEntity(TileEntityCapacitor.class, RedstoneMachinery.MOD_ID + "TileEntityCapacitor"); public class CapacitorBlock extends Block { public static final PropertyDirection FACING = BlockHorizontal.FACING; public static final PropertyInteger FILL_ENERGY = PropertyInteger.create("fill_energy", 0, 10); public static final PropertyBool CAN_EXTRACT_UP = PropertyBool.create("extract_up"); public static final PropertyBool CAN_EXTRACT_DOWN = PropertyBool.create("extract_down"); public static final PropertyBool CAN_EXTRACT_NORTH = PropertyBool.create("extract_north"); public static final PropertyBool CAN_EXTRACT_SOUTH = PropertyBool.create("extract_south"); public static final PropertyBool CAN_EXTRACT_EAST = PropertyBool.create("extract_east"); public static final PropertyBool CAN_EXTRACT_WEST = PropertyBool.create("extract_west"); private int capacity; private int transfer; public CapacitorBlock(String unlocName, String regName, int capacity, int transfer) { super(Material.IRON); this.setUnlocalizedName(unlocName); this.setRegistryName(regName); this.capacity = capacity; this.transfer = transfer; this.setSoundType(SoundType.METAL); this.setCreativeTab(RedstoneMachinery.CREATIVE_TAB_RFPLUS); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH) .withProperty(FILL_ENERGY, 0).withProperty(CAN_EXTRACT_UP, true).withProperty(CAN_EXTRACT_DOWN, true).withProperty(CAN_EXTRACT_NORTH, true).withProperty(CAN_EXTRACT_SOUTH, true).withProperty(CAN_EXTRACT_EAST, true).withProperty(CAN_EXTRACT_WEST, true)); this.setHardness(3.0F); } @SideOnly(Side.CLIENT) @Override public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn) { tooltip.add("Stores Redstone Flux"); if (stack.hasTagCompound()) { NumberFormat format = NumberFormat.getInstance(); int energy = stack.getTagCompound().getInteger("Energy"); tooltip.add(String.format("RF: %s / %s", format.format(energy), format.format(capacity))); } } @Override public boolean isOpaqueCube(IBlockState state) { return false; } @Override public boolean isFullCube(IBlockState state) { return false; } @Override public boolean isBlockNormalCube(IBlockState blockState) { return false; } @Override @SideOnly(Side.CLIENT) public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess worldIn, BlockPos pos, EnumFacing side) { return false; } @Override public EnumBlockRenderType getRenderType(IBlockState state) { return EnumBlockRenderType.ENTITYBLOCK_ANIMATED; } /** * Called by ItemBlocks after a block is set in the world, to allow * post-place logic */ @Override public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2); TileEntity te = worldIn.getTileEntity(pos); if (te instanceof TileEntityCapacitor) { if (stack.hasTagCompound()) { int energy = stack.getTagCompound().getInteger("Energy"); ((TileEntityCapacitor) te).setField(0, energy); } } } /** * Get the Item that this Block should drop when harvested. */ @Nullable public Item getItemDropped(IBlockState state, Random rand, int fortune) { return null; } @Override public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player) { if (!worldIn.isRemote) { if (!player.isCreative()) { TileEntity te = worldIn.getTileEntity(pos); if (te != null && te instanceof TileEntityCapacitor) { ItemStack stack = new ItemStack(RedstoneMachineryBlocks.capacitor); if (!stack.hasTagCompound()) { stack.setTagCompound(new NBTTagCompound()); } stack.getTagCompound().setInteger("Energy", ((TileEntityCapacitor) te).getField(0)); InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), stack); } } worldIn.removeTileEntity(pos); } } /** * Called serverside after this block is replaced with another in Chunk, but * before the Tile Entity is updated */ @Override public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { TileEntity te = worldIn.getTileEntity(pos); if (te instanceof TileEntityCapacitor) { InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityCapacitor) te); worldIn.updateComparatorOutputLevel(pos, this); } worldIn.removeTileEntity(pos); super.breakBlock(worldIn, pos, state); } @Override public TileEntity createTileEntity(World world, IBlockState state) { return new TileEntityCapacitor(); } @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (world.isRemote) { return true; } else { if (player.getHeldItem(hand).getItem() != RedstoneMachineryItems.wrench) { TileEntityCapacitor te = (TileEntityCapacitor) world.getTileEntity(pos); player.openGui(RedstoneMachinery.instance, GuiHandler.GuiCapacitor, world, pos.getX(), pos.getY(), pos.getZ()); return true; } if (player.getHeldItem(hand).getItem() == RedstoneMachineryItems.wrench) { return false; } return true; } } /** * Called after the block is set in the Chunk data, but before the Tile * Entity is set */ @Override public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) { this.setDefaultFacing(worldIn, pos, state); } private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state) { if (!worldIn.isRemote) { IBlockState iblockstate = worldIn.getBlockState(pos.north()); IBlockState iblockstate1 = worldIn.getBlockState(pos.south()); IBlockState iblockstate2 = worldIn.getBlockState(pos.west()); IBlockState iblockstate3 = worldIn.getBlockState(pos.east()); EnumFacing enumfacing = (EnumFacing) state.getValue(FACING); if (enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock()) { enumfacing = EnumFacing.SOUTH; } else if (enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock()) { enumfacing = EnumFacing.NORTH; } else if (enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock()) { enumfacing = EnumFacing.EAST; } else if (enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock()) { enumfacing = EnumFacing.WEST; } worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2); } } /** * Called by ItemBlocks just before a block is actually set in the world, to * allow for adjustments to the IBlockstate */ @Override public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()); } @Override public boolean hasComparatorInputOverride(IBlockState state) { return true; } @Override public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos) { TileEntityCapacitor te = (TileEntityCapacitor) worldIn.getTileEntity(pos); return te.changeState(worldIn, pos, te.getPercent(), true); } /** * Convert the given metadata into a BlockState for this Block */ @Override public IBlockState getStateFromMeta(int meta) { EnumFacing enumfacing = EnumFacing.getFront(meta); if (enumfacing.getAxis() == EnumFacing.Axis.Y) { enumfacing = EnumFacing.NORTH; } return this.getDefaultState().withProperty(FACING, enumfacing); } /** * Convert the BlockState into the correct metadata value */ @Override public int getMetaFromState(IBlockState state) { return ((EnumFacing) state.getValue(FACING)).getIndex(); } /** * Returns the blockstate with the given rotation from the passed * blockstate. If inapplicable, returns the passed blockstate. */ @Override public IBlockState withRotation(IBlockState state, Rotation rot) { return state.withProperty(FACING, rot.rotate((EnumFacing) state.getValue(FACING))); } /** * Returns the blockstate with the given mirror of the passed blockstate. If * inapplicable, returns the passed blockstate. */ @Override public IBlockState withMirror(IBlockState state, Mirror mirrorIn) { return state.withRotation(mirrorIn.toRotation((EnumFacing) state.getValue(FACING))); } @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, BlockHorizontal.FACING, FILL_ENERGY, CAN_EXTRACT_UP, CAN_EXTRACT_DOWN, CAN_EXTRACT_NORTH, CAN_EXTRACT_SOUTH, CAN_EXTRACT_EAST, CAN_EXTRACT_WEST); } @Override public boolean hasTileEntity(IBlockState state) { return true; } } public class TileEntityCapacitor extends TileEntityPowered implements ITickable { public TileEntityCapacitor() { super(1000000, 1000000, 1000000, 4); } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); IBlockState currentState = world.getBlockState(pos); this.world.setBlockState(pos, currentState.withProperty(CapacitorBlock.CAN_EXTRACT_UP, compound.getBoolean("up")) .withProperty(CapacitorBlock.CAN_EXTRACT_DOWN, compound.getBoolean("down")) .withProperty(CapacitorBlock.CAN_EXTRACT_NORTH, compound.getBoolean("north")) .withProperty(CapacitorBlock.CAN_EXTRACT_SOUTH, compound.getBoolean("south")) .withProperty(CapacitorBlock.CAN_EXTRACT_EAST, compound.getBoolean("east")) .withProperty(CapacitorBlock.CAN_EXTRACT_WEST, compound.getBoolean("west")), 2); } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); IBlockState state = world.getBlockState(pos); compound.setBoolean("up", state.getValue(CapacitorBlock.CAN_EXTRACT_UP)); compound.setBoolean("down", state.getValue(CapacitorBlock.CAN_EXTRACT_DOWN)); compound.setBoolean("north", state.getValue(CapacitorBlock.CAN_EXTRACT_NORTH)); compound.setBoolean("south", state.getValue(CapacitorBlock.CAN_EXTRACT_SOUTH)); compound.setBoolean("east", state.getValue(CapacitorBlock.CAN_EXTRACT_EAST)); compound.setBoolean("west", state.getValue(CapacitorBlock.CAN_EXTRACT_WEST)); return compound; } @Override public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { this.readFromNBT(pkt.getNbtCompound()); } @Override public SPacketUpdateTileEntity getUpdatePacket() { NBTTagCompound compound = new NBTTagCompound(); this.writeToNBT(compound); return new SPacketUpdateTileEntity(pos, 1, compound); } @Override public int getField(int id) { switch (id) { case 0: return this.storage.getEnergyStored(); case 1: return this.storage.getMaxEnergyStored(); case 2: return this.storage.getMaxReceive(); case 3: return this.storage.getMaxExtract(); default: return 0; } } @Override public void setField(int id, int value) { switch (id) { case 0: this.storage.setEnergyStored(value); break; case 1: this.storage.setCapacity(value); break; case 2: this.storage.setMaxReceive(value); break; case 3: this.storage.setMaxExtract(value); break; } } @Override public int getFieldCount() { return 4; } @Override public void update() { if (!this.world.isRemote) { float percent = this.getPercent(); if (this.storage.getEnergyStored() > 0) { for (EnumFacing side : EnumFacing.VALUES) { if (this.canExtract(side)) { int energy = (int) EnergyHelper.giveEnergy(world.getTileEntity(pos.offset(side)), Math.min(this.storage.getEnergyStored(), this.storage.getMaxExtract()), true, side); if (energy > 0) { this.storage.modifyEnergyStored(-(int) EnergyHelper .giveEnergy(world.getTileEntity(pos.offset(side)), energy, false, side)); } } else { } } this.changeState(world, pos, percent, false); } for (int i = 0; i < 4; i++) { if (!this.inventory.get(i).isEmpty()) { if (this.inventory.get(i).hasCapability(CapabilityEnergy.ENERGY, null)) { IEnergyStorage handler = this.inventory.get(i).getCapability(CapabilityEnergy.ENERGY, null); int energyReceived = handler.receiveEnergy( Math.min(this.storage.getEnergyStored(), this.storage.getMaxExtract()), true); if (energyReceived > 0) { handler.receiveEnergy(this.storage.extractEnergy(energyReceived, false), false); this.changeState(world, pos, percent, false); } } } } this.changeState(this.world, this.pos, percent, false); } } public boolean canExtract(EnumFacing side) { switch (side) { case UP: return this.world.getBlockState(this.pos).getValue(CapacitorBlock.CAN_EXTRACT_UP); case DOWN: return this.world.getBlockState(this.pos).getValue(CapacitorBlock.CAN_EXTRACT_DOWN); case NORTH: return this.world.getBlockState(this.pos).getValue(CapacitorBlock.CAN_EXTRACT_NORTH); case SOUTH: return this.world.getBlockState(this.pos).getValue(CapacitorBlock.CAN_EXTRACT_SOUTH); case EAST: return this.world.getBlockState(this.pos).getValue(CapacitorBlock.CAN_EXTRACT_EAST); case WEST: return this.world.getBlockState(this.pos).getValue(CapacitorBlock.CAN_EXTRACT_WEST); default: return false; } } public float getPercent() { return (this.storage.getEnergyStored() * 100.0f) / this.storage.getMaxEnergyStored(); } public int changeState(World world, BlockPos pos, float percent, boolean simulate) { IBlockState currentState = world.getBlockState(pos); if (percent > 0 && percent <= 10) { if (!simulate) { if (currentState.getValue(CapacitorBlock.FILL_ENERGY) != 0) { world.setBlockState(pos, currentState.withProperty(CapacitorBlock.FILL_ENERGY, 0)); } } return 1; } if (percent > 10 && percent <= 20) { if (!simulate) { if (currentState.getValue(CapacitorBlock.FILL_ENERGY) != 1) { world.setBlockState(pos, currentState.withProperty(CapacitorBlock.FILL_ENERGY, 1)); } } return 2; } if (percent > 20 && percent <= 30) { if (!simulate) { if (currentState.getValue(CapacitorBlock.FILL_ENERGY) != 2) { world.setBlockState(pos, currentState.withProperty(CapacitorBlock.FILL_ENERGY, 2)); } } return 4; } if (percent > 30 && percent <= 40) { if (!simulate) { if (currentState.getValue(CapacitorBlock.FILL_ENERGY) != 3) { world.setBlockState(pos, currentState.withProperty(CapacitorBlock.FILL_ENERGY, 3)); } } return 6; } if (percent > 40 && percent <= 50) { if (!simulate) { if (currentState.getValue(CapacitorBlock.FILL_ENERGY) != 4) { world.setBlockState(pos, currentState.withProperty(CapacitorBlock.FILL_ENERGY, 4)); } } return 7; } if (percent > 50 && percent <= 60) { if (!simulate) { if (currentState.getValue(CapacitorBlock.FILL_ENERGY) != 5) { world.setBlockState(pos, currentState.withProperty(CapacitorBlock.FILL_ENERGY, 5)); } } return 8; } if (percent > 60 && percent <= 70) { if (!simulate) { if (currentState.getValue(CapacitorBlock.FILL_ENERGY) != 6) { world.setBlockState(pos, currentState.withProperty(CapacitorBlock.FILL_ENERGY, 6)); } } return 10; } if (percent > 70 && percent <= 80) { if (!simulate) { if (currentState.getValue(CapacitorBlock.FILL_ENERGY) != 7) { world.setBlockState(pos, currentState.withProperty(CapacitorBlock.FILL_ENERGY, 7)); } } return 11; } if (percent > 80 && percent <= 90) { if (!simulate) { if (currentState.getValue(CapacitorBlock.FILL_ENERGY) != 8) { world.setBlockState(pos, currentState.withProperty(CapacitorBlock.FILL_ENERGY, 8)); } } return 13; } if (percent > 90 && percent <= 99) { if (!simulate) { if (currentState.getValue(CapacitorBlock.FILL_ENERGY) != 9) { world.setBlockState(pos, currentState.withProperty(CapacitorBlock.FILL_ENERGY, 9)); } } return 14; } if (percent > 99) { if (!simulate) { if (currentState.getValue(CapacitorBlock.FILL_ENERGY) != 10) { world.setBlockState(pos, currentState.withProperty(CapacitorBlock.FILL_ENERGY, 10)); } } return 15; } return 0; } @Override public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing) { IBlockState state = world.getBlockState(pos); if (capability == CapabilityEnergy.ENERGY && facing != state.getValue(CapacitorBlock.FACING)) { return (T) this.storage; } return super.getCapability(capability, facing); } @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { IBlockState state = world.getBlockState(pos); if (capability == CapabilityEnergy.ENERGY && facing != state.getValue(CapacitorBlock.FACING)) { return this.storage != null; } return super.hasCapability(capability, facing); } public PropertyBool getPropertyFromFacing(EnumFacing side) { switch (side) { case UP: return CapacitorBlock.CAN_EXTRACT_UP; case DOWN: return CapacitorBlock.CAN_EXTRACT_DOWN; case NORTH: return CapacitorBlock.CAN_EXTRACT_NORTH; case SOUTH: return CapacitorBlock.CAN_EXTRACT_SOUTH; case EAST: return CapacitorBlock.CAN_EXTRACT_EAST; case WEST: return CapacitorBlock.CAN_EXTRACT_WEST; default: return null; } } }
-
Registering 'custom furnace' recipes for NEI?
PizzaTime replied to Servant_Girl's topic in Modder Support
https://github.com/mezz/JustEnoughItems/wiki/Getting-Started