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;
}
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;
}
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());
}
}
}
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;
}
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;
}
Aggregations