Mushroom fixes
This commit is contained in:
parent
31e33ba2d3
commit
42ef270e2e
10 changed files with 181 additions and 17 deletions
|
@ -0,0 +1,45 @@
|
|||
package ru.betterend.mixin.common;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
|
||||
import net.minecraft.server.command.LocateCommand;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.gen.feature.StructureFeature;
|
||||
import ru.betterend.util.StructureHelper;
|
||||
|
||||
@Mixin(LocateCommand.class)
|
||||
public class LocateCommandMixin {
|
||||
@Shadow
|
||||
@Final
|
||||
private static SimpleCommandExceptionType FAILED_EXCEPTION;
|
||||
|
||||
@Shadow
|
||||
public static int sendCoordinates(ServerCommandSource source, String structure, BlockPos sourcePos,
|
||||
BlockPos structurePos, String successMessage) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Inject(method = "execute", at = @At("HEAD"), cancellable = true)
|
||||
private static void execute(ServerCommandSource source, StructureFeature<?> structureFeature, CallbackInfoReturnable<Integer> info) throws CommandSyntaxException {
|
||||
if (source.getWorld().getRegistryKey() == World.END) {
|
||||
BlockPos blockPos = new BlockPos(source.getPosition());
|
||||
BlockPos blockPos2 = StructureHelper.getNearestStructure(structureFeature, source.getWorld(), blockPos, 100);
|
||||
if (blockPos2 == null) {
|
||||
throw FAILED_EXCEPTION.create();
|
||||
} else {
|
||||
info.setReturnValue(sendCoordinates(source, structureFeature.getName(), blockPos, blockPos2, "commands.locate.success"));
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@ import ru.betterend.world.structures.piece.VoxelPiece;
|
|||
public class StructureRegistry {
|
||||
public static final StructurePieceType VOXEL_PIECE = register("voxel", VoxelPiece::new);
|
||||
|
||||
public static final EndStructureFeature GIANT_MOSSY_GLOWSHROOM = new EndStructureFeature("giant_mossy_glowshroom", new StructureGiantMossyGlowshroom(), Feature.RAW_GENERATION, 32, 8);
|
||||
public static final EndStructureFeature GIANT_MOSSY_GLOWSHROOM = new EndStructureFeature("giant_mossy_glowshroom", new StructureGiantMossyGlowshroom(), Feature.SURFACE_STRUCTURES, 16, 8);
|
||||
|
||||
public static void register() {}
|
||||
|
||||
|
|
62
src/main/java/ru/betterend/util/StructureHelper.java
Normal file
62
src/main/java/ru/betterend/util/StructureHelper.java
Normal file
|
@ -0,0 +1,62 @@
|
|||
package ru.betterend.util;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.gen.ChunkRandom;
|
||||
import net.minecraft.world.gen.chunk.StructureConfig;
|
||||
import net.minecraft.world.gen.feature.StructureFeature;
|
||||
|
||||
public class StructureHelper {
|
||||
private static final Set<ChunkPos> POSITIONS = new HashSet<ChunkPos>(64);
|
||||
|
||||
private static void collectNearby(ServerWorld world, StructureFeature<?> feature, int chunkX, int chunkZ, int radius, StructureConfig config, long worldSeed, ChunkRandom chunkRandom) {
|
||||
int x1 = chunkX - radius;
|
||||
int x2 = chunkX + radius;
|
||||
int z1 = chunkZ - radius;
|
||||
int z2 = chunkZ + radius;
|
||||
|
||||
POSITIONS.clear();
|
||||
for (int x = x1; x <= x2; x += 8) {
|
||||
for (int z = z1; z <= z2; z += 8) {
|
||||
ChunkPos chunk = feature.getStartChunk(config, worldSeed, chunkRandom, x, z);
|
||||
if (world.getBiome(chunk.getStartPos()).getGenerationSettings().hasStructureFeature(feature))
|
||||
POSITIONS.add(chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static long sqr(int x) {
|
||||
return (long) x * (long) x;
|
||||
}
|
||||
|
||||
public static BlockPos getNearestStructure(StructureFeature<?> feature, ServerWorld world, BlockPos pos, int radius) {
|
||||
int cx = pos.getX() >> 4;
|
||||
int cz = pos.getZ() >> 4;
|
||||
|
||||
StructureConfig config = world.getChunkManager().getChunkGenerator().getStructuresConfig().getForType(feature);
|
||||
if (config == null)
|
||||
return null;
|
||||
|
||||
collectNearby(world, feature, cx, cz, radius, config, world.getSeed(), new ChunkRandom());
|
||||
Iterator<ChunkPos> iterator = POSITIONS.iterator();
|
||||
if (iterator.hasNext()) {
|
||||
ChunkPos nearest = POSITIONS.iterator().next();
|
||||
long d = sqr(nearest.x - cx) + sqr(nearest.z - cz);
|
||||
while (iterator.hasNext()) {
|
||||
ChunkPos n = iterator.next();
|
||||
long d2 = sqr(n.x - cx) + sqr(n.z - cz);
|
||||
if (d2 < d) {
|
||||
d = d2;
|
||||
nearest = n;
|
||||
}
|
||||
}
|
||||
return nearest.getStartPos();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -24,7 +24,6 @@ public class EndStructureFeature {
|
|||
this.structure = FabricStructureBuilder.create(id, structure)
|
||||
.step(step)
|
||||
.defaultConfig(spacing, separation, RANDOM.nextInt(8192))
|
||||
.adjustsSurface()
|
||||
.register();
|
||||
|
||||
this.featureConfigured = this.structure.configure(DefaultFeatureConfig.DEFAULT);
|
||||
|
|
|
@ -18,8 +18,10 @@ import net.minecraft.world.chunk.Chunk;
|
|||
public class StructureWorld {
|
||||
private Map<ChunkPos, Part> parts = Maps.newHashMap();
|
||||
private int minX = Integer.MAX_VALUE;
|
||||
private int minY = Integer.MAX_VALUE;
|
||||
private int minZ = Integer.MAX_VALUE;
|
||||
private int maxX = Integer.MIN_VALUE;
|
||||
private int maxY = Integer.MIN_VALUE;
|
||||
private int maxZ = Integer.MIN_VALUE;
|
||||
|
||||
public StructureWorld() {}
|
||||
|
@ -27,8 +29,11 @@ public class StructureWorld {
|
|||
public StructureWorld(CompoundTag tag) {
|
||||
minX = tag.getInt("minX");
|
||||
maxX = tag.getInt("maxX");
|
||||
minY = tag.getInt("minY");
|
||||
maxY = tag.getInt("maxY");
|
||||
minZ = tag.getInt("minZ");
|
||||
maxZ = tag.getInt("maxZ");
|
||||
|
||||
ListTag map = tag.getList("parts", 10);
|
||||
map.forEach((element) -> {
|
||||
CompoundTag compound = (CompoundTag) element;
|
||||
|
@ -51,6 +56,8 @@ public class StructureWorld {
|
|||
if (cPos.z < minZ) minZ = cPos.z;
|
||||
if (cPos.z > maxZ) maxZ = cPos.z;
|
||||
}
|
||||
if (pos.getY() < minY) minY = pos.getY();
|
||||
if (pos.getY() > maxY) maxY = pos.getY();
|
||||
part.addBlock(pos, state);
|
||||
}
|
||||
|
||||
|
@ -68,6 +75,8 @@ public class StructureWorld {
|
|||
CompoundTag tag = new CompoundTag();
|
||||
tag.putInt("minX", minX);
|
||||
tag.putInt("maxX", maxX);
|
||||
tag.putInt("minY", minY);
|
||||
tag.putInt("maxY", maxY);
|
||||
tag.putInt("minZ", minZ);
|
||||
tag.putInt("maxZ", maxZ);
|
||||
ListTag map = new ListTag();
|
||||
|
@ -79,7 +88,10 @@ public class StructureWorld {
|
|||
}
|
||||
|
||||
public BlockBox getBounds() {
|
||||
return new BlockBox(minX << 4, minZ << 4, (maxX << 4) | 15, (maxZ << 4) | 15);
|
||||
if (minX == Integer.MAX_VALUE || maxX == Integer.MIN_VALUE || minZ == Integer.MAX_VALUE || maxZ == Integer.MIN_VALUE) {
|
||||
return BlockBox.empty();
|
||||
}
|
||||
return new BlockBox(minX << 4, minY, minZ << 4, (maxX << 4) | 15, maxY, (maxZ << 4) | 15);
|
||||
}
|
||||
|
||||
private static final class Part {
|
||||
|
@ -104,6 +116,7 @@ public class StructureWorld {
|
|||
|
||||
void placeChunk(Chunk chunk) {
|
||||
blocks.forEach((pos, state) -> {
|
||||
//if (pos.getY() > 10)
|
||||
chunk.setBlockState(pos, state, false);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -16,10 +16,7 @@ import ru.betterend.util.MHelper;
|
|||
import ru.betterend.util.sdf.SDF;
|
||||
import ru.betterend.world.structures.piece.VoxelPiece;
|
||||
|
||||
public abstract class SDFStructureFeature extends StructureFeature<DefaultFeatureConfig> {
|
||||
public SDFStructureFeature() {
|
||||
super(DefaultFeatureConfig.CODEC);
|
||||
}
|
||||
public abstract class SDFStructureFeature extends StructureFeatureBase {
|
||||
|
||||
protected abstract SDF getSDF(BlockPos pos, Random random);
|
||||
|
||||
|
@ -38,10 +35,12 @@ public abstract class SDFStructureFeature extends StructureFeature<DefaultFeatur
|
|||
int x = (chunkX << 4) | MHelper.randRange(4, 12, random);
|
||||
int z = (chunkZ << 4) | MHelper.randRange(4, 12, random);
|
||||
int y = chunkGenerator.getHeight(x, z, Type.WORLD_SURFACE_WG);
|
||||
if (y > 5) {
|
||||
BlockPos start = new BlockPos(x, y, z);
|
||||
VoxelPiece piece = new VoxelPiece((world) -> { ((SDFStructureFeature) this.getFeature()).getSDF(start, this.random).fillRecursive(world, start); }, random.nextInt());
|
||||
this.children.add(piece);
|
||||
this.boundingBox = piece.getBoundingBox();
|
||||
}
|
||||
this.setBoundingBoxFromChildren();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package ru.betterend.world.structures.features;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.util.BlockRotation;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.source.BiomeSource;
|
||||
import net.minecraft.world.gen.ChunkRandom;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
||||
import net.minecraft.world.gen.feature.StructureFeature;
|
||||
|
||||
public abstract class StructureFeatureBase extends StructureFeature<DefaultFeatureConfig> {
|
||||
public StructureFeatureBase() {
|
||||
super(DefaultFeatureConfig.CODEC);
|
||||
}
|
||||
|
||||
protected boolean shouldStartAt(ChunkGenerator chunkGenerator, BiomeSource biomeSource, long worldSeed, ChunkRandom chunkRandom, int chunkX, int chunkZ, Biome biome, ChunkPos chunkPos, DefaultFeatureConfig featureConfig) {
|
||||
return getGenerationHeight(chunkX, chunkZ, chunkGenerator) >= 50;
|
||||
}
|
||||
|
||||
private static int getGenerationHeight(int chunkX, int chunkZ, ChunkGenerator chunkGenerator) {
|
||||
Random random = new Random((long) (chunkX + chunkZ * 10387313));
|
||||
BlockRotation blockRotation = BlockRotation.random(random);
|
||||
int i = 5;
|
||||
int j = 5;
|
||||
if (blockRotation == BlockRotation.CLOCKWISE_90) {
|
||||
i = -5;
|
||||
} else if (blockRotation == BlockRotation.CLOCKWISE_180) {
|
||||
i = -5;
|
||||
j = -5;
|
||||
} else if (blockRotation == BlockRotation.COUNTERCLOCKWISE_90) {
|
||||
j = -5;
|
||||
}
|
||||
|
||||
int k = (chunkX << 4) + 7;
|
||||
int l = (chunkZ << 4) + 7;
|
||||
int m = chunkGenerator.getHeightInGround(k, l, Heightmap.Type.WORLD_SURFACE_WG);
|
||||
int n = chunkGenerator.getHeightInGround(k, l + j, Heightmap.Type.WORLD_SURFACE_WG);
|
||||
int o = chunkGenerator.getHeightInGround(k + i, l, Heightmap.Type.WORLD_SURFACE_WG);
|
||||
int p = chunkGenerator.getHeightInGround(k + i, l + j, Heightmap.Type.WORLD_SURFACE_WG);
|
||||
return Math.min(Math.min(m, n), Math.min(o, p));
|
||||
}
|
||||
}
|
|
@ -3,8 +3,6 @@ package ru.betterend.world.structures.features;
|
|||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import ru.betterend.blocks.BlockMossyGlowshroomCap;
|
||||
|
@ -28,8 +26,6 @@ import ru.betterend.util.sdf.primitive.SDFPrimitive;
|
|||
import ru.betterend.util.sdf.primitive.SDFSphere;
|
||||
|
||||
public class StructureGiantMossyGlowshroom extends SDFStructureFeature {
|
||||
private static final BlockState AIR = Blocks.AIR.getDefaultState();
|
||||
|
||||
@Override
|
||||
protected SDF getSDF(BlockPos center, Random random) {
|
||||
System.out.println(center);
|
||||
|
|
|
@ -22,10 +22,13 @@ public class VoxelPiece extends BasePiece {
|
|||
world = new StructureWorld();
|
||||
function.accept(world);
|
||||
this.boundingBox = world.getBounds();
|
||||
System.out.println(this.boundingBox);
|
||||
}
|
||||
|
||||
public VoxelPiece(StructureManager manager, CompoundTag tag) {
|
||||
super(StructureRegistry.VOXEL_PIECE, tag);
|
||||
this.boundingBox = world.getBounds();
|
||||
System.out.println(this.boundingBox);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
"AbstractBlockMixin",
|
||||
"LivingEntityMixin",
|
||||
"BiomeMixin",
|
||||
"SlimeEntityMixin"
|
||||
"SlimeEntityMixin",
|
||||
"LocateCommandMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue