-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a part of file about mapping module
- Loading branch information
CoolLoong
committed
Sep 1, 2023
1 parent
6ecfb0f
commit 9105270
Showing
81 changed files
with
126,942 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -15,3 +15,4 @@ buildSrc/** | |
/output/ | ||
/Allay-Server/src/test/resources/allayworld/db/ | ||
/output/ | ||
/cache/ |
16 changes: 15 additions & 1 deletion
16
Allay-Mapping/src/main/java/cn/allay/mapping/generator/id/IdentifierMapper.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 |
---|---|---|
@@ -1,4 +1,18 @@ | ||
package cn.allay.mapping.generator.id; | ||
|
||
public class IdentifierMapper { | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
public interface IdentifierMapper { | ||
Pair<String, Pair<String, Object>> translateIdentifier(String fullIdentifier); | ||
|
||
default String getStateValue(String fullIdentifier, String property) { | ||
String[] states = fullIdentifier.substring(fullIdentifier.lastIndexOf("[") + 1).replace("]", "").split(","); | ||
for (String state : states) { | ||
String key = state.split("=")[0]; | ||
if (property.equals(key)) { | ||
return state.split("=")[1]; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Allay-Mapping/src/main/java/cn/allay/mapping/generator/id/IdentifierRemapper.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,15 @@ | ||
package cn.allay.mapping.generator.id; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
@Retention(value = RetentionPolicy.RUNTIME) | ||
public @interface IdentifierRemapper { | ||
/** | ||
* Regex string to check for when remapping states for blocks. Leave | ||
* empty to check against all blocks. | ||
* | ||
* @return regex string to check against when remapping states for blocks | ||
*/ | ||
String[] blockRegex() default ""; | ||
} |
14 changes: 14 additions & 0 deletions
14
Allay-Mapping/src/main/java/cn/allay/mapping/generator/id/type/PlanksType.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,14 @@ | ||
package cn.allay.mapping.generator.id.type; | ||
|
||
import cn.allay.mapping.generator.id.IdentifierMapper; | ||
import cn.allay.mapping.generator.id.IdentifierRemapper; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
|
||
@IdentifierRemapper(blockRegex = ".*_planks$") | ||
public class PlanksType implements IdentifierMapper { | ||
@Override | ||
public Pair<String, Pair<String, Object>> translateIdentifier(String fullIdentifier) { | ||
return Pair.of("minecraft:planks", null); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
Allay-Mapping/src/main/java/cn/allay/mapping/generator/state/StateMapper.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,34 @@ | ||
package cn.allay.mapping.generator.state; | ||
|
||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
public abstract class StateMapper<T> { | ||
|
||
/** | ||
* Translates a state string from a Minecraft: Java Edition | ||
* block state to it's bedrock counterpart. | ||
* | ||
* @param fullIdentifier the full identifier of the block to translate the state for | ||
* @param value the value given in the Java blockstate | ||
* @return a state string for bedrock edition | ||
*/ | ||
public abstract Pair<String, T> translateState(String fullIdentifier, String value); | ||
|
||
public static <V> V asType(Pair<String, ?> pair, Class<V> type) { | ||
if (type.isInstance(pair.getValue())) { | ||
return type.cast(pair.getValue()); | ||
} | ||
throw new IllegalArgumentException("Mapping type " + pair.getValue().getClass().getSimpleName() + " cannot be cast to " + type.getSimpleName()); | ||
} | ||
|
||
protected String getStateValue(String fullIdentifier, String property) { | ||
String[] states = fullIdentifier.substring(fullIdentifier.lastIndexOf("[") + 1).replace("]", "").split(","); | ||
for (String state : states) { | ||
String key = state.split("=")[0]; | ||
if (property.equals(key)) { | ||
return state.split("=")[1]; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Allay-Mapping/src/main/java/cn/allay/mapping/generator/state/StateRemapper.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,23 @@ | ||
package cn.allay.mapping.generator.state; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
@Retention(value = RetentionPolicy.RUNTIME) | ||
public @interface StateRemapper { | ||
|
||
/** | ||
* Regex string to check for when remapping states for blocks. Leave | ||
* empty to check against all blocks. | ||
* | ||
* @return regex string to check against when remapping states for blocks | ||
*/ | ||
String[] blockRegex() default ""; | ||
|
||
/** | ||
* The name of the Minecraft: Java Edition blockstate data. | ||
* | ||
* @return the name of the Minecraft: java edition blockstate data. | ||
*/ | ||
String value(); | ||
} |
15 changes: 15 additions & 0 deletions
15
Allay-Mapping/src/main/java/cn/allay/mapping/generator/state/type/BambooBlockAxisMapper.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,15 @@ | ||
package cn.allay.mapping.generator.state.type; | ||
|
||
import cn.allay.mapping.generator.state.StateMapper; | ||
import cn.allay.mapping.generator.state.StateRemapper; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
|
||
@StateRemapper(value = "axis", blockRegex = "minecraft:(stripped_)?bamboo_block") | ||
public class BambooBlockAxisMapper extends StateMapper<String> { | ||
|
||
@Override | ||
public Pair<String, String> translateState(String fullIdentifier, String value) { | ||
return Pair.of("pillar_axis", value); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Allay-Mapping/src/main/java/cn/allay/mapping/generator/state/type/BasaltAxisMapper.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,15 @@ | ||
package cn.allay.mapping.generator.state.type; | ||
|
||
import cn.allay.mapping.generator.state.StateMapper; | ||
import cn.allay.mapping.generator.state.StateRemapper; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
|
||
@StateRemapper(value = "axis", blockRegex = ".*basalt.?$") | ||
public class BasaltAxisMapper extends StateMapper<String> { | ||
|
||
@Override | ||
public Pair<String, String> translateState(String fullIdentifier, String value) { | ||
return Pair.of("pillar_axis", value); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...y-Mapping/src/main/java/cn/allay/mapping/generator/state/type/BeeNestDirectionMapper.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,21 @@ | ||
package cn.allay.mapping.generator.state.type; | ||
|
||
import cn.allay.mapping.generator.state.StateMapper; | ||
import cn.allay.mapping.generator.state.StateRemapper; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
|
||
@StateRemapper(value = "facing", blockRegex = "^minecraft:bee_nest|^minecraft:beehive") | ||
public class BeeNestDirectionMapper extends StateMapper<Integer> { | ||
|
||
@Override | ||
public Pair<String, Integer> translateState(String fullIdentifier, String value) { | ||
int direction = switch (value) { | ||
case "west" -> 1; | ||
case "north" -> 2; | ||
case "east" -> 3; | ||
default -> 0; | ||
}; | ||
return Pair.of("direction", direction); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...pping/src/main/java/cn/allay/mapping/generator/state/type/BigDripleafDirectionMapper.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,21 @@ | ||
package cn.allay.mapping.generator.state.type; | ||
|
||
import cn.allay.mapping.generator.state.StateMapper; | ||
import cn.allay.mapping.generator.state.StateRemapper; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
|
||
@StateRemapper(value = "facing", blockRegex = "^minecraft:big_dripleaf|^minecraft:big_dripleaf_stem") | ||
public class BigDripleafDirectionMapper extends StateMapper<Integer> { | ||
|
||
@Override | ||
public Pair<String, Integer> translateState(String fullIdentifier, String value) { | ||
return Pair.of("direction", switch (value) { | ||
case "south" -> 0; | ||
case "west" -> 1; | ||
case "north" -> 2; | ||
case "east" -> 3; | ||
default -> throw new RuntimeException("Could not determine big dripleaf direction!"); | ||
}); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Allay-Mapping/src/main/java/cn/allay/mapping/generator/state/type/BigDripleafTiltMapper.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,21 @@ | ||
package cn.allay.mapping.generator.state.type; | ||
|
||
import cn.allay.mapping.generator.state.StateMapper; | ||
import cn.allay.mapping.generator.state.StateRemapper; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
|
||
@StateRemapper(value = "tilt", blockRegex = "^minecraft:big_dripleaf") | ||
public class BigDripleafTiltMapper extends StateMapper<String> { | ||
|
||
@Override | ||
public Pair<String, String> translateState(String fullIdentifier, String value) { | ||
return Pair.of("big_dripleaf_tilt", switch (value) { | ||
case "none" -> "none"; | ||
case "unstable" -> "unstable"; | ||
case "partial" -> "partial_tilt"; | ||
case "full" -> "full_tilt"; | ||
default -> throw new RuntimeException("Unknown tilt state for big dripleaf!"); | ||
}); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
Allay-Mapping/src/main/java/cn/allay/mapping/generator/state/type/ButtonFaceMapper.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,27 @@ | ||
package cn.allay.mapping.generator.state.type; | ||
|
||
import cn.allay.mapping.generator.state.StateMapper; | ||
import cn.allay.mapping.generator.state.StateRemapper; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
|
||
@StateRemapper(value = "face", blockRegex = ".*button.?$") | ||
public class ButtonFaceMapper extends StateMapper<Integer> { | ||
|
||
@Override | ||
public Pair<String, Integer> translateState(String fullIdentifier, String value) { | ||
String facing = this.getStateValue(fullIdentifier, "facing"); | ||
int facingDirection = switch (value) { | ||
case "floor" -> 1; | ||
case "wall" -> switch (facing) { | ||
case "north" -> 2; | ||
case "south" -> 3; | ||
case "west" -> 4; | ||
case "east" -> 5; | ||
default -> 0; | ||
}; | ||
default -> 0; | ||
}; | ||
return Pair.of("facing_direction", facingDirection); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Allay-Mapping/src/main/java/cn/allay/mapping/generator/state/type/ButtonPoweredMapper.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,15 @@ | ||
package cn.allay.mapping.generator.state.type; | ||
|
||
import cn.allay.mapping.generator.state.StateMapper; | ||
import cn.allay.mapping.generator.state.StateRemapper; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
|
||
@StateRemapper(value = "powered", blockRegex = ".*button.?$") | ||
public class ButtonPoweredMapper extends StateMapper<Boolean> { | ||
|
||
@Override | ||
public Pair<String, Boolean> translateState(String fullIdentifier, String value) { | ||
return Pair.of("button_pressed_bit", Boolean.parseBoolean(value)); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...rc/main/java/cn/allay/mapping/generator/state/type/CalibratedSculkSensorFacingMapper.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,22 @@ | ||
package cn.allay.mapping.generator.state.type; | ||
|
||
import cn.allay.mapping.generator.state.StateMapper; | ||
import cn.allay.mapping.generator.state.StateRemapper; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
|
||
@StateRemapper(value = "facing", blockRegex = "minecraft:calibrated_sculk_sensor") | ||
public class CalibratedSculkSensorFacingMapper extends StateMapper<Integer> { | ||
|
||
@Override | ||
public Pair<String, Integer> translateState(String fullIdentifier, String value) { | ||
int direction = switch (value) { | ||
case "south" -> 0; | ||
case "west" -> 1; | ||
case "north" -> 2; | ||
case "east" -> 3; | ||
default -> throw new IllegalArgumentException("Got " + value + " instead of a cardinal direction"); | ||
}; | ||
return Pair.of("direction", direction); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Allay-Mapping/src/main/java/cn/allay/mapping/generator/state/type/CampfireFacingMapper.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,21 @@ | ||
package cn.allay.mapping.generator.state.type; | ||
|
||
import cn.allay.mapping.generator.state.StateMapper; | ||
import cn.allay.mapping.generator.state.StateRemapper; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
|
||
@StateRemapper(value = "facing", blockRegex = ".*campfire.?$") | ||
public class CampfireFacingMapper extends StateMapper<Integer> { | ||
|
||
@Override | ||
public Pair<String, Integer> translateState(String fullIdentifier, String value) { | ||
int direction = switch (value) { | ||
case "north" -> 2; | ||
case "west" -> 1; | ||
case "east" -> 3; | ||
default -> 0; | ||
}; | ||
return Pair.of("direction", direction); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Allay-Mapping/src/main/java/cn/allay/mapping/generator/state/type/CampfireLitMapper.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,15 @@ | ||
package cn.allay.mapping.generator.state.type; | ||
|
||
import cn.allay.mapping.generator.state.StateMapper; | ||
import cn.allay.mapping.generator.state.StateRemapper; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
|
||
@StateRemapper(value = "lit", blockRegex = ".*campfire.?$") | ||
public class CampfireLitMapper extends StateMapper<Boolean> { | ||
|
||
@Override | ||
public Pair<String, Boolean> translateState(String fullIdentifier, String value) { | ||
return Pair.of("extinguished", value.equals("false")); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
Allay-Mapping/src/main/java/cn/allay/mapping/generator/state/type/CandleCountMapper.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,16 @@ | ||
package cn.allay.mapping.generator.state.type; | ||
|
||
import cn.allay.mapping.generator.state.StateMapper; | ||
import cn.allay.mapping.generator.state.StateRemapper; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
|
||
@StateRemapper(value = "candles", blockRegex = ".*candle$") | ||
public class CandleCountMapper extends StateMapper<Integer> { | ||
|
||
@Override | ||
public Pair<String, Integer> translateState(String fullIdentifier, String value) { | ||
// Java index starts at 1; Bedrock index starts at 0 | ||
return Pair.of("candles", Integer.parseInt(value) - 1); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Allay-Mapping/src/main/java/cn/allay/mapping/generator/state/type/CandleLitMapper.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,15 @@ | ||
package cn.allay.mapping.generator.state.type; | ||
|
||
import cn.allay.mapping.generator.state.StateMapper; | ||
import cn.allay.mapping.generator.state.StateRemapper; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
|
||
@StateRemapper(value = "lit", blockRegex = ".*candle.*") | ||
public class CandleLitMapper extends StateMapper<Boolean> { | ||
|
||
@Override | ||
public Pair<String, Boolean> translateState(String fullIdentifier, String value) { | ||
return Pair.of("lit", value.equals("true")); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...apping/src/main/java/cn/allay/mapping/generator/state/type/CauldronLiquidLevelMapper.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,19 @@ | ||
package cn.allay.mapping.generator.state.type; | ||
|
||
import cn.allay.mapping.generator.state.StateMapper; | ||
import cn.allay.mapping.generator.state.StateRemapper; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
|
||
@StateRemapper(value = "level", blockRegex = ".*cauldron.?$") | ||
public class CauldronLiquidLevelMapper extends StateMapper<Integer> { | ||
@Override | ||
public Pair<String, Integer> translateState(String fullIdentifier, String value) { | ||
return Pair.of("fill_level", switch (value) { | ||
case "1" -> 3; | ||
case "2" -> 4; | ||
case "3" -> 6; | ||
default -> throw new RuntimeException("Unknown cauldron liquid level!"); | ||
}); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Allay-Mapping/src/main/java/cn/allay/mapping/generator/state/type/ChainAxisMapper.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,15 @@ | ||
package cn.allay.mapping.generator.state.type; | ||
|
||
import cn.allay.mapping.generator.state.StateMapper; | ||
import cn.allay.mapping.generator.state.StateRemapper; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
|
||
@StateRemapper(value = "axis", blockRegex = "^minecraft:chain") | ||
public class ChainAxisMapper extends StateMapper<String> { | ||
|
||
@Override | ||
public Pair<String, String> translateState(String fullIdentifier, String value) { | ||
return Pair.of("pillar_axis", value); | ||
} | ||
} |
Oops, something went wrong.