Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
added ancient debris
Browse files Browse the repository at this point in the history
  • Loading branch information
19MisterX98 committed Dec 17, 2020
1 parent 361152e commit 0fed524
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 25 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ dependencies {

implementation('com.github.KaptainWutax:MathUtils:6c2d50eacad0241ff76119e6e703b70bac4b4bce') {transitive = false}
implementation('com.github.KaptainWutax:SeedUtils:0de70bc772fef95d8acfa6991e7278ee53a8b46c') {transitive = false}
implementation('com.github.KaptainWutax:BiomeUtils:62b374f2def7e09240447aceeb12a0a601b59a2b') {transitive = false}

include('com.github.KaptainWutax:MathUtils:6c2d50eacad0241ff76119e6e703b70bac4b4bce') {transitive = false}
include('com.github.KaptainWutax:SeedUtils:0de70bc772fef95d8acfa6991e7278ee53a8b46c') {transitive = false}
include('com.github.KaptainWutax:BiomeUtils:62b374f2def7e09240447aceeb12a0a601b59a2b') {transitive = false}
}

processResources {
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/misterx/diamondgen/SimDebrisGen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package misterx.diamondgen;

import misterx.diamondgen.render.Color;
import misterx.diamondgen.render.Cube;
import misterx.diamondgen.render.Renderer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class SimDebrisGen {

public List<Renderer> renderers = new ArrayList<>();

public boolean generate(Random random, BlockPos blockPos, int size) {
int i = random.nextInt(size + 1);
BlockPos.Mutable mutable = new BlockPos.Mutable();

for(int j = 0; j < i; ++j) {
this.getStartPos(mutable, random, blockPos, Math.min(j, 7));
renderers.add(new Cube(mutable, new Color(255, 255, 0)));
}

return true;
}

private void getStartPos(BlockPos.Mutable mutable, Random random, BlockPos pos, int size) {
int i = this.randomCoord(random, size);
int j = this.randomCoord(random, size);
int k = this.randomCoord(random, size);
mutable.set((Vec3i)pos, i, j, k);
}

private int randomCoord(Random random, int size) {
return Math.round((random.nextFloat() - random.nextFloat()) * (float)size);
}

}
71 changes: 49 additions & 22 deletions src/main/java/misterx/diamondgen/SimOreGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import misterx.diamondgen.render.Color;
import misterx.diamondgen.render.Cube;
import misterx.diamondgen.render.Renderer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.dimension.DimensionType;


import java.util.ArrayList;
Expand All @@ -17,62 +20,75 @@
public class SimOreGen {

public List<Renderer> renderers = new ArrayList<>();

public ClientWorld world = MinecraftClient.getInstance().world;


public void render() {
if(!DiamondGen.active){
return;
}
try {
this.renderers.forEach(renderer -> {
if (Util.distanceToPlayer(renderer.getPos()) < DiamondGen.range) {
if(DiamondGen.isOpaque()) {
if (Util.isOpaque(renderer.getPos())){
if (isOverworld(DiamondGen.gen.world.getDimension())) {
this.renderers.forEach(renderer -> {
if (Util.distanceToPlayer(renderer.getPos()) < DiamondGen.range) {
if (DiamondGen.isOpaque()) {
if (Util.isOpaque(renderer.getPos())) {
renderer.render();
}
} else {
renderer.render();
}
}else {
renderer.render();
}
}
});
});
}else if(isNether(DiamondGen.gen.world.getDimension())) {
DiamondGen.gen.simDebrisGen.renderers.forEach(renderer -> {
if (Util.distanceToPlayer(renderer.getPos()) < DiamondGen.range) {
if (DiamondGen.isOpaque()) {
if (Util.isOpaque(renderer.getPos())) {
renderer.render();
}
} else {
renderer.render();
}
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
}

public boolean generate(Random random, BlockPos blockPos, ClientWorld world) {
public boolean generate(Random random, BlockPos blockPos, ClientWorld world,int size) {
float f = random.nextFloat() * 3.1415927F;
float g = 1.0F;
int i = MathHelper.ceil((1.0F / 16.0F * 2.0F + 1.0F) / 2.0F);
double d = (double)blockPos.getX() + Math.sin(f) * (double)g;
double e = (double)blockPos.getX() - Math.sin(f) * (double)g;
double h = (double)blockPos.getZ() + Math.cos(f) * (double)g;
double j = (double)blockPos.getZ() - Math.cos(f) * (double)g;
double l = (blockPos.getY() + random.nextInt(3) - 2);
double m = (blockPos.getY() + random.nextInt(3) - 2);
float g = (float)size / 8.0F;
int i = MathHelper.ceil(((float)size / 16.0F * 2.0F + 1.0F) / 2.0F);
double d = (double)blockPos.getX() + Math.sin((double)f) * (double)g;
double e = (double)blockPos.getX() - Math.sin((double)f) * (double)g;
double h = (double)blockPos.getZ() + Math.cos((double)f) * (double)g;
double j = (double)blockPos.getZ() - Math.cos((double)f) * (double)g;
double l = (double)(blockPos.getY() + random.nextInt(3) - 2);
double m = (double)(blockPos.getY() + random.nextInt(3) - 2);
int n = blockPos.getX() - MathHelper.ceil(g) - i;
int o = blockPos.getY() - 2 - i;
int p = blockPos.getZ() - MathHelper.ceil(g) - i;
int q = 2 * (MathHelper.ceil(g) + i);
int r = 2 * (2 + i);

for(int s = n; s <= n + q; ++s) {
for(int t = p; t <= p + q; ++t) {
//if (o <= structureWorldAccess.getTopY(Heightmap.Type.OCEAN_FLOOR_WG, s, t)) {
return generateVeinPart(random, d, e, h, j, l, m, n, o, p, q, r, world);
return generateVeinPart(random, d, e, h, j, l, m, n, o, p, q, r, world, size);
//}
}
}

return false;
}

protected boolean generateVeinPart(Random random, double startX, double endX, double startZ, double endZ, double startY, double endY, int x, int y, int z, int size, int i,ClientWorld world) {
protected boolean generateVeinPart(Random random, double startX, double endX, double startZ, double endZ, double startY, double endY, int x, int y, int z, int size, int i,ClientWorld world,int veinSize) {
int j = 0;
BitSet bitSet = new BitSet(size * i * size);
BlockPos.Mutable mutable = new BlockPos.Mutable();
int k = 8;
int k = veinSize;
double[] ds = new double[k * 4];

int n;
Expand Down Expand Up @@ -155,4 +171,15 @@ protected boolean generateVeinPart(Random random, double startX, double endX, do

return j > 0;
}
private boolean isOverworld(DimensionType dimension) {
return ((DimensionTypeCaller)dimension).getInfiniburn().getPath().endsWith("overworld");
}

private boolean isNether(DimensionType dimension) {
return ((DimensionTypeCaller)dimension).getInfiniburn().getPath().endsWith("nether");
}

public interface DimensionTypeCaller {
Identifier getInfiniburn();
}
}
36 changes: 35 additions & 1 deletion src/main/java/misterx/diamondgen/StartGen.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package misterx.diamondgen;

import kaptainwutax.biomeutils.Biome;
import kaptainwutax.biomeutils.source.NetherBiomeSource;
import kaptainwutax.seedutils.mc.MCVersion;
import kaptainwutax.seedutils.mc.seed.ChunkSeeds;
import net.minecraft.client.MinecraftClient;
Expand All @@ -14,6 +16,7 @@ public class StartGen {
public ClientWorld world = MinecraftClient.getInstance().world;
public PlayerEntity player = MinecraftClient.getInstance().player;
public ChunkGenerated chunkList = new ChunkGenerated();
public SimDebrisGen simDebrisGen = new SimDebrisGen();
public long currentSeed = 0L;

StartGen(long seed) {
Expand All @@ -39,6 +42,37 @@ public void getStartingPos(int BlockX, int BlockZ) {


BlockPos blockPos = new BlockPos(x,y,z);
simOreGen.generate(random,blockPos,DiamondGen.gen.world);
simOreGen.generate(random,blockPos,DiamondGen.gen.world,8);
ancienDebris(BlockX,BlockZ);
}

public void ancienDebris(int BlockX,int BlockZ){
NetherBiomeSource netherBiomeSource = new NetherBiomeSource(MCVersion.v1_16_2,currentSeed);
Biome biome = netherBiomeSource.getBiome(BlockX,0,BlockZ);
int index = 15;
if(biome.getName().equals("warped_forest")) {
index = 13;
} else if(biome.getName().equals("crimson_forest")) {
index = 12;
}
long decSeed = ChunkSeeds.getDecoratorSeed(this.currentSeed, BlockX, BlockZ, index,7, MCVersion.v1_16_2);
Random random = new Random();
random.setSeed(decSeed);

int x = random.nextInt(16)+BlockX;
int z = random.nextInt(16)+BlockZ;
//int y = random.nextInt(128 - 16) + 8;
int y = random.nextInt(8) + random.nextInt(8) +8;
BlockPos blockPos = new BlockPos(x,y,z);
simDebrisGen.generate(random,blockPos,3);

decSeed = ChunkSeeds.getDecoratorSeed(this.currentSeed, BlockX, BlockZ, index+1,7, MCVersion.v1_16_2);
random.setSeed(decSeed);

x = random.nextInt(16)+BlockX;
z = random.nextInt(16)+BlockZ;
y = random.nextInt(112)+8;
BlockPos blockPos1 = new BlockPos(x,y,z);
simDebrisGen.generate(random,blockPos1,2);
}
}
2 changes: 2 additions & 0 deletions src/main/java/misterx/diamondgen/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@


import net.minecraft.client.MinecraftClient;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.dimension.DimensionType;

public class Util {
private static final MinecraftClient client = MinecraftClient.getInstance();
Expand Down
1 change: 0 additions & 1 deletion src/main/java/misterx/diamondgen/commands/SeedCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public void build(LiteralArgumentBuilder<ServerCommandSource> builder) {
}

private static int setSeed(long seed) {
System.out.println(seed);
DiamondGen.clear(seed);
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.command.CommandSource;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket;
import net.minecraft.network.packet.s2c.play.CommandTreeS2CPacket;
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
import net.minecraft.server.command.ServerCommandSource;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -23,10 +23,13 @@
public class ClientPlayNetworkHandlerMixin {
@Shadow private CommandDispatcher<CommandSource> commandDispatcher;

@Shadow private MinecraftClient client;

@Inject(method = "onChunkData", at = @At(value = "TAIL"))
private void onChunkData(ChunkDataS2CPacket packet, CallbackInfo ci) {
int posX = packet.getX() << 4;
int posZ = packet.getZ() << 4;
DiamondGen.gen.world = this.client.world;
DiamondGen.gen.getStartingPos(posX, posZ);
}

Expand All @@ -41,4 +44,8 @@ public void onInit(MinecraftClient mc, Screen screen, ClientConnection connectio
public void onOnCommandTree(CommandTreeS2CPacket packet, CallbackInfo ci) {
ClientCommands.registerCommands((CommandDispatcher<ServerCommandSource>)(Object)this.commandDispatcher);
}
@Inject(method = "onGameJoin",at = @At("TAIL"))
private void onGameJoin(GameJoinS2CPacket packet, CallbackInfo ci){
DiamondGen.clear(DiamondGen.gen.currentSeed);
}
}
20 changes: 20 additions & 0 deletions src/main/java/misterx/diamondgen/mixin/DimensionTypeMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package misterx.diamondgen.mixin;

import misterx.diamondgen.SimOreGen;
import net.minecraft.util.Identifier;
import net.minecraft.world.dimension.DimensionType;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(DimensionType.class)
public class DimensionTypeMixin implements SimOreGen.DimensionTypeCaller {

@Shadow @Final private Identifier infiniburn;

@Override
public Identifier getInfiniburn() {
return this.infiniburn;
}

}
1 change: 1 addition & 0 deletions src/main/resources/diamondgen.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"ClientPlayerEntityMixin",
"ClientPlayNetworkHandlerMixin",
"ClientWorldMixin",
"DimensionTypeMixin",
"DummyProfilerMixin",
"GameRendererMixin"
],
Expand Down

0 comments on commit 0fed524

Please sign in to comment.