use of net.minecraft.util.Direction in project Overloaded by CJ-MC-Mods.
the class TileEnergyInjectorChest method tick.
/**
* Like the old updateEntity(), except more generic.
*/
@Override
public void tick() {
if (this.getLevel().isClientSide) {
return;
}
BlockPos me = this.getBlockPos();
TileEntity frontTE = getLevel().getBlockEntity(me.offset(getFacing().getNormal()));
frontTE.getCapability(ENERGY, getFacing().getOpposite()).ifPresent(storage -> {
AtomicInteger energy = new AtomicInteger(storage.extractEnergy(Integer.MAX_VALUE, false));
for (Direction facing : Direction.values()) {
if (energy.get() == 0)
return;
if (facing == getFacing())
continue;
TileEntity te = level.getBlockEntity(me.offset(facing.getNormal()));
te.getCapability(ITEM_HANDLER_CAPABILITY, facing.getOpposite()).ifPresent(inventory -> {
for (int i = 0; i < inventory.getSlots(); i++) {
final ItemStack stack = inventory.getStackInSlot(i);
final int slot = i;
stack.getCapability(ENERGY, facing.getOpposite()).ifPresent(receiver -> {
ItemStack tempStack = inventory.extractItem(slot, 1, false);
if (tempStack.isEmpty() || !receiver.canReceive()) {
return;
}
int acceptedAmount = receiver.receiveEnergy(energy.get(), true);
if (acceptedAmount != 0) {
receiver.receiveEnergy(acceptedAmount, false);
energy.addAndGet(-storage.receiveEnergy(energy.get(), true));
}
tempStack = inventory.insertItem(slot, tempStack, false);
if (tempStack.isEmpty()) {
return;
}
getLevel().addFreshEntity(new ItemEntity(getLevel(), getBlockPos().getX(), getBlockPos().getY(), getBlockPos().getZ(), tempStack));
});
}
});
}
});
}
use of net.minecraft.util.Direction in project Overloaded by CJ-MC-Mods.
the class ModelRenderOBJ method renderModel.
private void renderModel(IBakedModel modelIn, ItemStack stack, int combinedLightIn, int combinedOverlayIn, MatrixStack matrixStackIn, IVertexBuilder bufferIn) {
Random random = new Random();
long i = 42L;
// matrixStackIn.translate(0,-12,0);
for (Direction direction : Direction.values()) {
random.setSeed(i);
Minecraft.getInstance().getItemRenderer().renderQuadList(matrixStackIn, bufferIn, modelIn.getQuads(null, direction, random), stack, combinedLightIn, combinedOverlayIn);
}
random.setSeed(i);
Minecraft.getInstance().getItemRenderer().renderQuadList(matrixStackIn, bufferIn, modelIn.getQuads(null, null, random), stack, combinedLightIn, combinedOverlayIn);
}
use of net.minecraft.util.Direction in project Overloaded by CJ-MC-Mods.
the class AbstractTileHyperReceiver method receive.
@Nonnull
public Type receive(@Nonnull Type stack) {
for (Direction side : Direction.values()) {
TileEntity te = this.getLevel().getBlockEntity(this.getBlockPos().offset(side.getNormal()));
if (te == null) {
continue;
}
LazyOptional<H> cap = te.getCapability(capability, side.getOpposite());
if (!cap.isPresent()) {
continue;
}
stack = cap.orElse(null).give(stack, true);
if (stack.getAmount().longValue() == 0L)
return stack;
}
return stack;
}
use of net.minecraft.util.Direction in project Overloaded by CJ-MC-Mods.
the class AbstractTileHyperSender method send.
private void send(@Nonnull AbstractTileHyperReceiver<T, H> partner) {
for (Direction side : Direction.values()) {
TileEntity te = this.getLevel().getBlockEntity(this.getBlockPos().offset(side.getNormal()));
if (te == null) {
continue;
}
LazyOptional<H> cap = te.getCapability(capability, side.getOpposite());
if (!cap.isPresent()) {
continue;
}
send(partner, te, side);
}
}
use of net.minecraft.util.Direction in project BluePower by Qmunity.
the class BlockEngine method setPlacedBy.
@SuppressWarnings("cast")
@Override
public void setPlacedBy(World world, BlockPos pos, BlockState state, LivingEntity player, ItemStack iStack) {
if (world.getBlockEntity(pos) instanceof TileEngine) {
Direction facing;
if (player.xRot > 45) {
facing = Direction.DOWN;
} else if (player.xRot < -45) {
facing = Direction.UP;
} else {
facing = player.getDirection().getOpposite();
}
TileEngine tile = (TileEngine) world.getBlockEntity(pos);
if (tile != null) {
tile.setOrientation(facing);
}
world.setBlock(pos, state.setValue(FACING, facing), 2);
}
}
Aggregations