aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr
diff options
context:
space:
mode:
authorsyeyoung <42869671+cyoung06@users.noreply.github.com>2020-11-22 22:58:40 +0900
committersyeyoung <42869671+cyoung06@users.noreply.github.com>2020-11-22 22:58:40 +0900
commitb46d3d8ce98b112d8c4f1b3ad5eed81b234b1892 (patch)
treeec852c4883effa2f961bd896db17bbca923bb595 /src/main/java/kr
parent70a753c2a0aac9bd7e7e21ca081c4ee994bc4891 (diff)
downloadSkyblock-Dungeons-Guide-b46d3d8ce98b112d8c4f1b3ad5eed81b234b1892.tar.gz
Skyblock-Dungeons-Guide-b46d3d8ce98b112d8c4f1b3ad5eed81b234b1892.tar.bz2
Skyblock-Dungeons-Guide-b46d3d8ce98b112d8c4f1b3ad5eed81b234b1892.zip
room building and door rendering
Diffstat (limited to 'src/main/java/kr')
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/EventListener.java24
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java2
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonDoor.java37
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoom.java26
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/utils/RenderUtils.java175
5 files changed, 264 insertions, 0 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java b/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java
index 291a158f..9cb73aa1 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java
@@ -1,16 +1,21 @@
package kr.syeyoung.dungeonsguide;
import kr.syeyoung.dungeonsguide.dungeon.DungeonContext;
+import kr.syeyoung.dungeonsguide.dungeon.data.DungeonDoor;
+import kr.syeyoung.dungeonsguide.dungeon.data.DungeonRoom;
import kr.syeyoung.dungeonsguide.utils.MapUtils;
+import kr.syeyoung.dungeonsguide.utils.RenderUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
+import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
+import java.awt.*;
import java.util.Map;
public class EventListener {
@@ -39,12 +44,31 @@ public class EventListener {
ResourceLocation location = Minecraft.getMinecraft().renderEngine.getDynamicTextureLocation("dungeons/map/", dynamicTexture);
@SubscribeEvent
public void onRender(RenderGameOverlayEvent.Post postRender) {
+ SkyblockStatus skyblockStatus = DungeonsGuide.getDungeonsGuide().getSkyblockStatus();
+ if (!skyblockStatus.isOnDungeon()) return;
int[] textureData = dynamicTexture.getTextureData();
MapUtils.getImage().getRGB(0,0,128,128, textureData, 0, 128);
dynamicTexture.updateDynamicTexture();
Minecraft.getMinecraft().getTextureManager().bindTexture(location);
+
GlStateManager.enableBlend();
GlStateManager.enableAlpha();
GuiScreen.drawModalRectWithCustomSizedTexture(0,0, 0, 0, 128, 128, 128, 128);
+
+ }
+
+ @SubscribeEvent
+ public void onWorldRender(RenderWorldLastEvent renderWorldLastEvent) {
+ SkyblockStatus skyblockStatus = DungeonsGuide.getDungeonsGuide().getSkyblockStatus();
+ if (!skyblockStatus.isOnDungeon()) return;
+
+ DungeonContext context = skyblockStatus.getContext();
+ if (context == null) return;
+
+ for (DungeonRoom dungeonRoom : context.getDungeonRoomList()) {
+ for(DungeonDoor door : dungeonRoom.getDoors()) {
+ RenderUtils.renderDoor(door, renderWorldLastEvent.partialTicks);
+ }
+ }
}
}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java
index 4ed8c7b5..a3e0d961 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java
@@ -149,6 +149,7 @@ public class MapProcessor {
private void processMap(byte[] mapData) {
int height = (int)((128.0 - topLeftMapPoint.y) / (unitRoomDimension.height + doorDimension.height));
int width = (int) ((128.0 - topLeftMapPoint.x) / (unitRoomDimension.width + doorDimension.height));
+ if (MapUtils.getMapColorAt(mapData,0,0) != 0) return;
for (int y = 0; y <= height; y++){
for (int x = 0; x <= width; x++) {
if (roomsFound.contains(new Point(x,y))) continue;
@@ -159,6 +160,7 @@ public class MapProcessor {
if (color != 0 && color != 85) {
MapUtils.record(mapData, mapPoint.x, mapPoint.y, new Color(0,255,255,80));
DungeonRoom rooms = buildRoom(mapData, new Point(x,y));
+ Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("New Map discovered! shape: "+rooms.getShape()+ " color: "+rooms.getColor()+" min: "+rooms.getMin()+" / "+x+","+y));
context.getDungeonRoomList().add(rooms);
for (Point p:rooms.getUnitPoints()) {
roomsFound.add(p);
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonDoor.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonDoor.java
new file mode 100644
index 00000000..4dea9cdb
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonDoor.java
@@ -0,0 +1,37 @@
+package kr.syeyoung.dungeonsguide.dungeon.data;
+
+import com.google.common.collect.Sets;
+import lombok.Getter;
+import net.minecraft.block.Block;
+import net.minecraft.init.Blocks;
+import net.minecraft.util.BlockPos;
+import net.minecraft.world.World;
+
+import java.util.Set;
+
+@Getter
+public class DungeonDoor {
+ private final World w;
+ private final BlockPos position;
+ private boolean exist = true;
+ private boolean isZDir;
+
+ private static final Set<Block> legalBlocks = Sets.newHashSet(Blocks.coal_block, Blocks.barrier, Blocks.monster_egg, Blocks.air, Blocks.hardened_clay);
+
+
+ public DungeonDoor(World world, BlockPos pos) {
+ this.w = world;
+ this.position = pos;
+ for (int x = -1; x<=1; x++)
+ for (int y = -1; y<=1; y++)
+ for (int z = -1; z<=1; z++) {
+ BlockPos pos2 = pos.add(x,y,z);
+ Block block = world.getChunkFromBlockCoords(pos2).getBlock(pos2);
+ if (!legalBlocks.contains(block)) exist = false;
+ }
+ if (exist) {
+ BlockPos ZCheck = pos.add(0,0,2);
+ isZDir = world.getChunkFromBlockCoords(ZCheck).getBlock(ZCheck) == Blocks.air;
+ }
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoom.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoom.java
index 9cf22ebb..5d79b119 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoom.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoom.java
@@ -1,11 +1,16 @@
package kr.syeyoung.dungeonsguide.dungeon.data;
+import com.google.common.collect.Sets;
import kr.syeyoung.dungeonsguide.dungeon.DungeonContext;
import lombok.Getter;
import net.minecraft.util.BlockPos;
+import javax.vecmath.Vector2d;
import java.awt.*;
+import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
@Getter
public class DungeonRoom {
@@ -17,11 +22,32 @@ public class DungeonRoom {
private final DungeonContext context;
+ private final List<DungeonDoor> doors = new ArrayList<DungeonDoor>();
+
public DungeonRoom(List<Point> points, short shape, byte color, BlockPos min, DungeonContext context) {
this.unitPoints = points;
this.shape = shape;
this.color = color;
this.min = min;
this.context = context;
+ buildDoors();
+ }
+
+ private static final Set<Vector2d> directions = Sets.newHashSet(new Vector2d(0,16), new Vector2d(0, -16), new Vector2d(16, 0), new Vector2d(-16 , 0));
+
+ private void buildDoors() {
+ Set<BlockPos> positions = new HashSet<BlockPos>();
+ for (Point p:unitPoints) {
+ BlockPos pos = context.getMapProcessor().roomPointToWorldPoint(p).add(16,0,16);
+ for (Vector2d vector2d : directions){
+ BlockPos doorLoc = pos.add(vector2d.x, 0, vector2d.y);
+ if (positions.contains(doorLoc)) positions.remove(doorLoc);
+ else positions.add(doorLoc);
+ }
+ }
+
+ for (BlockPos door : positions) {
+ doors.add(new DungeonDoor(context.getWorld(), door));
+ }
}
}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/utils/RenderUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/utils/RenderUtils.java
new file mode 100644
index 00000000..269629e2
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/utils/RenderUtils.java
@@ -0,0 +1,175 @@
+package kr.syeyoung.dungeonsguide.utils;
+
+import kr.syeyoung.dungeonsguide.dungeon.data.DungeonDoor;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.renderer.GlStateManager;
+import net.minecraft.client.renderer.Tessellator;
+import net.minecraft.client.renderer.WorldRenderer;
+import net.minecraft.entity.Entity;
+import net.minecraft.util.BlockPos;
+import net.minecraft.util.Vec3;
+import org.lwjgl.opengl.GL11;
+
+import java.awt.*;
+
+public class RenderUtils {
+ public static void renderDoor(DungeonDoor dungeonDoor, float partialTicks) {
+ Entity player = Minecraft.getMinecraft().thePlayer;
+ double playerX = player.prevPosX + (player.posX - player.prevPosX) * partialTicks;
+ double playerY = player.prevPosY + (player.posY - player.prevPosY) * partialTicks;
+ double playerZ = player.prevPosZ + (player.posZ - player.prevPosZ) * partialTicks;
+//because of the way 3D rendering is done, all coordinates are relative to the camera. This "resets" the "0,0,0" position to the location that is (0,0,0) in the world.
+
+ GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
+ GL11.glPushMatrix();
+ GL11.glTranslated(-playerX, -playerY, -playerZ);
+ GL11.glDisable(GL11.GL_TEXTURE_2D);
+ GL11.glDisable(GL11.GL_CULL_FACE);
+ GlStateManager.enableAlpha();
+
+ if (dungeonDoor.isExist())
+ GL11.glColor4ub((byte)0,(byte)255,(byte)0, (byte)255);
+ else
+ GL11.glColor4ub((byte)255,(byte)0,(byte)0, (byte)255);
+
+ double x = dungeonDoor.getPosition().getX() + 0.5;
+ double y = dungeonDoor.getPosition().getY() -0.99;
+ double z = dungeonDoor.getPosition().getZ() + 0.5;
+ GL11.glBegin(GL11.GL_QUADS);
+
+ GL11.glVertex3d(x - 2.5, y, z - 2.5);
+ GL11.glVertex3d(x - 2.5, y, z + 2.5);
+ GL11.glVertex3d(x + 2.5, y, z + 2.5);
+ GL11.glVertex3d(x + 2.5, y, z - 2.5);
+
+ GL11.glEnd();
+
+ if (dungeonDoor.isExist()) {
+ GL11.glBegin(GL11.GL_QUADS);
+
+ GL11.glColor4ub((byte)0,(byte)0,(byte)255, (byte)255);
+ if (dungeonDoor.isZDir()) {
+ GL11.glVertex3d(x - 0.5, y + 0.1, z - 2.5);
+ GL11.glVertex3d(x - 0.5, y+ 0.1, z + 2.5);
+ GL11.glVertex3d(x + 0.5, y+ 0.1, z + 2.5);
+ GL11.glVertex3d(x + 0.5, y+ 0.1, z - 2.5);
+ } else {
+ GL11.glVertex3d(x - 2.5, y+ 0.1, z - 0.5);
+ GL11.glVertex3d(x - 2.5, y+ 0.1, z + 0.5);
+ GL11.glVertex3d(x + 2.5, y+ 0.1, z + 0.5);
+ GL11.glVertex3d(x + 2.5, y+ 0.1, z - 0.5);
+ }
+
+ GL11.glEnd();
+ } else {
+ GL11.glLineWidth(5);
+ GL11.glBegin(GL11.GL_LINE_LOOP);
+ GL11.glVertex3d(x - 2.5, y, z - 2.5);
+ GL11.glVertex3d(x + 2.5, y + 5, z - 2.5);
+ GL11.glVertex3d(x + 2.5, y, z + 2.5);
+ GL11.glVertex3d(x - 2.5, y + 5, z + 2.5);
+ GL11.glEnd();
+ GL11.glBegin(GL11.GL_LINE_LOOP);
+ GL11.glVertex3d(x - 2.5, y +5, z - 2.5);
+ GL11.glVertex3d(x + 2.5, y, z - 2.5);
+ GL11.glVertex3d(x + 2.5, y + 5, z + 2.5);
+ GL11.glVertex3d(x - 2.5, y, z + 2.5);
+ GL11.glEnd();
+ GL11.glLineWidth(1);
+ }
+// GlStateManager.disableAlpha();
+ GlStateManager.disableBlend();
+
+ GL11.glEnable(GL11.GL_TEXTURE_2D);
+ GL11.glEnable(GL11.GL_CULL_FACE);
+
+ GL11.glPopAttrib();
+ GL11.glPopMatrix();
+
+ }
+
+ public static void highlightBlock(BlockPos blockpos, Color c, float partialTicks) {
+ Entity viewing_from = Minecraft.getMinecraft().getRenderViewEntity();
+
+ double x_fix = viewing_from.lastTickPosX + ((viewing_from.posX - viewing_from.lastTickPosX) * partialTicks);
+ double y_fix = viewing_from.lastTickPosY + ((viewing_from.posY - viewing_from.lastTickPosY) * partialTicks);
+ double z_fix = viewing_from.lastTickPosZ + ((viewing_from.posZ - viewing_from.lastTickPosZ) * partialTicks);
+
+ GlStateManager.pushMatrix();
+ GlStateManager.pushAttrib();
+ GlStateManager.translate(-x_fix, -y_fix, -z_fix);
+
+ GlStateManager.disableLighting();
+ GlStateManager.enableBlend();
+ GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
+ GlStateManager.disableTexture2D();
+
+ GL11.glDisable(GL11.GL_DEPTH_TEST);
+ GL11.glDepthMask(false);
+ GL11.glColor3ub((byte)c.getRed(), (byte)c.getGreen(), (byte)c.getBlue());
+
+ GL11.glTranslated(blockpos.getX(), blockpos.getY(), blockpos.getZ());
+
+ GL11.glBegin(GL11.GL_QUADS);
+ GL11.glVertex3d(0, 0, 0);
+ GL11.glVertex3d(0, 0, 1);
+ GL11.glVertex3d(0, 1, 1);
+ GL11.glVertex3d(0, 1, 0); // TOP LEFT / BOTTOM LEFT / TOP RIGHT/ BOTTOM RIGHT
+
+ GL11.glVertex3d(1, 0, 1);
+ GL11.glVertex3d(1, 0, 0);
+ GL11.glVertex3d(1, 1, 0);
+ GL11.glVertex3d(1, 1, 1);
+
+ GL11.glVertex3d(0, 1, 1);
+ GL11.glVertex3d(0, 0, 1);
+ GL11.glVertex3d(1, 0, 1);
+ GL11.glVertex3d(1, 1, 1); // TOP LEFT / BOTTOM LEFT / TOP RIGHT/ BOTTOM RIGHT
+
+ GL11.glVertex3d(0, 0, 0);
+ GL11.glVertex3d(0, 1, 0);
+ GL11.glVertex3d(1, 1, 0);
+ GL11.glVertex3d(1, 0, 0);
+
+ GL11.glVertex3d(0,1,0);
+ GL11.glVertex3d(0,1,1);
+ GL11.glVertex3d(1,1,1);
+ GL11.glVertex3d(1,1,0);
+
+ GL11.glVertex3d(0,0,1);
+ GL11.glVertex3d(0,0,0);
+ GL11.glVertex3d(1,0,0);
+ GL11.glVertex3d(1,0,1);
+
+
+
+ GL11.glEnd();
+
+
+ GL11.glEnable(GL11.GL_DEPTH_TEST);
+ GL11.glDepthMask(true);
+ GlStateManager.enableTexture2D();
+ GlStateManager.disableBlend();
+ GlStateManager.enableLighting();
+ GlStateManager.popMatrix();
+ GlStateManager.popAttrib();
+
+
+//...
+
+ }
+
+ private void drawLineWithGL(Vec3 blockA, Vec3 blockB) {
+ int d = Math.round((float)blockA.distanceTo(blockB)+0.2f);
+ GL11.glColor3f(0F, 1F, 0F);
+ float oz = (blockA.xCoord - blockB.xCoord == 0?0:-1f/16f);
+ float ox = (blockA.zCoord - blockB.zCoord == 0?0:1f/16f);
+ GL11.glBegin(GL11.GL_LINE_STRIP);
+
+ //you will want to modify these offsets.
+ GL11.glVertex3d(blockA.xCoord + 0.5,blockA.yCoord - 0.01,blockA.zCoord + 0.5);
+ GL11.glVertex3d(blockB.xCoord + 0.5,blockB.yCoord - 0.01,blockB.zCoord + 0.5);
+
+ GL11.glEnd();
+ }
+}