Skip to content

Commit

Permalink
1.20.0 pumpkins and 1.20.10 observers (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Konicai committed Sep 18, 2023
1 parent 83e8f73 commit 685aa96
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.cloudburstmc.blockstateupdater;

import org.cloudburstmc.blockstateupdater.util.OrderedUpdater;
import org.cloudburstmc.blockstateupdater.util.tagupdater.CompoundTagUpdaterContext;

import java.util.Map;
Expand Down Expand Up @@ -27,13 +28,6 @@ public class BlockStateUpdater_1_20_0 implements BlockStateUpdater {
"silver"
};

public static final String[] DIRECTIONS = {
"east",
"south",
"north",
"west"
};

@Override
public void registerUpdaters(CompoundTagUpdaterContext ctx) {
for (String color : COLORS) {
Expand Down Expand Up @@ -96,12 +90,13 @@ private void addTypeUpdater(CompoundTagUpdaterContext context, String identifier
}

private void addPumpkinUpdater(CompoundTagUpdaterContext ctx, String identifier) {
OrderedUpdater updater = OrderedUpdater.DIRECTION_TO_CARDINAL;
ctx.addUpdater(1, 20, 0)
.match("name", identifier)
.visit("states")
.edit("direction", helper -> {
.edit(updater.getOldProperty(), helper -> {
int value = (int) helper.getTag();
helper.replaceWith("minecraft:cardinal_direction", DIRECTIONS[value & 3]); // Don't ask me why namespace is in vanilla state
helper.replaceWith(updater.getNewProperty(), updater.translate(value)); // Don't ask me why namespace is in vanilla state
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.cloudburstmc.blockstateupdater;

import org.cloudburstmc.blockstateupdater.util.OrderedUpdater;
import org.cloudburstmc.blockstateupdater.util.tagupdater.CompoundTagUpdaterContext;

public class BlockStateUpdater_1_20_10 implements BlockStateUpdater {
Expand All @@ -25,14 +26,13 @@ public class BlockStateUpdater_1_20_10 implements BlockStateUpdater {
"silver"
};

public static final String[] DIRECTIONS = {
"east",
"south",
"north",
"west",
"up",
"down"
};
/**
* Literally the only block as of 1.20.30 that uses "minecraft:facing_direction"...
* Seems equivalent to "minecraft:block_face"
*/
public static final OrderedUpdater OBSERVER_DIRECTIONS = new OrderedUpdater(
"facing_direction", "minecraft:facing_direction",
"down", "up", "north", "south", "west", "east");

@Override
public void registerUpdaters(CompoundTagUpdaterContext ctx) {
Expand Down Expand Up @@ -63,9 +63,9 @@ private void addFacingDirectionUpdater(CompoundTagUpdaterContext ctx, String ide
ctx.addUpdater(1, 20, 10)
.match("name", identifier)
.visit("states")
.edit("facing_direction", helper -> {
.edit(OBSERVER_DIRECTIONS.getOldProperty(), helper -> {
int value = (int) helper.getTag();
helper.replaceWith("minecraft:facing_direction", DIRECTIONS[value & 5]); // Don't ask me why namespace is in vanilla state
helper.replaceWith(OBSERVER_DIRECTIONS.getNewProperty(), OBSERVER_DIRECTIONS.translate(value)); // Don't ask me why namespace is in vanilla state
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import org.cloudburstmc.blockstateupdater.util.OrderedUpdater;
import org.cloudburstmc.blockstateupdater.util.tagupdater.CompoundTagUpdaterContext;

import static org.cloudburstmc.blockstateupdater.util.OrderedUpdater.DIRECTION_TO_CARDINAL;
import static org.cloudburstmc.blockstateupdater.util.OrderedUpdater.FACING_TO_BLOCK;
import static org.cloudburstmc.blockstateupdater.util.OrderedUpdater.FACING_TO_CARDINAL;

public class BlockStateUpdater_1_20_30 implements BlockStateUpdater {

public static final BlockStateUpdater INSTANCE = new BlockStateUpdater_1_20_30();
Expand All @@ -26,18 +30,6 @@ public class BlockStateUpdater_1_20_30 implements BlockStateUpdater {
"silver"
};

public static final OrderedUpdater FACING_TO_BLOCK = new OrderedUpdater(
"facing_direction", "minecraft:block_face",
"down", "up", "north", "south", "west", "east");

public static final OrderedUpdater FACING_TO_CARDINAL = new OrderedUpdater(
"facing_direction", "minecraft:cardinal_direction", 2,
"north", "south", "west", "east");

public static final OrderedUpdater DIRECTION_TO_CARDINAL = new OrderedUpdater(
"direction", "minecraft:cardinal_direction",
"south", "west", "north", "east");

@Override
public void registerUpdaters(CompoundTagUpdaterContext ctx) {
for (String color : COLORS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
*/
public class OrderedUpdater {

public static final OrderedUpdater FACING_TO_BLOCK = new OrderedUpdater(
"facing_direction", "minecraft:block_face",
"down", "up", "north", "south", "west", "east");

public static final OrderedUpdater FACING_TO_CARDINAL = new OrderedUpdater(
"facing_direction", "minecraft:cardinal_direction", 2,
"north", "south", "west", "east");

public static final OrderedUpdater DIRECTION_TO_CARDINAL = new OrderedUpdater(
"direction", "minecraft:cardinal_direction",
"south", "west", "north", "east");

@Getter
private final String oldProperty;
@Getter
Expand Down

0 comments on commit 685aa96

Please sign in to comment.