-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
468faa4
commit 75a1e51
Showing
4 changed files
with
103 additions
and
98 deletions.
There are no files selected for viewing
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,8 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
max_line_length = off |
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
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 |
---|---|---|
@@ -1,63 +1,65 @@ | ||
package mcextract; | ||
|
||
import com.google.gson.JsonArray; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.phys.AABB; | ||
import net.minecraft.world.level.EmptyBlockGetter; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.phys.AABB; | ||
|
||
import java.util.*; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Objects; | ||
|
||
/** | ||
* The shape of a {@link BlockState}, composed of one or more axis-aligned {@link Box}es. | ||
* The shape of a {@link BlockState}, composed of one or more axis-aligned AABBs. | ||
*/ | ||
public class Shape { | ||
public static final Shape EMPTY = new Shape(Collections.emptyList()); | ||
public static final Shape EMPTY = new Shape(Collections.emptyList()); | ||
|
||
public final Collection<AABB> boxes; | ||
public final Collection<AABB> boxes; | ||
|
||
public Shape(Collection<AABB> boxes) { | ||
this.boxes = boxes; | ||
} | ||
public Shape(Collection<AABB> boxes) { | ||
this.boxes = boxes; | ||
} | ||
|
||
public Shape(BlockState blockState) { | ||
var collisionShape = blockState.getCollisionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO); | ||
public Shape(BlockState blockState) { | ||
var collisionShape = blockState.getCollisionShape(EmptyBlockGetter.INSTANCE, BlockPos.ZERO); | ||
var offset = blockState.getOffset(EmptyBlockGetter.INSTANCE, BlockPos.ZERO); | ||
var reversedOffset = offset.reverse(); | ||
var collisionShapeWithoutOffset = collisionShape.move(reversedOffset.x, reversedOffset.y, reversedOffset.z); | ||
|
||
this.boxes = collisionShapeWithoutOffset.toAabbs(); | ||
} | ||
|
||
public JsonArray toJson() { | ||
final JsonArray boxesJson = new JsonArray(); | ||
for (AABB box : boxes) { | ||
boxesJson.add(jsonArrayFromBox(box)); | ||
} | ||
return boxesJson; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Shape shape = (Shape) o; | ||
return Objects.equals(boxes, shape.boxes); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(boxes); | ||
} | ||
|
||
public static JsonArray jsonArrayFromBox(AABB box) { | ||
} | ||
|
||
public static JsonArray jsonArrayFromBox(AABB box) { | ||
final JsonArray boxJson = new JsonArray(); | ||
boxJson.add(box.minX); | ||
boxJson.add(box.minY); | ||
boxJson.add(box.minZ); | ||
boxJson.add(box.maxX); | ||
boxJson.add(box.maxY); | ||
boxJson.add(box.maxZ); | ||
return boxJson; | ||
} | ||
boxJson.add(box.minY); | ||
boxJson.add(box.minZ); | ||
boxJson.add(box.maxX); | ||
boxJson.add(box.maxY); | ||
boxJson.add(box.maxZ); | ||
return boxJson; | ||
} | ||
|
||
public JsonArray toJson() { | ||
final JsonArray boxesJson = new JsonArray(); | ||
for (AABB box : boxes) { | ||
boxesJson.add(jsonArrayFromBox(box)); | ||
} | ||
return boxesJson; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Shape shape = (Shape) o; | ||
return Objects.equals(boxes, shape.boxes); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(boxes); | ||
} | ||
} |