From 30c8dd17395c9db3b321d43aa41e495a5062843e Mon Sep 17 00:00:00 2001 From: gravityfox Date: Sun, 11 Dec 2016 17:58:12 -0800 Subject: [PATCH] Lots of changes to client graphics stuff --- gradle/versions.gradle | 2 +- .../sponge/foxcore/mod/FoxCoreClientMain.java | 1 + .../foxcore/mod/render/HighlightList.java | 2 +- .../mod/rendernew/world/RenderList.java | 22 ++++++ .../mod/rendernew/world/RenderManager.java | 72 +++++++++++++++++++ .../rendernew/world/geometry/Geometry.java | 22 ++++++ .../world/geometry/GeometryLine.java | 44 ++++++++++++ .../rendernew/world/renderable/Highlight.java | 63 ++++++++++++++++ .../world/renderable/IRenderable.java | 14 ++++ .../sponge/foxcore/plugin/FoxCoreMain.java | 7 +- 10 files changed, 244 insertions(+), 5 deletions(-) create mode 100644 src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/RenderList.java create mode 100644 src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/RenderManager.java create mode 100644 src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/geometry/Geometry.java create mode 100644 src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/geometry/GeometryLine.java create mode 100644 src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/renderable/Highlight.java create mode 100644 src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/renderable/IRenderable.java diff --git a/gradle/versions.gradle b/gradle/versions.gradle index aa5a58d..7779f85 100644 --- a/gradle/versions.gradle +++ b/gradle/versions.gradle @@ -1,4 +1,4 @@ ext.spongeVersion = '5.0.0-SNAPSHOT' ext.clientForgeVersion = '2079' ext.mcpMappings = 'snapshot_20160822' -ext.gradleWrapperVersion = '3.1' +ext.gradleWrapperVersion = '3.2.1' diff --git a/src/main/java/net/foxdenstudio/sponge/foxcore/mod/FoxCoreClientMain.java b/src/main/java/net/foxdenstudio/sponge/foxcore/mod/FoxCoreClientMain.java index 5957f78..e2943d7 100644 --- a/src/main/java/net/foxdenstudio/sponge/foxcore/mod/FoxCoreClientMain.java +++ b/src/main/java/net/foxdenstudio/sponge/foxcore/mod/FoxCoreClientMain.java @@ -71,6 +71,7 @@ public void preInit(FMLPreInitializationEvent event) { public void load(FMLInitializationEvent event) { logger.info("Registering event handlers"); MinecraftForge.EVENT_BUS.register(renderHandler = new RenderHandler(Minecraft.getMinecraft())); + //MinecraftForge.EVENT_BUS.register(RenderManager.instance()); MinecraftForge.EVENT_BUS.register(this); logger.info("Registering MinecraftForge networking channels"); FCClientNetworkManager.instance().registerNetworkingChannels(); diff --git a/src/main/java/net/foxdenstudio/sponge/foxcore/mod/render/HighlightList.java b/src/main/java/net/foxdenstudio/sponge/foxcore/mod/render/HighlightList.java index c0c135f..5be7da0 100644 --- a/src/main/java/net/foxdenstudio/sponge/foxcore/mod/render/HighlightList.java +++ b/src/main/java/net/foxdenstudio/sponge/foxcore/mod/render/HighlightList.java @@ -67,7 +67,7 @@ public void render(Vector2i offset) { public void sortZ(double x, double y, double z) { try { forEach(highlight -> highlight.distance = highlight.getPos().toDouble().add(0.5, 0.5, 0.5).distanceSquared(x, y, z)); - Collections.sort(this, (o1, o2) -> o1.distance > o2.distance ? -1 : (o1.distance < o2.distance ? 1 : 0)); + this.sort((o1, o2) -> o1.distance > o2.distance ? -1 : (o1.distance < o2.distance ? 1 : 0)); } catch (ConcurrentModificationException ignored) { } } diff --git a/src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/RenderList.java b/src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/RenderList.java new file mode 100644 index 0000000..76190e2 --- /dev/null +++ b/src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/RenderList.java @@ -0,0 +1,22 @@ +package net.foxdenstudio.sponge.foxcore.mod.rendernew.world; + +import net.foxdenstudio.sponge.foxcore.mod.rendernew.world.geometry.Geometry; + +import java.util.ArrayList; +import java.util.ConcurrentModificationException; + +/** + * Created by Fox on 12/4/2016. + */ +public class RenderList extends ArrayList { + + public void sortZ(double x, double y, double z) { + try { + for(Geometry geo : this){ + geo.distance = geo.position.distanceSquared(x, y, z); + } + this.sort((o1, o2) -> o1.distance > o2.distance ? -1 : (o1.distance < o2.distance ? 1 : 0)); + } catch (ConcurrentModificationException ignored) { + } + } +} diff --git a/src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/RenderManager.java b/src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/RenderManager.java new file mode 100644 index 0000000..1b7d11c --- /dev/null +++ b/src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/RenderManager.java @@ -0,0 +1,72 @@ +package net.foxdenstudio.sponge.foxcore.mod.rendernew.world; + +import com.flowpowered.math.vector.Vector3i; +import net.foxdenstudio.sponge.foxcore.mod.rendernew.world.geometry.Geometry; +import net.foxdenstudio.sponge.foxcore.mod.rendernew.world.renderable.Highlight; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraftforge.client.event.RenderWorldLastEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import static org.lwjgl.opengl.GL11.*; + +/** + * Created by Fox on 12/4/2016. + */ +public class RenderManager { + + private static RenderManager inst; + + private Minecraft mc; + private RenderList list; + + private RenderManager(Minecraft mc) { + this.mc = mc; + this.list = new RenderList(); + + list.addAll(new Highlight(new Vector3i(0,80,0)).getGeometry()); + } + + public static RenderManager instance() { + if (inst == null) { + inst = new RenderManager(Minecraft.getMinecraft()); + } + return inst; + } + + @SideOnly(Side.CLIENT) + @SubscribeEvent + public void render(RenderWorldLastEvent event) { + + //System.out.println("TEST"); + EntityPlayerSP player = mc.thePlayer; + float partialTicks = event.getPartialTicks(); + 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; + list.sortZ(playerX, playerY, playerZ); + + glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT); + + glDisable(GL_LIGHTING); + glDisable(GL_TEXTURE_2D); + glDisable(GL_ALPHA_TEST); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDepthMask(false); + //glDisable(GL_DEPTH_TEST); + + glLineWidth(2f); + + for (Geometry geo : list) { + glPushMatrix(); + glTranslated(geo.position.getX(), geo.position.getY(), geo.position.getZ()); + geo.render(); + glPopMatrix(); + } + + glPopAttrib(); + } +} diff --git a/src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/geometry/Geometry.java b/src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/geometry/Geometry.java new file mode 100644 index 0000000..3118f4f --- /dev/null +++ b/src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/geometry/Geometry.java @@ -0,0 +1,22 @@ +package net.foxdenstudio.sponge.foxcore.mod.rendernew.world.geometry; + +import com.flowpowered.math.vector.Vector3d; +import com.flowpowered.math.vector.Vector3f; + +import java.util.Vector; + +/** + * Created by Fox on 12/4/2016. + */ +public abstract class Geometry { + + public double distance; + public Vector3d position; + public Vector3f color; + public float opacity; + + abstract public void render(); + + + +} diff --git a/src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/geometry/GeometryLine.java b/src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/geometry/GeometryLine.java new file mode 100644 index 0000000..25039fb --- /dev/null +++ b/src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/geometry/GeometryLine.java @@ -0,0 +1,44 @@ +package net.foxdenstudio.sponge.foxcore.mod.rendernew.world.geometry; + +import com.flowpowered.math.vector.Vector3d; +import com.flowpowered.math.vector.Vector3f; + +import static org.lwjgl.opengl.GL11.*; + +/** + * Created by Fox on 12/4/2016. + */ +public class GeometryLine extends Geometry { + + Vector3d start, end; + Vector3d localStart, localEnd; + + + + public GeometryLine(Vector3d start, Vector3d end, Vector3f color, float opacity) { + this.start = start; + this.end = end; + this.color = color; + this.opacity = opacity; + + this.position = start.add(end).div(2); + this.localStart = start.sub(position); + this.localEnd = end.sub(position); + } + + @Override + public void render() { + glPushAttrib(GL_CURRENT_BIT | GL_LINE_BIT | GL_HINT_BIT); + glColor4f(color.getX(), color.getY(), color.getZ(), opacity); + glEnable(GL_LINE_SMOOTH); + glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); + + glBegin(GL_LINES); + + glVertex3d(localStart.getX(), localStart.getY(), localStart.getZ()); + glVertex3d(localEnd.getX(), localEnd.getY(), localEnd.getZ()); + + glEnd(); + glPopAttrib(); + } +} diff --git a/src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/renderable/Highlight.java b/src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/renderable/Highlight.java new file mode 100644 index 0000000..eb58245 --- /dev/null +++ b/src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/renderable/Highlight.java @@ -0,0 +1,63 @@ +package net.foxdenstudio.sponge.foxcore.mod.rendernew.world.renderable; + +import com.flowpowered.math.vector.Vector3d; +import com.flowpowered.math.vector.Vector3f; +import com.flowpowered.math.vector.Vector3i; +import net.foxdenstudio.sponge.foxcore.mod.rendernew.world.geometry.Geometry; +import net.foxdenstudio.sponge.foxcore.mod.rendernew.world.geometry.GeometryLine; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** + * Created by Fox on 12/4/2016. + */ +public class Highlight implements IRenderable { + + private static final double OFFSET = 0.01; + private static final float OPACITY = 0.5f; + + Vector3i pos; + Vector3f color; + + List geometries = new ArrayList<>(); + + public Highlight(Vector3i pos) { + this(pos, Vector3f.ONE); + } + + public Highlight(Vector3i pos, Vector3f color) { + this.pos = pos; + this.color = color; + } + + @Override + public Collection getGeometry() { + if (geometries.isEmpty()) { + final Vector3d posD = pos.toDouble(); + final Vector3d v1 = posD.add(-OFFSET, -OFFSET, -OFFSET); + final Vector3d v2 = posD.add(1 + OFFSET, -OFFSET, -OFFSET); + final Vector3d v3 = posD.add(-OFFSET, 1 + OFFSET, -OFFSET); + final Vector3d v4 = posD.add(-OFFSET, -OFFSET, 1 + OFFSET); + final Vector3d v5 = posD.add(1 + OFFSET, 1 + OFFSET, -OFFSET); + final Vector3d v6 = posD.add(-OFFSET, 1 + OFFSET, 1 + OFFSET); + final Vector3d v7 = posD.add(1 + OFFSET, -OFFSET, 1 + OFFSET); + final Vector3d v8 = posD.add(1 + OFFSET, 1 + OFFSET, 1 + OFFSET); + + geometries.add(new GeometryLine(v1, v2, color, OPACITY)); + geometries.add(new GeometryLine(v1, v3, color, OPACITY)); + geometries.add(new GeometryLine(v1, v4, color, OPACITY)); + geometries.add(new GeometryLine(v2, v5, color, OPACITY)); + geometries.add(new GeometryLine(v2, v7, color, OPACITY)); + geometries.add(new GeometryLine(v3, v5, color, OPACITY)); + geometries.add(new GeometryLine(v3, v6, color, OPACITY)); + geometries.add(new GeometryLine(v4, v6, color, OPACITY)); + geometries.add(new GeometryLine(v4, v7, color, OPACITY)); + geometries.add(new GeometryLine(v5, v8, color, OPACITY)); + geometries.add(new GeometryLine(v6, v8, color, OPACITY)); + geometries.add(new GeometryLine(v7, v8, color, OPACITY)); + } + return geometries; + } +} diff --git a/src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/renderable/IRenderable.java b/src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/renderable/IRenderable.java new file mode 100644 index 0000000..65b6e70 --- /dev/null +++ b/src/main/java/net/foxdenstudio/sponge/foxcore/mod/rendernew/world/renderable/IRenderable.java @@ -0,0 +1,14 @@ +package net.foxdenstudio.sponge.foxcore.mod.rendernew.world.renderable; + +import net.foxdenstudio.sponge.foxcore.mod.rendernew.world.geometry.Geometry; + +import java.util.Collection; + +/** + * Created by Fox on 12/4/2016. + */ +public interface IRenderable { + + Collection getGeometry(); + +} diff --git a/src/main/java/net/foxdenstudio/sponge/foxcore/plugin/FoxCoreMain.java b/src/main/java/net/foxdenstudio/sponge/foxcore/plugin/FoxCoreMain.java index b99dd73..d23d4dc 100644 --- a/src/main/java/net/foxdenstudio/sponge/foxcore/plugin/FoxCoreMain.java +++ b/src/main/java/net/foxdenstudio/sponge/foxcore/plugin/FoxCoreMain.java @@ -47,6 +47,7 @@ import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.EventManager; import org.spongepowered.api.event.Listener; +import org.spongepowered.api.event.Order; import org.spongepowered.api.event.block.InteractBlockEvent; import org.spongepowered.api.event.entity.InteractEntityEvent; import org.spongepowered.api.event.game.state.GameConstructionEvent; @@ -138,13 +139,13 @@ public void registerListeners(GameInitializationEvent event) { logger.error("Error registering Network Manager Listeners", e); } try { - manager.registerListener(this, InteractBlockEvent.class, new WandBlockListener()); + manager.registerListener(this, InteractBlockEvent.class, Order.FIRST, new WandBlockListener()); } catch (Exception e) { logger.error("Error registering Wand Block Listener", e); } try { - manager.registerListener(this, InteractEntityEvent.class, new WandEntityListener()); - } catch (Exception e){ + manager.registerListener(this, InteractEntityEvent.class, Order.FIRST, new WandEntityListener()); + } catch (Exception e) { logger.error("Error registering Wand Entity Listener", e); } }