use of mcjty.xnet.multiblock.XNetBlobData in project XNet by McJty.
the class ControllerBlock method findNeighbourConnector.
// Check neighbour blocks for a connector and inherit the color from that
private void findNeighbourConnector(World world, BlockPos pos) {
XNetBlobData blobData = XNetBlobData.getBlobData(world);
WorldBlob worldBlob = blobData.getWorldBlob(world);
ColorId oldColor = worldBlob.getColorAt(pos);
ColorId newColor = null;
for (EnumFacing facing : EnumFacing.VALUES) {
if (world.getBlockState(pos.offset(facing)).getBlock() instanceof ConnectorBlock) {
ColorId color = worldBlob.getColorAt(pos.offset(facing));
if (color != null) {
if (color == oldColor) {
// Nothing to do
return;
}
newColor = color;
}
}
}
if (newColor != null) {
if (worldBlob.getBlobAt(pos) != null) {
worldBlob.removeCableSegment(pos);
}
NetworkId networkId = worldBlob.newNetwork();
worldBlob.createNetworkProvider(pos, newColor, networkId);
blobData.save(world);
TileEntity te = world.getTileEntity(pos);
if (te instanceof TileEntityController) {
((TileEntityController) te).setNetworkId(networkId);
}
}
}
use of mcjty.xnet.multiblock.XNetBlobData 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.XNetBlobData 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.XNetBlobData 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.XNetBlobData in project XNet by McJty.
the class CommandGen method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) {
XNetBlobData data = XNetBlobData.getBlobData(server.getEntityWorld());
EntityPlayer player = (EntityPlayer) sender;
EnumFacing facing = player.getHorizontalFacing();
BlockPos pos = player.getPosition();
System.out.println("facing = " + facing);
System.out.println("pos = " + pos);
World world = player.getEntityWorld();
for (int i = 0; i < 1000; i++) {
System.out.println("i = " + i);
world.setBlockState(pos, NetCableSetup.netCableBlock.getDefaultState());
world.markBlockRangeForRenderUpdate(pos.add(-1, -1, -1), pos.add(1, 1, 1));
NetCableSetup.netCableBlock.createCableSegment(world, pos, ItemStack.EMPTY);
pos = pos.offset(facing);
}
// TeleportationTools.performTeleport(player, new TeleportDestination(pos, 0), 0, 0, true);
System.out.println("done");
}
Aggregations