Skip to content

Commit

Permalink
I'm actually going to die
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Aug 7, 2021
1 parent bbc38ae commit 2241a5c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
import java.lang.reflect.Field;

public class FastItemStackUtils {
private static final Field field;
private static final Field FIELD;

public static net.minecraft.server.v1_16_R3.ItemStack getNMSStack(@NotNull final ItemStack itemStack) {
if (!(itemStack instanceof CraftItemStack)) {
return CraftItemStack.asNMSCopy(itemStack);
} else {
try {
return (net.minecraft.server.v1_16_R3.ItemStack) field.get(itemStack);
net.minecraft.server.v1_16_R3.ItemStack nms = (net.minecraft.server.v1_16_R3.ItemStack) FIELD.get(itemStack);
return nms == null ? CraftItemStack.asNMSCopy(itemStack) : nms;
} catch (ReflectiveOperationException e) {
e.printStackTrace();
return null;
Expand All @@ -37,6 +38,6 @@ public static net.minecraft.server.v1_16_R3.ItemStack getNMSStack(@NotNull final
assert temp != null;
Validate.notNull(temp, "Error occurred in initialization!");

field = temp;
FIELD = temp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@

@UtilityClass
public class FastItemStackUtils {
private static final Field field;
private static final Field FIELD;

public static net.minecraft.world.item.ItemStack getNMSStack(@NotNull final ItemStack itemStack) {
if (!(itemStack instanceof CraftItemStack)) {
return CraftItemStack.asNMSCopy(itemStack);
} else {
try {
return (net.minecraft.world.item.ItemStack) field.get(itemStack);
net.minecraft.world.item.ItemStack nms = (net.minecraft.world.item.ItemStack) FIELD.get(itemStack);
return nms == null ? CraftItemStack.asNMSCopy(itemStack) : nms;
} catch (ReflectiveOperationException e) {
e.printStackTrace();
return null;
Expand All @@ -39,6 +40,6 @@ public static net.minecraft.world.item.ItemStack getNMSStack(@NotNull final Item
assert temp != null;
Validate.notNull(temp, "Error occurred in initialization!");

field = temp;
FIELD = temp;
}
}

0 comments on commit 2241a5c

Please sign in to comment.