Search in sources :

Example 1 with IMultiTileHost

use of icbm.classic.api.tile.multiblock.IMultiTileHost in project ICBM-Classic by BuiltBrokenModding.

the class ItemRadarGun method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = player.getHeldItem(hand);
    if (world.isRemote) {
        return EnumActionResult.SUCCESS;
    }
    Location location = new Location(world, pos);
    TileEntity tile = location.getTileEntity();
    if (tile instanceof IMultiTile) {
        IMultiTileHost host = ((IMultiTile) tile).getHost();
        if (host instanceof TileEntity) {
            tile = (TileEntity) host;
        }
    }
    if (player.isSneaking()) {
        stack.setTagCompound(null);
        stack.setItemDamage(0);
        LanguageUtility.addChatToPlayer(player, "gps.cleared.name");
        player.inventoryContainer.detectAndSendChanges();
        return EnumActionResult.SUCCESS;
    } else {
        Location storedLocation = getLocation(stack);
        if (ICBMClassicHelpers.isLauncher(tile, facing)) {
            if (storedLocation == null) {
                LanguageUtility.addChatToPlayer(player, "gps.error.pos.invalid.null.name");
                return EnumActionResult.SUCCESS;
            } else if (!storedLocation.isAboveBedrock()) {
                LanguageUtility.addChatToPlayer(player, "gps.error.pos.invalid.name");
                return EnumActionResult.SUCCESS;
            } else if (storedLocation.world != world) {
                LanguageUtility.addChatToPlayer(player, "gps.error.pos.invalid.world.name");
                return EnumActionResult.SUCCESS;
            } else {
                final IMissileLauncher launcher = ICBMClassicHelpers.getLauncher(tile, facing);
                if (launcher != null) {
                    launcher.setTarget(storedLocation.x(), storedLocation.y(), storedLocation.z());
                    LanguageUtility.addChatToPlayer(player, "gps.data.transferred.name");
                    return EnumActionResult.SUCCESS;
                }
            }
        } else if (// otherwise, save the currently clicked block as a location if the trace event has not been canceled
        trace(pos, player))
            return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.PASS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IMissileLauncher(icbm.classic.api.caps.IMissileLauncher) ItemStack(net.minecraft.item.ItemStack) IMultiTile(icbm.classic.api.tile.multiblock.IMultiTile) IMultiTileHost(icbm.classic.api.tile.multiblock.IMultiTileHost) Location(icbm.classic.lib.transform.vector.Location)

Example 2 with IMultiTileHost

use of icbm.classic.api.tile.multiblock.IMultiTileHost in project ICBM-Classic by BuiltBrokenModding.

the class BlockICBM method breakBlock.

@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
    TileEntity tile = world.getTileEntity(pos);
    if (tile instanceof IInventoryProvider && ((IInventoryProvider) tile).getInventory() != null) {
        InventoryHelper.dropInventoryItems(world, pos, ((IInventoryProvider) tile).getInventory());
    }
    if (tile instanceof IMultiTileHost) {
        // At this point the structure should already be dead if broken by a player
        MultiBlockHelper.destroyMultiBlockStructure((IMultiTileHost) tile, false, true, false);
    }
    super.breakBlock(world, pos, state);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IMultiTileHost(icbm.classic.api.tile.multiblock.IMultiTileHost) IInventoryProvider(icbm.classic.prefab.inventory.IInventoryProvider)

Aggregations

IMultiTileHost (icbm.classic.api.tile.multiblock.IMultiTileHost)2 TileEntity (net.minecraft.tileentity.TileEntity)2 IMissileLauncher (icbm.classic.api.caps.IMissileLauncher)1 IMultiTile (icbm.classic.api.tile.multiblock.IMultiTile)1 Location (icbm.classic.lib.transform.vector.Location)1 IInventoryProvider (icbm.classic.prefab.inventory.IInventoryProvider)1 ItemStack (net.minecraft.item.ItemStack)1