Search in sources :

Example 16 with Direction

use of net.minecraft.core.Direction 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 BlockSource source, @Nonnull ItemStack stack) {
    Level world = source.getLevel();
    Direction dispenserFacing = source.getBlockState().getValue(DispenserBlock.FACING);
    BlockPos blockpos = source.getPos().relative(dispenserFacing);
    FluidActionResult actionResult = FluidUtil.tryPickUpFluid(stack, null, world, blockpos, dispenserFacing.getOpposite());
    ItemStack resultStack = actionResult.getResult();
    if (!actionResult.isSuccess() || resultStack.isEmpty()) {
        return super.execute(source, stack);
    }
    if (stack.getCount() == 1) {
        return resultStack;
    } else if (((DispenserBlockEntity) source.getEntity()).addItem(resultStack) < 0) {
        this.dispenseBehavior.dispense(source, resultStack);
    }
    ItemStack stackCopy = stack.copy();
    stackCopy.shrink(1);
    return stackCopy;
}
Also used : DispenserBlockEntity(net.minecraft.world.level.block.entity.DispenserBlockEntity) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) Direction(net.minecraft.core.Direction) Nonnull(javax.annotation.Nonnull)

Example 17 with Direction

use of net.minecraft.core.Direction in project MinecraftForge by MinecraftForge.

the class SidedInvWrapper method create.

@SuppressWarnings("unchecked")
public static LazyOptional<IItemHandlerModifiable>[] create(WorldlyContainer inv, Direction... sides) {
    LazyOptional<IItemHandlerModifiable>[] ret = new LazyOptional[sides.length];
    for (int x = 0; x < sides.length; x++) {
        final Direction side = sides[x];
        ret[x] = LazyOptional.of(() -> new SidedInvWrapper(inv, side));
    }
    return ret;
}
Also used : LazyOptional(net.minecraftforge.common.util.LazyOptional) Direction(net.minecraft.core.Direction)

Aggregations

Direction (net.minecraft.core.Direction)17 BlockPos (net.minecraft.core.BlockPos)4 Nonnull (javax.annotation.Nonnull)3 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)3 ItemStack (net.minecraft.world.item.ItemStack)3 Level (net.minecraft.world.level.Level)2 BellBlock (net.minecraft.world.level.block.BellBlock)2 DispenserBlockEntity (net.minecraft.world.level.block.entity.DispenserBlockEntity)2 org.bukkit.block (org.bukkit.block)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)1 Transformation (com.mojang.math.Transformation)1 Vector3f (com.mojang.math.Vector3f)1 Vector4f (com.mojang.math.Vector4f)1 Optional (java.util.Optional)1 Nullable (javax.annotation.Nullable)1 BlockElementFace (net.minecraft.client.renderer.block.model.BlockElementFace)1