Skip to content

Commit

Permalink
Update wiki data
Browse files Browse the repository at this point in the history
  • Loading branch information
Nickid2018 committed May 27, 2024
1 parent 4a507c4 commit fd45fcd
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public class BlockDataExtractor {
private static final ExceptData SUPPORT_TYPE_EXCEPT = new ExceptData();
private static final PropertyWikiData BLOCK_PROPERTY_VALUES = new PropertyWikiData();
private static final PairMapWikiData<String, String> BLOCK_PROPERTIES = new PairMapWikiData<>();
private static final StringSetWikiData OCCLUSION_SHAPE_VALUES = new StringSetWikiData();
private static final StringSetWikiData LIQUID_COMPUTATION_VALUES = new StringSetWikiData();
private static final OcclusionWikiData OCCLUSION_SHAPE_VALUES = new OcclusionWikiData();
private static final LiquidComputationWikiData LIQUID_COMPUTATION_VALUES = new LiquidComputationWikiData();

@SneakyThrows
@SuppressWarnings({"unchecked", "rawtypes"})
Expand Down Expand Up @@ -106,33 +106,8 @@ public static void extractBlockData(MinecraftServer serverObj) {

for (BlockState state : states) {
VoxelShape occlusionShape = block.getOcclusionShape(state, serverOverworld, BlockPos.ZERO);
Map<String, String> occlusionMap = new HashMap<>();
Map<String, List<double[]>> occlusionMap = new HashMap<>();
Set<String> faceSturdySet = new TreeSet<>();
for (Direction direction : Direction.values()) {
String directionName = direction.name().toLowerCase();
if (state.isFaceSturdy(serverOverworld, BlockPos.ZERO, direction, SupportType.FULL))
faceSturdySet.add(directionName);
VoxelShape faceShape = Shapes.getFaceShape(occlusionShape, direction);
if (faceShape.isEmpty())
continue;
String aabbString = faceShape.toAabbs().stream().map(aabb -> switch (direction) {
case DOWN:
case UP:
yield "[" + aabb.minX + "," + aabb.minZ + "," + aabb.maxX + "," + aabb.maxZ + "]";
case NORTH:
case SOUTH:
yield "[" + aabb.minX + "," + aabb.minY + "," + aabb.maxX + "," + aabb.maxY + "]";
case WEST:
case EAST:
yield "[" + aabb.minZ + "," + aabb.minY + "," + aabb.maxZ + "," + aabb.maxY + "]";
}).collect(Collectors.joining(","));
occlusionMap.put(directionName, "[" + aabbString + "]");
}
occlusionMap.put("can_occlude", String.valueOf(state.canOcclude()));
String occlusionData = occlusionMap
.entrySet().stream()
.map(e -> "\"" + e.getKey() + "\":" + e.getValue())
.collect(Collectors.joining(","));
String stateName = state.toString();
if (stateName.contains("[")) {
String[] propertiesArray = stateName
Expand All @@ -146,13 +121,30 @@ public static void extractBlockData(MinecraftServer serverObj) {
stateName = "[" + String.join(",", collected) + "]";
} else
stateName = "";
OCCLUSION_SHAPE_VALUES.putNew("{" + occlusionData + "}", blockID + stateName);

if (state.blocksMotion() || !faceSturdySet.isEmpty()) {
String liquidComputationData = "{\"blocks_motion\":" + state.blocksMotion() + ",\"face_sturdy\":["
+ String.join(",", faceSturdySet.stream().map(s -> "\"" + s + "\"").toList()) + "]}";
LIQUID_COMPUTATION_VALUES.putNew(liquidComputationData, blockID + stateName);
for (Direction direction : Direction.values()) {
String directionName = direction.name().toLowerCase();
if (state.isFaceSturdy(serverOverworld, BlockPos.ZERO, direction, SupportType.FULL))
faceSturdySet.add(directionName);
VoxelShape faceShape = Shapes.getFaceShape(occlusionShape, direction);
if (faceShape.isEmpty())
continue;
List<double[]> aabbArray = faceShape.toAabbs().stream().map(aabb -> switch (direction) {
case DOWN:
case UP:
yield new double[]{aabb.minX , aabb.minZ , aabb.maxX ,aabb.maxZ};
case NORTH:
case SOUTH:
yield new double[]{aabb.minX , aabb.minY , aabb.maxX , aabb.maxY };
case WEST:
case EAST:
yield new double[]{aabb.minZ , aabb.minY , aabb.maxZ , aabb.maxY };
}).toList();
occlusionMap.put(directionName, aabbArray);
}

OCCLUSION_SHAPE_VALUES.put(blockID + stateName, state.canOcclude(), occlusionMap);
LIQUID_COMPUTATION_VALUES.put(blockID + stateName, state.blocksMotion(), faceSturdySet);
}

makeStatePredicateData(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.nickid2018.genwiki.autovalue.wikidata;

import com.google.gson.JsonElement;

public abstract class JsonWikiData implements WikiData {

public abstract JsonElement asJsonData();

@Override
public String output(int indent) {
return asJsonData().toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.github.nickid2018.genwiki.autovalue.wikidata;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import java.util.Set;

public class LiquidComputationWikiData extends JsonWikiData {

private final JsonObject data = new JsonObject();

public void put(String key, boolean blocksMotion, Set<String> sturdyFaces) {
JsonObject obj = new JsonObject();
obj.addProperty("blocks_motion", blocksMotion);
JsonArray array = new JsonArray();
sturdyFaces.forEach(array::add);
obj.add("face_sturdy", array);
data.add(key, obj);
}

@Override
public JsonElement asJsonData() {
return data;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.github.nickid2018.genwiki.autovalue.wikidata;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.minecraft.world.phys.AABB;

import java.util.List;
import java.util.Map;

public class OcclusionWikiData extends JsonWikiData {

private final JsonObject data = new JsonObject();

public void put(String key, boolean canOcclude, Map<String, List<double[]>> faces) {
JsonObject obj = new JsonObject();
obj.addProperty("can_occlude", canOcclude);
for (Map.Entry<String, List<double[]>> entry : faces.entrySet()) {
JsonArray array = new JsonArray();
for (double[] doubles : entry.getValue()) {
JsonArray face = new JsonArray();
for (double d : doubles)
face.add(d);
array.add(face);
}
obj.add(entry.getKey(), array);
}
data.add(key, obj);
}

@Override
public JsonElement asJsonData() {
return data;
}
}

0 comments on commit fd45fcd

Please sign in to comment.