mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-30 04:19:27 +00:00
细微修正
This commit is contained in:
@@ -8,6 +8,7 @@ import net.momirealms.craftengine.bukkit.util.ItemTags;
|
||||
import net.momirealms.craftengine.bukkit.util.KeyUtils;
|
||||
import net.momirealms.craftengine.core.item.ExternalItemSource;
|
||||
import net.momirealms.craftengine.core.item.ItemFactory;
|
||||
import net.momirealms.craftengine.core.item.ItemKeys;
|
||||
import net.momirealms.craftengine.core.item.ItemWrapper;
|
||||
import net.momirealms.craftengine.core.item.data.JukeboxPlayable;
|
||||
import net.momirealms.craftengine.core.item.setting.EquipmentData;
|
||||
@@ -84,14 +85,14 @@ public abstract class BukkitItemFactory<W extends ItemWrapper<ItemStack>> extend
|
||||
@Override
|
||||
protected Key vanillaId(W item) {
|
||||
Object i = FastNMS.INSTANCE.method$ItemStack$getItem(item.getLiteralObject());
|
||||
if (i == null) return null;
|
||||
if (i == null) return ItemKeys.AIR;
|
||||
return KeyUtils.resourceLocationToKey(FastNMS.INSTANCE.method$Registry$getKey(MBuiltInRegistries.ITEM, i));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Key id(W item) {
|
||||
if (FastNMS.INSTANCE.method$ItemStack$isEmpty(item.getLiteralObject())) {
|
||||
return null;
|
||||
return ItemKeys.AIR;
|
||||
}
|
||||
return customId(item).orElse(vanillaId(item));
|
||||
}
|
||||
@@ -118,14 +119,12 @@ public abstract class BukkitItemFactory<W extends ItemWrapper<ItemStack>> extend
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean is(W item, Key itemTag) {
|
||||
protected boolean hasItemTag(W item, Key itemTag) {
|
||||
Object literalObject = item.getLiteralObject();
|
||||
Object tag = ItemTags.getOrCreate(itemTag);
|
||||
return FastNMS.INSTANCE.method$ItemStack$is(literalObject, tag);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void setJavaComponent(W item, Object type, Object value) {
|
||||
throw new UnsupportedOperationException("This feature is only available on 1.20.5+");
|
||||
|
||||
@@ -368,7 +368,7 @@ public class RecipeEventListener implements Listener {
|
||||
repairItem = item;
|
||||
break;
|
||||
}
|
||||
if (wrappedFirst.is(tag)) {
|
||||
if (wrappedFirst.hasItemTag(tag)) {
|
||||
repairItem = item;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -345,7 +345,7 @@ public class RecipeInjector {
|
||||
|
||||
private static final Predicate<Item<ItemStack>> IS_DYEABLE =
|
||||
VersionHelper.isOrAbove1_20_5() ?
|
||||
(item -> item.is(ItemTags.DYEABLE)) :
|
||||
(item -> item.hasItemTag(ItemTags.DYEABLE)) :
|
||||
(item -> {
|
||||
Object itemLike = FastNMS.INSTANCE.method$ItemStack$getItem(item.getLiteralObject());
|
||||
return CoreReflections.clazz$DyeableLeatherItem.isInstance(itemLike);
|
||||
|
||||
@@ -638,7 +638,7 @@ public class BukkitServerPlayer extends Player {
|
||||
if (canInstabuild() && (itemMaterial == Material.DEBUG_STICK
|
||||
|| itemMaterial == Material.TRIDENT
|
||||
|| (VersionHelper.isOrAbove1_20_5() && itemMaterial == MaterialUtils.MACE)
|
||||
|| item.is(ItemTags.SWORDS))) {
|
||||
|| item.hasItemTag(ItemTags.SWORDS))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class InteractUtils {
|
||||
private InteractUtils() {}
|
||||
|
||||
static {
|
||||
registerInteraction(BlockKeys.NOTE_BLOCK, (player, item, blockState, result) -> result.getDirection() != Direction.UP || !item.is(NOTE_BLOCK_TOP_INSTRUMENTS));
|
||||
registerInteraction(BlockKeys.NOTE_BLOCK, (player, item, blockState, result) -> result.getDirection() != Direction.UP || !item.hasItemTag(NOTE_BLOCK_TOP_INSTRUMENTS));
|
||||
registerInteraction(BlockKeys.CAKE, (player, item, blockState, result) -> !canEat(player, false));
|
||||
registerInteraction(BlockKeys.CANDLE_CAKE, (player, item, blockState, result) -> !canEat(player, false));
|
||||
registerInteraction(BlockKeys.WHITE_CANDLE_CAKE, (player, item, blockState, result) -> !canEat(player, false));
|
||||
@@ -409,14 +409,14 @@ public class InteractUtils {
|
||||
registerEntityInteraction(EntityTypeKeys.BAMBOO_RAFT, (player, entity, item) -> !player.isSneaking());
|
||||
registerEntityInteraction(EntityTypeKeys.MINECART, (player, entity, item) -> !player.isSneaking());
|
||||
registerEntityInteraction(EntityTypeKeys.PARROT, (player, entity, item) -> {
|
||||
if (item != null && item.is(Key.of("parrot_poisonous_food"))) return true;
|
||||
if (item != null && item.hasItemTag(Key.of("parrot_poisonous_food"))) return true;
|
||||
return canFeed(entity, item) || isPetOwner(player, entity);
|
||||
});
|
||||
registerEntityInteraction(EntityTypeKeys.HAPPY_GHAST, (player, entity, item) -> {
|
||||
if (item != null && item.vanillaId().equals(ItemKeys.HARNESS)) return true;
|
||||
if (entity instanceof HappyGhast happyGhast && !player.isSneaking()) {
|
||||
ItemStack bodyItem = happyGhast.getEquipment().getItem(EquipmentSlot.BODY);
|
||||
return BukkitItemManager.instance().wrap(bodyItem).is(Key.of("harnesses"));
|
||||
return BukkitItemManager.instance().wrap(bodyItem).hasItemTag(Key.of("harnesses"));
|
||||
}
|
||||
return canFeed(entity, item);
|
||||
});
|
||||
@@ -499,7 +499,7 @@ public class InteractUtils {
|
||||
}
|
||||
|
||||
private static boolean canFeed(Entity entity, Item<ItemStack> item) {
|
||||
return entity instanceof Animals && item.is(Key.of(EntityUtils.getEntityType(entity).value() + "_food"));
|
||||
return entity instanceof Animals && item.hasItemTag(Key.of(EntityUtils.getEntityType(entity).value() + "_food"));
|
||||
}
|
||||
|
||||
private static boolean hasSaddle(Player player, Entity entity) {
|
||||
|
||||
Reference in New Issue
Block a user