use of net.minecraft.core.Direction 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(BlockSource source, @Nonnull ItemStack stack) {
ItemStack singleStack = stack.copy();
singleStack.setCount(1);
IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(singleStack).orElse(null);
if (fluidHandler == null) {
return super.execute(source, stack);
}
FluidStack fluidStack = fluidHandler.drain(FluidAttributes.BUCKET_VOLUME, IFluidHandler.FluidAction.EXECUTE);
Direction dispenserFacing = source.getBlockState().getValue(DispenserBlock.FACING);
BlockPos blockpos = source.getPos().relative(dispenserFacing);
FluidActionResult result = FluidUtil.tryPlaceFluid(null, source.getLevel(), InteractionHand.MAIN_HAND, blockpos, stack, fluidStack);
if (result.isSuccess()) {
ItemStack drainedStack = result.getResult();
if (drainedStack.getCount() == 1) {
return drainedStack;
} else if (!drainedStack.isEmpty() && ((DispenserBlockEntity) source.getEntity()).addItem(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.core.Direction in project MinecraftForge by MinecraftForge.
the class VanillaInventoryCodeHooks method dropperInsertHook.
/**
* Copied from BlockDropper#dispense and added capability support
*/
public static boolean dropperInsertHook(Level world, BlockPos pos, DispenserBlockEntity dropper, int slot, @Nonnull ItemStack stack) {
Direction enumfacing = world.getBlockState(pos).getValue(DropperBlock.FACING);
BlockPos blockpos = pos.relative(enumfacing);
return getItemHandler(world, (double) blockpos.getX(), (double) blockpos.getY(), (double) blockpos.getZ(), enumfacing.getOpposite()).map(destinationResult -> {
IItemHandler itemHandler = destinationResult.getKey();
Object destination = destinationResult.getValue();
ItemStack dispensedStack = stack.copy().split(1);
ItemStack remainder = putStackInInventoryAllSlots(dropper, destination, itemHandler, dispensedStack);
if (remainder.isEmpty()) {
remainder = stack.copy();
remainder.shrink(1);
} else {
remainder = stack.copy();
}
dropper.setItem(slot, remainder);
return false;
}).orElse(true);
}
use of net.minecraft.core.Direction in project MinecraftForge by MinecraftForge.
the class BlockStateProvider method paneBlock.
public void paneBlock(IronBarsBlock block, ModelFile post, ModelFile side, ModelFile sideAlt, ModelFile noSide, ModelFile noSideAlt) {
MultiPartBlockStateBuilder builder = getMultipartBuilder(block).part().modelFile(post).addModel().end();
PipeBlock.PROPERTY_BY_DIRECTION.entrySet().forEach(e -> {
Direction dir = e.getKey();
if (dir.getAxis().isHorizontal()) {
boolean alt = dir == Direction.SOUTH;
builder.part().modelFile(alt || dir == Direction.WEST ? sideAlt : side).rotationY(dir.getAxis() == Axis.X ? 90 : 0).addModel().condition(e.getValue(), true).end().part().modelFile(alt || dir == Direction.EAST ? noSideAlt : noSide).rotationY(dir == Direction.WEST ? 270 : dir == Direction.SOUTH ? 90 : 0).addModel().condition(e.getValue(), false);
}
});
}
use of net.minecraft.core.Direction in project MinecraftForge by MinecraftForge.
the class ModelBuilder method toJson.
@VisibleForTesting
public JsonObject toJson() {
JsonObject root = new JsonObject();
if (this.parent != null) {
root.addProperty("parent", this.parent.getLocation().toString());
}
if (!this.ambientOcclusion) {
root.addProperty("ambientocclusion", this.ambientOcclusion);
}
if (this.guiLight != null) {
root.addProperty("gui_light", this.guiLight.getSerializedName());
}
Map<Perspective, ItemTransform> transforms = this.transforms.build();
if (!transforms.isEmpty()) {
JsonObject display = new JsonObject();
for (Entry<Perspective, ItemTransform> e : transforms.entrySet()) {
JsonObject transform = new JsonObject();
ItemTransform vec = e.getValue();
if (vec.equals(ItemTransform.NO_TRANSFORM))
continue;
if (!vec.rotation.equals(ItemTransform.Deserializer.DEFAULT_ROTATION)) {
transform.add("rotation", serializeVector3f(vec.rotation));
}
if (!vec.translation.equals(ItemTransform.Deserializer.DEFAULT_TRANSLATION)) {
transform.add("translation", serializeVector3f(e.getValue().translation));
}
if (!vec.scale.equals(ItemTransform.Deserializer.DEFAULT_SCALE)) {
transform.add("scale", serializeVector3f(e.getValue().scale));
}
display.add(e.getKey().name, transform);
}
root.add("display", display);
}
if (!this.textures.isEmpty()) {
JsonObject textures = new JsonObject();
for (Entry<String, String> e : this.textures.entrySet()) {
textures.addProperty(e.getKey(), serializeLocOrKey(e.getValue()));
}
root.add("textures", textures);
}
if (!this.elements.isEmpty()) {
JsonArray elements = new JsonArray();
this.elements.stream().map(ElementBuilder::build).forEach(part -> {
JsonObject partObj = new JsonObject();
partObj.add("from", serializeVector3f(part.from));
partObj.add("to", serializeVector3f(part.to));
if (part.rotation != null) {
JsonObject rotation = new JsonObject();
rotation.add("origin", serializeVector3f(part.rotation.origin));
rotation.addProperty("axis", part.rotation.axis.getSerializedName());
rotation.addProperty("angle", part.rotation.angle);
if (part.rotation.rescale) {
rotation.addProperty("rescale", part.rotation.rescale);
}
partObj.add("rotation", rotation);
}
if (!part.shade) {
partObj.addProperty("shade", part.shade);
}
JsonObject faces = new JsonObject();
for (Direction dir : Direction.values()) {
BlockElementFace face = part.faces.get(dir);
if (face == null)
continue;
JsonObject faceObj = new JsonObject();
faceObj.addProperty("texture", serializeLocOrKey(face.texture));
if (!Arrays.equals(face.uv.uvs, part.uvsByFace(dir))) {
faceObj.add("uv", new Gson().toJsonTree(face.uv.uvs));
}
if (face.cullForDirection != null) {
faceObj.addProperty("cullface", face.cullForDirection.getSerializedName());
}
if (face.uv.rotation != 0) {
faceObj.addProperty("rotation", face.uv.rotation);
}
if (face.tintIndex != -1) {
faceObj.addProperty("tintindex", face.tintIndex);
}
faces.add(dir.getSerializedName(), faceObj);
}
if (!part.faces.isEmpty()) {
partObj.add("faces", faces);
}
elements.add(partObj);
});
root.add("elements", elements);
}
if (customLoader != null)
return customLoader.toJson(root);
return root;
}
use of net.minecraft.core.Direction in project MinecraftForge by MinecraftForge.
the class ItemLayerModel method getQuadsForSprite.
public static ImmutableList<BakedQuad> getQuadsForSprite(int tint, TextureAtlasSprite sprite, Transformation transform, boolean fullbright) {
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
int uMax = sprite.getWidth();
int vMax = sprite.getHeight();
FaceData faceData = new FaceData(uMax, vMax);
boolean translucent = false;
for (int f = 0; f < sprite.getFrameCount(); f++) {
boolean ptu;
boolean[] ptv = new boolean[uMax];
Arrays.fill(ptv, true);
for (int v = 0; v < vMax; v++) {
ptu = true;
for (int u = 0; u < uMax; u++) {
int alpha = sprite.getPixelRGBA(f, u, vMax - v - 1) >> 24 & 0xFF;
boolean t = alpha / 255f <= 0.1f;
if (!t && alpha < 255) {
translucent = true;
}
if (// left - transparent, right - opaque
ptu && !t) {
faceData.set(Direction.WEST, u, v);
}
if (// left - opaque, right - transparent
!ptu && t) {
faceData.set(Direction.EAST, u - 1, v);
}
if (// up - transparent, down - opaque
ptv[u] && !t) {
faceData.set(Direction.UP, u, v);
}
if (// up - opaque, down - transparent
!ptv[u] && t) {
faceData.set(Direction.DOWN, u, v - 1);
}
ptu = t;
ptv[u] = t;
}
if (// last - opaque
!ptu) {
faceData.set(Direction.EAST, uMax - 1, v);
}
}
// last line
for (int u = 0; u < uMax; u++) {
if (!ptv[u]) {
faceData.set(Direction.DOWN, u, vMax - 1);
}
}
}
// horizontal quads
for (Direction facing : HORIZONTALS) {
for (int v = 0; v < vMax; v++) {
int uStart = 0, uEnd = uMax;
boolean building = false;
for (int u = 0; u < uMax; u++) {
boolean face = faceData.get(facing, u, v);
if (!translucent) {
if (face) {
if (!building) {
building = true;
uStart = u;
}
uEnd = u + 1;
}
} else {
if (// finish current quad
building && !face) {
// make quad [uStart, u]
int off = facing == Direction.DOWN ? 1 : 0;
builder.add(buildSideQuad(transform, facing, tint, sprite, uStart, v + off, u - uStart, fullbright));
building = false;
} else if (// start new quad
!building && face) {
building = true;
uStart = u;
}
}
}
if (// build remaining quad
building) {
// make quad [uStart, uEnd]
int off = facing == Direction.DOWN ? 1 : 0;
builder.add(buildSideQuad(transform, facing, tint, sprite, uStart, v + off, uEnd - uStart, fullbright));
}
}
}
// vertical quads
for (Direction facing : VERTICALS) {
for (int u = 0; u < uMax; u++) {
int vStart = 0, vEnd = vMax;
boolean building = false;
for (int v = 0; v < vMax; v++) {
boolean face = faceData.get(facing, u, v);
if (!translucent) {
if (face) {
if (!building) {
building = true;
vStart = v;
}
vEnd = v + 1;
}
} else {
if (// finish current quad
building && !face) {
// make quad [vStart, v]
int off = facing == Direction.EAST ? 1 : 0;
builder.add(buildSideQuad(transform, facing, tint, sprite, u + off, vStart, v - vStart, fullbright));
building = false;
} else if (// start new quad
!building && face) {
building = true;
vStart = v;
}
}
}
if (// build remaining quad
building) {
// make quad [vStart, vEnd]
int off = facing == Direction.EAST ? 1 : 0;
builder.add(buildSideQuad(transform, facing, tint, sprite, u + off, vStart, vEnd - vStart, fullbright));
}
}
}
// front
builder.add(buildQuad(transform, Direction.NORTH, sprite, tint, fullbright, 0, 0, 7.5f / 16f, sprite.getU0(), sprite.getV1(), 0, 1, 7.5f / 16f, sprite.getU0(), sprite.getV0(), 1, 1, 7.5f / 16f, sprite.getU1(), sprite.getV0(), 1, 0, 7.5f / 16f, sprite.getU1(), sprite.getV1()));
// back
builder.add(buildQuad(transform, Direction.SOUTH, sprite, tint, fullbright, 0, 0, 8.5f / 16f, sprite.getU0(), sprite.getV1(), 1, 0, 8.5f / 16f, sprite.getU1(), sprite.getV1(), 1, 1, 8.5f / 16f, sprite.getU1(), sprite.getV0(), 0, 1, 8.5f / 16f, sprite.getU0(), sprite.getV0()));
return builder.build();
}
Aggregations