Search in sources :

Example 1 with TileEntityAncientChestMP

use of stevekung.mods.moreplanets.util.tileentity.TileEntityAncientChestMP in project MorePlanets by SteveKunG.

the class RoomChestMP method addComponentParts.

@Override
public boolean addComponentParts(World world, Random rand, StructureBoundingBox boundingBox) {
    if (super.addComponentParts(world, rand, boundingBox)) {
        int chestX = this.sizeX / 2;
        int chestY = 1;
        int chestZ = this.sizeZ / 2;
        this.setBlockState(world, this.configuration.getAncientChestBlock().withProperty(BlockStateHelper.FACING_HORIZON, this.getDirection().getOpposite()), chestX, chestY, chestZ, boundingBox);
        BlockPos blockpos = new BlockPos(this.getXWithOffset(chestX, chestZ), this.getYWithOffset(chestY), this.getZWithOffset(chestX, chestZ));
        TileEntityAncientChestMP chest = (TileEntityAncientChestMP) world.getTileEntity(blockpos);
        if (chest != null) {
            chest.setLootTable(MPLootTables.COMMON_SPACE_DUNGEON, rand.nextLong());
        }
        return true;
    }
    return false;
}
Also used : TileEntityAncientChestMP(stevekung.mods.moreplanets.util.tileentity.TileEntityAncientChestMP) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with TileEntityAncientChestMP

use of stevekung.mods.moreplanets.util.tileentity.TileEntityAncientChestMP in project MorePlanets by SteveKunG.

the class WorldGenSpaceDungeons method generate.

@Override
public boolean generate(World world, Random rand, BlockPos pos) {
    int i = rand.nextInt(2) + 2;
    int j = -i - 1;
    int k = i + 1;
    int l = rand.nextInt(2) + 2;
    int i1 = -l - 1;
    int j1 = l + 1;
    int k1 = 0;
    int l1;
    int i2;
    int j2;
    BlockPos blockpos1;
    for (l1 = j; l1 <= k; ++l1) {
        for (i2 = -1; i2 <= 4; ++i2) {
            for (j2 = i1; j2 <= j1; ++j2) {
                blockpos1 = pos.add(l1, i2, j2);
                Material material = world.getBlockState(blockpos1).getMaterial();
                boolean flag3 = material.isSolid();
                if (i2 == -1 && !flag3) {
                    return false;
                }
                if (i2 == 4 && !flag3) {
                    return false;
                }
                if ((l1 == j || l1 == k || j2 == i1 || j2 == j1) && i2 == 0 && world.isAirBlock(blockpos1) && world.isAirBlock(blockpos1.up())) {
                    ++k1;
                }
            }
        }
    }
    if (k1 >= 1 && k1 <= 5) {
        for (l1 = j; l1 <= k; ++l1) {
            for (i2 = 3; i2 >= -1; --i2) {
                for (j2 = i1; j2 <= j1; ++j2) {
                    blockpos1 = pos.add(l1, i2, j2);
                    if (l1 != j && i2 != -1 && j2 != i1 && l1 != k && i2 != 4 && j2 != j1) {
                        if (world.getBlockState(blockpos1).getBlock() != this.chest) {
                            world.setBlockToAir(blockpos1);
                        }
                    } else if (blockpos1.getY() >= 0 && !world.getBlockState(blockpos1.down()).getMaterial().isSolid()) {
                        world.setBlockToAir(blockpos1);
                    } else if (world.getBlockState(blockpos1).getMaterial().isSolid() && world.getBlockState(blockpos1).getBlock() != this.chest) {
                        if (i2 == -1 && rand.nextInt(4) != 0) {
                            world.setBlockState(blockpos1, this.moss.getStateFromMeta(this.mossMeta), 2);
                        } else {
                            world.setBlockState(blockpos1, this.cobblestone.getStateFromMeta(this.cobbleMeta), 2);
                        }
                    }
                }
            }
        }
        l1 = 0;
        while (l1 < 2) {
            i2 = 0;
            while (true) {
                if (i2 < 3) {
                    label100: {
                        j2 = pos.getX() + rand.nextInt(i * 2 + 1) - i;
                        int l2 = pos.getY();
                        int i3 = pos.getZ() + rand.nextInt(l * 2 + 1) - l;
                        BlockPos blockpos2 = new BlockPos(j2, l2, i3);
                        if (world.isAirBlock(blockpos2)) {
                            int k2 = 0;
                            Iterator iterator = EnumFacing.Plane.HORIZONTAL.iterator();
                            while (iterator.hasNext()) {
                                EnumFacing enumfacing = (EnumFacing) iterator.next();
                                if (world.getBlockState(blockpos2.offset(enumfacing)).getMaterial().isSolid()) {
                                    ++k2;
                                }
                            }
                            if (k2 == 1) {
                                world.setBlockState(blockpos2, ((BlockAncientChestMP) this.chest).correctFacing(world, blockpos2, this.chest.getDefaultState()), 2);
                                TileEntity tileentity1 = world.getTileEntity(blockpos2);
                                if (tileentity1 instanceof TileEntityAncientChestMP) {
                                    ((TileEntityAncientChestMP) tileentity1).setLootTable(MPLootTables.COMMON_SPACE_DUNGEON, rand.nextLong());
                                }
                                break label100;
                            }
                        }
                        ++i2;
                        continue;
                    }
                }
                ++l1;
                break;
            }
        }
        world.setBlockState(pos, Blocks.MOB_SPAWNER.getDefaultState(), 2);
        TileEntity tileentity = world.getTileEntity(pos);
        if (tileentity instanceof TileEntityMobSpawner) {
            ((TileEntityMobSpawner) tileentity).getSpawnerBaseLogic().setEntityId(this.pickMobSpawner(rand));
        } else {
            MPLog.error("Failed to fetch mob spawner entity at x:{} y:{} z:{}", pos.getX(), pos.getY(), pos.getZ());
        }
        MPLog.debug("Generate {} spawner at: x:{} y:{} z:{}", ((TileEntityMobSpawner) tileentity).getSpawnerBaseLogic().getEntityId().toString(), pos.getX(), pos.getY(), pos.getZ());
        return true;
    } else {
        return false;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityAncientChestMP(stevekung.mods.moreplanets.util.tileentity.TileEntityAncientChestMP) EnumFacing(net.minecraft.util.EnumFacing) Iterator(java.util.Iterator) BlockPos(net.minecraft.util.math.BlockPos) Material(net.minecraft.block.material.Material) TileEntityMobSpawner(net.minecraft.tileentity.TileEntityMobSpawner)

Example 3 with TileEntityAncientChestMP

use of stevekung.mods.moreplanets.util.tileentity.TileEntityAncientChestMP in project MorePlanets by SteveKunG.

the class DoubleAncientChestItemHandlerMP method get.

public static DoubleAncientChestItemHandlerMP get(TileEntityAncientChestMP chest) {
    World world = chest.getWorld();
    BlockPos pos = chest.getPos();
    if (world == null || pos == null || !world.isBlockLoaded(pos)) {
        return null;
    }
    Block blockType = chest.getBlockType();
    EnumFacing[] horizontals = EnumFacing.HORIZONTALS;
    for (int i = horizontals.length - 1; i >= 0; 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 TileEntityAncientChestMP) {
                TileEntityAncientChestMP otherChest = (TileEntityAncientChestMP) otherTE;
                return new DoubleAncientChestItemHandlerMP(chest, otherChest, enumfacing != net.minecraft.util.EnumFacing.WEST && enumfacing != net.minecraft.util.EnumFacing.NORTH);
            }
        }
    }
    return NO_ADJACENT_CHESTS_INSTANCE;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityAncientChestMP(stevekung.mods.moreplanets.util.tileentity.TileEntityAncientChestMP) EnumFacing(net.minecraft.util.EnumFacing) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World)

