Search in sources :

Example 6 with TileEntityBambooChest

use of net.tropicraft.core.common.block.tileentity.TileEntityBambooChest in project Tropicraft by Tropicraft.

the class BambooDoubleChestItemHandler method get.

@Nullable
public static BambooDoubleChestItemHandler get(TileEntityBambooChest chest) {
    World world = chest.getWorld();
    BlockPos pos = chest.getPos();
    if (world == null || pos == null || !world.isBlockLoaded(pos))
        // Still loading
        return null;
    Block blockType = chest.getBlockType();
    EnumFacing[] horizontals = EnumFacing.HORIZONTALS;
    for (// Use reverse order so we can return early
    int i = horizontals.length - 1; // Use reverse order so we can return early
    i >= 0; // Use reverse order so we can return early
    i--) {
        EnumFacing enumfacing = horizontals[i];
        BlockPos blockpos = pos.offset(enumfacing);
        Block block = world.getBlockState(blockpos).getBlock();
        if (block == blockType) {
            TileEntity otherTE = world.getTileEntity(blockpos);
            if (otherTE instanceof TileEntityBambooChest) {
                TileEntityBambooChest otherChest = (TileEntityBambooChest) otherTE;
                return new BambooDoubleChestItemHandler(chest, otherChest, enumfacing != net.minecraft.util.EnumFacing.WEST && enumfacing != net.minecraft.util.EnumFacing.NORTH);
            }
        }
    }
    // All alone
    return NO_ADJACENT_CHESTS_INSTANCE;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) TileEntityBambooChest(net.tropicraft.core.common.block.tileentity.TileEntityBambooChest) Nullable(javax.annotation.Nullable)

Example 7 with TileEntityBambooChest

use of net.tropicraft.core.common.block.tileentity.TileEntityBambooChest in project Tropicraft by Tropicraft.

the class BambooDoubleChestItemHandler method equals.

@Override
public boolean equals(Object o) {
    if (this == o)
        return true;
    if (o == null || getClass() != o.getClass())
        return false;
    BambooDoubleChestItemHandler that = (BambooDoubleChestItemHandler) o;
    if (hashCode != that.hashCode)
        return false;
    final TileEntityBambooChest otherChest = getOtherChest();
    if (mainChestIsUpper == that.mainChestIsUpper)
        return Objects.equal(mainChest, that.mainChest) && Objects.equal(otherChest, that.getOtherChest());
    else
        return Objects.equal(mainChest, that.getOtherChest()) && Objects.equal(otherChest, that.mainChest);
}
Also used : TileEntityBambooChest(net.tropicraft.core.common.block.tileentity.TileEntityBambooChest)

Example 8 with TileEntityBambooChest

use of net.tropicraft.core.common.block.tileentity.TileEntityBambooChest in project Tropicraft by Tropicraft.

the class BlockBambooChest method neighborChanged.

/**
 * Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
 * change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
 * block, etc.
 */
