protected boolean isValidSlave(World world, BlockPos pos) { if(!world.isBlockLoaded(pos)) { return false; } TileEntity te = world.getTileEntity(pos); // slave-blocks are only allowed if they already belong to this smeltery if(te instanceof MultiServantLogic) { MultiServantLogic slave = (MultiServantLogic) te; if(slave.hasValidMaster()) { if(!tile.getPos().equals(slave.getMasterPosition())) { return false; } } } return true; } }
public static void assignMultiBlock(World world, BlockPos master, List<BlockPos> servants) { TileEntity masterBlock = world.getTileEntity(master); if(!(masterBlock instanceof IMasterLogic)) { throw new IllegalArgumentException("Master must be of IMasterLogic"); } // assign master to each servant for(BlockPos pos : servants) { if(world.isBlockLoaded(pos)) { TileEntity slave = world.getTileEntity(pos); if(slave instanceof MultiServantLogic && slave.getWorld() != null) { ((MultiServantLogic) slave).overrideMaster(master); IBlockState state = world.getBlockState(pos); world.notifyBlockUpdate(pos, state, state, 3); } } } } }
@Override public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { super.onDataPacket(net, pkt); readFromNBT(pkt.getNbtCompound()); }
@Override public boolean verifyMaster(IMasterLogic logic, World world, BlockPos pos) { if(this.hasMaster) { return this.hasValidMaster(); } else { this.overrideMaster(pos); return true; } }
@Override public void notifyMasterOfChange() { if(this.hasValidMaster()) { IMasterLogic logic = (IMasterLogic) this.world.getTileEntity(this.master); logic.notifyChange(this, this.pos); } }
public void readFromNBT(NBTTagCompound tags) { super.readFromNBT(tags); this.readCustomNBT(tags); public NBTTagCompound writeToNBT(NBTTagCompound tags) { tags = super.writeToNBT(tags); return this.writeCustomNBT(tags); public NBTTagCompound getUpdateTag() { NBTTagCompound tag = new NBTTagCompound(); this.writeCustomNBT(tag); return tag;
@Override public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) { this.readCustomNBT(packet.getNbtCompound()); this.world.notifyLightSet(this.pos); IBlockState state = world.getBlockState(this.pos); this.world.notifyBlockUpdate(this.pos, state, state, 3); }
@Deprecated public boolean setMaster(BlockPos pos) { if(!this.hasMaster || this.world.getBlockState(this.master) != this.state || (this.world .getBlockState(this.master) .getBlock() != this.masterBlock)) { this.overrideMaster(pos); return true; } else { return false; } }