Skip to content

Commit

Permalink
Initial update to 1.21.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubenicos committed Dec 3, 2024
1 parent f18576f commit b7e408f
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group=com.saicone.rtag
version=1.5.8
version=1.5.9-SNAPSHOT
22 changes: 20 additions & 2 deletions rtag-item/src/main/java/com/saicone/rtag/RtagItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -510,12 +510,17 @@ public boolean setUnbreakable(boolean unbreakable) {
* @param model Model id, null of you want to remove it.
* @return true if the model was set or removed.
*/
@Deprecated
public boolean setCustomModelData(Integer model) {
if (ServerInstance.Release.COMPONENT) {
if (model == null) {
removeComponent("minecraft:custom_model_data");
} else {
setComponent("minecraft:custom_model_data", model);
if (ServerInstance.VERSION >= 21.03f) {
setComponent("minecraft:custom_model_data", Map.of("floats", List.of(model.floatValue())));
} else {
setComponent("minecraft:custom_model_data", model);
}
}
return true;
}
Expand Down Expand Up @@ -673,9 +678,22 @@ public int removeEnchantment(EnchantmentTag enchant) {
*
* @return Model id, null if the item doesn't have model.
*/
@Deprecated
public Integer getCustomModelData() {
if (ServerInstance.Release.COMPONENT) {
return (Integer) ComponentType.encodeJava("minecraft:custom_model_data", getComponent("minecraft:custom_model_data")).orElse(null);
return ComponentType.encodeJava("minecraft:custom_model_data", getComponent("minecraft:custom_model_data")).map(model -> {
if (model instanceof Map) {
final Object floats = ((Map<?, ?>) model).get("floats");
if (floats instanceof List && !((List<?>) floats).isEmpty()) {
final Object f = ((List<?>) floats).get(0);
if (f instanceof Float) {
return ((Float) f).intValue();
}
}
return null;
}
return (Integer) model;
}).orElse(null);
}
return get("CustomModelData");
}
Expand Down
6 changes: 4 additions & 2 deletions rtag-item/src/main/java/com/saicone/rtag/item/ItemObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ public class ItemObject {
if (ServerInstance.MAJOR_VERSION >= 18) {
save = "b";
setTag = "c";
if (ServerInstance.Release.COMPONENT) {
if (ServerInstance.VERSION >= 21.03f) {
getTag = "g";
} else if (ServerInstance.Release.COMPONENT) {
getTag = ServerInstance.DATA_VERSION >= 3839 ? "f" : "e";
} else if (ServerInstance.MAJOR_VERSION >= 20) {
getTag = "v";
Expand Down Expand Up @@ -155,7 +157,7 @@ public class ItemObject {
method$apply = EasyLookup.method(MC_ITEM, apply, void.class, "DataComponentPatch");
method$copy = EasyLookup.method(MC_ITEM, copy, MC_ITEM);
method$getItem = EasyLookup.method("RegistryBlocks", getItem, Object.class, "MinecraftKey");
method$getTag = EasyLookup.unreflectGetter("CustomData", getTag);
method$getTag = EasyLookup.getter("CustomData", getTag, "NBTTagCompound");
method$setItem = EasyLookup.unreflectSetter(MC_ITEM, setItem);
method$setCount = EasyLookup.method(MC_ITEM, setCount, void.class, int.class);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public boolean downgradeComponent(Object components, String id, Map<String, Obje
TRANSFORMATIONS.put("minecraft:use_remainder", new Food());
TRANSFORMATIONS.put("minecraft:fire_resistant", new DamageResistant());
TRANSFORMATIONS.put("minecraft:damage_resistant", new DamageResistant());
TRANSFORMATIONS.put("minecraft:custom_model_data", new CustomModelData());
TRANSFORMATIONS.put("minecraft:equippable", new Equippable());
}

@Override
Expand Down Expand Up @@ -1485,6 +1487,53 @@ public void downgrade(Object components, String id, Object component, float from
}
}

public static class CustomModelData implements Transformation {
@Override
public void upgrade(Object components, String id, Object component, float from, float to) {
if (to >= 21.03f && from < 21.03f) {
TagCompound.remove(components, id);
if (component instanceof Number) {
TagCompound.set(components, id, TagCompound.newTag(Map.of("floats", TagList.newTag(List.of(((Number) component).floatValue())))));
}
}
}

@Override
public void downgrade(Object components, String id, Object component, float from, float to) {
if (from >= 21.03f && to < 21.03f) {
TagCompound.remove(components, id);
final Object floats = TagCompound.get(component, "floats");
if (floats != null) {
Float modelData = null;
for (Object element : TagList.getValue(floats)) {
if (element == null) continue;
modelData = (Float) TagBase.getValue(element);
break;
}
if (modelData != null) {
TagCompound.set(components, id, TagBase.newTag(modelData.intValue()));
}
}
}
}
}

public static class Equippable implements Transformation {
@Override
public void upgrade(Object components, String id, Object component, float from, float to) {
if (to >= 21.03f && from < 21.03f) {
move(TagCompound.getValue(component), "model", "asset_id");
}
}

@Override
public void downgrade(Object components, String id, Object component, float from, float to) {
if (from >= 21.03f && to < 21.03f) {
move(TagCompound.getValue(component), "asset_id", "model");
}
}
}

private enum Color {
WHITE,
ORANGE,
Expand Down
10 changes: 10 additions & 0 deletions rtag-item/src/main/java/com/saicone/rtag/util/ItemMaterialTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ public enum ItemMaterialTag {
CHISELED_POLISHED_BLACKSTONE(16),
CHISELED_QUARTZ_BLOCK(13, "QUARTZ_BLOCK:1", 8),
CHISELED_RED_SANDSTONE(13, "RED_SANDSTONE:1", 8),
CHISELED_RESIN_BRICKS(21.03f),
CHISELED_SANDSTONE(13, "SANDSTONE:1", 8),
CHISELED_STONE_BRICKS(13, "STONEBRICK:3", 8, "SMOOTH_BRICK"),
CHISELED_TUFF(20.03f),
Expand All @@ -255,6 +256,7 @@ public enum ItemMaterialTag {
CLAY(8),
CLAY_BALL(8),
CLOCK(8, "WATCH"),
CLOSED_EYEBLOSSOM(21.03f),
COAL(8),
COAL_BLOCK(8),
COAL_ORE(8),
Expand Down Expand Up @@ -876,6 +878,7 @@ public enum ItemMaterialTag {
OCHRE_FROGLIGHT(19),
OMINOUS_BOTTLE(20.04f),
OMINOUS_TRIAL_KEY(20.04f),
OPEN_EYEBLOSSOM(21.03f),
ORANGE_BANNER(13, "BANNER:14", 8),
ORANGE_BED(13, "BED:1", 12),
ORANGE_BUNDLE(21.02f),
Expand Down Expand Up @@ -1089,6 +1092,13 @@ public enum ItemMaterialTag {
REINFORCED_DEEPSLATE(19),
REPEATER(8, "DIODE"),
REPEATING_COMMAND_BLOCK(9, "COMMAND_REPEATING"),
RESIN_BLOCK(21.03f),
RESIN_BRICK(21.03f),
RESIN_BRICK_SLAB(21.03f),
RESIN_BRICK_STAIRS(21.03f),
RESIN_BRICK_WALL(21.03f),
RESIN_BRICKS(21.03f),
RESIN_CLUMP(21.03f),
RESPAWN_ANCHOR(16),
RIB_ARMOR_TRIM_SMITHING_TEMPLATE(19.03f),
ROOTED_DIRT(17),
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/saicone/rtag/data/DataComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ public static class MapPatch {
map = "patch";
set = "set";
remove = "remove";
} else if (ServerInstance.VERSION >= 21.03f) {
remove = "e";
}

try {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/saicone/rtag/util/ServerInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class ServerInstance {
VERSION_MAP.put(3837, new Integer[] {20, 4, 12004});
VERSION_MAP.put(3953, new Integer[] {21, 1, 12101});
VERSION_MAP.put(4080, new Integer[] {21, 2, 12102});
VERSION_MAP.put(4189, new Integer[] {21, 3, 12103});

final String serverPackage = Bukkit.getServer().getClass().getPackage().getName();
if (serverPackage.startsWith("org.bukkit.craftbukkit.v1_")) {
Expand Down

0 comments on commit b7e408f

Please sign in to comment.