Search in sources :

Example 6 with Direction

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));
                    });
                }
            });
        }
    });
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITickableTileEntity(net.minecraft.tileentity.ITickableTileEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) Direction(net.minecraft.util.Direction)

Example 7 with Direction

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);
}
Also used : Random(java.util.Random) Direction(net.minecraft.util.Direction)

Example 8 with Direction

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Direction(net.minecraft.util.Direction) Nonnull(javax.annotation.Nonnull)

Example 9 with Direction

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);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITickableTileEntity(net.minecraft.tileentity.ITickableTileEntity) Direction(net.minecraft.util.Direction)

Example 10 with Direction

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);
    }
}
Also used : TileEngine(com.bluepowermod.tile.tier3.TileEngine) Direction(net.minecraft.util.Direction)

Aggregations

Direction (net.minecraft.util.Direction)50 BlockState (net.minecraft.block.BlockState)18 TileEntity (net.minecraft.tileentity.TileEntity)17 BlockPos (net.minecraft.util.math.BlockPos)15 ItemStack (net.minecraft.item.ItemStack)12 Block (net.minecraft.block.Block)10 Nonnull (javax.annotation.Nonnull)8 Nullable (javax.annotation.Nullable)8 CompoundNBT (net.minecraft.nbt.CompoundNBT)6 IPowerBase (com.bluepowermod.api.power.IPowerBase)5 PlayerEntity (net.minecraft.entity.player.PlayerEntity)5 World (net.minecraft.world.World)5 Capability (net.minecraftforge.common.capabilities.Capability)5 BlutricityStorage (com.bluepowermod.api.power.BlutricityStorage)4 CapabilityBlutricity (com.bluepowermod.api.power.CapabilityBlutricity)4 EnergyHelper (com.bluepowermod.helper.EnergyHelper)4 BPTileEntityType (com.bluepowermod.tile.BPTileEntityType)4 TileMachineBase (com.bluepowermod.tile.TileMachineBase)4 INBT (net.minecraft.nbt.INBT)4 LazyOptional (net.minecraftforge.common.util.LazyOptional)4