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;
}
Aggregations