forked from chunky-dev/chunky
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the pitcher crop and calibrated sculk sensor. (chunky-dev#1608)
* Add the pitcher crop block. * Add calibrated sculk sensor. * Fix inconsistencies in the pitcher crop top model. * Fix inactive amethyst emitting light by default.
- Loading branch information
Showing
12 changed files
with
945 additions
and
11 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
chunky/src/java/se/llbit/chunky/block/CalibratedSculkSensor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package se.llbit.chunky.block; | ||
|
||
import se.llbit.chunky.entity.CalibratedSculkSensorAmethyst; | ||
import se.llbit.chunky.entity.Entity; | ||
import se.llbit.chunky.model.CalibratedSculkSensorModel; | ||
import se.llbit.chunky.resources.Texture; | ||
import se.llbit.math.Vector3; | ||
|
||
public class CalibratedSculkSensor extends AbstractModelBlock { | ||
private final String phase; | ||
private final String facing; | ||
|
||
public CalibratedSculkSensor(String phase, String facing) { | ||
super("calibrated_sculk_sensor", Texture.calibratedSculkSensorTop); | ||
this.phase = phase; | ||
this.facing = facing; | ||
this.model = new CalibratedSculkSensorModel(isActive(), facing); | ||
} | ||
|
||
public boolean isActive() { | ||
return phase.equals("active") || phase.equals("cooldown"); | ||
} | ||
|
||
@Override | ||
public String description() { | ||
return "sculk_sensor_phase=" + phase + ", facing=" + facing; | ||
} | ||
|
||
@Override | ||
public boolean isEntity() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isBlockWithEntity() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Entity toEntity(Vector3 position) { | ||
return new CalibratedSculkSensorAmethyst(position, this.facing, isActive(), this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package se.llbit.chunky.block; | ||
|
||
import se.llbit.chunky.model.PitcherCropBottomModel; | ||
import se.llbit.chunky.model.PitcherCropTopModel; | ||
import se.llbit.chunky.resources.Texture; | ||
|
||
public class PitcherCrop extends AbstractModelBlock { | ||
private final String description; | ||
|
||
public PitcherCrop(int age, String half) { | ||
super("pitcher_crop", Texture.pitcherCropTop); | ||
localIntersect = true; | ||
opaque = false; | ||
this.model = half.equals("upper") | ||
? new PitcherCropTopModel(age) | ||
: new PitcherCropBottomModel(age); | ||
this.description = String.format("age=%d, half=%s", age, half); | ||
} | ||
|
||
@Override | ||
public String description() { | ||
return description; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
chunky/src/java/se/llbit/chunky/entity/CalibratedSculkSensorAmethyst.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package se.llbit.chunky.entity; | ||
|
||
import se.llbit.chunky.block.CalibratedSculkSensor; | ||
import se.llbit.chunky.model.Model; | ||
import se.llbit.chunky.resources.Texture; | ||
import se.llbit.chunky.world.Material; | ||
import se.llbit.chunky.world.material.TextureMaterial; | ||
import se.llbit.json.JsonObject; | ||
import se.llbit.json.JsonValue; | ||
import se.llbit.log.Log; | ||
import se.llbit.math.*; | ||
import se.llbit.math.primitive.Primitive; | ||
import se.llbit.util.JsonUtil; | ||
|
||
import java.util.Collection; | ||
import java.util.LinkedList; | ||
|
||
public class CalibratedSculkSensorAmethyst extends Entity { | ||
private static final Quad[] quadsNorth = Model.join( | ||
Model.rotateY( | ||
new Quad[]{ | ||
new Quad( | ||
new Vector3(8 / 16.0, 20 / 16.0, 16 / 16.0), | ||
new Vector3(8 / 16.0, 20 / 16.0, 0 / 16.0), | ||
new Vector3(8 / 16.0, 8 / 16.0, 16 / 16.0), | ||
new Vector4(16 / 16.0, 0 / 16.0, 12 / 16.0, 0 / 16.0) | ||
), | ||
new Quad( | ||
new Vector3(8 / 16.0, 20 / 16.0, 0 / 16.0), | ||
new Vector3(8 / 16.0, 20 / 16.0, 16 / 16.0), | ||
new Vector3(8 / 16.0, 8 / 16.0, 0 / 16.0), | ||
new Vector4(16 / 16.0, 0 / 16.0, 12 / 16.0, 0 / 16.0) | ||
) | ||
}, | ||
Math.toRadians(45) | ||
), | ||
Model.rotateY( | ||
new Quad[]{ | ||
new Quad( | ||
new Vector3(0 / 16.0, 20 / 16.0, 8 / 16.0), | ||
new Vector3(16 / 16.0, 20 / 16.0, 8 / 16.0), | ||
new Vector3(0 / 16.0, 8 / 16.0, 8 / 16.0), | ||
new Vector4(16 / 16.0, 0 / 16.0, 12 / 16.0, 0 / 16.0) | ||
), | ||
new Quad( | ||
new Vector3(16 / 16.0, 20 / 16.0, 8 / 16.0), | ||
new Vector3(0 / 16.0, 20 / 16.0, 8 / 16.0), | ||
new Vector3(16 / 16.0, 8 / 16.0, 8 / 16.0), | ||
new Vector4(16 / 16.0, 0 / 16.0, 12 / 16.0, 0 / 16.0) | ||
) | ||
}, | ||
Math.toRadians(45) | ||
) | ||
); | ||
private static final Quad[] quadsEast = Model.rotateY(quadsNorth); | ||
private static final Quad[] quadsSouth = Model.rotateY(quadsEast); | ||
private static final Quad[] quadsWest = Model.rotateNegY(quadsNorth); | ||
|
||
private final String facing; | ||
private final boolean active; | ||
private final CalibratedSculkSensor block; | ||
|
||
public static final Material activeMaterial = new TextureMaterial(Texture.calibratedSculkSensorAmethyst); | ||
public static final Material inactiveMaterial = new TextureMaterial(Texture.calibratedSculkSensorAmethyst); | ||
|
||
public CalibratedSculkSensorAmethyst(Vector3 position, String facing, boolean active, CalibratedSculkSensor block) { | ||
super(position); | ||
this.facing = facing; | ||
this.active = active; | ||
this.block = block; | ||
} | ||
|
||
public CalibratedSculkSensorAmethyst(JsonObject json) { | ||
super(JsonUtil.vec3FromJsonObject(json.get("position"))); | ||
this.facing = json.get("facing").stringValue("north"); | ||
this.active = json.get("active").boolValue(true); | ||
this.block = null; | ||
} | ||
|
||
@Override | ||
public Collection<Primitive> primitives(Vector3 offset) { | ||
Collection<Primitive> faces = new LinkedList<>(); | ||
Transform transform = Transform.NONE | ||
.translate(position.x + offset.x, position.y + offset.y, position.z + offset.z); | ||
|
||
Quad[] quads; | ||
if (facing.equals("east")) { | ||
quads = quadsEast; | ||
} else if (facing.equals("south")) { | ||
quads = quadsSouth; | ||
} else if (facing.equals("west")) { | ||
quads = quadsWest; | ||
} else { | ||
quads = quadsNorth; | ||
} | ||
|
||
Material material = active ? activeMaterial : inactiveMaterial; | ||
for (Quad quad : quads) { | ||
quad.addTriangles(faces, material, transform); | ||
} | ||
|
||
return faces; | ||
} | ||
|
||
@Override | ||
public JsonValue toJson() { | ||
JsonObject json = new JsonObject(); | ||
json.add("kind", "calibratedSculkSensorAmethyst"); | ||
json.add("position", position.toJson()); | ||
json.add("facing", facing); | ||
json.add("active", active); | ||
return json; | ||
} | ||
|
||
public static Entity fromJson(JsonObject json) { | ||
return new CalibratedSculkSensorAmethyst(json); | ||
} | ||
|
||
@Override | ||
public Grid.EmitterPosition[] getEmitterPosition() { | ||
if (block == null) { | ||
Log.warn("Attempted to build emitter grid from unassociated campfire entity."); | ||
return new Grid.EmitterPosition[0]; | ||
} | ||
|
||
if (active) { | ||
Grid.EmitterPosition[] pos = new Grid.EmitterPosition[1]; | ||
pos[0] = new Grid.EmitterPosition((int) position.x, (int) position.y, (int) position.z, block); | ||
return pos; | ||
} else { | ||
return new Grid.EmitterPosition[0]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.