Skip to content
5 changes: 5 additions & 0 deletions src/main/java/com/cleanroommc/modularui/factory/GuiData.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

import java.util.Objects;

Expand All @@ -27,6 +28,10 @@ public EntityPlayer getPlayer() {
return this.player;
}

public World getWorld() {
return this.player.getEntityWorld();
}

public boolean isClient() {
return NetworkUtils.isClient(this.player);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

/**
* See {@link GuiData} for an explanation for what this is for.
Expand All @@ -22,10 +21,6 @@ public PosGuiData(EntityPlayer player, int x, int y, int z) {
this.z = z;
}

public World getWorld() {
return getPlayer().world;
}

public int getX() {
return this.x;
}
Expand Down
27 changes: 25 additions & 2 deletions src/main/java/com/cleanroommc/modularui/test/TestTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import com.cleanroommc.modularui.api.IGuiHolder;
import com.cleanroommc.modularui.api.IPanelHandler;
import com.cleanroommc.modularui.api.drawable.IKey;
import com.cleanroommc.modularui.api.widget.IWidget;
import com.cleanroommc.modularui.drawable.Circle;
import com.cleanroommc.modularui.drawable.GuiTextures;
import com.cleanroommc.modularui.drawable.ItemDrawable;
import com.cleanroommc.modularui.drawable.Rectangle;
import com.cleanroommc.modularui.drawable.text.AnimatedText;
import com.cleanroommc.modularui.factory.GuiData;
import com.cleanroommc.modularui.factory.PosGuiData;
import com.cleanroommc.modularui.network.NetworkUtils;
import com.cleanroommc.modularui.screen.ModularPanel;
Expand All @@ -18,6 +20,9 @@
import com.cleanroommc.modularui.utils.Alignment;
import com.cleanroommc.modularui.utils.Color;
import com.cleanroommc.modularui.utils.Interpolation;
import com.cleanroommc.modularui.utils.fakeworld.ArraySchema;
import com.cleanroommc.modularui.utils.fakeworld.BlockHighlight;
import com.cleanroommc.modularui.utils.fakeworld.SchemaRenderer;
import com.cleanroommc.modularui.value.BoolValue;
import com.cleanroommc.modularui.value.IntValue;
import com.cleanroommc.modularui.value.StringValue;
Expand All @@ -40,6 +45,7 @@
import com.cleanroommc.modularui.widgets.PageButton;
import com.cleanroommc.modularui.widgets.PagedWidget;
import com.cleanroommc.modularui.widgets.ProgressWidget;
import com.cleanroommc.modularui.widgets.SchemaWidget;
import com.cleanroommc.modularui.widgets.ScrollingTextWidget;
import com.cleanroommc.modularui.widgets.SliderWidget;
import com.cleanroommc.modularui.widgets.SlotGroupWidget;
Expand Down Expand Up @@ -174,7 +180,10 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager syncManager, UI
.tab(GuiTextures.TAB_TOP, 0))
.child(new PageButton(3, tabController)
.tab(GuiTextures.TAB_TOP, 0)
.overlay(new ItemDrawable(Blocks.CHEST).asIcon())))
.overlay(new ItemDrawable(Blocks.CHEST).asIcon()))
.child(new PageButton(4, tabController)
.tab(GuiTextures.TAB_TOP, 0)
.overlay(new ItemDrawable(Items.ENDER_EYE).asIcon())))
.child(new Expandable()
.debugName("expandable")
.top(0)
Expand Down Expand Up @@ -438,7 +447,8 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager syncManager, UI
.child(new DynamicSyncedWidget<>()
.widthRel(1f)
.syncHandler(dynamicSyncHandler)))
)))
)
.addPage(createSchemaPage(guiData))))
.child(SlotGroupWidget.playerInventory(false))
);
/*panel.child(new ButtonWidget<>()
Expand All @@ -454,6 +464,19 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager syncManager, UI
return panel;
}

private IWidget createSchemaPage(GuiData data) {
ParentWidget<?> page = new ParentWidget<>();
page.debugName("page 5 schema");
page.sizeRel(1f);
page.child(IKey.str("schema").asWidget());
if (world.isRemote)
page.child(new SchemaWidget(new SchemaRenderer(ArraySchema.of(data.getPlayer(), 5))
.highlightRenderer(new BlockHighlight(Color.withAlpha(Color.GREEN.brighter(1), 0.9f), 1/32f)))
.pos(20, 20)
.size(100, 100));
return page;
}

public ModularPanel openSecondWindow(PanelSyncManager syncManager, IPanelHandler syncHandler) {
ModularPanel panel = new Dialog<>("second_window", null)
.setDisablePanelsBelow(false)
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/cleanroommc/modularui/utils/MathUtils.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package com.cleanroommc.modularui.utils;

import net.minecraft.util.math.MathHelper;

import org.mariuszgromada.math.mxparser.Constant;
import org.mariuszgromada.math.mxparser.Expression;

public class MathUtils {

public static final float PI = (float) Math.PI;
public static final float PI2 = 2f * PI;
public static final float PI_HALF = PI / 2f;
public static final float PI_QUART = PI / 4f;

// SI prefixes
public static final Constant k = new Constant("k", 1e3);
public static final Constant M = new Constant("M", 1e6);
Expand Down Expand Up @@ -154,4 +161,16 @@ public static int wrapDegrees(int angle) {
if (angle < -180) angle += 360;
return angle;
}

public static float sin(float v) {
return MathHelper.sin(v);
}

public static float cos(float v) {
return MathHelper.cos(v);
}

public static float tan(float v) {
return MathHelper.sin(v) / MathHelper.cos(v);
}
}
138 changes: 108 additions & 30 deletions src/main/java/com/cleanroommc/modularui/utils/Vector3f.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
package com.cleanroommc.modularui.utils;

import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;

import java.nio.FloatBuffer;
import java.util.Objects;

public class Vector3f {

public static final Vector3f UNIT_X = new Vector3f(1.0f, 0.0f, 0.0f);
public static final Vector3f UNIT_Y = new Vector3f(0.0f, 1.0f, 0.0f);
public static final Vector3f UNIT_Z = new Vector3f(0.0f, 0.0f, 1.0f);

public static void resetUnitVectors() {
UNIT_X.set(1.0f, 0.0f, 0.0f);
UNIT_Y.set(0.0f, 1.0f, 0.0f);
UNIT_Z.set(0.0f, 0.0f, 1.0f);
}

public float x, y, z;

/**
Expand All @@ -20,6 +34,10 @@ public Vector3f(Vector3f src) {
set(src);
}

public Vector3f(Vec3d src) {
set(src);
}

/**
* Constructor
*/
Expand All @@ -44,6 +62,12 @@ public void set(float x, float y, float z) {
this.z = z;
}

public void set(double x, double y, double z) {
this.x = (float) x;
this.y = (float) y;
this.z = (float) z;
}

/**
* Load from another Vec3f
*
Expand All @@ -57,6 +81,11 @@ public Vector3f set(Vector3f src) {
return this;
}

public Vector3f set(Vec3d src) {
set(src.x, src.y, src.z);
return this;
}

/**
* @return the length squared of the vector
*/
Expand All @@ -82,6 +111,10 @@ public Vector3f translate(float x, float y, float z) {
return this;
}

public Vector3f translate(double x, double y, double z) {
return translate((float) x, (float) y, (float) z);
}

/**
* Add a vector to another vector and place the result in a destination
* vector.
Expand All @@ -100,6 +133,20 @@ public static Vector3f add(Vector3f left, Vector3f right, Vector3f dest) {
}
}

public static Vector3f add(Vector3f a, Vector3f b, Vector3f c, Vector3f dest) {
if (dest == null) dest = new Vector3f();
dest.set(a.x + b.x + c.x, a.y + b.y + c.y, a.z + b.z + c.z);
return dest;
}

public Vector3f add(Vector3f v) {
return add(v, this, this);
}

public Vector3f add(Vector3f v, Vector3f dest) {
return add(this, v, dest);
}

/**
* Subtract a vector from another vector and place the result in a destination
* vector.
Expand Down Expand Up @@ -134,7 +181,6 @@ public static Vector3f cross(Vector3f left, Vector3f right, Vector3f dest) {
return dest;
}


/**
* Negate a vector
*
Expand All @@ -154,14 +200,16 @@ public Vector3f negate() {
* @return the negated vector
*/
public Vector3f negate(Vector3f dest) {
if (dest == null)
dest = new Vector3f();
if (dest == null) dest = new Vector3f();
dest.x = -x;
dest.y = -y;
dest.z = -z;
return dest;
}

public Vector3f normalise() {
return normalise(this);
}

/**
* Normalise this vector and place the result in another vector.
Expand All @@ -170,13 +218,11 @@ public Vector3f negate(Vector3f dest) {
* @return the normalised vector
*/
public Vector3f normalise(Vector3f dest) {
float l = length();

if (dest == null)
dest = new Vector3f(x / l, y / l, z / l);
else
dest.set(x / l, y / l, z / l);

if (dest == null) dest = new Vector3f();
float lsq = lengthSquared();
if (lsq == 1) return dest.set(this);
float f = (float) MathHelper.fastInvSqrt(lsq);
dest.set(x * f, y * f, z * f);
return dest;
}

Expand Down Expand Up @@ -222,42 +268,68 @@ public Vector3f load(FloatBuffer buf) {
* @see org.lwjgl.vector.Vec#scale(float)
*/
public Vector3f scale(float scale) {

x *= scale;
y *= scale;
z *= scale;

return this;

}

/* (non-Javadoc)
* @see org.lwjgl.vector.Vec#store(FloatBuffer)
*/
public Vector3f store(FloatBuffer buf) {

buf.put(x);
buf.put(y);
buf.put(z);
return this;
}

public float distanceTo(Vector3f vec) {
return MathHelper.sqrt(squareDistanceTo(vec));
}

public float squareDistanceTo(Vector3f v) {
return squareDistanceTo(v.x, v.y, v.z);
}

public float squareDistanceTo(float xIn, float yIn, float zIn) {
float d0 = xIn - this.x;
float d1 = yIn - this.y;
float d2 = zIn - this.z;
return d0 * d0 + d1 * d1 + d2 * d2;
}

public Vector3f rotatePitch(float pitch) {
float cos = MathHelper.cos(pitch);
float sin = MathHelper.sin(pitch);
float x = this.x;
float y = this.y * cos + this.z * sin;
float z = this.z * cos - this.y * sin;
set(x, y, z);
return this;
}

public Vector3f rotateYaw(float yaw) {
float sin = MathHelper.cos(yaw);
float cos = MathHelper.sin(yaw);
float x = this.x * sin + this.z * cos;
float y = this.y;
float z = this.z * sin - this.x * cos;
set(x, y, z);
return this;
}

public Vector3f copy() {
return new Vector3f(x, y, z);
}

public Vec3d toVec3d() {
return new Vec3d(x, y, z);
}

/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
StringBuilder sb = new StringBuilder(64);

sb.append("Vec3f[");
sb.append(x);
sb.append(", ");
sb.append(y);
sb.append(", ");
sb.append(z);
sb.append(']');
return sb.toString();
}

/**
* @return x
Expand Down Expand Up @@ -307,15 +379,21 @@ public float getZ() {
return z;
}

public String toString() {
return "Vec3f[" + x + ", " + y + ", " + z + ']';
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
Vector3f other = (Vector3f) obj;

if (x == other.x && y == other.y && z == other.z) return true;

return false;
return x == other.x && y == other.y && z == other.z;
}

@Override
public int hashCode() {
return Objects.hash(x, y, z);
}
}
Loading