Skip to content

Commit 3b148cf

Browse files
committed
better maths
1 parent d800022 commit 3b148cf

3 files changed

Lines changed: 18 additions & 21 deletions

File tree

src/main/java/me/dags/scraper/BlockScraper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/**
2222
* @author dags <dags@dags.me>
2323
*/
24-
@Mod(modid = BlockScraper.MOD_ID, version = "1.0")
24+
@Mod(modid = BlockScraper.MOD_ID, version = "1.0", dependencies = "required-after:Dynmap")
2525
public class BlockScraper {
2626

2727
public static final String MOD_ID = "blockscraper";

src/main/java/me/dags/scraper/asset/model/Element.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class Element {
1818
public final int x2, y2, z2;
1919
public final List<String> faces;
2020

21-
private Element(int x1, int y1, int z1, int x2, int y2, int z2, List<String> faces) {
21+
public Element(int x1, int y1, int z1, int x2, int y2, int z2, List<String> faces) {
2222
this.x1 = Math.min(x1, x2);
2323
this.y1 = Math.min(y1, y2);
2424
this.z1 = Math.min(z1, z2);
@@ -68,34 +68,31 @@ public boolean isValid() {
6868

6969
public Element rotateX(int degrees) {
7070
double rads = Math.toRadians(degrees);
71-
int yOff = degrees > 89 && degrees < 271 ? 16 : 0;
72-
int zOff = degrees > 179 && degrees < 361 ? 16 : 0;
73-
int z1 = (int) Math.round(this.z1 * Math.cos(rads) - this.y1 * Math.sin(rads)) + zOff;
74-
int y1 = (int) Math.round(this.y1 * Math.cos(rads) + this.z1 * Math.sin(rads)) + yOff;
75-
int z2 = (int) Math.round(this.z2 * Math.cos(rads) - this.y2 * Math.sin(rads)) + zOff;
76-
int y2 = (int) Math.round(this.y2 * Math.cos(rads) + this.z2 * Math.sin(rads)) + yOff;
71+
int cz = 8, cy = 8;
72+
int z1 = cz + (int) Math.round((this.z1 - cz) * Math.cos(rads) - (this.y1 - cy) * Math.sin(rads));
73+
int y1 = cy + (int) Math.round((this.y1 - cy) * Math.cos(rads) + (this.z1 - cz) * Math.sin(rads));
74+
int z2 = cz + (int) Math.round((this.z2 - cz) * Math.cos(rads) - (this.y2 - cy) * Math.sin(rads));
75+
int y2 = cy + (int) Math.round((this.y2 - cy) * Math.cos(rads) + (this.z2 - cz) * Math.sin(rads));
7776
return new Element(x1, y1, z1, x2, y2, z2, faces);
7877
}
7978

8079
public Element rotateY(int degrees) {
8180
double rads = Math.toRadians(degrees);
82-
int xOff = degrees > 89 && degrees < 270 ? 16 : 0;
83-
int zOff = degrees > 179 && degrees < 360 ? 16 : 0;
84-
int x1 = (int) Math.round(this.x1 * Math.cos(rads) - this.z1 * Math.sin(rads)) + xOff;
85-
int z1 = (int) Math.round(this.z1 * Math.cos(rads) + this.x1 * Math.sin(rads)) + zOff;
86-
int x2 = (int) Math.round(this.x2 * Math.cos(rads) - this.z2 * Math.sin(rads)) + xOff;
87-
int z2 = (int) Math.round(this.z2 * Math.cos(rads) + this.x2 * Math.sin(rads)) + zOff;
81+
int cx = 8, cz = 8;
82+
int x1 = cx + (int) Math.round((this.x1 - cx) * Math.cos(rads) - (this.z1 - cz) * Math.sin(rads));
83+
int z1 = cz + (int) Math.round((this.z1 - cz) * Math.cos(rads) + (this.x1 - cx) * Math.sin(rads));
84+
int x2 = cx + (int) Math.round((this.x2 - cx) * Math.cos(rads) - (this.z2 - cz) * Math.sin(rads));
85+
int z2 = cz + (int) Math.round((this.z2 - cz) * Math.cos(rads) + (this.x2 - cx) * Math.sin(rads));
8886
return new Element(x1, y1, z1, x2, y2, z2, faces);
8987
}
9088

9189
public Element rotateZ(int degrees) {
9290
double rads = Math.toRadians(degrees);
93-
int xOff = degrees > 89 && degrees < 271 ? 16 : 0;
94-
int yOff = degrees > 179 && degrees < 361 ? 16 : 0;
95-
int x1 = (int) Math.round(this.x1 * Math.cos(rads) - this.y1 * Math.sin(rads)) + xOff;
96-
int y1 = (int) Math.round(this.y1 * Math.cos(rads) + this.x1 * Math.sin(rads)) + yOff;
97-
int x2 = (int) Math.round(this.x2 * Math.cos(rads) - this.y2 * Math.sin(rads)) + xOff;
98-
int y2 = (int) Math.round(this.y2 * Math.cos(rads) + this.x2 * Math.sin(rads)) + yOff;
91+
int cx = 8, cy = 8;
92+
int x1 = cx + (int) Math.round((this.x1 - cx) * Math.cos(rads) - (this.z1 - cy) * Math.sin(rads));
93+
int y1 = cy + (int) Math.round((this.y1 - cy) * Math.cos(rads) + (this.x1 - cx) * Math.sin(rads));
94+
int x2 = cx + (int) Math.round((this.x2 - cx) * Math.cos(rads) - (this.z2 - cy) * Math.sin(rads));
95+
int y2 = cy + (int) Math.round((this.y2 - cy) * Math.cos(rads) + (this.x2 - cx) * Math.sin(rads));
9996
return new Element(x1, y1, z1, x2, y2, z2, faces);
10097
}
10198

src/main/java/me/dags/scraper/dynmap/ModelRegistrar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private void registerTextures(ModTextureDefinition definition, BlockTextureRecor
145145

146146
if (icon != null) {
147147
ResourcePath texture = new ResourcePath(icon, "textures/blocks", ".png");
148-
TextureFile textureFile = definition.registerTextureFile(texture.getResourceName(), texture.getFilePath());
148+
TextureFile textureFile = getTextureFile(definition, texture);
149149

150150
if (textureFile == null) {
151151
throw new UnsupportedOperationException("Missing Asset: " + texture.getFilePath());

0 commit comments

Comments
 (0)