Skip to content
This repository was archived by the owner on Dec 23, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: "java"
apply plugin: "application"

version = "0.7.0"
version = "0.7.1"
mainClassName = "com.mrcrayfish.modelcreator.Start"
sourceCompatibility = targetCompatibility = 1.8

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/mrcrayfish/modelcreator/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class Constants
{
public static final String NAME = "MrCrayfish's Model Creator";
public static final String VERSION = "0.7.0";
public static final String VERSION = "0.7.1";

public static final String URL_DONATE = "https://www.patreon.com/mrcrayfish?ty=h";
public static final String URL_TWITTER = "https://www.twitter.com/MrCraayfish";
Expand Down
75 changes: 60 additions & 15 deletions src/main/java/com/mrcrayfish/modelcreator/ExporterJavaCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,18 @@ public void writeCodeToClipboard() throws IOException
@Override
protected void write(BufferedWriter writer) throws IOException
{
if(version == Version.V_1_13)
boolean V_1_13 = version == Version.V_1_13;
boolean V_1_14 = version == Version.V_1_14;
if(V_1_13 || V_1_14)
{
String state = V_1_13 ? "I" : "";
if(includeFields)
{
/* Generates member fields */
writeNewLine(writer, "/* Member variables */");
if(generateRotatedBounds)
{
writeNewLine(writer, "public final ImmutableMap<IBlockState, VoxelShape> SHAPES;");
writeNewLine(writer, "public final ImmutableMap<" + state + "BlockState, VoxelShape> SHAPES;");
}
else
{
Expand Down Expand Up @@ -83,7 +86,7 @@ protected void write(BufferedWriter writer) throws IOException
/* Creates method for generating voxel shapes for rotatable blocks */
if(generateRotatedBounds)
{
writeNewLine(writer, "private ImmutableMap<IBlockState, VoxelShape> generateShapes(ImmutableList<IBlockState> states)");
writeNewLine(writer, "private ImmutableMap<" + state + "BlockState, VoxelShape> generateShapes(ImmutableList<" + state + "BlockState> states)");
writeNewLine(writer, "{");
for(Element element : manager.getAllElements())
{
Expand All @@ -104,18 +107,32 @@ protected void write(BufferedWriter writer) throws IOException
}

writer.newLine();
writeNewLine(writer, " ImmutableMap.Builder<IBlockState, VoxelShape> builder = new ImmutableMap.Builder<>();");
writeNewLine(writer, " for(IBlockState state : states)");
writeNewLine(writer, " ImmutableMap.Builder<" + state + "BlockState, VoxelShape> builder = new ImmutableMap.Builder<>();");
writeNewLine(writer, " for(" + state + "BlockState state : states)");
writeNewLine(writer, " {");
writeNewLine(writer, " EnumFacing facing = state.getValue(HORIZONTAL_FACING);");
if(V_1_13)
{
writeNewLine(writer, " EnumFacing facing = state.getValue(HORIZONTAL_FACING);");
}
else
{
writeNewLine(writer, " Direction direction = state.get(DIRECTION);");
}
writeNewLine(writer, " List<VoxelShape> shapes = new ArrayList<>();");

for(Element element : manager.getAllElements())
{
if(element.getRotation() == 0)
{
String name = element.getName().toUpperCase().replaceAll(" ", "_");
writeNewLine(writer, String.format(" shapes.add(%s[facing.getHorizontalIndex()]);", name));
if(V_1_13)
{
writeNewLine(writer, String.format(" shapes.add(%s[facing.getHorizontalIndex()]);", name));
}
else
{
writeNewLine(writer, String.format(" shapes.add(%s[direction.getHorizontalIndex()]);", name));
}
}
}

Expand Down Expand Up @@ -155,10 +172,10 @@ protected void write(BufferedWriter writer) throws IOException
else
{
writer.newLine();
writeNewLine(writer, " VoxelShape result = ShapeUtils.empty();");
writeNewLine(writer, " VoxelShape result = VoxelShapes.empty();");
writeNewLine(writer, " for(VoxelShape shape : shapes)");
writeNewLine(writer, " {");
writeNewLine(writer, " result = ShapeUtils.combine(result, shape, IBooleanFunction.OR);");
writeNewLine(writer, " result = VoxelShapes.combine(result, shape, IBooleanFunction.OR);");
writeNewLine(writer, " }");
writeNewLine(writer, " return result.simplify();");
}
Expand All @@ -168,7 +185,14 @@ protected void write(BufferedWriter writer) throws IOException

/* Produces the method for selection box */
writeNewLine(writer, "@Override");
writeNewLine(writer, "public VoxelShape getShape(IBlockState state, IBlockReader reader, BlockPos pos)");
if(V_1_13)
{
writeNewLine(writer, "public VoxelShape getShape(" + state + "BlockState state, IBlockReader reader, BlockPos pos)");
}
else
{
writeNewLine(writer, "public VoxelShape getShape(" + state + "BlockState state, IBlockReader reader, BlockPos pos, ISelectionContext context)");
}
writeNewLine(writer, "{");
if(generateRotatedBounds)
{
Expand All @@ -183,7 +207,14 @@ protected void write(BufferedWriter writer) throws IOException

/* Produces the method for collisions */
writeNewLine(writer, "@Override");
writeNewLine(writer, "public VoxelShape getCollisionShape(IBlockState state, IBlockReader reader, BlockPos pos)");
if(V_1_13)
{
writeNewLine(writer, "public VoxelShape getCollisionShape(" + state + "BlockState state, IBlockReader reader, BlockPos pos)");
}
else
{
writeNewLine(writer, "public VoxelShape getCollisionShape(" + state + "BlockState state, IBlockReader reader, BlockPos pos, ISelectionContext context)");
}
writeNewLine(writer, "{");
if(generateRotatedBounds)
{
Expand Down Expand Up @@ -332,16 +363,30 @@ else if(generateRotatedBounds)

private String format(double value)
{
return FORMAT.format(useBoundsHelper ? value : value * 0.0625);
if(version == Version.V_1_12 || version == Version.V_1_13)
{
return FORMAT.format(useBoundsHelper ? value : value * 0.0625);
}
else
{
return FORMAT.format(useBoundsHelper ? value : value);
}
}

private void writeField(BufferedWriter writer, ModelBounds bounds, String name, double minX, double minY, double minZ, double maxX, double maxY, double maxZ) throws IOException
{
if(version == Version.V_1_13)
if(version == Version.V_1_13 || version == Version.V_1_14)
{
if(generateRotatedBounds)
{
writer.write(String.format("final VoxelShape[] %s = VoxelShapeHelper.getRotatedVoxelShapes(Block.makeCuboidShape(%s, %s, %s, %s, %s, %s));", name, format(minX), format(minY), format(minZ), format(maxX), format(maxY), format(maxZ)));
if(version == Version.V_1_13)
{
writer.write(String.format("final VoxelShape[] %s = VoxelShapeHelper.getRotatedShapes(Block.makeCuboidShape(%s, %s, %s, %s, %s, %s));", name, format(minX), format(minY), format(minZ), format(maxX), format(maxY), format(maxZ)));
}
else
{
writer.write(String.format("final VoxelShape[] %s = VoxelShapeHelper.getRotatedShapes(VoxelShapeHelper.rotate(Block.makeCuboidShape(%s, %s, %s, %s, %s, %s), Direction.SOUTH));", name, format(minX), format(minY), format(minZ), format(maxX), format(maxY), format(maxZ)));
}
}
else
{
Expand Down Expand Up @@ -407,7 +452,7 @@ private void union(double minX, double minY, double minZ, double maxX, double ma

public enum Version
{
V_1_12("1.12"), V_1_13("1.13");
V_1_12("1.12"), V_1_13("1.13"), V_1_14("1.14");

private String label;

Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/mrcrayfish/modelcreator/Importer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.ResourceBundle;

public class Importer
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.mrcrayfish.modelcreator.sidebar.Sidebar;
import com.mrcrayfish.modelcreator.sidebar.UVSidebar;
import com.mrcrayfish.modelcreator.texture.TextureAtlas;
import com.mrcrayfish.modelcreator.texture.TextureEntry;
import com.mrcrayfish.modelcreator.util.FontManager;
import com.mrcrayfish.modelcreator.util.KeyboardUtil;
import org.lwjgl.LWJGLException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.mrcrayfish.modelcreator.ModelCreator;
import com.mrcrayfish.modelcreator.display.CanvasRenderer;
import com.mrcrayfish.modelcreator.display.DisplayProperties;
import com.mrcrayfish.modelcreator.element.ElementManager;
import com.mrcrayfish.modelcreator.panels.DisplayEntryPanel;
import com.mrcrayfish.modelcreator.util.ComponentUtil;

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/mrcrayfish/modelcreator/component/Menu.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.mrcrayfish.modelcreator.component;

import com.mrcrayfish.modelcreator.*;
import com.mrcrayfish.modelcreator.display.CanvasRenderer;
import com.mrcrayfish.modelcreator.display.DisplayProperties;
import com.mrcrayfish.modelcreator.element.Face;
import com.mrcrayfish.modelcreator.panels.DisplayEntryPanel;
import com.mrcrayfish.modelcreator.screenshot.PendingScreenshot;
import com.mrcrayfish.modelcreator.screenshot.Screenshot;
import com.mrcrayfish.modelcreator.screenshot.Uploader;
Expand All @@ -21,7 +19,6 @@
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
import java.util.Set;

public class Menu extends JMenuBar
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.mrcrayfish.modelcreator.util.AtlasRenderUtil;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;
import org.newdawn.slick.opengl.TextureImpl;

import static org.lwjgl.opengl.GL11.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import com.mrcrayfish.modelcreator.display.CanvasRenderer;
import com.mrcrayfish.modelcreator.element.Element;
import com.mrcrayfish.modelcreator.element.ElementManager;
import com.mrcrayfish.modelcreator.element.Face;
import com.mrcrayfish.modelcreator.util.FontManager;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.Color;
import org.newdawn.slick.opengl.TextureImpl;

Expand Down
38 changes: 37 additions & 1 deletion src/main/java/com/mrcrayfish/modelcreator/element/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.mrcrayfish.modelcreator.object.FaceDimension;
import com.mrcrayfish.modelcreator.sidebar.UVSidebar;
import com.mrcrayfish.modelcreator.texture.TextureEntry;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.Sphere;

Expand All @@ -28,6 +27,7 @@ public class Element
private double rotation;
private int axis = 0;
private boolean rescale = false;
private boolean snapOrigin = false;

// Extra Variables
private boolean shade = true;
Expand Down Expand Up @@ -59,6 +59,7 @@ public Element(Element cuboid)
this.rotation = cuboid.getRotation();
this.axis = cuboid.getRotationAxis();
this.rescale = cuboid.shouldRescale();
this.snapOrigin = cuboid.shouldSnapOrigin();
this.shade = cuboid.isShaded();
this.selectedFace = cuboid.getSelectedFaceIndex();
initFaces();
Expand Down Expand Up @@ -134,6 +135,14 @@ public void setAllTextures(TextureEntry entry)
face.setTexture(entry);
}
}

public void setAllAutoUV(boolean uv)
{
for(Face face : faces)
{
face.setAutoUVEnabled(uv);
}
}

public void draw()
{
Expand Down Expand Up @@ -559,11 +568,21 @@ public void setRescale(boolean rescale)
{
this.rescale = rescale;
}

public void setSnapOrigin(boolean snapOrigin)
{
this.snapOrigin = snapOrigin;
}

public boolean shouldRescale()
{
return rescale;
}

public boolean shouldSnapOrigin()
{
return snapOrigin;
}

public boolean isShaded()
{
Expand Down Expand Up @@ -606,6 +625,23 @@ public void updateEndUVs()
face.updateEndUV();
}
}

public void updateOrigin()
{
if(snapOrigin)
{
originX = startX;
originY = startY;
originZ = startZ;
}
}

public void setOrigin()
{
originX = startX;
originY = startY;
originZ = startZ;
}

private void rotateAxis()
{
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/mrcrayfish/modelcreator/element/Face.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import java.nio.FloatBuffer;

import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL11.GL_BLEND;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;

public class Face
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mrcrayfish.modelcreator.panels;

import com.mrcrayfish.modelcreator.Icons;
import com.mrcrayfish.modelcreator.ModelCreator;
import com.mrcrayfish.modelcreator.StateManager;
import com.mrcrayfish.modelcreator.element.Element;
Expand All @@ -14,6 +15,7 @@ public class ElementExtraPanel extends JPanel implements IElementUpdater
private ElementManager manager;

private JRadioButton btnShade;
private JButton btnSetOrigin;

public ElementExtraPanel(ElementManager manager)
{
Expand All @@ -23,11 +25,14 @@ public ElementExtraPanel(ElementManager manager)
this.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(ModelCreator.BACKGROUND, 5), "<html><b>Extras</b></html>"));
this.setMaximumSize(new Dimension(186, 50));
this.initComponents();
this.initProperties();
this.addComponents();
}

private void initComponents()
{
btnSetOrigin = new JButton("Origin", Icons.clipboard);

btnShade = ComponentUtil.createRadioButton("Shade", "<html>Determines if shadows should be rendered<br>Default: On</html>");
btnShade.setBackground(ModelCreator.BACKGROUND);
btnShade.addActionListener(e ->
Expand All @@ -40,10 +45,28 @@ private void initComponents()
}
});
}

private void initProperties()
{
btnSetOrigin.setToolTipText("Set the origin to the position");
btnSetOrigin.addActionListener(e ->
{
Element selectedElement = manager.getSelectedElement();
if(selectedElement != null)
{
selectedElement.setOriginX(selectedElement.getStartX());
selectedElement.setOriginY(selectedElement.getStartY());
selectedElement.setOriginZ(selectedElement.getStartZ());
selectedElement.setOrigin();
manager.updateValues();
}
});
}

private void addComponents()
{
add(btnShade);
add(btnSetOrigin);
}

@Override
Expand Down
Loading