Tree fixes
|
@ -4,16 +4,27 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
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.Material;
|
import net.minecraft.block.Material;
|
||||||
import net.minecraft.block.MaterialColor;
|
import net.minecraft.block.MaterialColor;
|
||||||
|
import net.minecraft.client.color.block.BlockColorProvider;
|
||||||
|
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.sound.BlockSoundGroup;
|
import net.minecraft.sound.BlockSoundGroup;
|
||||||
|
import net.minecraft.state.StateManager;
|
||||||
|
import net.minecraft.state.property.IntProperty;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
import ru.betterend.blocks.basis.BlockBase;
|
import ru.betterend.blocks.basis.BlockBase;
|
||||||
|
import ru.betterend.interfaces.IColorProvider;
|
||||||
import ru.betterend.registry.EndBlocks;
|
import ru.betterend.registry.EndBlocks;
|
||||||
|
import ru.betterend.util.MHelper;
|
||||||
|
|
||||||
public class BlockHelixTreeLeaves extends BlockBase {
|
public class BlockHelixTreeLeaves extends BlockBase implements IColorProvider {
|
||||||
|
public static final IntProperty COLOR = IntProperty.of("color", 0, 7);
|
||||||
|
|
||||||
public BlockHelixTreeLeaves() {
|
public BlockHelixTreeLeaves() {
|
||||||
super(FabricBlockSettings.of(Material.LEAVES)
|
super(FabricBlockSettings.of(Material.LEAVES)
|
||||||
.strength(0.2F)
|
.strength(0.2F)
|
||||||
|
@ -25,4 +36,33 @@ public class BlockHelixTreeLeaves extends BlockBase {
|
||||||
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
|
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
|
||||||
return Collections.singletonList(new ItemStack(EndBlocks.HELIX_TREE_SAPLING));
|
return Collections.singletonList(new ItemStack(EndBlocks.HELIX_TREE_SAPLING));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) {
|
||||||
|
stateManager.add(COLOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockColorProvider getProvider() {
|
||||||
|
return (state, world, pos, tintIndex) -> {
|
||||||
|
return MHelper.color(237, getGreen(state.get(COLOR)), 20);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemColorProvider getItemProvider() {
|
||||||
|
return (stack, tintIndex) -> {
|
||||||
|
return MHelper.color(237, getGreen(4), 20);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||||
|
return this.getDefaultState().with(COLOR, MHelper.randRange(3, 5, ctx.getWorld().getRandom()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getGreen(int color) {
|
||||||
|
float delta = color / 7F;
|
||||||
|
return (int) MathHelper.lerp(delta, 35, 102);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,7 +169,7 @@ public class SplineHelper {
|
||||||
BlocksHelper.setWithoutUpdate(world, bPos, state);
|
BlocksHelper.setWithoutUpdate(world, bPos, state);
|
||||||
bPos.setY(bPos.getY() - 1);
|
bPos.setY(bPos.getY() - 1);
|
||||||
bState = world.getBlockState(bPos);
|
bState = world.getBlockState(bPos);
|
||||||
if (down && bState.equals(state) || replace.apply(bState)) {
|
if (down && replace.apply(bState)) {
|
||||||
BlocksHelper.setWithoutUpdate(world, bPos, state);
|
BlocksHelper.setWithoutUpdate(world, bPos, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,7 +183,7 @@ public class SplineHelper {
|
||||||
BlocksHelper.setWithoutUpdate(world, bPos, state);
|
BlocksHelper.setWithoutUpdate(world, bPos, state);
|
||||||
bPos.setY(bPos.getY() - 1);
|
bPos.setY(bPos.getY() - 1);
|
||||||
bState = world.getBlockState(bPos);
|
bState = world.getBlockState(bPos);
|
||||||
if (down && bState.equals(state) || replace.apply(bState)) {
|
if (down && replace.apply(bState)) {
|
||||||
BlocksHelper.setWithoutUpdate(world, bPos, state);
|
BlocksHelper.setWithoutUpdate(world, bPos, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,16 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
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.BlockPos.Mutable;
|
||||||
import net.minecraft.util.math.Box;
|
import net.minecraft.util.math.Box;
|
||||||
import net.minecraft.util.math.MathHelper;
|
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.BlockHelixTreeLeaves;
|
||||||
import ru.betterend.registry.EndBlocks;
|
import ru.betterend.registry.EndBlocks;
|
||||||
import ru.betterend.registry.EndTags;
|
import ru.betterend.registry.EndTags;
|
||||||
import ru.betterend.util.BlocksHelper;
|
import ru.betterend.util.BlocksHelper;
|
||||||
|
@ -76,7 +79,7 @@ public class HelixTreeFeature extends DefaultFeature {
|
||||||
float radius = 1 - i * 0.05F;
|
float radius = 1 - i * 0.05F;
|
||||||
radius = radius * radius * 2 - 1;
|
radius = radius * radius * 2 - 1;
|
||||||
radius *= radius;
|
radius *= radius;
|
||||||
radius = (1 - radius) * 10F * scale;
|
radius = (1 - radius) * 8F * scale;
|
||||||
dx = (float) Math.sin(i * 0.45F + angle) * radius;
|
dx = (float) Math.sin(i * 0.45F + angle) * radius;
|
||||||
dz = (float) Math.cos(i * 0.45F + angle) * radius;
|
dz = (float) Math.cos(i * 0.45F + angle) * radius;
|
||||||
spline.add(new Vector3f(dx, i * scale * 1.75F, dz));
|
spline.add(new Vector3f(dx, i * scale * 1.75F, dz));
|
||||||
|
@ -85,37 +88,68 @@ public class HelixTreeFeature extends DefaultFeature {
|
||||||
Vector3f start = new Vector3f();
|
Vector3f start = new Vector3f();
|
||||||
Vector3f end = new Vector3f();
|
Vector3f end = new Vector3f();
|
||||||
lastPoint = spline.get(0);
|
lastPoint = spline.get(0);
|
||||||
|
BlockState leaf = EndBlocks.HELIX_TREE_LEAVES.getDefaultState();
|
||||||
for (int i = 1; i < spline.size(); i++) {
|
for (int i = 1; i < spline.size(); i++) {
|
||||||
Vector3f point = spline.get(i);
|
Vector3f point = spline.get(i);
|
||||||
int minY = MHelper.floor(lastPoint.getY());
|
int minY = MHelper.floor(lastPoint.getY());
|
||||||
int maxY = MHelper.floor(point.getY());
|
int maxY = MHelper.floor(point.getY());
|
||||||
float div = point.getY() - lastPoint.getY();
|
float div = point.getY() - lastPoint.getY();
|
||||||
for (float py = minY; py <= maxY; py += 0.2F) {
|
for (float py = minY; py <= maxY; py += 0.1F) {
|
||||||
start.set(0, py, 0);
|
start.set(0, py, 0);
|
||||||
float delta = (float) (py - minY) / div;
|
float delta = (float) (py - minY) / div;
|
||||||
float px = MathHelper.lerp(delta, lastPoint.getX(), point.getX());
|
float px = MathHelper.lerp(delta, lastPoint.getX(), point.getX());
|
||||||
float pz = MathHelper.lerp(delta, lastPoint.getZ(), point.getZ());
|
float pz = MathHelper.lerp(delta, lastPoint.getZ(), point.getZ());
|
||||||
end.set(px, py, pz);
|
end.set(px, py, pz);
|
||||||
SplineHelper.fillLineForce(start, end, world, EndBlocks.HELIX_TREE_LEAVES.getDefaultState(), leafStart, (state) -> {
|
fillLine(start, end, world, leaf, leafStart, i / 2 - 1);
|
||||||
return state.getMaterial().isReplaceable();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
lastPoint = point;
|
lastPoint = point;
|
||||||
}
|
}
|
||||||
|
|
||||||
leafStart = leafStart.add(0, lastPoint.getY() + 1, 0);
|
leaf = leaf.with(BlockHelixTreeLeaves.COLOR, 7);
|
||||||
|
leafStart = leafStart.add(0, lastPoint.getY(), 0);
|
||||||
if (world.getBlockState(leafStart).isAir()) {
|
if (world.getBlockState(leafStart).isAir()) {
|
||||||
BlocksHelper.setWithoutUpdate(world, leafStart, EndBlocks.HELIX_TREE_LEAVES);
|
BlocksHelper.setWithoutUpdate(world, leafStart, leaf);
|
||||||
leafStart = leafStart.up();
|
leafStart = leafStart.up();
|
||||||
if (world.getBlockState(leafStart).isAir()) {
|
if (world.getBlockState(leafStart).isAir()) {
|
||||||
BlocksHelper.setWithoutUpdate(world, leafStart, EndBlocks.HELIX_TREE_LEAVES);
|
BlocksHelper.setWithoutUpdate(world, leafStart, leaf);
|
||||||
leafStart = leafStart.up();
|
leafStart = leafStart.up();
|
||||||
if (world.getBlockState(leafStart).isAir()) {
|
if (world.getBlockState(leafStart).isAir()) {
|
||||||
BlocksHelper.setWithoutUpdate(world, leafStart, EndBlocks.HELIX_TREE_LEAVES);
|
BlocksHelper.setWithoutUpdate(world, leafStart, leaf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void fillLine(Vector3f start, Vector3f end, StructureWorldAccess world, BlockState state, BlockPos pos, int offset) {
|
||||||
|
float dx = end.getX() - start.getX();
|
||||||
|
float dy = end.getY() - start.getY();
|
||||||
|
float dz = end.getZ() - start.getZ();
|
||||||
|
float max = MHelper.max(Math.abs(dx), Math.abs(dy), Math.abs(dz));
|
||||||
|
int count = MHelper.floor(max + 1);
|
||||||
|
dx /= max;
|
||||||
|
dy /= max;
|
||||||
|
dz /= max;
|
||||||
|
float x = start.getX();
|
||||||
|
float y = start.getY();
|
||||||
|
float z = start.getZ();
|
||||||
|
|
||||||
|
Mutable bPos = new Mutable();
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
int color = MHelper.floor((float) i / (float) count * 7F + 0.5F) + offset;
|
||||||
|
color = MathHelper.clamp(color, 0, 7);
|
||||||
|
bPos.set(x + pos.getX(), y + pos.getY(), z + pos.getZ());
|
||||||
|
if (world.getBlockState(bPos).getMaterial().isReplaceable()) {
|
||||||
|
BlocksHelper.setWithoutUpdate(world, bPos, state.with(BlockHelixTreeLeaves.COLOR, color));
|
||||||
|
}
|
||||||
|
x += dx;
|
||||||
|
y += dy;
|
||||||
|
z += dz;
|
||||||
|
}
|
||||||
|
bPos.set(end.getX() + pos.getX(), end.getY() + pos.getY(), end.getZ() + pos.getZ());
|
||||||
|
if (world.getBlockState(bPos).getMaterial().isReplaceable()) {
|
||||||
|
BlocksHelper.setWithoutUpdate(world, bPos, state.with(BlockHelixTreeLeaves.COLOR, 7));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"variants": {
|
||||||
|
"": { "model": "betterend:block/helix_tree_leaves" }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "betterend:block/tint_cube_noshade",
|
||||||
|
"textures": {
|
||||||
|
"texture": "betterend:block/helix_tree_leaves"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"parent": "betterend:block/helix_tree_leaves"
|
||||||
|
}
|
Before Width: | Height: | Size: 393 B After Width: | Height: | Size: 680 B |
Before Width: | Height: | Size: 215 B After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 298 B After Width: | Height: | Size: 407 B |
Before Width: | Height: | Size: 405 B After Width: | Height: | Size: 372 B |