use of mcjty.xnet.blocks.cables.ConnectorBlock 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.blocks.cables.ConnectorBlock in project XNet by McJty.
the class GuiProxy method getServerGuiElement.
@Override
public Object getServerGuiElement(int guiid, EntityPlayer entityPlayer, World world, int x, int y, int z) {
if (guiid == GUI_MANUAL_XNET) {
return null;
}
BlockPos pos = new BlockPos(x, y, z);
Block block = world.getBlockState(pos).getBlock();
if (block instanceof GenericBlock) {
GenericBlock<?, ?> genericBlock = (GenericBlock<?, ?>) block;
TileEntity te = world.getTileEntity(pos);
return genericBlock.createServerContainer(entityPlayer, te);
} else if (block instanceof ConnectorBlock) {
return new EmptyContainer(entityPlayer, null);
}
return null;
}
use of mcjty.xnet.blocks.cables.ConnectorBlock 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.blocks.cables.ConnectorBlock in project XNet by McJty.
the class ConnectorIterator method findNext.
private void findNext() {
foundPos = null;
while (facingIdx != -1) {
BlockPos connectorPos = pos.offset(EnumFacing.VALUES[facingIdx]);
facingIdx++;
if (facingIdx >= EnumFacing.VALUES.length) {
facingIdx = -1;
}
IBlockState state = world.getBlockState(connectorPos);
if (state.getBlock() instanceof ConnectorBlock) {
CableColor color = state.getValue(GenericCableBlock.COLOR);
if ((color == CableColor.ROUTING) == routing) {
foundPos = connectorPos;
return;
}
}
}
}
use of mcjty.xnet.blocks.cables.ConnectorBlock in project XNet by McJty.
the class RenderWorldLastEventHandler method renderCablesInt.
private static void renderCablesInt(RenderWorldLastEvent evt, Minecraft mc) {
EntityPlayerSP p = mc.player;
WorldClient world = mc.world;
double doubleX = p.lastTickPosX + (p.posX - p.lastTickPosX) * evt.getPartialTicks();
double doubleY = p.lastTickPosY + (p.posY - p.lastTickPosY) * evt.getPartialTicks();
double doubleZ = p.lastTickPosZ + (p.posZ - p.lastTickPosZ) * evt.getPartialTicks();
GlStateManager.pushMatrix();
GlStateManager.color(1.0f, 0, 0);
GlStateManager.glLineWidth(2);
GlStateManager.translate(-doubleX, -doubleY, -doubleZ);
GlStateManager.disableDepth();
GlStateManager.disableTexture2D();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
buffer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
for (int dx = -20; dx <= 20; dx++) {
for (int dy = -20; dy <= 20; dy++) {
for (int dz = -20; dz <= 20; dz++) {
BlockPos c = p.getPosition().add(dx, dy, dz);
IBlockState state = world.getBlockState(c);
Block block = state.getBlock();
if (block instanceof FacadeBlock || block instanceof ConnectorBlock || block instanceof GenericCableBlock) {
IExtendedBlockState extendedBlockState;
if (state.getBlock() instanceof FacadeBlock) {
extendedBlockState = (IExtendedBlockState) ((FacadeBlock) state.getBlock()).getStateInternal(state, world, c);
} else {
extendedBlockState = (IExtendedBlockState) state.getBlock().getExtendedState(state, world, c);
}
FacadeBlockId facadeId = extendedBlockState.getValue(GenericCableBlock.FACADEID);
if (((!GeneralConfiguration.showNonFacadedCablesWhileSneaking) || (!p.isSneaking())) && facadeId == null && !(block instanceof FacadeBlock)) {
continue;
}
CableColor color = extendedBlockState.getValue(GenericCableBlock.COLOR);
float r = 0;
float g = 0;
float b = 0;
switch(color) {
case BLUE:
r = .4f;
g = .4f;
b = 1f;
break;
case RED:
r = 1f;
g = .4f;
b = .4f;
break;
case YELLOW:
r = 1f;
g = 1f;
b = .4f;
break;
case GREEN:
r = .4f;
g = 1f;
b = .4f;
break;
case ROUTING:
r = .7f;
g = .7f;
b = .7f;
break;
}
List<Rect> quads = getQuads(extendedBlockState);
for (Rect quad : quads) {
renderRect(buffer, quad, c, r, g, b, 0.5f);
}
}
}
}
}
tessellator.draw();
GlStateManager.enableTexture2D();
GlStateManager.popMatrix();
}
Aggregations