Skip to content

Commit

Permalink
Lots of changes to client graphics stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
gravityfox committed Dec 12, 2016
1 parent 09ebca7 commit 30c8dd1
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle/versions.gradle
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Geometry> {

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) {
}
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();



}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<Geometry> 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<Geometry> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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<Geometry> getGeometry();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 30c8dd1

Please sign in to comment.