Skip to content

Commit 7314193

Browse files
committed
feat: fix all for 1.21.11
1 parent 86ae0b5 commit 7314193

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+626
-265
lines changed

src/main/java/me/matl114/SlimefunHelper.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,25 @@
1414
import net.fabricmc.api.ModInitializer;
1515

1616

17+
import net.fabricmc.fabric.api.client.model.loading.v1.ExtraModelKey;
1718
import net.fabricmc.fabric.api.client.model.loading.v1.PreparableModelLoadingPlugin;
19+
import net.fabricmc.fabric.api.client.model.loading.v1.SimpleUnbakedExtraModel;
1820
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
1921
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
2022

2123
import net.fabricmc.fabric.impl.client.model.loading.ModelLoadingPluginManager;
2224
import net.minecraft.client.MinecraftClient;
25+
import net.minecraft.client.render.item.model.BasicItemModel;
26+
import net.minecraft.client.render.item.model.ItemModel;
27+
import net.minecraft.client.render.model.UnbakedModel;
2328
import net.minecraft.resource.ResourceManager;
2429
import net.minecraft.resource.ResourceType;
2530
import net.minecraft.util.Identifier;
2631

2732
import java.util.Collection;
33+
import java.util.List;
2834
import java.util.Objects;
35+
import java.util.Set;
2936
import java.util.concurrent.CompletableFuture;
3037

3138

