use of net.minecraft.util.EnumFacing in project MinecraftForge by MinecraftForge.
the class ForgeBlockModelRenderer method render.
public static boolean render(VertexLighterFlat lighter, IBlockAccess world, IBakedModel model, IBlockState state, BlockPos pos, VertexBuffer wr, boolean checkSides, long rand) {
lighter.setWorld(world);
lighter.setState(state);
lighter.setBlockPos(pos);
boolean empty = true;
List<BakedQuad> quads = model.getQuads(state, null, rand);
if (!quads.isEmpty()) {
lighter.updateBlockInfo();
empty = false;
for (BakedQuad quad : quads) {
quad.pipe(lighter);
}
}
for (EnumFacing side : EnumFacing.values()) {
quads = model.getQuads(state, side, rand);
if (!quads.isEmpty()) {
if (!checkSides || state.shouldSideBeRendered(world, pos, side)) {
if (empty)
lighter.updateBlockInfo();
empty = false;
for (BakedQuad quad : quads) {
quad.pipe(lighter);
}
}
}
}
return !empty;
}
use of net.minecraft.util.EnumFacing in project MinecraftForge by MinecraftForge.
the class DispenseFluidContainer method fillContainer.
/**
* Picks up fluid in front of a Dispenser and fills a container with it.
*/
@Nonnull
private ItemStack fillContainer(@Nonnull IBlockSource source, @Nonnull ItemStack stack) {
World world = source.getWorld();
EnumFacing dispenserFacing = source.getBlockState().getValue(BlockDispenser.FACING);
BlockPos blockpos = source.getBlockPos().offset(dispenserFacing);
FluidActionResult actionResult = FluidUtil.tryPickUpFluid(stack, null, world, blockpos, dispenserFacing.getOpposite());
ItemStack resultStack = actionResult.getResult();
if (!actionResult.isSuccess() || resultStack.isEmpty()) {
return super.dispenseStack(source, stack);
}
if (stack.getCount() == 1) {
return resultStack;
} else if (((TileEntityDispenser) source.getBlockTileEntity()).addItemStack(resultStack) < 0) {
this.dispenseBehavior.dispense(source, resultStack);
}
ItemStack stackCopy = stack.copy();
stackCopy.shrink(1);
return stackCopy;
}
use of net.minecraft.util.EnumFacing in project MinecraftForge by MinecraftForge.
the class DispenseFluidContainer method dumpContainer.
/**
* Drains a filled container and places the fluid in front of the Dispenser.
*/
@Nonnull
private ItemStack dumpContainer(IBlockSource source, @Nonnull ItemStack stack) {
ItemStack singleStack = stack.copy();
singleStack.setCount(1);
IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(singleStack);
if (fluidHandler == null) {
return super.dispenseStack(source, stack);
}
FluidStack fluidStack = fluidHandler.drain(Fluid.BUCKET_VOLUME, false);
EnumFacing dispenserFacing = source.getBlockState().getValue(BlockDispenser.FACING);
BlockPos blockpos = source.getBlockPos().offset(dispenserFacing);
FluidActionResult result = fluidStack != null ? FluidUtil.tryPlaceFluid(null, source.getWorld(), blockpos, stack, fluidStack) : FluidActionResult.FAILURE;
if (result.isSuccess()) {
ItemStack drainedStack = result.getResult();
if (drainedStack.getCount() == 1) {
return drainedStack;
} else if (!drainedStack.isEmpty() && ((TileEntityDispenser) source.getBlockTileEntity()).addItemStack(drainedStack) < 0) {
this.dispenseBehavior.dispense(source, drainedStack);
}
ItemStack stackCopy = drainedStack.copy();
stackCopy.shrink(1);
return stackCopy;
} else {
return this.dispenseBehavior.dispense(source, stack);
}
}
use of net.minecraft.util.EnumFacing in project MinecraftForge by MinecraftForge.
the class VanillaInventoryCodeHooks method dropperInsertHook.
/**
* Copied from BlockDropper#dispense and added capability support
*/
public static boolean dropperInsertHook(World world, BlockPos pos, TileEntityDispenser dropper, int slot, @Nonnull ItemStack stack) {
EnumFacing enumfacing = world.getBlockState(pos).getValue(BlockDropper.FACING);
BlockPos blockpos = pos.offset(enumfacing);
Pair<IItemHandler, Object> destinationResult = getItemHandler(world, (double) blockpos.getX(), (double) blockpos.getY(), (double) blockpos.getZ(), enumfacing.getOpposite());
if (destinationResult == null) {
return true;
} else {
IItemHandler itemHandler = destinationResult.getKey();
Object destination = destinationResult.getValue();
ItemStack dispensedStack = stack.copy().splitStack(1);
ItemStack remainder = putStackInInventoryAllSlots(dropper, destination, itemHandler, dispensedStack);
if (remainder.isEmpty()) {
remainder = stack.copy();
remainder.shrink(1);
} else {
remainder = stack.copy();
}
dropper.setInventorySlotContents(slot, remainder);
return false;
}
}
use of net.minecraft.util.EnumFacing in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class BlockCannon method setDefaultDirection.
private void setDefaultDirection(World worldIn, BlockPos pos, IBlockState state) {
if (!worldIn.isRemote) {
EnumFacing enumfacing = (EnumFacing) state.getValue(LOOKING);
boolean flag = worldIn.getBlockState(pos.north()).isFullBlock();
boolean flag1 = worldIn.getBlockState(pos.south()).isFullBlock();
if (enumfacing == EnumFacing.NORTH && flag && !flag1) {
enumfacing = EnumFacing.SOUTH;
} else if (enumfacing == EnumFacing.SOUTH && flag1 && !flag) {
enumfacing = EnumFacing.NORTH;
} else {
boolean flag2 = worldIn.getBlockState(pos.west()).isFullBlock();
boolean flag3 = worldIn.getBlockState(pos.east()).isFullBlock();
if (enumfacing == EnumFacing.WEST && flag2 && !flag3) {
enumfacing = EnumFacing.EAST;
} else if (enumfacing == EnumFacing.EAST && flag3 && !flag2) {
enumfacing = EnumFacing.WEST;
}
}
worldIn.setBlockState(pos, state.withProperty(LOOKING, enumfacing), 2);
}
}
Aggregations