Search in sources :

Example 1 with IMultiTile

use of icbm.classic.api.tile.multiblock.IMultiTile 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 IMultiTile

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

the class MultiBlockHelper method buildMultiBlock.

/**
 * Builds a multi block structure using data from the provided hostTile
 *
 * @param world    - world
 * @param hostTile - multiblock host
 * @param validate - if true will check if a hostTile already exists at location rather than placing a new one
 * @param offset   - offset the map position by the hostTile center
 */
public static void buildMultiBlock(World world, IMultiTileHost hostTile, boolean validate, boolean offset) {
    // Rare edge case, should never happen
    if (world == null) {
        logger.error("MultiBlockHelper: buildMultiBlock was called with a null world by " + hostTile, new RuntimeException());
        return;
    }
    // Rare edge case, should never happen
    if (hostTile == null) {
        logger.error("MultiBlockHelper: buildMultiBlock was called with a null hostTile ", new RuntimeException());
        return;
    }
    // Multi-block should be registered but just in case a dev forgot
    if (BlockReg.multiBlock != null) {
        // Get layout of multi-block for it's current state
        Collection<BlockPos> placementList = hostTile.getLayoutOfMultiBlock();
        // Ensure the map is not null or empty in case there is no structure to generate
        if (placementList != null && !placementList.isEmpty()) {
            // Keep track of position just for traceability
            int i = 0;
            // Loop all blocks and start placement
            for (BlockPos location : placementList) {
                if (location == null) {
                    logger.error("MultiBlockHelper: location[" + i + "] is null, this is most likely in error in " + hostTile);
                    i++;
                    continue;
                }
                // Moves the position based on the location of the host
                if (offset) {
                    location = location.add(hostTile.xi(), hostTile.yi(), hostTile.zi());
                }
                TileEntity tile = world.getTileEntity(location);
                if (!validate || tile == null) {
                    if (!world.setBlockState(location, BlockReg.multiBlock.getDefaultState(), 3)) {
                        logger.error("MultiBlockHelper:  error block was not placed ");
                    }
                    tile = world.getTileEntity(location);
                }
                if (tile instanceof IMultiTile) {
                    ((IMultiTile) tile).setHost(hostTile);
                } else {
                    logger.error("MultiBlockHelper: hostTile at location is not IMultiTile, " + tile);
                }
                i++;
            }
        } else {
            logger.error("Tile[" + hostTile + "] didn't return a structure map");
        }
    } else {
        logger.error("MultiBlock was never registered, this is a critical error and can have negative effects on gameplay. " + "Make sure the block was not disabled in the configs and contact support to ensure nothing is broken", new RuntimeException());
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) IMultiTile(icbm.classic.api.tile.multiblock.IMultiTile)

Example 3 with IMultiTile

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

the class MultiBlockHelper method destroyMultiBlockStructure.

/**
 * Breaks down the multiblock stucture linked to the host
 *
 * @param host     - host providing the layour of the structure
 * @param doDrops  - attempt to drop blocks?
 * @param offset   - offset the layout by the location of the host?
 * @param killHost - destroy the host block as well?
 */
public static void destroyMultiBlockStructure(IMultiTileHost host, boolean doDrops, boolean offset, boolean killHost) {
    if (host != null && host.world() != null) {
        // Get tile map
        final Collection<BlockPos> map = host.getLayoutOfMultiBlock();
        if (map != null && !map.isEmpty()) {
            // Get host as a position
            final BlockPos center = host.getPos();
            // Loop tile map
            for (BlockPos pos : map) {
                // Offset position
                if (offset) {
                    pos = pos.add(center);
                }
                // Get tile
                TileEntity tile = host.world().getTileEntity(pos);
                // Validate it is a multi-tile and that it belongs to the host
                if (tile instanceof IMultiTile && ((IMultiTile) tile).isHost(host)) {
                    // Clear and destroy
                    ((IMultiTile) tile).setHost(null);
                    host.world().setBlockToAir(pos);
                }
            }
            // Drop item
            if (doDrops) {
                InventoryUtility.dropBlockAsItem(((TileEntity) host).getWorld(), center, killHost);
            } else // Destroy tile
            if (killHost) {
                ((TileEntity) host).getWorld().setBlockToAir(center);
            }
        } else {
            logger.error("MultiBlockHelper >> Tile[" + host + "]'s structure map is empty");
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) IMultiTile(icbm.classic.api.tile.multiblock.IMultiTile)

Example 4 with IMultiTile

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

the class BlockMultiblock method getPickBlock.

@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
    final IMultiTile multiblock = getTile(world, pos);
    if (multiblock != null && multiblock.getHost() instanceof TileEntity) {
        // Get tile
        TileEntity tileEntity = ((TileEntity) multiblock.getHost());
        // Get state
        IBlockState blockState = tileEntity.getWorld().getBlockState(tileEntity.getPos());
        Block block = blockState.getBlock();
        // Get actual block state
        blockState = block.getActualState(blockState, world, pos);
        // Get stack from state
        ItemStack stack = block.getPickBlock(blockState, target, world, tileEntity.getPos(), player);
        return stack;
    }
    return ItemStack.EMPTY;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) IMultiTile(icbm.classic.api.tile.multiblock.IMultiTile) ItemStack(net.minecraft.item.ItemStack)

Example 5 with IMultiTile

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

the class BlockMultiblock method onBlockAdded.

@Override
public void onBlockAdded(World world, BlockPos pos, IBlockState state) {
    IMultiTile tile = getTile(world, pos);
    if (tile != null && tile.getHost() != null) {
        tile.getHost().onMultiTileAdded(tile);
    }
    super.onBlockAdded(world, pos, state);
}
Also used : IMultiTile(icbm.classic.api.tile.multiblock.IMultiTile)

Aggregations

IMultiTile (icbm.classic.api.tile.multiblock.IMultiTile)6 TileEntity (net.minecraft.tileentity.TileEntity)4 ItemStack (net.minecraft.item.ItemStack)2 BlockPos (net.minecraft.util.math.BlockPos)2 IMissileLauncher (icbm.classic.api.caps.IMissileLauncher)1 IMultiTileHost (icbm.classic.api.tile.multiblock.IMultiTileHost)1 Location (icbm.classic.lib.transform.vector.Location)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1