@@ -71,7 +78,8 @@ public void reload(ResourceManager manager) {
7178
(resourceManager, executor) -> CompletableFuture.supplyAsync(()->{
7279
Debug.info("check model plugin work");
7380
ModConfig.reloadModConfig();
74-
return RenderListener.getReloadingResources(resourceManager.getResourceManager());
81+
//we removed the itemModel auto register to ItemAssetsLoader
82+
return Set.of();//RenderListener.getReloadingResources(resourceManager.getResourceManager());
7583
}),
7684
(PreparableModelLoadingPlugin<Collection<Identifier>>) (data, pluginContext) -> {
7785
// here we should auto register these to BasicItemModel s or SpecialItemModels
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package me.matl114.bukkit;
2+
3+
public class BukkitCodec {
4+
}

src/main/java/me/matl114/bukkit/BukkitItemStack.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import java.util.Locale;
1313
import java.util.Map;
1414

15-
public class BukkitItemStack implements Cloneable, ConfigurationSerializable {
15+
public sealed class BukkitItemStack implements Cloneable, ConfigurationSerializable permits CraftItemStack{
1616
private Item type;
1717
private int amount;
1818
private BukkitMetaItem meta;
@@ -158,10 +158,13 @@ public Map<String, Object> serialize() {
158158

159159
return result;
160160
}
161-
161+
private static final String VERSION_1_21_10_FLAG = "schema_version";
162162

163163
@NotNull
164164
public static BukkitItemStack deserialize(@NotNull Map<String, Object> args) {
165+
if(args.containsKey(VERSION_1_21_10_FLAG)) {
166+
return CraftItemStack.deserializeModern(args);
167+
}
165168
short damage = 0;
166169
int amount = 1;
167170
if (args.containsKey("damage")) {

src/main/java/me/matl114/bukkit/BukkitItemStackUtils.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public static void init(){
2727

2828
public static ItemStack getAsDisplayItem(BukkitItemStack itemStack){
2929
try{
30+
if(itemStack instanceof CraftItemStack cis){
31+
return cis.buildDisplay();
32+
}
3033
ItemStack stack=new ItemStack(itemStack.getType());
3134
stack.setCount(itemStack.getAmount());
3235
if(itemStack.hasItemMeta()){
@@ -65,7 +68,7 @@ public static ItemStack getAsDisplayItem(BukkitItemStack itemStack){
6568

6669
}catch (Throwable e) {
6770
Debug.info("error in ItemConvertion");
68-
return null;
71+
return STACK_FORBIDDEN;
6972
}
7073
}
7174

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
package me.matl114.bukkit;
2+
3+
import com.google.common.collect.ImmutableMap;
4+
import com.mojang.brigadier.exceptions.CommandSyntaxException;
5+
import com.mojang.datafixers.util.Pair;
6+
import com.mojang.serialization.*;
7+
import com.mojang.serialization.codecs.RecordCodecBuilder;
8+
import it.unimi.dsi.fastutil.objects.Reference2ObjectArrayMap;
9+
import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
10+
import me.matl114.utils.ItemStackUtils;
11+
import me.matl114.versioned.api.VItem;
12+
import me.matl114.versioned.api.VNbt;
13+
import net.minecraft.SharedConstants;
14+
import net.minecraft.component.ComponentChanges;
15+
import net.minecraft.component.ComponentMapImpl;
16+
import net.minecraft.component.ComponentType;
17+
import net.minecraft.component.DataComponentTypes;
18+
import net.minecraft.component.type.CustomModelDataComponent;
19+
import net.minecraft.item.Item;
20+
import net.minecraft.item.ItemStack;
21+
import net.minecraft.item.Items;
22+
import net.minecraft.nbt.*;
23+
import net.minecraft.registry.Registries;
24+
import net.minecraft.text.Style;
25+
import net.minecraft.util.Identifier;
26+
import net.minecraft.util.dynamic.Codecs;
27+
28+
import java.util.*;
29+
30+
public final class CraftItemStack extends BukkitItemStack {
31+
Map<String, String> compoundTag;
32+
String item;
33+
int count;
34+
int version;
35+
int dataVersion;
36+
ItemStack display;
37+
public CraftItemStack(String item, int count, Map<String, String> compoundTag, int dataVersion, int version) {
38+
this.item = item;
39+
this.count = count;
40+
this.dataVersion = dataVersion;
41+
this.compoundTag = compoundTag;
42+
this.display = buildDisplay0(compoundTag);
43+
}
44+
45+
public static final Codec<ComponentChanges> CODEC_DISPLAY_CHANGES =
46+
Codec.<ComponentChanges>of(
47+
ComponentChanges.CODEC,
48+
Codec.<String, Dynamic<?>>unboundedMap(Codec.STRING, Codec.PASSTHROUGH)
49+
.map(s -> {
50+
if (s.isEmpty()) {
51+
return ComponentChanges.EMPTY;
52+
} else {
53+
Reference2ObjectMap<ComponentType<?>, Optional<?>> reference2ObjectMap = new Reference2ObjectArrayMap<>(s.size());
54+
55+
for (Map.Entry<String, Dynamic<?>> entry : s.entrySet()) {
56+
String string = entry.getKey();
57+
String realKey ;
58+
boolean removal = false;
59+
if(string.startsWith("!")){
60+
realKey = string.substring(1);
61+
removal = true;
62+
}else {
63+
realKey = string;
64+
}
65+
ComponentType<?> type = Registries.DATA_COMPONENT_TYPE.get(Identifier.tryParse(realKey));
66+
if(type != null) {
67+
if(removal){
68+
reference2ObjectMap.put(type, Optional.empty());
69+
}else {
70+
Codec<?> codec = type.getCodecOrThrow();
71+
codec = VItem.getInstance().getVersionCompatCodecs().getOrDefault(type, codec);
72+
var dataResult = codec.decode(entry.getValue());
73+
if(dataResult.isSuccess()){
74+
reference2ObjectMap.put(type, dataResult.result().map(Pair::getFirst));
75+
}
76+
}
77+
}
78+
}
79+
return new ComponentChanges(reference2ObjectMap);
80+
}
81+
82+
})
83+
);
84+
private ItemStack buildDisplay0(Map<String, String> tag){
85+
if (!Objects.equals(item, "minecraft:air")) {
86+
try{
87+
Item item = Registries.ITEM.get(Identifier.tryParse(this.item));
88+
// if not air then it is unknown item
89+
item = item == Items.AIR ? Items.BARRIER : item;
90+
ItemStack stack = new ItemStack(item, count);
91+
NbtCompound tagCompound = new NbtCompound();
92+
for (var entry : tag.entrySet()) {
93+
try{
94+
final NbtElement componentTag = VNbt.getInstance().readNbtNoRegistry(entry.getValue());
95+
tagCompound.put(entry.getKey(), componentTag);
96+
}catch (Throwable ignoreFormatError){
97+
}
98+
}
99+
ComponentChanges displayChanges = CODEC_DISPLAY_CHANGES.decode(ItemStackUtils.registry().getOps(NbtOps.INSTANCE), tagCompound).result().map(Pair::getFirst).orElse(ComponentChanges.EMPTY);
100+
stack.applyChanges(displayChanges);
101+
102+
return stack;
103+
}catch (Throwable throwable){
104+
return new ItemStack(Items.BARRIER);
105+
}
106+
107+
}else return ItemStack.EMPTY;
108+
}
109+
110+
public ItemStack buildDisplay(){
111+
return display.copy();
112+
}
113+
114+
public static CraftItemStack deserializeModern(Map<String, Object> args) {
115+
final int version = args.getOrDefault("schema_version", 1) instanceof Number val ? val.intValue() : -1;
116+
//from paper1.21.10
117+
String id = "minecraft:air"; int cnt = 0; Map<String, String> compoundTag = Map.of();int dataversion = 0;
118+
for (var entry : args.entrySet()) {
119+
switch (entry.getKey()) {
120+
case "id" -> {
121+
id = (String) entry.getValue();
122+
}
123+
case "count" -> {
124+
cnt = ((Number) entry.getValue()).intValue();
125+
}
126+
case "components" -> {
127+
128+
if (entry.getValue() instanceof Map map0) {
129+
compoundTag = map0;
130+
} else {
131+
throw new IllegalArgumentException("components must be a Map");
132+
}
133+
134+
}
135+
case "DataVersion" -> {
136+
dataversion = ((Number) entry.getValue()).intValue();
137+
}
138+
default -> {
139+
// Ignore
140+
}
141+
}
142+
}
143+
return new CraftItemStack(id, cnt, compoundTag, dataversion, version);
144+
}
145+
146+
147+
148+
public Map<String, Object> serialize() {
149+
final Map<String, Object> ret = new LinkedHashMap<>();
150+
ret.put("id", this.item);
151+
ret.put("count", this.count);
152+
ret.put("components", this.compoundTag);
153+
ret.put("DataVersion", this.dataVersion);
154+
ret.put("schema_version", this.version);
155+
return ret;
156+
}
157+
}

src/main/java/me/matl114/events/Listener.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ private static Packet<?> unpackMultiPacket(ClientConnection connection,Packet<?>
301301
@Broadcast
302302
private static final EventChannel<Screen> postCloseScreen = new EventChannel<>();
303303
@Getter
304+
@Cancelable
305+
@Modifiable
306+
private static final EventChannel<Screen> preSetScreen = new EventChannel<>();
307+
@Getter
304308
@Cancelable //note: this cancels post operations of setting a screen , like cursor lock, render refresh and title update
305309
private static final EventChannel<Screen> postSetScreen = new EventChannel<>();
306310
@Getter

src/main/java/me/matl114/events/RenderListener.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import net.minecraft.text.Text;
1515
import net.minecraft.util.Identifier;
1616
import net.minecraft.util.crash.CrashException;
17-
import org.lwjgl.opengl.GL11;
1817

1918
import java.util.*;
2019

@@ -54,7 +53,8 @@ public static ItemModel getModelOf(Identifier modeled){
5453
return getCustomModelOf(modeled);
5554
}
5655
public static ItemModel getCustomModelOf(Identifier identifier){
57-
return mc.getBakedModelManager().getItemModel(identifier);
56+
ItemModel model = mc.getBakedModelManager().getItemModel(identifier);
57+
return model == mc.getBakedModelManager().missingModels.item() ? null : model;
5858
}
5959

6060

@@ -85,7 +85,7 @@ public static ItemStack getContainedItemInfo(ItemStack stack){
8585
@ExtraArgs(value = {float.class}, names = {"ticksDelta"})
8686
private static final EventChannel<MatrixStack> renderLayerTasks = new EventChannel<>();
8787
public static void renderMoreTasks(MatrixStack stack, float tickDelta){
88-
GL11.glEnable(GL11.GL_LINE_SMOOTH);
88+
//GL11.glEnable(GL11.GL_LINE_SMOOTH);
8989

9090
try{
9191
// This stack start with the position with RenderUtils.getCameraPose();
@@ -95,7 +95,7 @@ public static void renderMoreTasks(MatrixStack stack, float tickDelta){
9595
}catch (ConcurrentModificationException | NullPointerException | CrashException e){
9696
Debug.info("Error while handling Render Event:", e.getMessage());
9797
}finally {
98-
GL11.glDisable(GL11.GL_LINE_SMOOTH);
98+
//GL11.glDisable(GL11.GL_LINE_SMOOTH);
9999
}
100100

101101

@@ -130,7 +130,7 @@ public static void renderHandledScreen(DrawContext context, HandledScreen<?> scr
130130
@Getter
131131
@Broadcast
132132
@ExtraArgs(value = {ResourceManager.class})
133-
private static final EventChannel<Set<Identifier>> asyncResourceSupply = new EventChannel<>();
133+
private static final EventChannel<Set<Identifier>> asyncItemModelSupply = new EventChannel<>();
134134

135135
public static void onResourceReload(ResourceManager manager){
136136
Event<ResourceManager> resourceReloadEvent = new Event<>(manager, false,false);
@@ -139,7 +139,7 @@ public static void onResourceReload(ResourceManager manager){
139139

140140
public static Collection<Identifier> getReloadingResources(ResourceManager manager){
141141
Event<Set<Identifier>> resourceReloadEvent = new Event<>(new LinkedHashSet<>(), false,false, manager);
142-
asyncResourceSupply.handleValue(resourceReloadEvent);
142+
asyncItemModelSupply.handleValue(resourceReloadEvent);
143143
return resourceReloadEvent.context();
144144
}
145145

src/main/java/me/matl114/gui/GenericScreen.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,19 @@ public final boolean mouseReleased(Click click) {
8484

8585
@Override
8686
public final boolean mouseClicked(Click click, boolean input) {
87-
boolean val = super.mouseClicked(click, input);
87+
//remove the fucking super method
88+
boolean val = false;
89+
for (Element element : this.children()) {
90+
if (element.mouseClicked(click, input)) {
91+
this.setFocused(element);
92+
if (click.button() == 0) {
93+
this.setDragging(true);
94+
}
95+
96+
val = true;
97+
break;
98+
}
99+
}
88100
if(click.button() == 0){
89101
for (var iter: this.children()){
90102
if(iter instanceof Draggable drag && drag.startDrag(this, click.x(), click.y())){
@@ -120,8 +132,5 @@ public void resetScreen(){
120132
//mc.executeSync(()->this.init(mc,mc.getWindow().getScaledWidth(), mc.getWindow().getScaledHeight()));
121133
}
122134

123-
// ==================================== API compat for higher version ===========================//
124-
125-
126135

127136
}

src/main/java/me/matl114/gui/basic/LabelElement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public LabelElement(TextProvider text, int color, int alignment){
3131
public void renderCentered0(DrawableWidget element, VDrawContext context, int mouseX, int mouseY, float delta, float alpha, boolean shouldHighlight) {
3232
Text text1 = text.getLabel(element);
3333
if(text1 != null){
34-
RenderHandler.drawScaledText0(context, mc.textRenderer, text1, 0,0,element.getTextureWidth(), element.getTextureHeight(), color, alignment);
3534
context.drawTexturedQuad(BACKGROUND_RESOURCE, 0,element.getTextureWidth(), 0, element.getTextureHeight(), 0,u0,u1,v0,v1 );
35+
RenderHandler.drawScaledText0(context, mc.textRenderer, text1, 0,0,element.getTextureWidth(), element.getTextureHeight(), color, alignment);
3636
}
3737
}
3838
}

src/main/java/me/matl114/gui/itemEdit/ItemEditScreen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ public DrawableWidget factory(int x, int y){
493493
ButtonAction.run(()-> sec.setHideFlag(sample, !sec.isHide(sample))),
494494
(bl)->sec.isHide(sample)
495495
)
496-
.withTooltips(TooltipHandler.of(List.of(Text.literal(sec.name().toLowerCase(Locale.ROOT)))))
496+
.withTooltips(TooltipHandler.of(List.of(Text.literal(sec.displayName()))))
497497
)
498498
);
499499
}

0 commit comments

Comments
 (0)