Search in sources :

Example 6 with ConnectorTileEntity

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;
    }
}
Also used : SoundType(net.minecraft.block.SoundType) ConnectorTileEntity(mcjty.xnet.blocks.cables.ConnectorTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) ConnectorTileEntity(mcjty.xnet.blocks.cables.ConnectorTileEntity) GenericCableBlock(mcjty.xnet.blocks.generic.GenericCableBlock) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 7 with ConnectorTileEntity

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;
}
Also used : SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) ConnectorTileEntity(mcjty.xnet.blocks.cables.ConnectorTileEntity) GenericEnergyReceiverTileEntity(mcjty.lib.entity.GenericEnergyReceiverTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ConnectedBlockClientInfo(mcjty.xnet.clientinfo.ConnectedBlockClientInfo) SidedPos(mcjty.xnet.api.keys.SidedPos) ConnectorTileEntity(mcjty.xnet.blocks.cables.ConnectorTileEntity) EnumFacing(net.minecraft.util.EnumFacing) WorldBlob(mcjty.xnet.multiblock.WorldBlob) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

ConnectorTileEntity (mcjty.xnet.blocks.cables.ConnectorTileEntity)7 TileEntity (net.minecraft.tileentity.TileEntity)7 BlockPos (net.minecraft.util.math.BlockPos)5 EnumFacing (net.minecraft.util.EnumFacing)4 WorldBlob (mcjty.xnet.multiblock.WorldBlob)3 Block (net.minecraft.block.Block)3 IBlockState (net.minecraft.block.state.IBlockState)3 GenericEnergyReceiverTileEntity (mcjty.lib.entity.GenericEnergyReceiverTileEntity)2 SidedConsumer (mcjty.xnet.api.keys.SidedConsumer)2 SidedPos (mcjty.xnet.api.keys.SidedPos)2 ConnectorBlock (mcjty.xnet.blocks.cables.ConnectorBlock)2 GenericCableBlock (mcjty.xnet.blocks.generic.GenericCableBlock)2 ConnectedBlockClientInfo (mcjty.xnet.clientinfo.ConnectedBlockClientInfo)2 ItemStack (net.minecraft.item.ItemStack)2 SPacketUpdateTileEntity (net.minecraft.network.play.server.SPacketUpdateTileEntity)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 World (net.minecraft.world.World)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Nonnull (javax.annotation.Nonnull)1