@Override
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) {
    super.neighborChanged(state, worldIn, pos, blockIn, fromPos);
    TileEntity tileentity = worldIn.getTileEntity(pos);
    if (tileentity instanceof TileEntityBambooChest) {
        tileentity.updateContainingBlockInfo();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityBambooChest(net.tropicraft.core.common.block.tileentity.TileEntityBambooChest)

Example 9 with TileEntityBambooChest

use of net.tropicraft.core.common.block.tileentity.TileEntityBambooChest in project Tropicraft by Tropicraft.

the class WorldGenSunkenShip method generate.

@Override
public boolean generate(BlockPos pos) {
    int i = pos.getX();
    int j = pos.getY();
    int k = pos.getZ();
    this.setOrigin(i, k);
    if (TCGenUtils.getBlock(worldObj, i, j + 4, k) != BlockRegistry.tropicsWater) {
        // Must be water 4 blocks above the sea floor
        return false;
    }
    // Move the "origin" up
    j += 1;
    final int length = this.rand.nextInt(25) + 25;
    int y = j;
    while (true) {
        // Acting y loop
        boolean hasGenned = false;
        int fib = 2;
        int lastFib = 1;
        int width = y - j;
        for (int x = 0; x < length; x++) {
            if (x == fib && x <= (length / 3D)) {
                width++;
                fib += lastFib;
                lastFib = fib - lastFib;
            }
            if (x > length - 3) {
                width--;
            }
            if (width >= 0) {
                for (int z = -width; z <= width; z++) {
                    if (rand.nextInt(5) < 3) {
                        if (y == j || x == length - 1) {
                            this.placeBlockWithDir(x, y, z, PLANK_STATE);
                            if (z == -width || z == width || x == length - 1) {
                                this.placeBlockWithDir(x, y + 1, z, PLANK_STATE);
                            }
                            if (x == length / 2 && z == 0) {
                                this.placeBlockWithDir(x, y + 1, z, PLANK_STATE);
                                this.placeBlockWithDir(x, y + 2, z, PLANK_STATE);
                                this.placeBlockWithDir(x, y + 3, z, PLANK_STATE);
                            }
                        } else if (x == length / 2 && z == 0 && y == j - 2) {
                            this.placeBlockWithDir(x, y, z, BlockRegistry.bambooChest.getDefaultState());
                            BlockPos pos2 = new BlockPos(x, y, z);
                            TileEntityBambooChest chest = (TileEntityBambooChest) this.getTEWithDir(pos2);
                            if (chest != null) {
                                for (int b = 0; b < rand.nextInt(5) + 10; b++) {
                                    chest.setInventorySlotContents(b, this.randLoot());
                                }
                            }
                        } else if (z == -width || z == width) {
                            this.placeBlockWithDir(x, y, z, PLANK_STATE);
                        } else {
                            this.placeBlockWithDir(x, y, z, Blocks.AIR.getDefaultState());
                        }
                    }
                }
                hasGenned = true;
            }
        }
        if (!hasGenned) {
            break;
        }
        y--;
    }
    return false;
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) TileEntityBambooChest(net.tropicraft.core.common.block.tileentity.TileEntityBambooChest)

Example 10 with TileEntityBambooChest

use of net.tropicraft.core.common.block.tileentity.TileEntityBambooChest in project Tropicraft by Tropicraft.

the class TeleporterTropics method placeInExistingPortal.

@Override
public boolean placeInExistingPortal(Entity entity, float f) {
    int searchArea = 148;
    double closestPortal = -1D;
    int foundX = 0;
    int foundY = 0;
    int foundZ = 0;
    int entityX = MathHelper.floor(entity.posX);
    int entityZ = MathHelper.floor(entity.posZ);
    BlockPos blockpos = BlockPos.ORIGIN;
    boolean notInCache = true;
    long j1 = ChunkPos.asLong(entityX, entityZ);
    if (destinationCoordinateCache.containsKey(j1)) {
        // System.out.println("Setting closest portal to 0");
        PortalPosition portalposition = (PortalPosition) destinationCoordinateCache.get(j1);
        closestPortal = 0.0D;
        blockpos = portalposition;
        portalposition.lastUpdateTime = world.getTotalWorldTime();
        notInCache = false;
    } else {
        for (int x = entityX - searchArea; x <= entityX + searchArea; x++) {
            double distX = x + 0.5D - entity.posX;
            for (int z = entityZ - searchArea; z <= entityZ + searchArea; z++) {
                double distZ = z + 0.5D - entity.posZ;
                for (int y = world.getActualHeight() - 1; y >= 0; y--) {
                    BlockPos pos = new BlockPos(x, y, z);
                    if (world.getBlockState(pos).getBlock() == PORTAL_BLOCK) {
                        pos = pos.down();
                        while (world.getBlockState(pos).getBlock() == PORTAL_BLOCK) {
                            --y;
                            pos = pos.down();
                        }
                        double distY = y + 0.5D - entity.posY;
                        double distance = distX * distX + distY * distY + distZ * distZ;
                        if (closestPortal < 0.0D || distance < closestPortal) {
                            closestPortal = distance;
                            foundX = x;
                            foundY = y;
                            foundZ = z;
                        }
                    }
                }
            }
        }
    }
    if (closestPortal >= 0.0D) {
        if (notInCache) {
            this.destinationCoordinateCache.put(j1, new Teleporter.PortalPosition(blockpos, this.world.getTotalWorldTime()));
        }
        int x = foundX;
        int y = foundY;
        int z = foundZ;
        double newLocX = x + 0.5D;
        double newLocY = y + 0.5D;
        double newLocZ = z + 0.5D;
        BlockPos pos = new BlockPos(x, y, z);
        if (world.getBlockState(pos.offset(EnumFacing.WEST)).getBlock() == PORTAL_BLOCK) {
            newLocX -= 0.5D;
        }
        if (world.getBlockState(pos.offset(EnumFacing.EAST)).getBlock() == PORTAL_BLOCK) {
            newLocX += 0.5D;
        }
        if (world.getBlockState(pos.offset(EnumFacing.NORTH)).getBlock() == PORTAL_BLOCK) {
            newLocZ -= 0.5D;
        }
        if (world.getBlockState(pos.offset(EnumFacing.SOUTH)).getBlock() == PORTAL_BLOCK) {
            newLocZ += 0.5D;
        }
        entity.setLocationAndAngles(newLocX, newLocY + 2, newLocZ, entity.rotationYaw, 0.0F);
        // TODO + ((new Random()).nextBoolean() ? 3 : -3);
        int worldSpawnX = MathHelper.floor(newLocX);
        // TODO + ((new Random()).nextBoolean() ? 3 : -3);
        int worldSpawnZ = MathHelper.floor(newLocZ);
        // Move to top of portal
        int worldSpawnY = foundY + 5;
        entity.motionX = entity.motionY = entity.motionZ = 0.0D;
        // already in the chest)
        if (entity instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) entity;
            if (world.provider instanceof WorldProviderTropicraft) {
                // TODO improve this logical check to an NBT tag or something?
                if (!player.inventory.hasItemStack(new ItemStack(ItemRegistry.encyclopedia))) {
                    // Search for the spawn chest
                    TileEntityBambooChest chest = null;
                    int chestX = MathHelper.floor(newLocX);
                    int chestZ = MathHelper.floor(newLocZ);
                    chestSearch: for (int searchX = -3; searchX < 4; searchX++) {
                        for (int searchZ = -3; searchZ < 4; searchZ++) {
                            for (int searchY = -4; searchY < 5; searchY++) {
                                BlockPos chestPos = new BlockPos(chestX + searchX, worldSpawnY + searchY, chestZ + searchZ);
                                if (world.getBlockState(chestPos).getBlock() == BlockRegistry.bambooChest) {
                                    chest = (TileEntityBambooChest) world.getTileEntity(chestPos);
                                    if (chest != null && chest.isUnbreakable()) {
                                        break chestSearch;
                                    }
                                }
                            }
                        }
                    }
                    // Make sure chest doesn't have the encyclopedia
                    if (chest != null && chest.isUnbreakable()) {
                        boolean hasEncyclopedia = false;
                        for (int inv = 0; inv < chest.getSizeInventory(); inv++) {
                            ItemStack stack = chest.getStackInSlot(inv);
                            if (stack.getItem() == ItemRegistry.encyclopedia) {
                                hasEncyclopedia = true;
                            }
                        }
                        // Give out a new encyclopedia
                        if (!hasEncyclopedia) {
                            for (int inv = 0; inv < chest.getSizeInventory(); inv++) {
                                ItemStack stack = chest.getStackInSlot(inv);
                                if (stack.isEmpty()) {
                                    chest.setInventorySlotContents(inv, new ItemStack(ItemRegistry.encyclopedia, 1));
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        return true;
    } else {
        return false;
    }
}
Also used : Teleporter(net.minecraft.world.Teleporter) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) TileEntityBambooChest(net.tropicraft.core.common.block.tileentity.TileEntityBambooChest)

Aggregations

TileEntityBambooChest (net.tropicraft.core.common.block.tileentity.TileEntityBambooChest)10 BlockPos (net.minecraft.util.math.BlockPos)5 ItemStack (net.minecraft.item.ItemStack)3 TileEntity (net.minecraft.tileentity.TileEntity)3 Nonnull (javax.annotation.Nonnull)2 Nullable (javax.annotation.Nullable)2 Block (net.minecraft.block.Block)2 EnumFacing (net.minecraft.util.EnumFacing)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 InventoryLargeChest (net.minecraft.inventory.InventoryLargeChest)1 ILockableContainer (net.minecraft.world.ILockableContainer)1 Teleporter (net.minecraft.world.Teleporter)1 World (net.minecraft.world.World)1 IItemHandler (net.minecraftforge.items.IItemHandler)1 IItemHandlerModifiable (net.minecraftforge.items.IItemHandlerModifiable)1