use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.
the class ConnectorBlock method getDrops.
@Override
public List<ItemStack> getDrops(IBlockAccess blockAccess, BlockPos pos, IBlockState state, int fortune) {
List<ItemStack> drops = super.getDrops(blockAccess, pos, state, fortune);
if (blockAccess instanceof World) {
World world = (World) blockAccess;
for (ItemStack drop : drops) {
if (!drop.hasTagCompound()) {
drop.setTagCompound(new NBTTagCompound());
}
WorldBlob worldBlob = XNetBlobData.getBlobData(world).getWorldBlob(world);
ConsumerId consumer = worldBlob.getConsumerAt(pos);
if (consumer != null) {
drop.getTagCompound().setInteger("consumerId", consumer.getId());
}
}
}
return drops;
}
use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.
the class ConnectorUpgradeItem method onItemUse.
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block == NetCableSetup.connectorBlock) {
if (!world.isRemote) {
TileEntity te = world.getTileEntity(pos);
if (te instanceof ConnectorTileEntity) {
NBTTagCompound tag = new NBTTagCompound();
te.writeToNBT(tag);
CableColor color = world.getBlockState(pos).getValue(GenericCableBlock.COLOR);
XNetBlobData blobData = XNetBlobData.getBlobData(world);
WorldBlob worldBlob = blobData.getWorldBlob(world);
ConsumerId consumer = worldBlob.getConsumerAt(pos);
((ConnectorBlock) block).unlinkBlock(world, pos);
world.setBlockState(pos, NetCableSetup.advancedConnectorBlock.getDefaultState().withProperty(GenericCableBlock.COLOR, color));
IBlockState blockState = world.getBlockState(pos);
((ConnectorBlock) blockState.getBlock()).createCableSegment(world, pos, consumer);
te = TileEntity.create(world, tag);
if (te != null) {
world.getChunkFromBlockCoords(pos).addTileEntity(te);
te.markDirty();
world.notifyBlockUpdate(pos, blockState, blockState, 3);
player.inventory.decrStackSize(player.inventory.currentItem, 1);
player.openContainer.detectAndSendChanges();
player.sendStatusMessage(new TextComponentString(TextFormatting.GREEN + "Connector was upgraded"), false);
} else {
player.sendStatusMessage(new TextComponentString(TextFormatting.RED + "Something went wrong during upgrade!"), false);
return EnumActionResult.FAIL;
}
}
}
return EnumActionResult.SUCCESS;
} else if (block == NetCableSetup.advancedConnectorBlock) {
if (!world.isRemote) {
player.sendStatusMessage(new TextComponentString(TextFormatting.YELLOW + "This connector is already advanced!"), false);
}
return EnumActionResult.SUCCESS;
} else {
if (!world.isRemote) {
player.sendStatusMessage(new TextComponentString(TextFormatting.RED + "Use this item on a connector to upgrade it!"), false);
}
return EnumActionResult.SUCCESS;
}
}
use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.
the class GenericCableBlock method createCableSegment.
public void createCableSegment(World world, BlockPos pos, ItemStack stack) {
XNetBlobData blobData = XNetBlobData.getBlobData(world);
WorldBlob worldBlob = blobData.getWorldBlob(world);
CableColor color = world.getBlockState(pos).getValue(COLOR);
worldBlob.createCableSegment(pos, new ColorId(color.ordinal() + 1));
blobData.save(world);
}
use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.
the class RouterBlock method breakBlock.
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
if (!world.isRemote) {
XNetBlobData blobData = XNetBlobData.getBlobData(world);
WorldBlob worldBlob = blobData.getWorldBlob(world);
worldBlob.removeCableSegment(pos);
blobData.save(world);
}
super.breakBlock(world, pos, state);
}
use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.
the class GenericCableBlock method unlinkBlock.
public void unlinkBlock(World world, BlockPos pos) {
if (!world.isRemote) {
XNetBlobData blobData = XNetBlobData.getBlobData(world);
WorldBlob worldBlob = blobData.getWorldBlob(world);
worldBlob.removeCableSegment(pos);
blobData.save(world);
}
}
Aggregations