use of net.minecraft.fluid.FluidState in project Bookshelf by Darkhax-Minecraft.
the class RenderUtils method renderState.
/**
* Renders a block state onto the screen as if it were in the world.
*
* @param state The block state to render.
* @param world The world context for rendering the state.
* @param pos The position to render the block state at.
* @param matrix The rendering matrix stack.
* @param buffer The rendering buffer.
* @param light Packed lighting data.
* @param overlay Packed overlay data.
* @param withFluid Should fluid states be rendered?
* @param preferredSides The sides of the block that should rendered. This is used to cull
* the sides that you don't want. Due to invasive changes made by Optifine this will
* be ignored when Optifine is installed.
*/
public static void renderState(BlockState state, World world, BlockPos pos, MatrixStack matrix, IRenderTypeBuffer buffer, int light, int overlay, boolean withFluid, Direction... preferredSides) {
if (!ModUtils.isOptifineLoaded()) {
renderBlock(state, world, pos, matrix, buffer, preferredSides);
} else {
renderBlock(state, world, pos, matrix, buffer);
}
if (withFluid) {
// Handle fluids and waterlogging.
final FluidState fluidState = state.getFluidState();
if (fluidState != null && !fluidState.isEmpty()) {
final Fluid fluid = fluidState.getType();
final ResourceLocation texture = fluid.getAttributes().getStillTexture();
final int[] color = unpackColor(fluid.getAttributes().getColor(world, pos));
final TextureAtlasSprite sprite = Minecraft.getInstance().getTextureAtlas(PlayerContainer.BLOCK_ATLAS).apply(texture);
renderBlockSprite(buffer.getBuffer(RenderType.translucent()), matrix, sprite, light, overlay, color);
}
}
}
use of net.minecraft.fluid.FluidState in project AgriCraft by AgriCraft.
the class JsonPlant method initGrowthRequirement.
public static IAgriGrowthRequirement initGrowthRequirement(AgriPlant plant) {
// Run checks
if (plant == null) {
return AgriGrowthRequirement.getNone();
}
// Initialize utility objects
IAgriGrowthRequirement.Builder builder = AgriApi.getGrowthRequirementBuilder();
// Define requirement for humidity
String humidityString = plant.getRequirement().getHumiditySoilCondition().getCondition();
IAgriSoil.Humidity humidity = IAgriSoil.Humidity.fromString(humidityString).orElse(IAgriSoil.Humidity.INVALID);
handleSoilCriterion(humidity, builder::defineHumidity, plant.getRequirement().getHumiditySoilCondition().getType(), plant.getRequirement().getHumiditySoilCondition().getToleranceFactor(), () -> AgriCore.getLogger("agricraft").warn("Plant: \"{0}\" has an invalid humidity criterion (\"{1}\")!", plant.getId(), humidityString));
// Define requirement for acidity
String acidityString = plant.getRequirement().getAciditySoilCondition().getCondition();
IAgriSoil.Acidity acidity = IAgriSoil.Acidity.fromString(acidityString).orElse(IAgriSoil.Acidity.INVALID);
handleSoilCriterion(acidity, builder::defineAcidity, plant.getRequirement().getAciditySoilCondition().getType(), plant.getRequirement().getAciditySoilCondition().getToleranceFactor(), () -> AgriCore.getLogger("agricraft").warn("Plant: \"{0}\" has an invalid acidity criterion (\"{1}\")!", plant.getId(), acidityString));
// Define requirement for nutrients
String nutrientString = plant.getRequirement().getNutrientSoilCondition().getCondition();
IAgriSoil.Nutrients nutrients = IAgriSoil.Nutrients.fromString(nutrientString).orElse(IAgriSoil.Nutrients.INVALID);
handleSoilCriterion(nutrients, builder::defineNutrients, plant.getRequirement().getNutrientSoilCondition().getType(), plant.getRequirement().getNutrientSoilCondition().getToleranceFactor(), () -> AgriCore.getLogger("agricraft").warn("Plant: \"{0}\" has an invalid nutrients criterion (\"{1}\")!", plant.getId(), nutrientString));
// Define requirement for light
final double f = plant.getRequirement().getLightToleranceFactor();
final int minLight = plant.getRequirement().getMinLight();
final int maxLight = plant.getRequirement().getMaxLight();
builder.defineLightLevel((strength, light) -> {
int lower = minLight - (int) (f * strength);
int upper = maxLight + (int) (f * strength);
return light >= lower && light <= upper ? IAgriGrowthResponse.FERTILE : IAgriGrowthResponse.INFERTILE;
});
// Define requirement for nearby blocks
plant.getRequirement().getConditions().forEach(obj -> {
BlockPos min = new BlockPos(obj.getMinX(), obj.getMinY(), obj.getMinZ());
BlockPos max = new BlockPos(obj.getMaxX(), obj.getMaxY(), obj.getMaxZ());
builder.addCondition(builder.blockStatesNearby(obj.convertAll(BlockState.class), obj.getAmount(), min, max));
});
// Define requirement for seasons
List<AgriSeason> seasons = plant.getRequirement().getSeasons().stream().map(AgriSeason::fromString).filter(Optional::isPresent).map(Optional::get).distinct().collect(Collectors.toList());
if (seasons.size() > 0) {
builder.defineSeasonality((str, season) -> {
if (str >= AgriApi.getStatRegistry().strengthStat().getMax() || seasons.stream().anyMatch(season::matches)) {
return IAgriGrowthResponse.FERTILE;
} else {
return IAgriGrowthResponse.INFERTILE;
}
});
}
// Define requirement for fluids
List<Fluid> fluids = plant.getRequirement().getFluid().convertAll(FluidState.class).stream().map(FluidState::getFluid).distinct().collect(Collectors.toList());
BiFunction<Integer, Fluid, IAgriGrowthResponse> response = (strength, fluid) -> {
if (fluids.size() > 0) {
if (fluids.contains(fluid)) {
return IAgriGrowthResponse.FERTILE;
}
return fluid.equals(Fluids.LAVA) ? IAgriGrowthResponse.KILL_IT_WITH_FIRE : IAgriGrowthResponse.LETHAL;
} else {
if (fluid.equals(Fluids.LAVA)) {
return IAgriGrowthResponse.KILL_IT_WITH_FIRE;
}
return fluid.equals(Fluids.EMPTY) ? IAgriGrowthResponse.FERTILE : IAgriGrowthResponse.LETHAL;
}
};
builder.defineFluid(response);
// Build the growth requirement
IAgriGrowthRequirement req = builder.build();
// Log warning if no soils exist for this requirement combination
if (noSoilsMatch(req)) {
AgriCore.getLogger("agricraft").warn("Plant: \"{0}\" has no valid soils to plant on for any strength level!", plant.getId());
}
// Return the growth requirements
return req;
}
use of net.minecraft.fluid.FluidState in project BluePower by Qmunity.
the class BlockBPMicroblock method getStateForPlacement.
@Nullable
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
PlayerEntity player = context.getPlayer();
FluidState fluidstate = context.getLevel().getFluidState(context.getClickedPos());
if (player != null && !player.isCrouching()) {
return this.defaultBlockState().setValue(FACING, context.getClickedFace()).setValue(WATERLOGGED, fluidstate.getType() == Fluids.WATER);
}
Vector3d vec = context.getPlayer().getLookAngle();
return this.defaultBlockState().setValue(FACING, Direction.getNearest(vec.x, vec.y, vec.z)).setValue(WATERLOGGED, fluidstate.getType() == Fluids.WATER);
}
use of net.minecraft.fluid.FluidState in project BluePower by Qmunity.
the class BlockGateBase method getStateForPlacement.
@Nullable
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
FluidState fluidstate = context.getLevel().getFluidState(context.getClickedPos());
Direction face = context.getClickedFace();
return this.defaultBlockState().setValue(ROTATION, context.getHorizontalDirection().getOpposite().get2DDataValue()).setValue(FACING, face).setValue(WATERLOGGED, fluidstate.getType() == Fluids.WATER);
}
use of net.minecraft.fluid.FluidState in project BluePower by Qmunity.
the class BlockBPCableBase method getStateForPos.
private BlockState getStateForPos(World world, BlockPos pos, BlockState state, Direction face) {
List<Direction> directions = new ArrayList<>(FACING.getPossibleValues());
List<Direction> internal = null;
boolean connected_left = false;
boolean connected_right = false;
boolean connected_front = false;
boolean connected_back = false;
boolean join_left = false;
boolean join_right = false;
boolean join_front = false;
boolean join_back = false;
// Make sure the side we are trying to connect on isn't blocked.
TileEntity ownTile = world.getBlockEntity(pos);
if (ownTile instanceof TileBPMultipart) {
directions.removeIf(d -> ((TileBPMultipart) ownTile).isSideBlocked(getCapability(), d));
internal = ((TileBPMultipart) ownTile).getStates().stream().filter(s -> s.getBlock() == this).map(s -> s.getValue(FACING)).collect(Collectors.toList());
}
// Make sure the cable is on the same side of the block
directions.removeIf(d -> {
TileEntity t = world.getBlockEntity(pos.relative(d));
return (world.getBlockState(pos.relative(d)).getBlock() == this && world.getBlockState(pos.relative(d)).getValue(FACING) != face) || (t instanceof TileBPMultipart && ((TileBPMultipart) t).getStates().stream().noneMatch(s -> s.getValue(FACING) == face));
});
// Populate all directions
for (Direction d : directions) {
TileEntity tileEntity = world.getBlockEntity(pos.relative(d));
BlockState dirState = world.getBlockState(pos.relative(d));
BlockPos dirPos = pos.relative(d);
boolean join = false;
// If Air look for a change in Direction
if (world.getBlockState(pos.relative(d)).getBlock() == Blocks.AIR) {
dirState = world.getBlockState(pos.relative(d).relative(face.getOpposite()));
dirPos = pos.relative(d).relative(face.getOpposite());
if (dirState.getBlock() == this && dirState.getValue(FACING) == d) {
tileEntity = world.getBlockEntity(pos.relative(d).relative(face.getOpposite()));
join = true;
} else if (dirState.getBlock() instanceof BlockBPMultipart) {
tileEntity = world.getBlockEntity(pos.relative(d).relative(face.getOpposite()));
if (tileEntity instanceof TileBPMultipart && ((TileBPMultipart) tileEntity).getStates().stream().filter(s -> s.getBlock() == this).anyMatch(s -> s.getValue(FACING) == d)) {
join = true;
} else {
tileEntity = null;
}
}
}
// Check Capability for Direction
switch(state.getValue(FACING)) {
case UP:
case DOWN:
switch(d) {
case EAST:
connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case WEST:
connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case NORTH:
connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case SOUTH:
connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
}
break;
case NORTH:
switch(d) {
case WEST:
connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case EAST:
connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case UP:
connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case DOWN:
connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
}
break;
case SOUTH:
switch(d) {
case EAST:
connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case WEST:
connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case UP:
connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case DOWN:
connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
}
break;
case EAST:
switch(d) {
case NORTH:
connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case SOUTH:
connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case UP:
connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case DOWN:
connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
}
break;
case WEST:
switch(d) {
case SOUTH:
connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case NORTH:
connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case UP:
connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
case DOWN:
connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
break;
}
}
}
if (internal != null)
for (Direction d : internal) {
switch(state.getValue(FACING)) {
case UP:
case DOWN:
switch(d) {
case EAST:
connected_left = true;
break;
case WEST:
connected_right = true;
break;
case NORTH:
connected_back = true;
break;
case SOUTH:
connected_front = true;
break;
}
break;
case NORTH:
switch(d) {
case WEST:
connected_left = true;
break;
case EAST:
connected_right = true;
break;
case UP:
connected_back = true;
break;
case DOWN:
connected_front = true;
break;
}
break;
case SOUTH:
switch(d) {
case EAST:
connected_left = true;
break;
case WEST:
connected_right = true;
break;
case UP:
connected_back = true;
break;
case DOWN:
connected_front = true;
break;
}
break;
case EAST:
switch(d) {
case NORTH:
connected_left = true;
break;
case SOUTH:
connected_right = true;
break;
case UP:
connected_back = true;
break;
case DOWN:
connected_front = true;
break;
}
break;
case WEST:
switch(d) {
case SOUTH:
connected_left = true;
break;
case NORTH:
connected_right = true;
break;
case UP:
connected_back = true;
break;
case DOWN:
connected_front = true;
break;
}
}
}
FluidState fluidstate = world.getFluidState(pos);
return state.setValue(CONNECTED_LEFT, connected_left).setValue(CONNECTED_RIGHT, connected_right).setValue(CONNECTED_FRONT, connected_front).setValue(CONNECTED_BACK, connected_back).setValue(JOIN_LEFT, join_left).setValue(JOIN_RIGHT, join_right).setValue(JOIN_FRONT, join_front).setValue(JOIN_BACK, join_back).setValue(WATERLOGGED, fluidstate.getType() == Fluids.WATER);
}
Aggregations