Jellyshroom cap colors
This commit is contained in:
parent
5fdc1d8b93
commit
2f4caeb673
6 changed files with 95 additions and 19 deletions
|
@ -6,28 +6,54 @@ import java.util.List;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.block.SlimeBlock;
|
import net.minecraft.block.SlimeBlock;
|
||||||
import net.minecraft.client.color.block.BlockColorProvider;
|
import net.minecraft.client.color.block.BlockColorProvider;
|
||||||
import net.minecraft.client.color.item.ItemColorProvider;
|
import net.minecraft.client.color.item.ItemColorProvider;
|
||||||
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.loot.context.LootContext;
|
import net.minecraft.loot.context.LootContext;
|
||||||
|
import net.minecraft.state.StateManager;
|
||||||
|
import net.minecraft.state.property.IntProperty;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
import net.minecraft.util.math.Vec3i;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
import ru.betterend.client.render.ERenderLayer;
|
import ru.betterend.client.render.ERenderLayer;
|
||||||
import ru.betterend.interfaces.IColorProvider;
|
import ru.betterend.interfaces.IColorProvider;
|
||||||
import ru.betterend.interfaces.IRenderTypeable;
|
import ru.betterend.interfaces.IRenderTypeable;
|
||||||
|
import ru.betterend.noise.OpenSimplexNoise;
|
||||||
import ru.betterend.patterns.BlockPatterned;
|
import ru.betterend.patterns.BlockPatterned;
|
||||||
import ru.betterend.patterns.Patterns;
|
import ru.betterend.patterns.Patterns;
|
||||||
import ru.betterend.util.MHelper;
|
import ru.betterend.util.MHelper;
|
||||||
|
|
||||||
public class BlockJellyshroomCap extends SlimeBlock implements IRenderTypeable, BlockPatterned, IColorProvider {
|
public class BlockJellyshroomCap extends SlimeBlock implements IRenderTypeable, BlockPatterned, IColorProvider {
|
||||||
private final int color;
|
public static final IntProperty COLOR = IntProperty.of("color", 0, 7);
|
||||||
|
private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(0);
|
||||||
|
private final Vec3i colorStart;
|
||||||
|
private final Vec3i colorEnd;
|
||||||
|
private final int coloritem;
|
||||||
|
|
||||||
public BlockJellyshroomCap(int r, int g, int b) {
|
public BlockJellyshroomCap(int r1, int g1, int b1, int r2, int g2, int b2) {
|
||||||
super(FabricBlockSettings.copyOf(Blocks.SLIME_BLOCK));
|
super(FabricBlockSettings.copyOf(Blocks.SLIME_BLOCK));
|
||||||
color = MHelper.color(r, g, b);
|
colorStart = new Vec3i(r1, g1, b1);
|
||||||
|
colorEnd = new Vec3i(r2, g2, b2);
|
||||||
|
coloritem = MHelper.color((r1 + r2) >> 1, (g1 + g2) >> 1, (b1 + b2) >> 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||||
|
double px = ctx.getBlockPos().getX() * 0.1;
|
||||||
|
double py = ctx.getBlockPos().getY() * 0.1;
|
||||||
|
double pz = ctx.getBlockPos().getZ() * 0.1;
|
||||||
|
return this.getDefaultState().with(COLOR, MHelper.floor(NOISE.eval(px, py, pz) * 3.5 + 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) {
|
||||||
|
stateManager.add(COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -59,14 +85,18 @@ public class BlockJellyshroomCap extends SlimeBlock implements IRenderTypeable,
|
||||||
@Override
|
@Override
|
||||||
public BlockColorProvider getProvider() {
|
public BlockColorProvider getProvider() {
|
||||||
return (state, world, pos, tintIndex) -> {
|
return (state, world, pos, tintIndex) -> {
|
||||||
return color;
|
float delta = (float) state.get(COLOR) / 7F;
|
||||||
|
int r = MathHelper.floor(MathHelper.lerp(delta, colorStart.getX() / 255F, colorEnd.getX() / 255F) * 255F);
|
||||||
|
int g = MathHelper.floor(MathHelper.lerp(delta, colorStart.getY() / 255F, colorEnd.getY() / 255F) * 255F);
|
||||||
|
int b = MathHelper.floor(MathHelper.lerp(delta, colorStart.getZ() / 255F, colorEnd.getZ() / 255F) * 255F);
|
||||||
|
return MHelper.color(r, g, b);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemColorProvider getItemProvider() {
|
public ItemColorProvider getItemProvider() {
|
||||||
return (stack, tintIndex) -> {
|
return (stack, tintIndex) -> {
|
||||||
return color;
|
return coloritem;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,7 +188,7 @@ public class EndBlocks {
|
||||||
public static final Block UMBRELLA_TREE_CLUSTER_EMPTY = registerBlock("umbrella_tree_cluster_empty", new BlockUmbrellaTreeClusterEmpty());
|
public static final Block UMBRELLA_TREE_CLUSTER_EMPTY = registerBlock("umbrella_tree_cluster_empty", new BlockUmbrellaTreeClusterEmpty());
|
||||||
public static final WoodenMaterial UMBRELLA_TREE = new WoodenMaterial("umbrella_tree", MaterialColor.BLUE, MaterialColor.GREEN);
|
public static final WoodenMaterial UMBRELLA_TREE = new WoodenMaterial("umbrella_tree", MaterialColor.BLUE, MaterialColor.GREEN);
|
||||||
|
|
||||||
public static final Block JELLYSHROOM_CAP_PURPLE = registerBlock("jellyshroom_cap_purple", new BlockJellyshroomCap(255, 0, 255));
|
public static final Block JELLYSHROOM_CAP_PURPLE = registerBlock("jellyshroom_cap_purple", new BlockJellyshroomCap(217, 142, 255, 164, 0, 255));
|
||||||
public static final WoodenMaterial JELLYSHROOM = new WoodenMaterial("jellyshroom", MaterialColor.PURPLE, MaterialColor.LIGHT_BLUE);
|
public static final WoodenMaterial JELLYSHROOM = new WoodenMaterial("jellyshroom", MaterialColor.PURPLE, MaterialColor.LIGHT_BLUE);
|
||||||
|
|
||||||
// Small Plants //
|
// Small Plants //
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ru.betterend.util;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import net.minecraft.client.util.math.Vector3f;
|
import net.minecraft.client.util.math.Vector3f;
|
||||||
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
public class MHelper {
|
public class MHelper {
|
||||||
public static final float PI2 = (float) (Math.PI * 2);
|
public static final float PI2 = (float) (Math.PI * 2);
|
||||||
|
@ -251,6 +252,43 @@ public class MHelper {
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Vec3d fromRGBtoHSBV(int r, int g, int b) {
|
||||||
|
int max = max(r, g, b);
|
||||||
|
int min = min(r, g, b);
|
||||||
|
|
||||||
|
float brightness = (float) max / 255.0F;
|
||||||
|
float saturation;
|
||||||
|
if (max != 0) {
|
||||||
|
saturation = (float) (max - min) / (float) max;
|
||||||
|
} else {
|
||||||
|
saturation = 0.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
float hue;
|
||||||
|
if (saturation == 0.0F) {
|
||||||
|
hue = 0.0F;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
float var9 = (float) (max - r) / (float) (max - min);
|
||||||
|
float var10 = (float) (max - g) / (float) (max - min);
|
||||||
|
float var11 = (float) (max - b) / (float) (max - min);
|
||||||
|
if (r == max) {
|
||||||
|
hue = var11 - var10;
|
||||||
|
} else if (g == max) {
|
||||||
|
hue = 2.0F + var9 - var11;
|
||||||
|
} else {
|
||||||
|
hue = 4.0F + var10 - var9;
|
||||||
|
}
|
||||||
|
|
||||||
|
hue /= 6.0F;
|
||||||
|
if (hue < 0.0F) {
|
||||||
|
++hue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Vec3d(hue, saturation, brightness);
|
||||||
|
}
|
||||||
|
|
||||||
public static final float radiandToDegrees(float value) {
|
public static final float radiandToDegrees(float value) {
|
||||||
return value * RAD_TO_DEG;
|
return value * RAD_TO_DEG;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,14 +10,15 @@ import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Material;
|
import net.minecraft.block.Material;
|
||||||
import net.minecraft.client.util.math.Vector3f;
|
import net.minecraft.client.util.math.Vector3f;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.world.StructureWorldAccess;
|
import net.minecraft.world.StructureWorldAccess;
|
||||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||||
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
||||||
|
import ru.betterend.blocks.BlockJellyshroomCap;
|
||||||
import ru.betterend.registry.EndBlocks;
|
import ru.betterend.registry.EndBlocks;
|
||||||
import ru.betterend.registry.EndTags;
|
import ru.betterend.registry.EndTags;
|
||||||
import ru.betterend.util.MHelper;
|
import ru.betterend.util.MHelper;
|
||||||
import ru.betterend.util.SplineHelper;
|
import ru.betterend.util.SplineHelper;
|
||||||
import ru.betterend.util.sdf.PosInfo;
|
|
||||||
import ru.betterend.util.sdf.SDF;
|
import ru.betterend.util.sdf.SDF;
|
||||||
import ru.betterend.util.sdf.operator.SDFFlatWave;
|
import ru.betterend.util.sdf.operator.SDFFlatWave;
|
||||||
import ru.betterend.util.sdf.operator.SDFScale3D;
|
import ru.betterend.util.sdf.operator.SDFScale3D;
|
||||||
|
@ -29,7 +30,6 @@ import ru.betterend.world.features.DefaultFeature;
|
||||||
|
|
||||||
public class JellyshroomFeature extends DefaultFeature {
|
public class JellyshroomFeature extends DefaultFeature {
|
||||||
private static final Function<BlockState, Boolean> REPLACE;
|
private static final Function<BlockState, Boolean> REPLACE;
|
||||||
private static final Function<PosInfo, BlockState> POST;
|
|
||||||
private static final List<Vector3f> ROOT;
|
private static final List<Vector3f> ROOT;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,11 +51,26 @@ public class JellyshroomFeature extends DefaultFeature {
|
||||||
if (radius < 1.5F) {
|
if (radius < 1.5F) {
|
||||||
radius = 1.5F;
|
radius = 1.5F;
|
||||||
}
|
}
|
||||||
SDF cap = makeCap(radius, random, membrane);
|
final float membraneRadius = radius;
|
||||||
Vector3f last = spline.get(spline.size() - 1);
|
SDF cap = makeCap(membraneRadius, random, membrane);
|
||||||
|
final Vector3f last = spline.get(spline.size() - 1);
|
||||||
cap = new SDFTranslate().setTranslate(last.getX(), last.getY(), last.getZ()).setSource(cap);
|
cap = new SDFTranslate().setTranslate(last.getX(), last.getY(), last.getZ()).setSource(cap);
|
||||||
sdf = new SDFSmoothUnion().setRadius(3F).setSourceA(sdf).setSourceB(cap);
|
sdf = new SDFSmoothUnion().setRadius(3F).setSourceA(sdf).setSourceB(cap);
|
||||||
sdf.setReplaceFunction(REPLACE).setPostProcess(POST).fillRecursive(world, pos);
|
sdf.setReplaceFunction(REPLACE).setPostProcess((info) -> {
|
||||||
|
if (EndBlocks.JELLYSHROOM.isTreeLog(info.getState())) {
|
||||||
|
if (EndBlocks.JELLYSHROOM.isTreeLog(info.getStateUp()) && EndBlocks.JELLYSHROOM.isTreeLog(info.getStateDown())) {
|
||||||
|
return EndBlocks.JELLYSHROOM.log.getDefaultState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (info.getState().isOf(EndBlocks.JELLYSHROOM_CAP_PURPLE)) {
|
||||||
|
float dx = info.getPos().getX() - pos.getX() - last.getX();
|
||||||
|
float dz = info.getPos().getZ() - pos.getZ() - last.getZ();
|
||||||
|
float distance = MHelper.length(dx, dz) / membraneRadius * 7F;
|
||||||
|
int color = MathHelper.clamp(MHelper.floor(distance), 0, 7);
|
||||||
|
return info.getState().with(BlockJellyshroomCap.COLOR, color);
|
||||||
|
}
|
||||||
|
return info.getState();
|
||||||
|
}).fillRecursive(world, pos);
|
||||||
radius = height * 0.5F;
|
radius = height * 0.5F;
|
||||||
makeRoots(world, pos.add(0, 2, 0), radius, random, bark);
|
makeRoots(world, pos.add(0, 2, 0), radius, random, bark);
|
||||||
|
|
||||||
|
@ -104,13 +119,6 @@ public class JellyshroomFeature extends DefaultFeature {
|
||||||
);
|
);
|
||||||
SplineHelper.offset(ROOT, new Vector3f(0, -0.45F, 0));
|
SplineHelper.offset(ROOT, new Vector3f(0, -0.45F, 0));
|
||||||
|
|
||||||
POST = (info) -> {
|
|
||||||
if (EndBlocks.JELLYSHROOM.isTreeLog(info.getStateUp()) && EndBlocks.JELLYSHROOM.isTreeLog(info.getStateDown())) {
|
|
||||||
return EndBlocks.JELLYSHROOM.log.getDefaultState();
|
|
||||||
}
|
|
||||||
return info.getState();
|
|
||||||
};
|
|
||||||
|
|
||||||
REPLACE = (state) -> {
|
REPLACE = (state) -> {
|
||||||
if (state.isIn(EndTags.END_GROUND) || state.getMaterial().equals(Material.PLANT)) {
|
if (state.isIn(EndTags.END_GROUND) || state.getMaterial().equals(Material.PLANT)) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class IslandLayer {
|
||||||
int px = pox + ix;
|
int px = pox + ix;
|
||||||
for (int poz = -1; poz < 2; poz++) {
|
for (int poz = -1; poz < 2; poz++) {
|
||||||
int pz = poz + iz;
|
int pz = poz + iz;
|
||||||
if ((long) px + (long) pz > center) {
|
if (TerrainGenerator.noRingVoid() || (long) px + (long) pz > center) {
|
||||||
RANDOM.setSeed(getSeed(px, pz));
|
RANDOM.setSeed(getSeed(px, pz));
|
||||||
double posX = (px + RANDOM.nextFloat()) * distance;
|
double posX = (px + RANDOM.nextFloat()) * distance;
|
||||||
double posY = MHelper.randRange(minY, maxY, RANDOM);
|
double posY = MHelper.randRange(minY, maxY, RANDOM);
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 250 B After Width: | Height: | Size: 1.6 KiB |
Loading…
Add table
Add a link
Reference in a new issue