Skip to content

Commit

Permalink
Fix inventory problems with CustomNPC [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
TonimatasDEV committed Nov 18, 2024
1 parent 08ed5d8 commit 77c18b1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,17 @@
}
}
} else {
@@ -310,17 +_,48 @@
@@ -310,17 +_,44 @@
}
}

- private static boolean burn(@Nullable Recipe<?> p_155027_, NonNullList<ItemStack> p_155028_, int p_155029_) {
+ //Magma start - mixin inject
+ private @Nullable Level burn_level;
+ private @Nullable BlockPos burn_pos;
+ private final java.util.concurrent.atomic.AtomicReference<Level> burn_level = new java.util.concurrent.atomic.AtomicReference<>();
+ private final java.util.concurrent.atomic.AtomicReference<BlockPos> burn_pos = new java.util.concurrent.atomic.AtomicReference<>();
+ private boolean burn(@Nullable Recipe<?> p_155027_, NonNullList<ItemStack> p_155028_, int p_155029_) {
+ Level level = burn_level;
+ BlockPos blockposition = burn_pos;
+
+ //reset
+ burn_level = null;
+ burn_pos = null;
+ Level level = burn_level.getAndSet(null);
+ BlockPos blockposition = burn_pos.getAndSet(null);
+
if (p_155027_ != null && canBurn(p_155027_, p_155028_, p_155029_)) {
ItemStack itemstack = p_155028_.get(0);
Expand Down Expand Up @@ -181,8 +177,8 @@
}

+ private boolean burn(Level level, BlockPos blockposition, @Nullable Recipe<?> p_155027_, NonNullList<ItemStack> p_155028_, int p_155029_) {
+ burn_level = level;
+ burn_pos = blockposition;
+ burn_level.set(level);
+ burn_pos.set(blockposition);
+ return burn(p_155027_, p_155028_, p_155029_);
+ }
+ //Magma end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;

import com.google.common.collect.ImmutableMap;
import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -96,6 +97,7 @@ public static CraftItemStack asNewCraftStack(Item item, int amount) {
*/
private CraftItemStack(net.minecraft.world.item.ItemStack item) {
this.handle = item;
setItemMeta(getItemMeta()); // Magma - Add ForgeCaps to all items used by CraftBukkit
}

private CraftItemStack(ItemStack item) {
Expand Down Expand Up @@ -362,7 +364,9 @@ public static ItemMeta getItemMeta(net.minecraft.world.item.ItemStack item) {
case BUNDLE -> new CraftMetaBundle(item.getTag());
default -> new CraftMetaItem(item.getTag());
};
meta.offerUnhandledTags(item);
if (item == null) return meta;
CompoundTag tag = item.getTag();
if (tag != null) meta.offerUnhandledTags(tag);
meta.setForgeCaps(item.getForgeCaps());
return meta;
//Magma end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ static <T> T getObject(Class<T> clazz, Map<?, ?> map, Object field, boolean null

//Magma start - this is a list of nbt tags that don't get removed when CraftItemStack.setItemMeta gets called, add things to this list to prevent them from getting removed
private static final Set<String> EXTEND_TAGS = ImmutableSet.of(
"Name",
"Items",
"Schedule",
"map_is_scaling",
"map",
"CustomPotionEffects",
Expand Down Expand Up @@ -335,9 +338,11 @@ static <T> T getObject(Class<T> clazz, Map<?, ?> map, Object field, boolean null
this.version = meta.version;

//Magma start
CompoundTag forgeCaps = meta.getForgeCaps();
if (forgeCaps != null) {
this.forgeCaps = forgeCaps.copy();
if (meta != null) {
CompoundTag forgeCaps = meta.getForgeCaps();
if (forgeCaps != null) {
this.forgeCaps = forgeCaps.copy();
}
}
//Magma end
}
Expand Down Expand Up @@ -420,15 +425,10 @@ public CompoundTag getForgeCaps() {
return forgeCaps;
}

public void offerUnhandledTags(ItemStack stack) { //Code based on Arclight's implementation
CompoundTag nbt = stack.getTag();
if (nbt == null)
return;

public void offerUnhandledTags(CompoundTag nbt) {
if (getClass().equals(CraftMetaItem.class)) {
boolean transformable = ItemMetaTransformer.isTransformable(stack);
for (String s : nbt.getAllKeys()) {
if (EXTEND_TAGS.contains(s) || !transformable) {
if (EXTEND_TAGS.contains(s)) {
this.unhandledTags.put(s, nbt.get(s));
}
}
Expand Down Expand Up @@ -596,8 +596,8 @@ static Multimap<Attribute, AttributeModifier> buildModifiers(CompoundTag tag, It
}

//Magma start
if (map.containsKey("forgeCaps")) {
Object forgeCaps = map.get("forgeCaps");
if (map.containsKey("ForgeCaps")) {
Object forgeCaps = map.get("ForgeCaps");
try {
ByteArrayInputStream buf = new ByteArrayInputStream(Base64.getDecoder().decode(forgeCaps.toString()));
this.forgeCaps = NbtIo.readCompressed(buf);
Expand Down Expand Up @@ -1229,10 +1229,10 @@ boolean equalsCommon(CraftMetaItem that) {
//Magma start
CompoundTag forgeCaps = that.getForgeCaps();
boolean ret;
if (this.getForgeCaps() == null)
if (this.forgeCaps == null)
ret = forgeCaps != null && forgeCaps.size() != 0;
else
ret = forgeCaps == null ? this.getForgeCaps().size() != 0 : !this.getForgeCaps().equals(forgeCaps);
ret = forgeCaps == null ? this.forgeCaps.size() != 0 : !this.forgeCaps.equals(forgeCaps);
if (ret) return false;
//Magma end
return ((this.hasDisplayName() ? that.hasDisplayName() && this.displayName.equals(that.displayName) : !that.hasDisplayName()))
Expand Down Expand Up @@ -1310,11 +1310,11 @@ public CraftMetaItem clone() {
clone.version = this.version;

//Magma start
if (this.getUnhandledTags() != null)
clone.setUnhandledTags(getUnhandledTags());
if (this.unhandledTags != null)
clone.getUnhandledTags().putAll(this.unhandledTags);

if (this.getForgeCaps() != null)
clone.setForgeCaps(this.getForgeCaps().copy());
if (this.forgeCaps != null)
clone.setForgeCaps(this.forgeCaps.copy());
//Magma end

return clone;
Expand Down

0 comments on commit 77c18b1

Please sign in to comment.