This commit is contained in:
Unknown
2019-10-08 19:33:08 -04:00
parent 3088fe091e
commit d0458f80f9
14 changed files with 297 additions and 34 deletions
@@ -0,0 +1,54 @@
package kaptainwutax.seedcracker;
import com.mojang.blaze3d.platform.GlStateManager;
import kaptainwutax.seedcracker.finder.BuriedTreasureFinder;
import kaptainwutax.seedcracker.finder.Finder;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.List;
public class FinderQueue {
private final static FinderQueue INSTANCE = new FinderQueue();
private List<Finder> activeFinders = new ArrayList<>();
public FinderQueue() {
}
public static FinderQueue get() {
return INSTANCE;
}
public void onChunkData(World world, ChunkPos chunkPos) {
BuriedTreasureFinder buriedTreasure = new BuriedTreasureFinder(world, chunkPos);
buriedTreasure.findInChunk();
this.activeFinders.add(buriedTreasure);
}
public void renderFinders() {
GlStateManager.disableTexture();
//Makes it render through blocks.
GlStateManager.disableDepthTest();
this.activeFinders.removeIf(Finder::isUseless);
this.activeFinders.forEach(finder -> {
if(finder.shouldRender()) {
finder.render();
}
});
GlStateManager.enableTexture();
GlStateManager.enableDepthTest();
}
public void clear() {
this.activeFinders.clear();
}
}
@@ -1,15 +1,13 @@
package kaptainwutax.seedcracker;
import kaptainwutax.seedcracker.finder.BlockFinder;
import kaptainwutax.seedcracker.render.RenderQueue;
import net.fabricmc.api.ModInitializer;
import net.minecraft.block.Blocks;
public class SeedCracker implements ModInitializer {
@Override
public void onInitialize() {
BlockFinder finder1 = new BlockFinder(Blocks.CHEST.getDefaultState());
BlockFinder finder2 = new BlockFinder(Blocks.CHEST);
RenderQueue.get().add("hand", FinderQueue.get()::renderFinders);
}
}
@@ -7,36 +7,37 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkSection;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class BlockFinder extends Finder {
public abstract class BlockFinder extends Finder {
private Set<BlockState> targetBlockStates = new HashSet<>();
public BlockFinder(Block block) {
public BlockFinder(World world, ChunkPos chunkPos, Block block) {
super(world, chunkPos);
this.targetBlockStates.addAll(block.getStateFactory().getStates());
}
public BlockFinder(BlockState blockState) {
public BlockFinder(World world, ChunkPos chunkPos, BlockState blockState) {
super(world, chunkPos);
this.targetBlockStates.add(blockState);
}
@Override
public List<BlockPos> findInChunk(World world, ChunkPos chunkPos) {
public List<BlockPos> findInChunk() {
List<BlockPos> result = new ArrayList<>();
ChunkWrapper chunkWrapper = new ChunkWrapper(world, chunkPos);
ChunkWrapper chunkWrapper = new ChunkWrapper(this.world, this.chunkPos);
Chunk chunk = chunkWrapper.getChunk();
for(BlockPos pos: CHUNK_POSITIONS) {
BlockState currentState = chunk.getBlockState(pos);
for(BlockPos blockPos: CHUNK_POSITIONS) {
BlockState currentState = chunk.getBlockState(blockPos);
if(this.targetBlockStates.contains(currentState)) {
result.add(chunkPos.getCenterBlockPos().add(pos));
result.add(this.chunkPos.getCenterBlockPos().add(blockPos));
}
}
@@ -1,5 +1,6 @@
package kaptainwutax.seedcracker.finder;
import kaptainwutax.seedcracker.render.Cube;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
@@ -23,14 +24,15 @@ public class BuriedTreasureFinder extends BlockFinder {
CHEST_HOLDERS.add(Blocks.DIORITE.getDefaultState());
}
public BuriedTreasureFinder() {
super(Blocks.CHEST);
public BuriedTreasureFinder(World world, ChunkPos chunkPos) {
super(world, chunkPos, Blocks.CHEST);
}
@Override
public List<BlockPos> findInChunk(World world, ChunkPos chunkPos) {
public List<BlockPos> findInChunk() {
//Gets all the positions with a chest in the chunk.
List<BlockPos> result = super.findInChunk(world, chunkPos);
List<BlockPos> result = super.findInChunk();
result.removeIf(pos -> {
//Buried treasure chests always generate at (9, 9) within a chunk.
@@ -47,9 +49,11 @@ public class BuriedTreasureFinder extends BlockFinder {
if(!biome.hasStructureFeature(Feature.BURIED_TREASURE))return true;
//Damn that chest be lucky!
return true;
return false;
});
result.forEach(pos -> this.renderers.add(new Cube(pos)));
return result;
}
@@ -1,7 +1,10 @@
package kaptainwutax.seedcracker.finder;
import kaptainwutax.seedcracker.render.Renderer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import java.util.ArrayList;
@@ -12,6 +15,11 @@ public abstract class Finder {
protected static final List<BlockPos> CHUNK_POSITIONS = new ArrayList<>();
protected static final List<BlockPos> SUB_CHUNK_POSITIONS = new ArrayList<>();
protected MinecraftClient mc = MinecraftClient.getInstance();
protected List<Renderer> renderers = new ArrayList<>();
protected World world;
protected ChunkPos chunkPos;
static {
for(int x = 0; x < 16; x++) {
for(int z = 0; z < 16; z++) {
@@ -24,10 +32,32 @@ public abstract class Finder {
}
}
public Finder() {
public Finder(World world, ChunkPos chunkPos) {
this.world = world;
this.chunkPos = chunkPos;
}
public abstract List<BlockPos> findInChunk(World world, ChunkPos chunkPos);
public abstract List<BlockPos> findInChunk();
public boolean shouldRender() {
Vec3d playerPos = mc.player.getPos();
double distance = playerPos.squaredDistanceTo(
this.chunkPos.x * 16,
playerPos.y,
this.chunkPos.z * 16
);
int renderDistance = mc.options.viewDistance * 16 + 16;
return distance <= renderDistance * renderDistance + 32;
}
public void render() {
this.renderers.forEach(Renderer::render);
}
public boolean isUseless() {
return this.renderers.isEmpty();
}
}
@@ -0,0 +1,26 @@
package kaptainwutax.seedcracker.mixin;
import kaptainwutax.seedcracker.FinderQueue;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.packet.ChunkDataS2CPacket;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.ChunkPos;
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.CallbackInfo;
@Mixin(ClientPlayNetworkHandler.class)
public class ClientPlayNetworkHandlerMixin {
@Shadow private ClientWorld world;
@Inject(method = "onChunkData", at = @At("TAIL"))
private void onChunkData(ChunkDataS2CPacket packet, CallbackInfo ci) {
int chunkX = packet.getX();
int chunkZ = packet.getZ();
FinderQueue.get().onChunkData(this.world, new ChunkPos(chunkX, chunkZ));
}
}
@@ -0,0 +1,18 @@
package kaptainwutax.seedcracker.mixin;
import kaptainwutax.seedcracker.FinderQueue;
import net.minecraft.client.world.ClientWorld;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ClientWorld.class)
public abstract class ClientWorldMixin {
@Inject(method = "disconnect", at = @At("TAIL"))
private void disconnect(CallbackInfo ci) {
FinderQueue.get().clear();
}
}
@@ -1,6 +1,6 @@
package kaptainwutax.seedcracker.mixin;
import kaptainwutax.seedcracker.render.RenderTracker;
import kaptainwutax.seedcracker.render.RenderQueue;
import net.minecraft.util.profiler.DisableableProfiler;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
@@ -8,11 +8,11 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(DisableableProfiler.class)
public class DisableableProfilerMixin {
public abstract class DisableableProfilerMixin {
@Inject(method = "swap(Ljava/lang/String;)V", at = @At("HEAD"))
private void swap(String type, CallbackInfo ci) {
RenderTracker.get().onRender(type);
RenderQueue.get().onRender(type);
}
}
@@ -1,6 +1,6 @@
package kaptainwutax.seedcracker.mixin;
import kaptainwutax.seedcracker.render.RenderTracker;
import kaptainwutax.seedcracker.render.RenderQueue;
import net.minecraft.client.render.GameRenderer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
@@ -8,16 +8,16 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(GameRenderer.class)
public class GameRendererMixin {
public abstract class GameRendererMixin {
@Inject(method = "renderCenter", at = @At("HEAD"))
private void renderCenterStart(float delta, long time, CallbackInfo ci) {
RenderTracker.get().setTrackRender(true);
RenderQueue.get().setTrackRender(true);
}
@Inject(method = "renderCenter", at = @At("TAIL"))
private void renderCenterFinish(float delta, long time, CallbackInfo ci) {
RenderTracker.get().setTrackRender(false);
RenderQueue.get().setTrackRender(false);
}
}
@@ -0,0 +1,48 @@
package kaptainwutax.seedcracker.render;
import net.minecraft.client.util.math.Vector4f;
import net.minecraft.util.math.BlockPos;
public class Cube extends Renderer {
public BlockPos pos;
public Vector4f color;
private Line[] edges = new Line[12];
public Cube() {
this(BlockPos.ORIGIN, new Vector4f(1.0f, 1.0f, 1.0f, 1.0f));
}
public Cube(BlockPos pos) {
this(pos, new Vector4f(1.0f, 1.0f, 1.0f, 1.0f));
}
public Cube(BlockPos pos, Vector4f color) {
this.pos = pos;
this.color = color;
this.edges[0] = new Line(toVec3d(pos), toVec3d(pos.add(1, 0, 0)), this.color);
this.edges[1] = new Line(toVec3d(pos), toVec3d(pos.add(0, 1, 0)), this.color);
this.edges[2] = new Line(toVec3d(pos), toVec3d(pos.add(0, 0, 1)), this.color);
this.edges[3] = new Line(toVec3d(pos.add(1, 0, 1)), toVec3d(pos.add(1, 0, 0)), this.color);
this.edges[4] = new Line(toVec3d(pos.add(1, 0, 1)), toVec3d(pos.add(1, 1, 1)), this.color);
this.edges[5] = new Line(toVec3d(pos.add(1, 0, 1)), toVec3d(pos.add(0, 0, 1)), this.color);
this.edges[6] = new Line(toVec3d(pos.add(1, 1, 0)), toVec3d(pos.add(1, 0, 0)), this.color);
this.edges[7] = new Line(toVec3d(pos.add(1, 1, 0)), toVec3d(pos.add(0, 1, 0)), this.color);
this.edges[8] = new Line(toVec3d(pos.add(1, 1, 0)), toVec3d(pos.add(1, 1, 1)), this.color);
this.edges[9] = new Line(toVec3d(pos.add(0, 1, 1)), toVec3d(pos.add(0, 0, 1)), this.color);
this.edges[10] = new Line(toVec3d(pos.add(0, 1, 1)), toVec3d(pos.add(0, 1, 0)), this.color);
this.edges[11] = new Line(toVec3d(pos.add(0, 1, 1)), toVec3d(pos.add(1, 1, 1)), this.color);
}
@Override
public void render() {
if(this.pos == null || this.color == null || this.edges == null)return;
for(Line edge: this.edges) {
if(edge == null)continue;
edge.render();
}
}
}
@@ -0,0 +1,65 @@
package kaptainwutax.seedcracker.render;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.Vector4f;
import net.minecraft.util.math.Vec3d;
public class Line extends Renderer {
public Vec3d start;
public Vec3d end;
public Vector4f color;
public Line() {
this(Vec3d.ZERO, Vec3d.ZERO, new Vector4f(1.0f, 1.0f, 1.0f, 1.0f));
}
public Line(Vec3d start, Vec3d end) {
this(start, end, new Vector4f(1.0f, 1.0f, 1.0f, 1.0f));
}
public Line(Vec3d start, Vec3d end, Vector4f color) {
this.start = start;
this.end = end;
this.color = color;
}
@Override
public void render() {
if(this.start == null || this.end == null || this.color == null)return;
Vec3d camPos = this.mc.gameRenderer.getCamera().getPos();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBufferBuilder();
//This is how thick the line is.
GlStateManager.lineWidth(2.0f);
buffer.begin(3, VertexFormats.POSITION_COLOR);
//Put the start and end vertices in the buffer.
this.putVertex(buffer, camPos, this.start);
this.putVertex(buffer, camPos, this.end);
//Draw it all.
tessellator.draw();
}
protected void putVertex(BufferBuilder buffer, Vec3d camPos, Vec3d pos) {
for(int i = 0; i < 2; i++) {
buffer.vertex(
pos.getX() - camPos.x,
pos.getY() - camPos.y,
pos.getZ() - camPos.z
).color(
this.color.getX(),
this.color.getY(),
this.color.getZ(),
this.color.getW()
).next();
}
}
}
@@ -2,18 +2,18 @@ package kaptainwutax.seedcracker.render;
import java.util.*;
public class RenderTracker {
public class RenderQueue {
private static RenderTracker INSTANCE = new RenderTracker();
private final static RenderQueue INSTANCE = new RenderQueue();
private Map<String, List<Runnable>> typeRunnableMap = new HashMap<>();
private boolean trackRender = false;
public static RenderTracker get() {
public static RenderQueue get() {
return INSTANCE;
}
public void addRenderRunnable(String type, Runnable runnable) {
public void add(String type, Runnable runnable) {
Objects.requireNonNull(type);
Objects.requireNonNull(runnable);
@@ -25,7 +25,7 @@ public class RenderTracker {
runnableList.add(runnable);
}
public void removeRenderRunnable(String type, Runnable runnable) {
public void remove(String type, Runnable runnable) {
Objects.requireNonNull(type);
Objects.requireNonNull(runnable);
@@ -0,0 +1,17 @@
package kaptainwutax.seedcracker.render;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
public abstract class Renderer {
protected MinecraftClient mc = MinecraftClient.getInstance();
public abstract void render();
protected Vec3d toVec3d(BlockPos pos) {
return new Vec3d(pos.getX(), pos.getY(), pos.getZ());
}
}
+3 -1
View File
@@ -6,7 +6,9 @@
],
"client": [
"DisableableProfilerMixin",
"GameRendererMixin"
"GameRendererMixin",
"ClientPlayNetworkHandlerMixin",
"ClientWorldMixin"
],
"injectors": {
"defaultRequire": 1