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;
}
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();
}
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);
}
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();
}
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;
}
Aggregations