mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 16:19:03 +01:00
Better item validation
By: Thinkofdeath <thinkofdeath@spigotmc.org>
This commit is contained in:
parent
804b118219
commit
4a1b3a723a
1 changed files with 31 additions and 26 deletions
|
@ -40,7 +40,7 @@
|
||||||
import net.minecraft.world.level.saveddata.maps.MapId;
|
import net.minecraft.world.level.saveddata.maps.MapId;
|
||||||
import org.apache.commons.lang3.mutable.MutableBoolean;
|
import org.apache.commons.lang3.mutable.MutableBoolean;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
+
|
|
||||||
+// CraftBukkit start
|
+// CraftBukkit start
|
||||||
+import java.util.Map;
|
+import java.util.Map;
|
||||||
+import java.util.Objects;
|
+import java.util.Objects;
|
||||||
|
@ -71,7 +71,7 @@
|
||||||
+import org.bukkit.event.player.PlayerItemDamageEvent;
|
+import org.bukkit.event.player.PlayerItemDamageEvent;
|
||||||
+import org.bukkit.event.world.StructureGrowEvent;
|
+import org.bukkit.event.world.StructureGrowEvent;
|
||||||
+// CraftBukkit end
|
+// CraftBukkit end
|
||||||
|
+
|
||||||
public final class ItemStack implements DataComponentHolder {
|
public final class ItemStack implements DataComponentHolder {
|
||||||
|
|
||||||
private static final List<Component> OP_NBT_WARNING = List.of(Component.translatable("item.op_warning.line1").withStyle(ChatFormatting.RED, ChatFormatting.BOLD), Component.translatable("item.op_warning.line2").withStyle(ChatFormatting.RED), Component.translatable("item.op_warning.line3").withStyle(ChatFormatting.RED));
|
private static final List<Component> OP_NBT_WARNING = List.of(Component.translatable("item.op_warning.line1").withStyle(ChatFormatting.RED, ChatFormatting.BOLD), Component.translatable("item.op_warning.line2").withStyle(ChatFormatting.RED), Component.translatable("item.op_warning.line3").withStyle(ChatFormatting.RED));
|
||||||
|
@ -89,7 +89,7 @@
|
||||||
return instance.group(Item.CODEC.fieldOf("id").forGetter(ItemStack::getItemHolder), DataComponentPatch.CODEC.optionalFieldOf("components", DataComponentPatch.EMPTY).forGetter((itemstack) -> {
|
return instance.group(Item.CODEC.fieldOf("id").forGetter(ItemStack::getItemHolder), DataComponentPatch.CODEC.optionalFieldOf("components", DataComponentPatch.EMPTY).forGetter((itemstack) -> {
|
||||||
return itemstack.components.asPatch();
|
return itemstack.components.asPatch();
|
||||||
})).apply(instance, (holder, datacomponentpatch) -> {
|
})).apply(instance, (holder, datacomponentpatch) -> {
|
||||||
@@ -132,19 +161,25 @@
|
@@ -132,19 +161,29 @@
|
||||||
if (i <= 0) {
|
if (i <= 0) {
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
} else {
|
} else {
|
||||||
|
@ -115,11 +115,15 @@
|
||||||
} else {
|
} else {
|
||||||
registryfriendlybytebuf.writeVarInt(itemstack.getCount());
|
registryfriendlybytebuf.writeVarInt(itemstack.getCount());
|
||||||
- null.ITEM_STREAM_CODEC.encode(registryfriendlybytebuf, itemstack.getItemHolder());
|
- null.ITEM_STREAM_CODEC.encode(registryfriendlybytebuf, itemstack.getItemHolder());
|
||||||
|
+ // Spigot start - filter
|
||||||
|
+ itemstack = itemstack.copy();
|
||||||
|
+ CraftItemStack.setItemMeta(itemstack, CraftItemStack.getItemMeta(itemstack));
|
||||||
|
+ // Spigot end
|
||||||
+ ITEM_STREAM_CODEC.encode(registryfriendlybytebuf, itemstack.getItemHolder()); // CraftBukkit - decompile error
|
+ ITEM_STREAM_CODEC.encode(registryfriendlybytebuf, itemstack.getItemHolder()); // CraftBukkit - decompile error
|
||||||
DataComponentPatch.STREAM_CODEC.encode(registryfriendlybytebuf, itemstack.components.asPatch());
|
DataComponentPatch.STREAM_CODEC.encode(registryfriendlybytebuf, itemstack.components.asPatch());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -187,7 +222,7 @@
|
@@ -187,7 +226,7 @@
|
||||||
|
|
||||||
return dataresult.isError() ? dataresult.map((unit) -> {
|
return dataresult.isError() ? dataresult.map((unit) -> {
|
||||||
return stack;
|
return stack;
|
||||||
|
@ -128,7 +132,7 @@
|
||||||
int i = stack.getCount();
|
int i = stack.getCount();
|
||||||
|
|
||||||
return "Item stack with stack size of " + i + " was larger than maximum: " + stack.getMaxStackSize();
|
return "Item stack with stack size of " + i + " was larger than maximum: " + stack.getMaxStackSize();
|
||||||
@@ -294,8 +329,9 @@
|
@@ -294,8 +333,9 @@
|
||||||
j = itemstack.getMaxStackSize();
|
j = itemstack.getMaxStackSize();
|
||||||
} while (i <= j);
|
} while (i <= j);
|
||||||
|
|
||||||
|
@ -139,7 +143,7 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -370,32 +406,190 @@
|
@@ -370,32 +410,190 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public InteractionResult useOn(UseOnContext context) {
|
public InteractionResult useOn(UseOnContext context) {
|
||||||
|
@ -335,7 +339,7 @@
|
||||||
ItemStack itemstack = this.copy();
|
ItemStack itemstack = this.copy();
|
||||||
boolean flag = this.getUseDuration(user) <= 0;
|
boolean flag = this.getUseDuration(user) <= 0;
|
||||||
InteractionResult enuminteractionresult = this.getItem().use(world, user, hand);
|
InteractionResult enuminteractionresult = this.getItem().use(world, user, hand);
|
||||||
@@ -492,7 +686,22 @@
|
@@ -492,7 +690,22 @@
|
||||||
|
|
||||||
public void hurtAndBreak(int amount, ServerLevel world, @Nullable ServerPlayer player, Consumer<Item> breakCallback) {
|
public void hurtAndBreak(int amount, ServerLevel world, @Nullable ServerPlayer player, Consumer<Item> breakCallback) {
|
||||||
int j = this.processDurabilityChange(amount, world, player);
|
int j = this.processDurabilityChange(amount, world, player);
|
||||||
|
@ -358,7 +362,7 @@
|
||||||
if (j != 0) {
|
if (j != 0) {
|
||||||
this.applyDamage(this.getDamageValue() + j, player, breakCallback);
|
this.applyDamage(this.getDamageValue() + j, player, breakCallback);
|
||||||
}
|
}
|
||||||
@@ -511,6 +720,11 @@
|
@@ -511,6 +724,11 @@
|
||||||
this.setDamageValue(damage);
|
this.setDamageValue(damage);
|
||||||
if (this.isBroken()) {
|
if (this.isBroken()) {
|
||||||
Item item = this.getItem();
|
Item item = this.getItem();
|
||||||
|
@ -370,7 +374,7 @@
|
||||||
|
|
||||||
this.shrink(1);
|
this.shrink(1);
|
||||||
breakCallback.accept(item);
|
breakCallback.accept(item);
|
||||||
@@ -518,7 +732,7 @@
|
@@ -518,7 +736,7 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,7 +383,7 @@
|
||||||
if (player instanceof ServerPlayer entityplayer) {
|
if (player instanceof ServerPlayer entityplayer) {
|
||||||
int j = this.processDurabilityChange(amount, entityplayer.serverLevel(), entityplayer);
|
int j = this.processDurabilityChange(amount, entityplayer.serverLevel(), entityplayer);
|
||||||
|
|
||||||
@@ -580,11 +794,11 @@
|
@@ -580,11 +798,11 @@
|
||||||
return this.getItem().getBarColor(this);
|
return this.getItem().getBarColor(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,7 +397,7 @@
|
||||||
return this.getItem().overrideOtherStackedOnMe(this, stack, slot, clickType, player, cursorStackReference);
|
return this.getItem().overrideOtherStackedOnMe(this, stack, slot, clickType, player, cursorStackReference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -592,8 +806,8 @@
|
@@ -592,8 +810,8 @@
|
||||||
Item item = this.getItem();
|
Item item = this.getItem();
|
||||||
|
|
||||||
if (item.hurtEnemy(this, target, user)) {
|
if (item.hurtEnemy(this, target, user)) {
|
||||||
|
@ -404,7 +408,7 @@
|
||||||
|
|
||||||
entityhuman.awardStat(Stats.ITEM_USED.get(item));
|
entityhuman.awardStat(Stats.ITEM_USED.get(item));
|
||||||
}
|
}
|
||||||
@@ -608,7 +822,7 @@
|
@@ -608,7 +826,7 @@
|
||||||
this.getItem().postHurtEnemy(this, target, user);
|
this.getItem().postHurtEnemy(this, target, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,7 +417,7 @@
|
||||||
Item item = this.getItem();
|
Item item = this.getItem();
|
||||||
|
|
||||||
if (item.mineBlock(this, world, state, pos, miner)) {
|
if (item.mineBlock(this, world, state, pos, miner)) {
|
||||||
@@ -617,11 +831,11 @@
|
@@ -617,11 +835,11 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,7 +431,7 @@
|
||||||
return this.getItem().interactLivingEntity(this, user, entity, hand);
|
return this.getItem().interactLivingEntity(this, user, entity, hand);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -736,7 +950,7 @@
|
@@ -736,7 +954,7 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,20 +440,21 @@
|
||||||
player.awardStat(Stats.ITEM_CRAFTED.get(this.getItem()), amount);
|
player.awardStat(Stats.ITEM_CRAFTED.get(this.getItem()), amount);
|
||||||
this.getItem().onCraftedBy(this, world, player);
|
this.getItem().onCraftedBy(this, world, player);
|
||||||
}
|
}
|
||||||
@@ -770,6 +984,12 @@
|
@@ -768,7 +986,13 @@
|
||||||
return this.getItem().useOnRelease(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public boolean useOnRelease() {
|
||||||
|
return this.getItem().useOnRelease(this);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
+ public void restorePatch(DataComponentPatch datacomponentpatch) {
|
+ public void restorePatch(DataComponentPatch datacomponentpatch) {
|
||||||
+ this.components.restorePatch(datacomponentpatch);
|
+ this.components.restorePatch(datacomponentpatch);
|
||||||
+ }
|
}
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
+
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public <T> T set(DataComponentType<? super T> type, @Nullable T value) {
|
public <T> T set(DataComponentType<? super T> type, @Nullable T value) {
|
||||||
return this.components.set(type, value);
|
@@ -858,7 +1082,7 @@
|
||||||
@@ -858,7 +1078,7 @@
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends TooltipProvider> void addToTooltip(DataComponentType<T> componentType, Item.TooltipContext context, Consumer<Component> textConsumer, TooltipFlag type) {
|
private <T extends TooltipProvider> void addToTooltip(DataComponentType<T> componentType, Item.TooltipContext context, Consumer<Component> textConsumer, TooltipFlag type) {
|
||||||
|
@ -458,7 +463,7 @@
|
||||||
|
|
||||||
if (t0 != null) {
|
if (t0 != null) {
|
||||||
t0.addToTooltip(context, textConsumer, type);
|
t0.addToTooltip(context, textConsumer, type);
|
||||||
@@ -866,7 +1086,7 @@
|
@@ -866,7 +1090,7 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -467,7 +472,7 @@
|
||||||
boolean flag = this.getItem().shouldPrintOpWarning(this, player);
|
boolean flag = this.getItem().shouldPrintOpWarning(this, player);
|
||||||
|
|
||||||
if (!type.isCreative() && this.has(DataComponents.HIDE_TOOLTIP)) {
|
if (!type.isCreative() && this.has(DataComponents.HIDE_TOOLTIP)) {
|
||||||
@@ -941,7 +1161,7 @@
|
@@ -941,7 +1165,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -476,7 +481,7 @@
|
||||||
ItemAttributeModifiers itemattributemodifiers = (ItemAttributeModifiers) this.getOrDefault(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY);
|
ItemAttributeModifiers itemattributemodifiers = (ItemAttributeModifiers) this.getOrDefault(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY);
|
||||||
|
|
||||||
if (itemattributemodifiers.showInTooltip()) {
|
if (itemattributemodifiers.showInTooltip()) {
|
||||||
@@ -966,7 +1186,7 @@
|
@@ -966,7 +1190,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,7 +490,7 @@
|
||||||
double d0 = modifier.amount();
|
double d0 = modifier.amount();
|
||||||
boolean flag = false;
|
boolean flag = false;
|
||||||
|
|
||||||
@@ -1091,6 +1311,13 @@
|
@@ -1091,6 +1315,13 @@
|
||||||
EnchantmentHelper.forEachModifier(this, slot, attributeModifierConsumer);
|
EnchantmentHelper.forEachModifier(this, slot, attributeModifierConsumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,7 +504,7 @@
|
||||||
public Component getDisplayName() {
|
public Component getDisplayName() {
|
||||||
MutableComponent ichatmutablecomponent = Component.empty().append(this.getHoverName());
|
MutableComponent ichatmutablecomponent = Component.empty().append(this.getHoverName());
|
||||||
|
|
||||||
@@ -1153,7 +1380,7 @@
|
@@ -1153,7 +1384,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public void consume(int amount, @Nullable LivingEntity entity) {
|
public void consume(int amount, @Nullable LivingEntity entity) {
|
||||||
|
|
Loading…
Reference in a new issue