use of mcjty.xnet.blocks.cables.ConnectorTileEntity in project XNet by McJty.
the class FacadeItemBlock 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();
ItemStack itemstack = player.getHeldItem(hand);
if (!itemstack.isEmpty()) {
if (block == NetCableSetup.netCableBlock) {
int i = this.getMetadata(itemstack.getMetadata());
FacadeBlock facadeBlock = (FacadeBlock) this.block;
IBlockState placementState = facadeBlock.getPlacementState(world, pos, facing, hitX, hitY, hitZ, i, player).withProperty(GenericCableBlock.COLOR, state.getValue(GenericCableBlock.COLOR));
if (placeBlockAt(itemstack, player, world, pos, facing, hitX, hitY, hitZ, placementState)) {
SoundType soundtype = world.getBlockState(pos).getBlock().getSoundType(world.getBlockState(pos), world, pos, player);
world.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
TileEntity te = world.getTileEntity(pos);
if (te instanceof FacadeTileEntity) {
((FacadeTileEntity) te).setMimicBlock(getMimicBlock(itemstack));
}
int amount = -1;
itemstack.grow(amount);
}
} else if (block == NetCableSetup.connectorBlock || block == NetCableSetup.advancedConnectorBlock) {
TileEntity te = world.getTileEntity(pos);
if (te instanceof ConnectorTileEntity) {
ConnectorTileEntity connectorTileEntity = (ConnectorTileEntity) te;
if (connectorTileEntity.getMimicBlock() == null) {
connectorTileEntity.setMimicBlock(getMimicBlock(itemstack));
SoundType soundtype = world.getBlockState(pos).getBlock().getSoundType(world.getBlockState(pos), world, pos, player);
world.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
int amount = -1;
itemstack.grow(amount);
} else {
return EnumActionResult.FAIL;
}
}
} else if (block == ModBlocks.facadeBlock) {
return EnumActionResult.FAIL;
} else {
setMimicBlock(itemstack, state);
if (world.isRemote) {
player.sendStatusMessage(new TextComponentString("Facade is now mimicing " + block.getLocalizedName()), false);
}
}
return EnumActionResult.SUCCESS;
} else {
return EnumActionResult.FAIL;
}
}
use of mcjty.xnet.blocks.cables.ConnectorTileEntity in project XNet by McJty.
the class TileEntityController method getConnectedBlockPositions.
@Override
public List<SidedPos> getConnectedBlockPositions() {
WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
List<SidedPos> result = new ArrayList<>();
Set<ConnectedBlockClientInfo> set = new HashSet<>();
for (BlockPos consumerPos : worldBlob.getConsumers(networkId)) {
String name = "";
TileEntity te = getWorld().getTileEntity(consumerPos);
if (te instanceof ConnectorTileEntity) {
// Should always be the case. @todo error?
name = ((ConnectorTileEntity) te).getConnectorName();
} else {
XNet.logger.warn("What? The connector at " + BlockPosTools.toString(consumerPos) + " is not a connector?");
}
for (EnumFacing facing : EnumFacing.VALUES) {
if (ConnectorBlock.isConnectable(getWorld(), consumerPos, facing)) {
BlockPos pos = consumerPos.offset(facing);
SidedPos sidedPos = new SidedPos(pos, facing.getOpposite());
result.add(sidedPos);
}
}
}
return result;
}
Aggregations