mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 17:54:56 +00:00
Match bed rule key to version
- Write explodes for 26.1.2 and 26.2 bed rules - Rename explodes to destroy_on_use on 26.3 - Test bed rules for both fixer versions
This commit is contained in:
3 files changed
+43
-8
No files matched your search
@@ -143,7 +143,7 @@ public class DataFixerV1217 extends DataFixerV1213 {
|
||||
attributes.put("minecraft:gameplay/bed_rule", new JSONObject()
|
||||
.put("can_set_spawn", "never")
|
||||
.put("can_sleep", "never")
|
||||
.put("destroy_on_use", true));
|
||||
.put("explodes", true));
|
||||
}
|
||||
|
||||
attributes.put("minecraft:gameplay/respawn_anchor_works", json.remove("respawn_anchor_works"));
|
||||
|
||||
@@ -49,6 +49,16 @@ public final class DataFixerV263 extends DataFixerV1217 {
|
||||
return fixed;
|
||||
}
|
||||
|
||||
/** 26.3 renamed the bed rule's explodes flag to destroy_on_use; the old key is ignored there. */
|
||||
@Override
|
||||
public void fixDimension(Dimension dimension, JSONObject json) {
|
||||
super.fixDimension(dimension, json);
|
||||
JSONObject bedRule = json.getJSONObject("attributes").optJSONObject("minecraft:gameplay/bed_rule");
|
||||
if (bedRule != null && bedRule.has("explodes")) {
|
||||
bedRule.put("destroy_on_use", bedRule.remove("explodes"));
|
||||
}
|
||||
}
|
||||
|
||||
private static void color(JSONObject object, String key) {
|
||||
if (object.opt(key) instanceof Number value) {
|
||||
object.put(key, String.format(Locale.ROOT, "#%06x", value.intValue() & 0xFFFFFF));
|
||||
|
||||
+32
-7
@@ -1,6 +1,7 @@
|
||||
package art.arcane.iris.pack.datapack.v1217;
|
||||
|
||||
import art.arcane.iris.pack.datapack.IDataFixer.Dimension;
|
||||
import art.arcane.iris.pack.datapack.v263.DataFixerV263;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -10,6 +11,7 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class DataFixerV1217BedRuleTest {
|
||||
private final DataFixerV1217 fixer = new DataFixerV1217();
|
||||
private final DataFixerV1217 fixer263 = new DataFixerV263();
|
||||
|
||||
@Test
|
||||
public void overworldBedsSleepWhenDark() {
|
||||
@@ -21,25 +23,48 @@ public class DataFixerV1217BedRuleTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void netherBedsAreDestroyedOnUse() {
|
||||
assertDestroyedOnUse(bedRule(Dimension.NETHER));
|
||||
public void netherBedsExplodeBefore263() {
|
||||
assertNoSleep(bedRule(fixer, Dimension.NETHER), "explodes", "destroy_on_use");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endBedsAreDestroyedOnUse() {
|
||||
assertDestroyedOnUse(bedRule(Dimension.END));
|
||||
public void endBedsExplodeBefore263() {
|
||||
assertNoSleep(bedRule(fixer, Dimension.END), "explodes", "destroy_on_use");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void netherBedsAreDestroyedOnUseFrom263() {
|
||||
assertNoSleep(bedRule(fixer263, Dimension.NETHER), "destroy_on_use", "explodes");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endBedsAreDestroyedOnUseFrom263() {
|
||||
assertNoSleep(bedRule(fixer263, Dimension.END), "destroy_on_use", "explodes");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void overworldBedsSleepWhenDarkFrom263() {
|
||||
JSONObject rule = bedRule(fixer263, Dimension.OVERWORLD);
|
||||
|
||||
assertEquals("when_dark", rule.getString("can_sleep"));
|
||||
assertFalse(rule.has("explodes"));
|
||||
assertFalse(rule.has("destroy_on_use"));
|
||||
}
|
||||
|
||||
private JSONObject bedRule(Dimension dimension) {
|
||||
return bedRule(fixer, dimension);
|
||||
}
|
||||
|
||||
private static JSONObject bedRule(DataFixerV1217 fixer, Dimension dimension) {
|
||||
return fixer.createDimension(dimension, -64, 384, 384, null)
|
||||
.getJSONObject("attributes")
|
||||
.getJSONObject("minecraft:gameplay/bed_rule");
|
||||
}
|
||||
|
||||
private static void assertDestroyedOnUse(JSONObject rule) {
|
||||
private static void assertNoSleep(JSONObject rule, String presentKey, String absentKey) {
|
||||
assertEquals("never", rule.getString("can_sleep"));
|
||||
assertEquals("never", rule.getString("can_set_spawn"));
|
||||
assertTrue(rule.getBoolean("destroy_on_use"));
|
||||
assertFalse(rule.has("explodes"));
|
||||
assertTrue(rule.getBoolean(presentKey));
|
||||
assertFalse(rule.has(absentKey));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user