More SDF tests
This commit is contained in:
parent
cf8955ea4b
commit
2e632bf245
13 changed files with 111 additions and 22 deletions
|
@ -1,7 +1,6 @@
|
|||
package ru.betterend;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
|
||||
import ru.betterend.config.MainConfig;
|
||||
import ru.betterend.recipe.CraftingRecipes;
|
||||
import ru.betterend.registry.BiomeRegistry;
|
||||
|
|
|
@ -7,7 +7,6 @@ import java.util.Random;
|
|||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
|
@ -38,7 +37,6 @@ import net.minecraft.util.math.BlockPos;
|
|||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import ru.betterend.blocks.basis.BaseBlockWithEntity;
|
||||
import ru.betterend.blocks.entities.EndStoneSmelterBlockEntity;
|
||||
|
||||
|
|
|
@ -7,10 +7,9 @@ import java.util.Map;
|
|||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap.Entry;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectIterator;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap.Entry;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.LockableContainerBlockEntity;
|
||||
import net.minecraft.entity.ExperienceOrbEntity;
|
||||
|
@ -37,7 +36,6 @@ import net.minecraft.util.math.Direction;
|
|||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.blocks.EndStoneSmelter;
|
||||
import ru.betterend.client.gui.EndStoneSmelterScreenHandler;
|
||||
|
|
|
@ -3,7 +3,6 @@ package ru.betterend.client.gui;
|
|||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
|
@ -20,7 +19,6 @@ import net.minecraft.screen.ScreenHandlerType;
|
|||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.blocks.EndStoneSmelter;
|
||||
import ru.betterend.blocks.entities.EndStoneSmelterBlockEntity;
|
||||
|
|
|
@ -4,7 +4,6 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
|
||||
import ru.betterend.blocks.entities.EndStoneSmelterBlockEntity;
|
||||
|
||||
public class SmelterOutputSlot extends Slot {
|
||||
|
|
|
@ -7,7 +7,6 @@ import com.google.common.collect.Lists;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.block.entity.BlockEntityType.Builder;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
|
|
@ -72,4 +72,8 @@ public class MHelper {
|
|||
public static float length(float x, float y, float z) {
|
||||
return (float) Math.sqrt(x * x + y * y + z * z);
|
||||
}
|
||||
|
||||
public static float dot(float x1, float y1, float z1, float x2, float y2, float z2) {
|
||||
return x1 * x2 + y1 * y2 + z1 * z2;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public interface ISDF {
|
|||
run &= Math.abs(pos.getZ()) < dz;
|
||||
|
||||
if (!blocks.contains(pos) && canReplace.apply(world.getBlockState(wpos))) {
|
||||
if (this.getDistance(pos.getX(), pos.getY(), pos.getZ()) <= 0) {
|
||||
if (this.getDistance(pos.getX(), pos.getY(), pos.getZ()) < 0) {
|
||||
BlocksHelper.setWithoutUpdate(world, wpos, Blocks.STONE);
|
||||
add.add(pos);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package ru.betterend.util.sdf.operator;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
|
||||
public class SDFDisplacement extends SDFUnary {
|
||||
private static final Vector3f POS = new Vector3f();
|
||||
private Function<Vector3f, Float> displace;
|
||||
|
||||
public SDFDisplacement setFunction(Function<Vector3f, Float> displace) {
|
||||
this.displace = displace;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDistance(float x, float y, float z) {
|
||||
POS.set(x, y, z);
|
||||
return this.source.getDistance(x, y, z) + displace.apply(POS);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package ru.betterend.util.sdf.operator;
|
||||
|
||||
public class SDFFlatWave extends SDFDisplacement {
|
||||
private int rayCount = 1;
|
||||
private float intensity;
|
||||
|
||||
public SDFFlatWave() {
|
||||
setFunction((pos) -> {
|
||||
return (float) Math.cos(Math.atan2(pos.getX(), pos.getZ()) * rayCount) * intensity;
|
||||
});
|
||||
}
|
||||
|
||||
public SDFFlatWave setRaysCount(int count) {
|
||||
this.rayCount = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SDFFlatWave setIntensity(float intensity) {
|
||||
this.intensity = intensity;
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -20,6 +20,6 @@ public class SDFCapsule implements ISDF {
|
|||
|
||||
@Override
|
||||
public float getDistance(float x, float y, float z) {
|
||||
return MHelper.length(x, MathHelper.clamp(y, -height, 0), z) - radius;
|
||||
return MHelper.length(x, y - MathHelper.clamp(y, 0, height), z) - radius;
|
||||
}
|
||||
}
|
||||
|
|
50
src/main/java/ru/betterend/util/sdf/primitive/SDFLine.java
Normal file
50
src/main/java/ru/betterend/util/sdf/primitive/SDFLine.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
package ru.betterend.util.sdf.primitive;
|
||||
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import ru.betterend.util.MHelper;
|
||||
import ru.betterend.util.sdf.ISDF;
|
||||
|
||||
public class SDFLine implements ISDF {
|
||||
private float radius;
|
||||
private float x1;
|
||||
private float y1;
|
||||
private float z1;
|
||||
private float x2;
|
||||
private float y2;
|
||||
private float z2;
|
||||
|
||||
public SDFLine setRadius(float radius) {
|
||||
this.radius = radius;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SDFLine setStart(float x, float y, float z) {
|
||||
this.x1 = x;
|
||||
this.y1 = y;
|
||||
this.z1 = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SDFLine setEnd(float x, float y, float z) {
|
||||
this.x2 = x;
|
||||
this.y2 = y;
|
||||
this.z2 = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDistance(float x, float y, float z) {
|
||||
float pax = x - x1;
|
||||
float pay = y - y1;
|
||||
float paz = z - z1;
|
||||
|
||||
float bax = x2 - x1;
|
||||
float bay = y2 - y1;
|
||||
float baz = z2 - z1;
|
||||
|
||||
float dpb = MHelper.dot(pax, pay, paz, bax, bay, baz);
|
||||
float dbb = MHelper.dot(bax, bay, baz, bax, bay, baz);
|
||||
float h = MathHelper.clamp(dpb / dbb, 0F, 1F);
|
||||
return MHelper.length(pax - bax * h, pay - bay * h, paz - baz * h) - radius;
|
||||
}
|
||||
}
|
|
@ -10,11 +10,12 @@ import net.minecraft.world.gen.chunk.ChunkGenerator;
|
|||
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
||||
import ru.betterend.registry.BlockTagRegistry;
|
||||
import ru.betterend.util.sdf.ISDF;
|
||||
import ru.betterend.util.sdf.operator.SDFFlatWave;
|
||||
import ru.betterend.util.sdf.operator.SDFScale3D;
|
||||
import ru.betterend.util.sdf.operator.SDFSmoothUnion;
|
||||
import ru.betterend.util.sdf.operator.SDFSubtraction;
|
||||
import ru.betterend.util.sdf.operator.SDFTranslate;
|
||||
import ru.betterend.util.sdf.primitive.SDFCapsule;
|
||||
import ru.betterend.util.sdf.primitive.SDFLine;
|
||||
import ru.betterend.util.sdf.primitive.SDFSphere;
|
||||
|
||||
public class MossyGlowshroomFeature extends DefaultFeature {
|
||||
|
@ -30,26 +31,26 @@ public class MossyGlowshroomFeature extends DefaultFeature {
|
|||
if (!world.getBlockState(blockPos.down()).isIn(BlockTagRegistry.END_GROUND)) {
|
||||
return false;
|
||||
}
|
||||
FUNCTION.fillRecursive(world, getTopPos(world, blockPos), REPLACE, 10, 20, 10);
|
||||
FUNCTION.fillRecursive(world, getTopPos(world, blockPos), REPLACE, 20, 50, 20);
|
||||
return true;
|
||||
}
|
||||
|
||||
static {
|
||||
SDFCapsule capsule = new SDFCapsule().setRadius(1.7F).setHeight(5);
|
||||
SDFLine stem = new SDFLine().setRadius(2F).setEnd(0, 15, 0);
|
||||
|
||||
SDFSphere outerSphere = new SDFSphere().setRadius(10);
|
||||
SDFSphere innerSphere = new SDFSphere().setRadius(30);
|
||||
SDFSphere innerSphere = new SDFSphere().setRadius(10);
|
||||
|
||||
ISDF scaled1 = new SDFScale3D().setScale(1, 0.3F, 1).setSource(outerSphere);
|
||||
ISDF scaled2 = new SDFScale3D().setScale(1, 0.3F, 1).setSource(innerSphere);
|
||||
SDFTranslate sphereOffset = new SDFTranslate().setTranslate(0, -10F, 0);
|
||||
|
||||
ISDF head = new SDFSubtraction().setSourceA(scaled1).setSourceB(sphereOffset.setSource(scaled2));
|
||||
SDFFlatWave wave = new SDFFlatWave().setRaysCount(5).setIntensity(1.2F);
|
||||
ISDF head = new SDFSubtraction().setSourceA(outerSphere).setSourceB(sphereOffset.setSource(innerSphere));
|
||||
head = new SDFScale3D().setScale(1, 0.5F, 1).setSource(head);
|
||||
head = wave.setSource(head);
|
||||
|
||||
SDFTranslate headOffset = new SDFTranslate().setTranslate(0, 10, 0);
|
||||
SDFTranslate headOffset = new SDFTranslate().setTranslate(0, 15, 0);
|
||||
|
||||
//FUNCTION = new SDFSmoothUnion().setRadius(3).setSourceA(capsule).setSourceB(headOffset.setSource(head));
|
||||
FUNCTION = headOffset.setSource(head);
|
||||
FUNCTION = new SDFSmoothUnion().setRadius(5).setSourceA(stem).setSourceB(headOffset.setSource(head));
|
||||
|
||||
REPLACE = (state) -> {
|
||||
return state.getMaterial().isReplaceable();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue