Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated forge and mappings. #5

Open
wants to merge 19 commits into
base: 1.12
Choose a base branch
from
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ artifacts {
}

minecraft {
version = "1.12.2-14.23.1.2583"
version = "1.12.2-14.23.4.2705"
runDir = "run"
replace '${version}', project.version
mappings = "snapshot_20180203"

//Formatted as YYYYMMDD
mappings = "snapshot_20180611"
}

repositories {
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/cjminecraft/core/CJCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
import cjminecraft.core.init.CJCoreItems;
import cjminecraft.core.items.ItemMultimeter;
import cjminecraft.core.proxy.CommonProxy;
import net.minecraft.command.ICommandManager;
import net.minecraft.command.ServerCommandManager;
import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.CustomProperty;
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/cjminecraft/core/access/AccessHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cjminecraft.core.access;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.launchwrapper.Launch;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

/**
* A utility class for handling all things to do with the game (which normally we don't have access to)
*
* @author Hypeirochus
*/
public class AccessHandler {

/**
* @return The minecraft instance
*/
@SideOnly(Side.CLIENT)
public static Minecraft getMinecraft() {
return Minecraft.instance;
}

/**
* @return The minecraft font renderer instance
*/
@SideOnly(Side.CLIENT)
public static FontRenderer getFontRenderer() {
return getMinecraft().fontRenderer;
}

/**
* @return The percentage from last update and this update
*/
@SideOnly(Side.CLIENT)
public static float getPartialTicks() {
return getMinecraft().timer.renderPartialTicks;
}

/**
* @return Whether or not the environment is deobfuscated
*/
public static boolean isDeobfuscatedEnvironment() {
return (boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
}
}
13 changes: 13 additions & 0 deletions src/main/java/cjminecraft/core/client/GameResources.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cjminecraft.core.client;

import cjminecraft.core.CJCore;
import cjminecraft.core.client.render.Texture;

public class GameResources {
public static final Texture PARTICLES = new Texture("textures/particle/particles.png");
public static final Texture SKY_SUN = new Texture("textures/environment/sun.png");
public static final Texture SKY_RAIN = new Texture("textures/environment/rain.png");
public static final Texture SKY_CLOUDS = new Texture("textures/environment/clouds.png");

public static final Texture BLANK = new Texture(CJCore.MODID, "textures/misc/blank.png");
}
16 changes: 16 additions & 0 deletions src/main/java/cjminecraft/core/client/KeyBindingHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package cjminecraft.core.client;

import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.fml.client.registry.ClientRegistry;

public class KeyBindingHandler {

public static void registerKeybinding(String unlocalizedName, int keyboardCode, String CATEGORY) {
KeyBinding key = new KeyBinding(unlocalizedName, keyboardCode, CATEGORY);
ClientRegistry.registerKeyBinding(key);
}

public static void registerKeybinding(KeyBinding key) {
ClientRegistry.registerKeyBinding(key);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cjminecraft.core.client.gui.element;

import java.io.IOException;
import java.text.NumberFormat;
import java.util.List;

import javax.annotation.Nullable;
Expand All @@ -12,18 +11,13 @@
import cjminecraft.core.config.CJCoreConfig;
import cjminecraft.core.energy.EnergyData;
import cjminecraft.core.energy.EnergyUnits.EnergyUnit;
import cjminecraft.core.energy.compat.forge.CustomForgeEnergyStorage;
import cjminecraft.core.energy.EnergyUtils;
import cjminecraft.core.util.RenderUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.common.capabilities.Capability;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.List;

import cjminecraft.core.CJCore;
import cjminecraft.core.client.gui.GuiCore;
import cjminecraft.core.client.gui.ISpecialOverlayElement;
import net.minecraft.item.ItemStack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import cjminecraft.core.client.gui.GuiCore;
import cjminecraft.core.util.RenderUtils;
import net.minecraft.tileentity.TileEntity;

/**
* A simple yet effective progress bar which displays an operations progress in
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package cjminecraft.core.client.gui.element;

import java.util.List;

import cjminecraft.core.CJCore;
import cjminecraft.core.client.gui.GuiCore;
import cjminecraft.core.util.RenderUtils;
import net.minecraft.util.ResourceLocation;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import com.google.common.collect.ImmutableList;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package cjminecraft.core.client.particle;

import java.util.Random;

import org.lwjgl.opengl.GL11;

import cjminecraft.core.client.GameResources;
import cjminecraft.core.client.render.OpenGL;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;

public class EntityFXElectricArc extends Particle {
private static final ResourceLocation PARTICLES = new ResourceLocation("textures/particle/particles.png");

private Random rand;
private int color;
private int tessellation;
private float rotYaw;
private float rotPitch;
private float density;
private double targetX;
private double targetY;
private double targetZ;
private double displacement;
private double complexity;

public EntityFXElectricArc(World world, double x, double y, double z, double targetX, double targetY, double targetZ, int age) {
this(world, x, y, z, targetX, targetY, targetZ, age, 1.6D, 0.1D, 0.1F, 0xFFAA99FF);
}

public EntityFXElectricArc(World world, double x, double y, double z, double targetX, double targetY, double targetZ, int age, int color) {
this(world, x, y, z, targetX, targetY, targetZ, age, 1.6D, 0.1D, 0.1F, color);
}

public EntityFXElectricArc(World world, double x, double y, double z, double targetX, double targetY, double targetZ, int age, double displacement, double complexity, float density, int color) {
super(world, x, y, z);
this.rand = new Random();
this.tessellation = 2;
this.particleMaxAge = age;
this.targetX = targetX;
this.targetY = targetY;
this.targetZ = targetZ;
this.displacement = displacement;
this.complexity = complexity;
this.density = density;
this.color = color;
this.changeDirection((float) (this.posX - this.targetX), (float) (this.posY - this.targetY), (float) (this.posZ - this.targetZ));
}

@Override
public void renderParticle(BufferBuilder buffer, Entity entity, float partialTicks, float rX, float rZ, float rYZ, float rXY, float rXZ) {
GameResources.BLANK.bind();
this.drawArc(buffer, posX, posY, posZ, targetX, targetY, targetZ, displacement, complexity, density);
}

public EntityFXElectricArc setTessellation(int tessellation) {
this.tessellation = tessellation;
return this;
}

private void changeDirection(float x, float y, float z) {
double variance = MathHelper.sqrt(x * x + z * z);
this.rotYaw = ((float) (Math.atan2(x, z) * 180.0D / Math.PI));
this.rotPitch = ((float) (Math.atan2(y, variance) * 180.0D / Math.PI));
}

private void drawArc(BufferBuilder buffer, double x, double y, double z, double targetX, double targetY, double targetZ, double displacement, double complexity, float density) {
if (displacement < complexity) {
float rx = (float) (x - targetX);
float ry = (float) (y - targetY);
float rz = (float) (z - targetZ);

this.changeDirection(rx, ry, rz);

OpenGL.pushMatrix();
OpenGL.translate((float) (x - interpPosX), (float) (y - interpPosY), (float) (z - interpPosZ));
OpenGL.enableBlend();
OpenGL.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_CURRENT_BIT);
OpenGL.disableCullFace();
OpenGL.rotate(90.0F, 1.0F, 0.0F, 0.0F);
OpenGL.rotate(180.0F + this.rotYaw, 0.0F, 0.0F, -1.0F);
OpenGL.rotate(this.rotPitch, 1.0F, 0.0F, 0.0F);
OpenGL.disableLightMapping();
OpenGL.disableLight();

double vX1 = density * -0.15;
double vX2 = density * -0.15 * 1.0;
double vY2 = MathHelper.sqrt(rx * rx + ry * ry + rz * rz);
double vY1 = 0.0D;

int a = (color >> 24 & 255);
int r = (color >> 16 & 255);
int g = (color >> 8 & 255);
int b = (color & 255);

for (int i2 = 0; i2 < tessellation; i2++) {
GlStateManager.rotate((360F / tessellation) / 2, 0.0F, 1.0F, 0.0F);
OpenGL.color(r / 255F, g / 255F, b / 255F, a / 255F);
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
buffer.pos(vX2, vY2, 0).color(255, 255, 255, 255).endVertex();
buffer.pos(vX1, vY1, 0).color(255, 255, 255, 255).endVertex();
buffer.pos(-vX1, vY1, 0).color(255, 255, 255, 255).endVertex();
buffer.pos(-vX2, vY2, 0).color(255, 255, 255, 255).endVertex();
Tessellator.getInstance().draw();
}

OpenGL.enableLight();
OpenGL.color(1.0F, 1.0F, 1.0F, 1.0F);
OpenGL.enableCullFace();
OpenGL.disableBlend();
OpenGL.popMatrix();
} else {
double splitX = (targetX + x) / 2;
double splitY = (targetY + y) / 2;
double splitZ = (targetZ + z) / 2;
splitX += (rand.nextFloat() - 0.5) * displacement;
splitY += (rand.nextFloat() - 0.5) * displacement;
splitZ += (rand.nextFloat() - 0.5) * displacement;
drawArc(buffer, x, y, z, splitX, splitY, splitZ, displacement / 2, complexity, density);
drawArc(buffer, targetX, targetY, targetZ, splitX, splitY, splitZ, displacement / 2, complexity, density);
}
}

@Override
public void onUpdate() {
if (this.particleAge++ > this.particleMaxAge) {
this.setExpired();
}
}

@Override
public int getFXLayer() {
return 3;
}
}
73 changes: 73 additions & 0 deletions src/main/java/cjminecraft/core/client/render/Color.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package cjminecraft.core.client.render;

import java.nio.ByteBuffer;

public class Color {
public float r, g, b, a;

public Color(float r, float g, float b, float a) {
this.r = r;
this.g = g;
this.b = b;
this.a = a;
}

public Color(Color c) {
this(c.r, c.g, c.b, c.a);
}

/**
* Converts 4 RGBA values into a single hexadecimal color value.
*
* @param alpha
* - Alpha value ranged from 0-255
* @param red
* - Red value ranged from 0-255
* @param green
* - Green value ranged from 0-255
* @param blue
* - Blue value ranged from 0-255
* @return Hexadecimal created from the provided RGBA values.
*/
public static int createHexadecimal(int alpha, int red, int green, int blue) {
org.lwjgl.util.Color color = new org.lwjgl.util.Color(alpha, red, green, blue);
ByteBuffer dest = ByteBuffer.allocate(4);

color.writeRGBA(dest);
dest.rewind();

return dest.getInt();
}

public int toHexadecimal() {
org.lwjgl.util.Color color = new org.lwjgl.util.Color(toIntRange(a), toIntRange(r), toIntRange(g), toIntRange(b));
ByteBuffer dest = ByteBuffer.allocate(4);

color.writeRGBA(dest);
dest.rewind();

return dest.getInt();
}

/**
* Convert float color range to integer color range.
*
* @param f
* - Float color range (0.0F - 1.0F)
* @return Integer color range (1 - 255)
*/
public static int toIntRange(float f) {
return (int) ((f * 255) / 1F);
}

/**
* Convert integer color range to float color range.
*
* @param i
* - Integer color range (1 - 255)
* @return Float color range (0.0F - 1.0F)
*/
public static float toFloatRange(int i) {
return (i * 1.0F) / 255;
}
}
Loading