Search in sources :

Example 61 with Direction

use of net.minecraft.util.Direction in project Ceramics by KnightMiner.

the class FlowingChannelBlock method fromOffset.

private static Direction fromOffset(BlockPos pos, BlockPos neighbor) {
    BlockPos offset = neighbor.subtract(pos);
    for (Direction direction : Direction.values()) {
        if (direction.getDirectionVec().equals(offset)) {
            return direction;
        }
    }
    Ceramics.LOG.error("Channel found no offset for position pair {} and {} on neighbor changed", pos, neighbor);
    return Direction.DOWN;
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction)

Example 62 with Direction

use of net.minecraft.util.Direction in project Ceramics by KnightMiner.

the class ChannelTileEntity method tick.

/* Flow */
/**
 * Ticking logic
 */
@Override
public void tick() {
    if (world == null || world.isRemote) {
        return;
    }
    // must have fluid first
    FluidStack fluid = tank.getFluid();
    if (!fluid.isEmpty()) {
        // if we have down and can flow, skip sides
        boolean hasFlown = false;
        BlockState state = getBlockState();
        if (state.get(ChannelBlock.DOWN)) {
            hasFlown = trySide(Direction.DOWN, FaucetTileEntity.MB_PER_TICK);
        }
        // try sides if we have any sides
        int outputs = countOutputs(state);
        if (!hasFlown && outputs > 0) {
            // split the fluid evenly between sides
            int flowRate = MathHelper.clamp(tank.getMaxUsable() / outputs, 1, FaucetTileEntity.MB_PER_TICK);
            // then transfer on each side
            for (Direction side : Plane.HORIZONTAL) {
                trySide(side, flowRate);
            }
        }
    }
    // clear flowing if we should no longer flow on a side
    for (int i = 0; i < 5; i++) {
        if (isFlowing[i] > 0) {
            isFlowing[i]--;
            if (isFlowing[i] == 0) {
                Direction direction;
                if (i == 0) {
                    direction = Direction.DOWN;
                } else {
                    direction = Direction.byIndex(i + 1);
                }
                syncFlowToClient(direction, false);
            }
        }
    }
    tank.freeFluid();
}
Also used : BlockState(net.minecraft.block.BlockState) FluidStack(net.minecraftforge.fluids.FluidStack) Direction(net.minecraft.util.Direction)

Example 63 with Direction

use of net.minecraft.util.Direction in project Ceramics by KnightMiner.

the class CrackedModel method bake.

@Override
public IBakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function<RenderMaterial, TextureAtlasSprite> spriteGetter, IModelTransform transform, ItemOverrideList overrides, ResourceLocation location) {
    // fetch textures
    RenderMaterial[] textures = new RenderMaterial[5];
    for (int i = 0; i < 5; i++) {
        textures[i] = owner.resolveTexture("cracks_" + (i + 1));
    }
    // create extra quads
    List<BlockPart> elements = model.getElements();
    List<BlockPart> newElements = new ArrayList<>(elements.size() * 2);
    newElements.addAll(elements);
    for (BlockPart element : elements) {
        Map<Direction, BlockPartFace> mapFaces = new HashMap<>();
        for (Entry<Direction, BlockPartFace> entry : element.mapFaces.entrySet()) {
            BlockPartFace face = entry.getValue();
            mapFaces.put(entry.getKey(), new BlockPartFace(face.cullFace, -1, "cracks", face.blockFaceUV));
        }
        newElements.add(new BlockPart(element.positionFrom, element.positionTo, mapFaces, element.partRotation, element.shade));
    }
    // wrap the original model
    IBakedModel original = model.bakeModel(owner, transform, OVERRIDES, spriteGetter, location);
    return new BakedModel(original, owner, newElements, textures, transform);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Direction(net.minecraft.util.Direction) BlockPart(net.minecraft.client.renderer.model.BlockPart) BlockPartFace(net.minecraft.client.renderer.model.BlockPartFace) IBakedModel(net.minecraft.client.renderer.model.IBakedModel) RenderMaterial(net.minecraft.client.renderer.model.RenderMaterial) IBakedModel(net.minecraft.client.renderer.model.IBakedModel)

Example 64 with Direction

use of net.minecraft.util.Direction in project Ceramics by KnightMiner.

the class GaugeBlock method isValidPosition.

@SuppressWarnings("deprecation")
@Deprecated
@Override
public boolean isValidPosition(BlockState state, IWorldReader world, BlockPos pos) {
    Direction direction = state.get(HORIZONTAL_FACING);
    TileEntity te = world.getTileEntity(pos.offset(direction.getOpposite()));
    return te != null && te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, direction).isPresent();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Direction(net.minecraft.util.Direction)

Example 65 with Direction

use of net.minecraft.util.Direction in project Ceramics by KnightMiner.

the class GaugeBlock method onBlockActivated.

/* Behavior */
@SuppressWarnings("deprecation")
@Deprecated
@Override
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
    // display adjacent tank contents
    if (!world.isRemote()) {
        Direction side = state.get(HORIZONTAL_FACING);
        TileEntity te = world.getTileEntity(pos.offset(side.getOpposite()));
        if (te != null) {
            te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side).ifPresent(handler -> {
                FluidStack fluid = handler.getFluidInTank(0);
                if (fluid.isEmpty()) {
                    player.sendStatusMessage(new TranslationTextComponent(Ceramics.lang("block", "gauge.empty")), true);
                } else {
                    player.sendStatusMessage(new TranslationTextComponent(Ceramics.lang("block", "gauge.contents"), fluid.getAmount(), fluid.getDisplayName()), true);
                }
            });
        }
    }
    return ActionResultType.SUCCESS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidStack(net.minecraftforge.fluids.FluidStack) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Direction(net.minecraft.util.Direction)

Aggregations

Direction (net.minecraft.util.Direction)66 BlockState (net.minecraft.block.BlockState)26 BlockPos (net.minecraft.util.math.BlockPos)21 TileEntity (net.minecraft.tileentity.TileEntity)19 ItemStack (net.minecraft.item.ItemStack)14 Block (net.minecraft.block.Block)11 Nullable (javax.annotation.Nullable)10 World (net.minecraft.world.World)9 Nonnull (javax.annotation.Nonnull)8 PlayerEntity (net.minecraft.entity.player.PlayerEntity)8 CompoundNBT (net.minecraft.nbt.CompoundNBT)6 IPowerBase (com.bluepowermod.api.power.IPowerBase)5 FluidStack (net.minecraftforge.fluids.FluidStack)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 ArrayList (java.util.ArrayList)4 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)4