Search in sources :

Example 1 with TileEntityEtherCompressor

use of ValkyrienWarfareBase.API.Block.EtherCompressor.TileEntityEtherCompressor in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ItemSystemLinker method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    IBlockState state = worldIn.getBlockState(pos);
    Block block = state.getBlock();
    NBTTagCompound stackCompound = stack.getTagCompound();
    if (stackCompound == null) {
        stackCompound = new NBTTagCompound();
        stack.setTagCompound(stackCompound);
    }
    if (block instanceof BlockHovercraftController) {
        if (!worldIn.isRemote) {
            NBTUtils.writeBlockPosToNBT("controllerPos", pos, stackCompound);
            playerIn.addChatMessage(new TextComponentString("ControllerPos set <" + pos.getX() + ":" + pos.getY() + ":" + pos.getZ() + ">"));
        } else {
            return EnumActionResult.SUCCESS;
        }
    }
    if (block instanceof BlockEtherCompressor) {
        if (!worldIn.isRemote) {
            BlockPos controllerPos = NBTUtils.readBlockPosFromNBT("controllerPos", stackCompound);
            if (controllerPos.equals(BlockPos.ORIGIN)) {
                playerIn.addChatMessage(new TextComponentString("No selected Controller"));
            } else {
                PhysicsWrapperEntity controllerWrapper = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(worldIn, controllerPos);
                PhysicsWrapperEntity engineWrapper = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(worldIn, pos);
                if (controllerWrapper != engineWrapper) {
                    playerIn.addChatMessage(new TextComponentString("Controller and Engine are on seperate ships"));
                    return EnumActionResult.SUCCESS;
                }
                TileEntity worldTile = worldIn.getTileEntity(pos);
                if (worldTile instanceof TileEntityEtherCompressor) {
                    TileEntityEtherCompressor tileEntity = (TileEntityEtherCompressor) worldTile;
                    BlockPos gravControllerPos = tileEntity.controllerPos;
                    if (gravControllerPos.equals(BlockPos.ORIGIN)) {
                        playerIn.addChatMessage(new TextComponentString("Set Controller To " + controllerPos.toString()));
                    } else {
                        playerIn.addChatMessage(new TextComponentString("Replaced controller position from: " + gravControllerPos.toString() + " to: " + controllerPos.toString()));
                    }
                    tileEntity.setController(controllerPos);
                }
            }
        } else {
            return EnumActionResult.SUCCESS;
        }
    }
    return EnumActionResult.PASS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockHovercraftController(ValkyrienWarfareControl.Block.BlockHovercraftController) BlockEtherCompressor(ValkyrienWarfareBase.API.Block.EtherCompressor.BlockEtherCompressor) IBlockState(net.minecraft.block.state.IBlockState) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) TileEntityEtherCompressor(ValkyrienWarfareBase.API.Block.EtherCompressor.TileEntityEtherCompressor) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

BlockEtherCompressor (ValkyrienWarfareBase.API.Block.EtherCompressor.BlockEtherCompressor)1 TileEntityEtherCompressor (ValkyrienWarfareBase.API.Block.EtherCompressor.TileEntityEtherCompressor)1 PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)1 BlockHovercraftController (ValkyrienWarfareControl.Block.BlockHovercraftController)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 TextComponentString (net.minecraft.util.text.TextComponentString)1