Example 4 with TileEntityAncientChestMP

use of stevekung.mods.moreplanets.util.tileentity.TileEntityAncientChestMP in project MorePlanets by SteveKunG.

the class DoubleAncientChestItemHandlerMP method getStackInSlot.

@Override
public ItemStack getStackInSlot(int slot) {
    boolean accessingUpperChest = slot < 27;
    int targetSlot = accessingUpperChest ? slot : slot - 27;
    TileEntityAncientChestMP chest = this.getChest(accessingUpperChest);
    return chest != null ? chest.getStackInSlot(targetSlot) : ItemStack.EMPTY;
}
Also used : TileEntityAncientChestMP(stevekung.mods.moreplanets.util.tileentity.TileEntityAncientChestMP)

Example 5 with TileEntityAncientChestMP

use of stevekung.mods.moreplanets.util.tileentity.TileEntityAncientChestMP in project MorePlanets by SteveKunG.

the class DoubleAncientChestItemHandlerMP method equals.

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }
    if (o == null || this.getClass() != o.getClass()) {
        return false;
    }
    DoubleAncientChestItemHandlerMP that = (DoubleAncientChestItemHandlerMP) o;
    if (this.hashCode != that.hashCode) {
        return false;
    }
    TileEntityAncientChestMP otherChest = this.getOtherChest();
    if (this.mainChestIsUpper == that.mainChestIsUpper) {
        return Objects.equal(this.mainChest, that.mainChest) && Objects.equal(otherChest, that.getOtherChest());
    } else {
        return Objects.equal(this.mainChest, that.getOtherChest()) && Objects.equal(otherChest, that.mainChest);
    }
}
Also used : TileEntityAncientChestMP(stevekung.mods.moreplanets.util.tileentity.TileEntityAncientChestMP)

Aggregations

TileEntityAncientChestMP (stevekung.mods.moreplanets.util.tileentity.TileEntityAncientChestMP)8 BlockPos (net.minecraft.util.math.BlockPos)4 TileEntity (net.minecraft.tileentity.TileEntity)2 EnumFacing (net.minecraft.util.EnumFacing)2 Iterator (java.util.Iterator)1 Block (net.minecraft.block.Block)1 Material (net.minecraft.block.material.Material)1 TileEntityMobSpawner (net.minecraft.tileentity.TileEntityMobSpawner)1 World (net.minecraft.world.World)1