mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 09:26:11 -04:00
add support for ConditionalModels
This commit is contained in:
parent
4c52ebab97
commit
4089ff42d8
12
pom.xml
12
pom.xml
@ -25,15 +25,9 @@
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>
|
||||
14
|
||||
</source>
|
||||
<target>
|
||||
14
|
||||
</target>
|
||||
<compilerArgs>
|
||||
--enable-preview
|
||||
</compilerArgs>
|
||||
<source>15</source>
|
||||
<target>15</target>
|
||||
<compilerArgs>--enable-preview</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
@ -53,7 +53,7 @@ public class BlockModel implements BlockModelInterface {
|
||||
for (Axis axis : Axis.values()) {
|
||||
String lowercase = axis.name().toLowerCase();
|
||||
if (state.has(lowercase)) {
|
||||
BlockModelInterface.rotateModel(model, axis, state.get(lowercase).getAsInt());
|
||||
BlockModelInterface.rotateModel(model, axis, state.get(lowercase).getAsDouble());
|
||||
}
|
||||
}
|
||||
stateMap.put(properties, model);
|
||||
|
@ -58,7 +58,7 @@ public interface BlockModelInterface {
|
||||
return load(json, allModels, new HashMap<>());
|
||||
}
|
||||
|
||||
static void rotateModel(HashSet<SubBlock> subBlocks, Axis axis, int rotation) {
|
||||
static void rotateModel(HashSet<SubBlock> subBlocks, Axis axis, double rotation) {
|
||||
for (SubBlock subBlock : subBlocks) {
|
||||
subBlock.rotate(axis, rotation);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import de.bixilon.minosoft.data.mappings.blocks.Block;
|
||||
import de.bixilon.minosoft.data.world.BlockPosition;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.Axis;
|
||||
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation;
|
||||
import de.bixilon.minosoft.render.blockModels.subBlocks.SubBlock;
|
||||
import org.apache.commons.collections.primitives.ArrayFloatList;
|
||||
@ -25,6 +26,7 @@ import org.apache.commons.collections.primitives.ArrayFloatList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ConditionalModel implements BlockModelInterface {
|
||||
HashMap<BlockCondition, HashSet<SubBlock>> conditionMap;
|
||||
@ -39,7 +41,13 @@ public class ConditionalModel implements BlockModelInterface {
|
||||
} else {
|
||||
condition = BlockCondition.trueCondition;
|
||||
}
|
||||
HashSet<SubBlock> model = blockModels.get(block.get("model").getAsString());
|
||||
HashSet<SubBlock> model = blockModels.get(block.get("model").getAsString()).stream().map(SubBlock::new).collect(Collectors.toCollection(HashSet::new));
|
||||
for (Axis axis : Axis.values()) {
|
||||
String lowercase = axis.name().toLowerCase();
|
||||
if (block.has(lowercase)) {
|
||||
BlockModelInterface.rotateModel(model, axis, block.get(lowercase).getAsDouble());
|
||||
}
|
||||
}
|
||||
conditionMap.put(condition, model);
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ public class Cuboid {
|
||||
};
|
||||
}
|
||||
|
||||
public void rotate(Axis axis, int rotation) {
|
||||
public void rotate(Axis axis, double rotation) {
|
||||
for (int i = 0; i < positions.length; i++) {
|
||||
positions[i] = positions[i].rotated(axis, rotation);
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ public class SubBlock {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void rotate(Axis axis, int rotation) {
|
||||
public void rotate(Axis axis, double rotation) {
|
||||
cuboid.rotate(axis, rotation);
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ public class SubBlockPosition {
|
||||
vector = new Vec3(position.vector);
|
||||
}
|
||||
|
||||
public SubBlockPosition rotated(Axis axis, int rotation) {
|
||||
public SubBlockPosition rotated(Axis axis, double rotation) {
|
||||
return new SubBlockRotation(middlePos, axis, rotation).apply(this);
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ public class SubBlockRotation {
|
||||
private final double sin;
|
||||
private final double cos;
|
||||
|
||||
public SubBlockRotation(SubBlockPosition origin, Axis axis, float angle) {
|
||||
public SubBlockRotation(SubBlockPosition origin, Axis axis, double angle) {
|
||||
this.origin = origin.getVector();
|
||||
this.axis = axis;
|
||||
double angleRad = Math.toRadians(angle);
|
||||
|
Loading…
x
Reference in New Issue
Block a user