Search in sources :

Example 1 with TileEntityChestMP

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

the class SpaceDoubleChestItemHandlerMP method get.

public static SpaceDoubleChestItemHandlerMP get(TileEntityChestMP 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 TileEntityChestMP) {
                TileEntityChestMP otherChest = (TileEntityChestMP) otherTE;
                return new SpaceDoubleChestItemHandlerMP(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) TileEntityChestMP(stevekung.mods.moreplanets.util.tileentity.TileEntityChestMP) EnumFacing(net.minecraft.util.EnumFacing) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World)

Example 2 with TileEntityChestMP

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

the class SpaceDoubleChestItemHandlerMP method getStackInSlot.

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

Example 3 with TileEntityChestMP

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

the class BlockChestMP method onBlockPlacedBy.

@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack itemStack) {
    EnumFacing enumfacing = EnumFacing.getHorizontal(MathHelper.floor(placer.rotationYaw * 4.0F / 360.0F + 0.5D) & 3).getOpposite();
    state = state.withProperty(BlockStateHelper.FACING_HORIZON, enumfacing);
    BlockPos blockpos = pos.north();
    BlockPos blockpos1 = pos.south();
    BlockPos blockpos2 = pos.west();
    BlockPos blockpos3 = pos.east();
    boolean flag = this == world.getBlockState(blockpos).getBlock();
    boolean flag1 = this == world.getBlockState(blockpos1).getBlock();
    boolean flag2 = this == world.getBlockState(blockpos2).getBlock();
    boolean flag3 = this == world.getBlockState(blockpos3).getBlock();
    if (!flag && !flag1 && !flag2 && !flag3) {
        world.setBlockState(pos, state, 3);
    } else if (enumfacing.getAxis() != EnumFacing.Axis.X || !flag && !flag1) {
        if (enumfacing.getAxis() == EnumFacing.Axis.Z && (flag2 || flag3)) {
            if (flag2) {
                world.setBlockState(blockpos2, state, 3);
            } else {
                world.setBlockState(blockpos3, state, 3);
            }
            world.setBlockState(pos, state, 3);
        }
    } else {
        if (flag) {
            world.setBlockState(blockpos, state, 3);
        } else {
            world.setBlockState(blockpos1, state, 3);
        }
        world.setBlockState(pos, state, 3);
    }
    if (itemStack.hasDisplayName()) {
        TileEntity tileentity = world.getTileEntity(pos);
        if (tileentity instanceof TileEntityChestMP) {
            ((TileEntityChestMP) tileentity).setCustomName(itemStack.getDisplayName());
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityChestMP(stevekung.mods.moreplanets.util.tileentity.TileEntityChestMP) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with TileEntityChestMP

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

the class SpaceDoubleChestItemHandlerMP method insertItem.

@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
    boolean accessingUpperChest = slot < 27;
    int targetSlot = accessingUpperChest ? slot : slot - 27;
    TileEntityChestMP chest = this.getChest(accessingUpperChest);
    return chest != null ? chest.getSingleChestHandler().insertItem(targetSlot, stack, simulate) : stack;
}
Also used : TileEntityChestMP(stevekung.mods.moreplanets.util.tileentity.TileEntityChestMP)

Example 5 with TileEntityChestMP

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

the class SpaceDoubleChestItemHandlerMP method extractItem.

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

Aggregations

TileEntityChestMP (stevekung.mods.moreplanets.util.tileentity.TileEntityChestMP)8 TileEntity (net.minecraft.tileentity.TileEntity)4 BlockPos (net.minecraft.util.math.BlockPos)4 IBlockState (net.minecraft.block.state.IBlockState)2 Block (net.minecraft.block.Block)1 EnumFacing (net.minecraft.util.EnumFacing)1 World (net.minecraft.world.World)1