Search in sources :

Example 1 with TileEntityBackpack

use of net.mcft.copy.betterstorage.tile.entity.TileEntityBackpack in project BetterStorage by copygirl.

the class ItemBackpack method placeBackpack.

/** Place a backpack down on a block.
	 * @param carrier The carrier of the backpack (non-null).
	 * @param player The player placing the backpack, if any.
	 *               Used to check if they're allowed to place it.
	 * @param backpack The backpack stack.
	 *                 Stack size is decreased if placed successfully.
	 * @param side The side of block the backpack is placed on.
	 *             Anything other than top usually doesn't place it.
	 * @param orientation The orientation the backpack will be placed in.
	 * @param despawn If the backpack should despawn after a while.
	 *                True for mobs, unless hit recently.
	 * @param deathDrop True if the backpack is dropped on death.
	 *                  Will not check for block solidity or entities.
	 * @return If the backpack was placed successfully. */
public static boolean placeBackpack(EntityLivingBase carrier, EntityPlayer player, ItemStack backpack, int x, int y, int z, int side, ForgeDirection orientation, boolean despawn, boolean deathDrop) {
    if (backpack.stackSize == 0)
        return false;
    World world = carrier.worldObj;
    Block blockBackpack = ((ItemBackpack) backpack.getItem()).getBlockType();
    // Return false if there's block is too low or too high.
    if ((y <= 0) || (y >= world.getHeight() - 1))
        return false;
    // Otherwise, check if the top side was clicked and adjust the position.
    if (!world.getBlock(x, y, z).isReplaceable(world, x, y, z)) {
        if (side != 1)
            return false;
        y++;
    }
    // If the backpack is dropped on death, return false
    // if it's placed on a non-replaceable block. Otherwise,
    // return false if the block isn't solid on top.
    Block blockBelow = world.getBlock(x, y - 1, z);
    if ((deathDrop ? blockBelow.isReplaceable(world, x, y - 1, z) : !world.isSideSolid(x, y - 1, z, ForgeDirection.UP)))
        return false;
    // Return false if there's an entity blocking the placement.
    if (!world.canPlaceEntityOnSide(blockBackpack, x, y, z, deathDrop, side, carrier, backpack))
        return false;
    // Return false if the player can't edit the block.
    if ((player != null) && (!world.canMineBlock(player, x, y, z) || !player.canPlayerEdit(x, y, z, side, backpack)))
        return false;
    // Do not actually place the backpack on the client.
    if (world.isRemote)
        return true;
    if (!world.setBlock(x, y, z, blockBackpack, orientation.ordinal(), 3))
        return false;
    if (world.getBlock(x, y, z) != blockBackpack)
        return false;
    blockBackpack.onBlockPlacedBy(world, x, y, z, carrier, backpack);
    blockBackpack.onPostBlockPlaced(world, x, y, z, orientation.ordinal());
    TileEntityBackpack te = WorldUtils.get(world, x, y, z, TileEntityBackpack.class);
    te.stack = backpack.copy();
    if (ItemBackpack.getBackpack(carrier) == backpack)
        te.unequip(carrier, despawn);
    String sound = blockBackpack.stepSound.func_150496_b();
    float volume = (blockBackpack.stepSound.getVolume() + 1.0F) / 2.0F;
    float pitch = blockBackpack.stepSound.getPitch() * 0.8F;
    world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5F, sound, volume, pitch);
    backpack.stackSize--;
    return true;
}
Also used : TileEntityBackpack(net.mcft.copy.betterstorage.tile.entity.TileEntityBackpack) Block(net.minecraft.block.Block) World(net.minecraft.world.World)

Example 2 with TileEntityBackpack

use of net.mcft.copy.betterstorage.tile.entity.TileEntityBackpack in project BetterStorage by copygirl.

the class TileEnderBackpack method teleportRandomly.

public static boolean teleportRandomly(World world, double sourceX, double sourceY, double sourceZ, boolean canFloat, ItemStack stack) {
    int x = (int) sourceX + RandomUtils.getInt(-12, 12 + 1);
    int y = (int) sourceY + RandomUtils.getInt(-8, 8 + 1);
    int z = (int) sourceZ + RandomUtils.getInt(-12, 12 + 1);
    y = Math.max(1, Math.min(world.getHeight() - 1, y));
    if (!world.blockExists(x, y, z))
        return false;
    Block block = world.getBlock(x, y, z);
    if (!block.isReplaceable(world, x, y, z))
        return false;
    if (!canFloat && !world.isSideSolid(x, y - 1, z, ForgeDirection.UP))
        return false;
    BetterStorage.networkChannel.sendToAllAround(new PacketBackpackTeleport(sourceX, sourceY, sourceZ, x, y, z), world, sourceX + 0.5, sourceY + 0.5, sourceZ + 0.5, 256);
    world.playSoundEffect(sourceX + 0.5, sourceY + 0.5, sourceZ + 0.5, "mob.endermen.portal", 1.0F, 1.0F);
    world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, "mob.endermen.portal", 1.0F, 1.0F);
    world.setBlock(x, y, z, ((ItemBackpack) stack.getItem()).getBlockType(), RandomUtils.getInt(2, 6), 3);
    TileEntityBackpack newBackpack = WorldUtils.get(world, x, y, z, TileEntityBackpack.class);
    newBackpack.stack = stack;
    return true;
}
Also used : PacketBackpackTeleport(net.mcft.copy.betterstorage.network.packet.PacketBackpackTeleport) TileEntityBackpack(net.mcft.copy.betterstorage.tile.entity.TileEntityBackpack) Block(net.minecraft.block.Block)

Example 3 with TileEntityBackpack

use of net.mcft.copy.betterstorage.tile.entity.TileEntityBackpack in project BetterStorage by copygirl.

the class TileEnderBackpack method onBlockActivated.

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
    if (!world.isRemote) {
        TileEntityBackpack backpack = WorldUtils.get(world, x, y, z, TileEntityBackpack.class);
        IInventory inventory = new InventoryTileEntity(backpack, player.getInventoryEnderChest());
        Container container = new ContainerBetterStorage(player, inventory, 9, 3);
        String name = "container." + Constants.modId + ".enderBackpack";
        PlayerUtils.openGui(player, name, 9, 3, backpack.getCustomTitle(), container);
    }
    return true;
}
Also used : IInventory(net.minecraft.inventory.IInventory) ContainerBetterStorage(net.mcft.copy.betterstorage.container.ContainerBetterStorage) Container(net.minecraft.inventory.Container) TileEntityBackpack(net.mcft.copy.betterstorage.tile.entity.TileEntityBackpack) InventoryTileEntity(net.mcft.copy.betterstorage.inventory.InventoryTileEntity)

Aggregations

TileEntityBackpack (net.mcft.copy.betterstorage.tile.entity.TileEntityBackpack)3 Block (net.minecraft.block.Block)2 ContainerBetterStorage (net.mcft.copy.betterstorage.container.ContainerBetterStorage)1 InventoryTileEntity (net.mcft.copy.betterstorage.inventory.InventoryTileEntity)1 PacketBackpackTeleport (net.mcft.copy.betterstorage.network.packet.PacketBackpackTeleport)1 Container (net.minecraft.inventory.Container)1 IInventory (net.minecraft.inventory.IInventory)1 World (net.minecraft.world.World)1