9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-27 19:09:08 +00:00

Merge pull request #86 from Xiao-MoMi/dev

0.0.44
This commit is contained in:
XiaoMoMi
2025-04-05 14:49:57 +08:00
committed by GitHub
45 changed files with 981 additions and 295 deletions

View File

@@ -2,7 +2,7 @@ config=${config_version}
builder=${builder}
supported-languages=${supported_languages}
lang-version=${lang_version}
latest-version=${latest_minecraft_version}
latest-version=${latest_supported_version}
asm=${asm_version}
asm-commons=${asm_commons_version}
jar-relocator=${jar_relocator_version}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -2411,6 +2411,25 @@
],
"subtitle": "subtitles.block.bubble_column.whirlpool_inside"
},
"block.cactus_flower.break": {
"sounds": [
"block/cactus_flower/break1",
"block/cactus_flower/break2",
"block/cactus_flower/break3",
"block/cactus_flower/break4",
"block/cactus_flower/break5"
],
"subtitle": "subtitles.block.generic.break"
},
"block.cactus_flower.place": {
"sounds": [
"block/cactus_flower/place1",
"block/cactus_flower/place2",
"block/cactus_flower/place3",
"block/cactus_flower/place4"
],
"subtitle": "subtitles.block.generic.place"
},
"block.cake.add_candle": {
"sounds": [
"block/cake/add_candle1",
@@ -4160,6 +4179,59 @@
],
"subtitle": "subtitles.block.generic.break"
},
"block.deadbush.idle": {
"sounds": [
{
"name": "block/deadbush/sandblock_version/bushrustle1",
"volume": 4.0
},
{
"name": "block/deadbush/sandblock_version/bushrustle2",
"volume": 4.0
},
{
"name": "block/deadbush/sandblock_version/bushrustle3",
"volume": 4.0
},
{
"name": "block/deadbush/sandblock_version/creakysand1",
"volume": 4.0
},
{
"name": "block/deadbush/sandblock_version/crickets",
"volume": 4.0,
"weight": 3
},
{
"name": "block/deadbush/sandblock_version/howlingwind1",
"volume": 4.0
},
{
"name": "block/deadbush/sandblock_version/insect1",
"volume": 4.0
},
{
"name": "block/deadbush/sandblock_version/leaves",
"volume": 4.0
},
{
"name": "block/deadbush/sandblock_version/movingsand1",
"volume": 4.0,
"weight": 2
},
{
"name": "block/deadbush/sandblock_version/movingsand2",
"volume": 4.0,
"weight": 2
},
{
"name": "block/deadbush/sandblock_version/movingsand3",
"volume": 4.0,
"weight": 2
}
],
"subtitle": "subtitles.block.deadbush.idle"
},
"block.decorated_pot.break": {
"sounds": [
"block/decorated_pot/break1",
@@ -4757,6 +4829,59 @@
],
"subtitle": "subtitles.block.fire.extinguish"
},
"block.firefly_bush.idle": {
"sounds": [
{
"name": "block/firefly_bush/firefly_bush1",
"volume": 4.0
},
{
"name": "block/firefly_bush/firefly_bush2",
"volume": 4.0
},
{
"name": "block/firefly_bush/firefly_bush3",
"volume": 4.0
},
{
"name": "block/firefly_bush/firefly_bush4",
"volume": 4.0
},
{
"name": "block/firefly_bush/firefly_bush5",
"volume": 4.0
},
{
"name": "block/firefly_bush/firefly_bush6",
"volume": 4.0
},
{
"name": "block/firefly_bush/firefly_bush7",
"volume": 4.0,
"weight": 2
},
{
"name": "block/firefly_bush/firefly_bush8",
"volume": 4.0,
"weight": 2
},
{
"name": "block/firefly_bush/firefly_bush9",
"volume": 4.0,
"weight": 2
},
{
"name": "block/firefly_bush/firefly_bush10",
"volume": 4.0,
"weight": 2
},
{
"name": "block/firefly_bush/firefly_bush11",
"volume": 4.0
}
],
"subtitle": "subtitles.block.firefly_bush.idle"
},
"block.flowering_azalea.break": {
"sounds": [
"block/azalea/break1",
@@ -5647,6 +5772,59 @@
],
"subtitle": "subtitles.block.generic.footsteps"
},
"block.iron.break": {
"sounds": [
"block/iron/break1",
"block/iron/break2",
"block/iron/break3",
"block/iron/break4",
"block/iron/break5",
"block/iron/break6",
"block/iron/break7",
"block/iron/break8"
],
"subtitle": "subtitles.block.generic.break"
},
"block.iron.fall": {
"sounds": [
"block/iron/step1",
"block/iron/step2",
"block/iron/step3",
"block/iron/step4"
],
"subtitle": "subtitles.block.generic.fall"
},
"block.iron.hit": {
"sounds": [
"block/iron/step1",
"block/iron/step2",
"block/iron/step3",
"block/iron/step4"
],
"subtitle": "subtitles.block.generic.hit"
},
"block.iron.place": {
"sounds": [
"block/iron/break1",
"block/iron/break2",
"block/iron/break3",
"block/iron/break4",
"block/iron/break5",
"block/iron/break6",
"block/iron/break7",
"block/iron/break8"
],
"subtitle": "subtitles.block.generic.place"
},
"block.iron.step": {
"sounds": [
"block/iron/step1",
"block/iron/step2",
"block/iron/step3",
"block/iron/step4"
],
"subtitle": "subtitles.block.generic.footsteps"
},
"block.iron_door.close": {
"sounds": [
{
@@ -5916,6 +6094,59 @@
],
"subtitle": "subtitles.block.lava.ambient"
},
"block.leaf_litter.break": {
"sounds": [
"block/leaf_litter/break1",
"block/leaf_litter/break2",
"block/leaf_litter/break3",
"block/leaf_litter/break4",
"block/leaf_litter/break5"
],
"subtitle": "subtitles.block.generic.break"
},
"block.leaf_litter.fall": {
"sounds": [
"block/leaf_litter/step1",
"block/leaf_litter/step2",
"block/leaf_litter/step3",
"block/leaf_litter/step4",
"block/leaf_litter/step5",
"block/leaf_litter/step6"
],
"subtitle": "subtitles.block.generic.fall"
},
"block.leaf_litter.hit": {
"sounds": [
"block/leaf_litter/step1",
"block/leaf_litter/step2",
"block/leaf_litter/step3",
"block/leaf_litter/step4",
"block/leaf_litter/step5",
"block/leaf_litter/step6"
],
"subtitle": "subtitles.block.generic.hit"
},
"block.leaf_litter.place": {
"sounds": [
"block/leaf_litter/place1",
"block/leaf_litter/place2",
"block/leaf_litter/place3",
"block/leaf_litter/place4",
"block/leaf_litter/place5"
],
"subtitle": "subtitles.block.generic.place"
},
"block.leaf_litter.step": {
"sounds": [
"block/leaf_litter/step1",
"block/leaf_litter/step2",
"block/leaf_litter/step3",
"block/leaf_litter/step4",
"block/leaf_litter/step5",
"block/leaf_litter/step6"
],
"subtitle": "subtitles.block.generic.footsteps"
},
"block.lever.click": {
"sounds": [
"random/click"
@@ -8934,6 +9165,109 @@
],
"subtitle": "subtitles.block.generic.hit"
},
"block.sand.idle": {
"sounds": [
{
"name": "block/sand/sand1",
"volume": 4.0,
"weight": 2
},
{
"name": "block/sand/sand2",
"volume": 4.0,
"weight": 2
},
{
"name": "block/sand/sand3",
"volume": 4.0,
"weight": 2
},
{
"name": "block/sand/sand4",
"volume": 4.0
},
{
"name": "block/sand/sand5",
"volume": 4.0,
"weight": 2
},
{
"name": "block/sand/sand6",
"volume": 4.0,
"weight": 2
},
{
"name": "block/sand/sand7",
"volume": 4.0
},
{
"name": "block/sand/sand8",
"volume": 4.0
},
{
"name": "block/sand/sand9",
"volume": 4.0
},
{
"name": "block/sand/sand10",
"volume": 4.0
},
{
"name": "block/sand/sand10",
"volume": 4.0,
"weight": 2
},
{
"name": "block/sand/sand11",
"volume": 4.0
},
{
"name": "block/sand/sand12",
"volume": 4.0
},
{
"name": "block/sand/sand12",
"volume": 4.0
},
{
"name": "block/sand/sand13",
"volume": 4.0
},
{
"name": "block/sand/sand14",
"volume": 4.0
},
{
"name": "block/sand/sand15",
"volume": 4.0
},
{
"name": "block/sand/sand16",
"volume": 4.0
},
{
"name": "block/sand/sand17",
"volume": 4.0
},
{
"name": "block/sand/sand18",
"volume": 4.0
},
{
"name": "block/sand/sand19",
"volume": 4.0
},
{
"name": "block/sand/sand20",
"volume": 4.0
},
{
"name": "block/sand/sand21",
"volume": 4.0
}
],
"subtitle": "subtitles.block.sand.idle"
},
"block.sand.place": {
"sounds": [
"dig/sand1",
@@ -8953,6 +9287,23 @@
],
"subtitle": "subtitles.block.generic.footsteps"
},
"block.sand.wind": {
"sounds": [
"block/sand/wind1",
"block/sand/wind2",
"block/sand/wind3",
"block/sand/wind4",
"block/sand/wind5",
"block/sand/wind6",
"block/sand/wind7",
"block/sand/wind8",
"block/sand/wind9",
"block/sand/wind10",
"block/sand/wind11",
"block/sand/wind12"
],
"subtitle": "subtitles.block.sand.wind"
},
"block.scaffolding.break": {
"sounds": [
{
@@ -12699,7 +13050,8 @@
{
"name": "entity.horse.saddle",
"pitch": 0.8,
"type": "event"
"type": "event",
"volume": 0.5
}
],
"subtitle": "subtitles.entity.camel.saddle"
@@ -15189,7 +15541,10 @@
},
"entity.horse.saddle": {
"sounds": [
"mob/horse/leather"
{
"name": "mob/horse/leather",
"volume": 0.5
}
],
"subtitle": "subtitles.entity.horse.saddle"
},
@@ -16677,7 +17032,10 @@
},
"entity.pig.saddle": {
"sounds": [
"mob/horse/leather"
{
"name": "mob/horse/leather",
"volume": 0.5
}
],
"subtitle": "subtitles.entity.pig.saddle"
},
@@ -18498,7 +18856,10 @@
},
"entity.strider.saddle": {
"sounds": [
"mob/horse/leather"
{
"name": "mob/horse/leather",
"volume": 0.5
}
]
},
"entity.strider.step": {
@@ -19541,45 +19902,39 @@
},
"entity.wolf.ambient": {
"sounds": [
"mob/wolf/bark1",
"mob/wolf/bark2",
"mob/wolf/bark3"
"mob/wolf/classic/bark1",
"mob/wolf/classic/bark2",
"mob/wolf/classic/bark3"
],
"subtitle": "subtitles.entity.wolf.ambient"
"subtitle": "subtitles.entity.wolf.bark"
},
"entity.wolf.death": {
"sounds": [
"mob/wolf/death"
"mob/wolf/classic/death"
],
"subtitle": "subtitles.entity.wolf.death"
},
"entity.wolf.growl": {
"sounds": [
"mob/wolf/growl1",
"mob/wolf/growl2",
"mob/wolf/growl3"
"mob/wolf/classic/growl1",
"mob/wolf/classic/growl2",
"mob/wolf/classic/growl3"
],
"subtitle": "subtitles.entity.wolf.growl"
},
"entity.wolf.howl": {
"sounds": [
"mob/wolf/howl1",
"mob/wolf/howl2"
]
},
"entity.wolf.hurt": {
"sounds": [
"mob/wolf/hurt1",
"mob/wolf/hurt2",
"mob/wolf/hurt3"
"mob/wolf/classic/hurt1",
"mob/wolf/classic/hurt2",
"mob/wolf/classic/hurt3"
],
"subtitle": "subtitles.entity.wolf.hurt"
},
"entity.wolf.pant": {
"sounds": [
"mob/wolf/panting"
"mob/wolf/classic/panting"
],
"subtitle": "subtitles.entity.wolf.ambient"
"subtitle": "subtitles.entity.wolf.pant"
},
"entity.wolf.shake": {
"sounds": [
@@ -19599,9 +19954,267 @@
},
"entity.wolf.whine": {
"sounds": [
"mob/wolf/whine"
"mob/wolf/classic/whine"
],
"subtitle": "subtitles.entity.wolf.ambient"
"subtitle": "subtitles.entity.wolf.whine"
},
"entity.wolf_angry.ambient": {
"sounds": [
"mob/wolf/angry/bark1",
"mob/wolf/angry/bark2",
"mob/wolf/angry/bark3"
],
"subtitle": "subtitles.entity.wolf.bark"
},
"entity.wolf_angry.death": {
"sounds": [
"mob/wolf/angry/death"
],
"subtitle": "subtitles.entity.wolf.death"
},
"entity.wolf_angry.growl": {
"sounds": [
"mob/wolf/angry/growl1",
"mob/wolf/angry/growl2",
"mob/wolf/angry/growl3"
],
"subtitle": "subtitles.entity.wolf.growl"
},
"entity.wolf_angry.hurt": {
"sounds": [
"mob/wolf/angry/hurt1",
"mob/wolf/angry/hurt2",
"mob/wolf/angry/hurt3"
],
"subtitle": "subtitles.entity.wolf.hurt"
},
"entity.wolf_angry.pant": {
"sounds": [
"mob/wolf/angry/panting"
],
"subtitle": "subtitles.entity.wolf.pant"
},
"entity.wolf_angry.whine": {
"sounds": [
"mob/wolf/angry/whine"
],
"subtitle": "subtitles.entity.wolf.whine"
},
"entity.wolf_big.ambient": {
"sounds": [
"mob/wolf/big/bark1",
"mob/wolf/big/bark2",
"mob/wolf/big/bark3"
],
"subtitle": "subtitles.entity.wolf.bark"
},
"entity.wolf_big.death": {
"sounds": [
"mob/wolf/big/death"
],
"subtitle": "subtitles.entity.wolf.death"
},
"entity.wolf_big.growl": {
"sounds": [
"mob/wolf/big/growl1",
"mob/wolf/big/growl2",
"mob/wolf/big/growl3"
],
"subtitle": "subtitles.entity.wolf.growl"
},
"entity.wolf_big.hurt": {
"sounds": [
"mob/wolf/big/hurt1",
"mob/wolf/big/hurt2",
"mob/wolf/big/hurt3"
],
"subtitle": "subtitles.entity.wolf.hurt"
},
"entity.wolf_big.pant": {
"sounds": [
"mob/wolf/big/panting"
],
"subtitle": "subtitles.entity.wolf.pant"
},
"entity.wolf_big.whine": {
"sounds": [
"mob/wolf/big/whine"
],
"subtitle": "subtitles.entity.wolf.whine"
},
"entity.wolf_cute.ambient": {
"sounds": [
"mob/wolf/cute/bark1",
"mob/wolf/cute/bark2",
"mob/wolf/cute/bark3"
],
"subtitle": "subtitles.entity.wolf.bark"
},
"entity.wolf_cute.death": {
"sounds": [
"mob/wolf/cute/death"
],
"subtitle": "subtitles.entity.wolf.death"
},
"entity.wolf_cute.growl": {
"sounds": [
"mob/wolf/cute/growl1",
"mob/wolf/cute/growl2",
"mob/wolf/cute/growl3"
],
"subtitle": "subtitles.entity.wolf.growl"
},
"entity.wolf_cute.hurt": {
"sounds": [
"mob/wolf/cute/hurt1",
"mob/wolf/cute/hurt2",
"mob/wolf/cute/hurt3"
],
"subtitle": "subtitles.entity.wolf.hurt"
},
"entity.wolf_cute.pant": {
"sounds": [
"mob/wolf/cute/panting"
],
"subtitle": "subtitles.entity.wolf.pant"
},
"entity.wolf_cute.whine": {
"sounds": [
"mob/wolf/cute/whine"
],
"subtitle": "subtitles.entity.wolf.whine"
},
"entity.wolf_grumpy.ambient": {
"sounds": [
"mob/wolf/grumpy/bark1",
"mob/wolf/grumpy/bark2",
"mob/wolf/grumpy/bark3"
],
"subtitle": "subtitles.entity.wolf.bark"
},
"entity.wolf_grumpy.death": {
"sounds": [
"mob/wolf/grumpy/death"
],
"subtitle": "subtitles.entity.wolf.death"
},
"entity.wolf_grumpy.growl": {
"sounds": [
"mob/wolf/grumpy/growl1",
"mob/wolf/grumpy/growl2",
"mob/wolf/grumpy/growl3"
],
"subtitle": "subtitles.entity.wolf.growl"
},
"entity.wolf_grumpy.hurt": {
"sounds": [
"mob/wolf/grumpy/hurt1",
"mob/wolf/grumpy/hurt2",
"mob/wolf/grumpy/hurt3"
],
"subtitle": "subtitles.entity.wolf.hurt"
},
"entity.wolf_grumpy.pant": {
"sounds": [
"mob/wolf/grumpy/panting"
],
"subtitle": "subtitles.entity.wolf.pant"
},
"entity.wolf_grumpy.whine": {
"sounds": [
"mob/wolf/grumpy/whine"
],
"subtitle": "subtitles.entity.wolf.whine"
},
"entity.wolf_puglin.ambient": {
"sounds": [
"mob/wolf/puglin/bark1",
"mob/wolf/puglin/bark2",
"mob/wolf/puglin/bark3"
],
"subtitle": "subtitles.entity.wolf.bark"
},
"entity.wolf_puglin.death": {
"sounds": [
"mob/wolf/puglin/death"
],
"subtitle": "subtitles.entity.wolf.death"
},
"entity.wolf_puglin.growl": {
"sounds": [
"mob/wolf/puglin/growl1",
"mob/wolf/puglin/growl2",
"mob/wolf/puglin/growl3"
],
"subtitle": "subtitles.entity.wolf.growl"
},
"entity.wolf_puglin.hurt": {
"sounds": [
"mob/wolf/puglin/hurt1",
"mob/wolf/puglin/hurt2",
"mob/wolf/puglin/hurt3"
],
"subtitle": "subtitles.entity.wolf.hurt"
},
"entity.wolf_puglin.pant": {
"sounds": [
"mob/wolf/puglin/panting"
],
"subtitle": "subtitles.entity.wolf.pant"
},
"entity.wolf_puglin.whine": {
"sounds": [
"mob/wolf/puglin/whine"
],
"subtitle": "subtitles.entity.wolf.whine"
},
"entity.wolf_sad.ambient": {
"sounds": [
"mob/wolf/sad/bark1",
"mob/wolf/sad/bark2",
"mob/wolf/sad/bark3"
],
"subtitle": "subtitles.entity.wolf.bark"
},
"entity.wolf_sad.death": {
"sounds": [
"mob/wolf/sad/death"
],
"subtitle": "subtitles.entity.wolf.death"
},
"entity.wolf_sad.growl": {
"sounds": [
"mob/wolf/sad/growl1",
"mob/wolf/sad/growl2",
"mob/wolf/sad/growl3"
],
"subtitle": "subtitles.entity.wolf.growl"
},
"entity.wolf_sad.hurt": {
"sounds": [
"mob/wolf/sad/hurt1",
"mob/wolf/sad/hurt2",
"mob/wolf/sad/hurt3"
],
"subtitle": "subtitles.entity.wolf.hurt"
},
"entity.wolf_sad.pant": {
"sounds": [
"mob/wolf/sad/panting"
],
"subtitle": "subtitles.entity.wolf.pant"
},
"entity.wolf_sad.whine": {
"sounds": [
"mob/wolf/sad/whine"
],
"subtitle": "subtitles.entity.wolf.whine"
},
"entity.wolf_whine.whine": {
"sounds": [
"mob/wolf/puglin/whine"
],
"subtitle": "subtitles.entity.wolf.whine"
},
"entity.zoglin.ambient": {
"sounds": [

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -659,7 +659,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
private void recordVanillaNoteBlocks() {
try {
Object resourceLocation = Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, BlockKeys.NOTE_BLOCK.namespace(), BlockKeys.NOTE_BLOCK.value());
Object resourceLocation = KeyUtils.toResourceLocation(BlockKeys.NOTE_BLOCK);
Object block = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$BLOCK, resourceLocation);
Object stateDefinition = Reflections.field$Block$StateDefinition.get(block);
@SuppressWarnings("unchecked")

View File

@@ -2,6 +2,7 @@ package net.momirealms.craftengine.bukkit.block;
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
import net.momirealms.craftengine.bukkit.util.KeyUtils;
import net.momirealms.craftengine.bukkit.util.Reflections;
import net.momirealms.craftengine.bukkit.util.SoundUtils;
import net.momirealms.craftengine.core.block.*;
@@ -125,7 +126,7 @@ public class BukkitCustomBlock extends CustomBlock {
Object holder = BukkitCraftEngine.instance().blockManager().getMinecraftBlockHolder(state.customBlockState().registryId());
Set<Object> tags = new HashSet<>();
for (Key tag : settings.tags()) {
tags.add(Reflections.method$TagKey$create.invoke(null, Reflections.instance$Registries$BLOCK, Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, tag.namespace(), tag.value())));
tags.add(Reflections.method$TagKey$create.invoke(null, Reflections.instance$Registries$BLOCK, KeyUtils.toResourceLocation(tag)));
}
Reflections.field$Holder$Reference$tags.set(holder, tags);
// set burning properties

View File

@@ -6,8 +6,10 @@ import net.momirealms.craftengine.bukkit.item.behavior.BoneMealItemBehavior;
import net.momirealms.craftengine.bukkit.item.behavior.BucketItemBehavior;
import net.momirealms.craftengine.bukkit.item.behavior.WaterBucketItemBehavior;
import net.momirealms.craftengine.bukkit.item.factory.BukkitItemFactory;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
import net.momirealms.craftengine.bukkit.util.ItemUtils;
import net.momirealms.craftengine.bukkit.util.KeyUtils;
import net.momirealms.craftengine.bukkit.util.MaterialUtils;
import net.momirealms.craftengine.bukkit.util.Reflections;
import net.momirealms.craftengine.core.entity.player.Player;
@@ -579,22 +581,19 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
@SuppressWarnings("unchecked")
private void registerAllVanillaItems() {
try {
for (Material material : Registry.MATERIAL) {
if (material.getKey().namespace().equals("minecraft")) {
if (!material.isLegacy() && material.isItem()) {
Key id = Key.from(material.getKey().asString());
VANILLA_ITEMS.add(id);
Holder.Reference<Key> holder = BuiltInRegistries.OPTIMIZED_ITEM_ID.get(id)
.orElseGet(() -> ((WritableRegistry<Key>) BuiltInRegistries.OPTIMIZED_ITEM_ID)
.register(new ResourceKey<>(BuiltInRegistries.OPTIMIZED_ITEM_ID.key().location(), id), id));
Object resourceLocation = Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, id.namespace(), id.value());
Object mcHolder = ((Optional<Object>) Reflections.method$Registry$getHolder1.invoke(Reflections.instance$BuiltInRegistries$ITEM, Reflections.method$ResourceKey$create.invoke(null, Reflections.instance$Registries$ITEM, resourceLocation))).get();
Set<Object> tags = (Set<Object>) Reflections.field$Holder$Reference$tags.get(mcHolder);
for (Object tag : tags) {
Key tagId = Key.of(Reflections.field$TagKey$location.get(tag).toString());
VANILLA_ITEM_TAGS.computeIfAbsent(tagId, (key) -> new ArrayList<>()).add(holder);
}
for (NamespacedKey item : FastNMS.INSTANCE.getAllVanillaItems()) {
if (item.getNamespace().equals("minecraft")) {
Key id = KeyUtils.namespacedKey2Key(item);
VANILLA_ITEMS.add(id);
Holder.Reference<Key> holder = BuiltInRegistries.OPTIMIZED_ITEM_ID.get(id)
.orElseGet(() -> ((WritableRegistry<Key>) BuiltInRegistries.OPTIMIZED_ITEM_ID)
.register(new ResourceKey<>(BuiltInRegistries.OPTIMIZED_ITEM_ID.key().location(), id), id));
Object resourceLocation = KeyUtils.toResourceLocation(id.namespace(), id.value());
Object mcHolder = ((Optional<Object>) Reflections.method$Registry$getHolder1.invoke(Reflections.instance$BuiltInRegistries$ITEM, Reflections.method$ResourceKey$create.invoke(null, Reflections.instance$Registries$ITEM, resourceLocation))).get();
Set<Object> tags = (Set<Object>) Reflections.field$Holder$Reference$tags.get(mcHolder);
for (Object tag : tags) {
Key tagId = Key.of(Reflections.field$TagKey$location.get(tag).toString());
VANILLA_ITEM_TAGS.computeIfAbsent(tagId, (key) -> new ArrayList<>()).add(holder);
}
}
}

View File

@@ -27,10 +27,15 @@ public abstract class BukkitItemFactory extends ItemFactory<CraftEngine, RTagIte
return new UniversalItemFactory(plugin);
}
case "1.20.5", "1.20.6",
"1.21", "1.21.1", "1.21.2", "1.21.3", "1.21.4", "1.21.5",
"1.22", "1.22.1" -> {
"1.21", "1.21.1", "1.21.2", "1.21.3" -> {
return new ComponentItemFactory(plugin);
}
case "1.21.4" -> {
return new ComponentItemFactory1_21_4(plugin);
}
case "1.21.5", "1.22", "1.22.1" -> {
return new ComponentItemFactory1_21_5(plugin);
}
default -> throw new IllegalStateException("Unsupported server version: " + plugin.serverVersion());
}
}

View File

@@ -25,30 +25,8 @@ import java.util.function.Function;
@SuppressWarnings("UnstableApiUsage")
public class ComponentItemFactory extends BukkitItemFactory {
private final BiConsumer<ItemWrapper<ItemStack>, Integer> customModelDataSetter;
private final Function<ItemWrapper<ItemStack>, Optional<Integer>> customModelDataGetter;
public ComponentItemFactory(CraftEngine plugin) {
super(plugin);
this.customModelDataSetter = VersionHelper.isVersionNewerThan1_21_4() ?
((item, data) -> item.setComponent(ComponentKeys.CUSTOM_MODEL_DATA,
Map.of("floats", List.of(data.floatValue())))) : ((item, data) -> item.setComponent(ComponentKeys.CUSTOM_MODEL_DATA, data));
this.customModelDataGetter = VersionHelper.isVersionNewerThan1_21_4() ?
(item) -> {
Optional<Object> optional = ComponentType.encodeJava(ComponentKeys.CUSTOM_MODEL_DATA, item.getComponent(ComponentKeys.CUSTOM_MODEL_DATA));
if (optional.isEmpty()) return Optional.empty();
@SuppressWarnings("unchecked")
Map<String, Object> data = (Map<String, Object>) optional.get();
@SuppressWarnings("unchecked")
List<Float> floats = (List<Float>) data.get("floats");
if (floats == null || floats.isEmpty()) return Optional.empty();
return Optional.of((int) Math.floor(floats.get(0)));
} : (item) -> Optional.ofNullable(
(Integer) ComponentType.encodeJava(
ComponentKeys.CUSTOM_MODEL_DATA,
item.getComponent(ComponentKeys.CUSTOM_MODEL_DATA)
).orElse(null)
);
}
@Override
@@ -61,14 +39,18 @@ public class ComponentItemFactory extends BukkitItemFactory {
if (data == null) {
item.removeComponent(ComponentKeys.CUSTOM_MODEL_DATA);
} else {
this.customModelDataSetter.accept(item, data);
item.setComponent(ComponentKeys.CUSTOM_MODEL_DATA, data);
}
}
@Override
protected Optional<Integer> customModelData(ItemWrapper<ItemStack> item) {
if (!item.hasComponent(ComponentKeys.CUSTOM_MODEL_DATA)) return Optional.empty();
return this.customModelDataGetter.apply(item);
return Optional.ofNullable(
(Integer) ComponentType.encodeJava(
ComponentKeys.CUSTOM_MODEL_DATA,
item.getComponent(ComponentKeys.CUSTOM_MODEL_DATA)
).orElse(null));
}
@Override

View File

@@ -0,0 +1,41 @@
package net.momirealms.craftengine.bukkit.item.factory;
import com.saicone.rtag.data.ComponentType;
import net.momirealms.craftengine.core.item.ComponentKeys;
import net.momirealms.craftengine.core.item.ItemWrapper;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import org.bukkit.inventory.ItemStack;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@SuppressWarnings("UnstableApiUsage")
public class ComponentItemFactory1_21_4 extends ComponentItemFactory {
public ComponentItemFactory1_21_4(CraftEngine plugin) {
super(plugin);
}
@Override
protected Optional<Integer> customModelData(ItemWrapper<ItemStack> item) {
if (!item.hasComponent(ComponentKeys.CUSTOM_MODEL_DATA)) return Optional.empty();
Optional<Object> optional = ComponentType.encodeJava(ComponentKeys.CUSTOM_MODEL_DATA, item.getComponent(ComponentKeys.CUSTOM_MODEL_DATA));
if (optional.isEmpty()) return Optional.empty();
@SuppressWarnings("unchecked")
Map<String, Object> data = (Map<String, Object>) optional.get();
@SuppressWarnings("unchecked")
List<Float> floats = (List<Float>) data.get("floats");
if (floats == null || floats.isEmpty()) return Optional.empty();
return Optional.of((int) Math.floor(floats.get(0)));
}
@Override
protected void customModelData(ItemWrapper<ItemStack> item, Integer data) {
if (data == null) {
item.removeComponent(ComponentKeys.CUSTOM_MODEL_DATA);
} else {
item.setComponent(ComponentKeys.CUSTOM_MODEL_DATA, Map.of("floats", List.of(data.floatValue())));
}
}
}

View File

@@ -0,0 +1,82 @@
package net.momirealms.craftengine.bukkit.item.factory;
import com.saicone.rtag.data.ComponentType;
import com.saicone.rtag.tag.TagList;
import com.saicone.rtag.util.ChatComponent;
import net.momirealms.craftengine.bukkit.util.ComponentUtils;
import net.momirealms.craftengine.core.item.ComponentKeys;
import net.momirealms.craftengine.core.item.ItemWrapper;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@SuppressWarnings("UnstableApiUsage")
public class ComponentItemFactory1_21_5 extends ComponentItemFactory1_21_4 {
public ComponentItemFactory1_21_5(CraftEngine plugin) {
super(plugin);
}
@Override
protected void customName(ItemWrapper<ItemStack> item, String json) {
if (json == null) {
item.removeComponent(ComponentKeys.CUSTOM_NAME);
} else {
item.setComponent(ComponentKeys.CUSTOM_NAME, ChatComponent.toTag(ComponentUtils.jsonToMinecraft(json)));
}
}
@Override
protected Optional<String> customName(ItemWrapper<ItemStack> item) {
if (!item.hasComponent(ComponentKeys.CUSTOM_NAME)) return Optional.empty();
return ComponentType.encodeJava(ComponentKeys.CUSTOM_NAME, item.getComponent(ComponentKeys.ITEM_NAME)).map(ChatComponent::fromTag).map(ComponentUtils::minecraftToJson);
}
@Override
protected void itemName(ItemWrapper<ItemStack> item, String json) {
if (json == null) {
item.removeComponent(ComponentKeys.ITEM_NAME);
} else {
item.setComponent(ComponentKeys.ITEM_NAME, ChatComponent.toTag(ComponentUtils.jsonToMinecraft(json)));
}
}
@Override
protected Optional<String> itemName(ItemWrapper<ItemStack> item) {
if (!item.hasComponent(ComponentKeys.ITEM_NAME)) return Optional.empty();
return ComponentType.encodeJava(ComponentKeys.ITEM_NAME, item.getComponent(ComponentKeys.ITEM_NAME)).map(ChatComponent::fromTag).map(ComponentUtils::minecraftToJson);
}
@Override
protected Optional<List<String>> lore(ItemWrapper<ItemStack> item) {
if (!item.hasComponent(ComponentKeys.LORE)) return Optional.empty();
return ComponentType.encodeJava(
ComponentKeys.LORE,
item.getComponent(ComponentKeys.LORE)
).map(list -> {
List<String> lore = new ArrayList<>();
List<Object> tagList = TagList.getValue(list);
for (Object o : tagList) {
lore.add(ComponentUtils.minecraftToJson(ChatComponent.fromTag(o)));
}
return lore;
});
}
@Override
protected void lore(ItemWrapper<ItemStack> item, List<String> lore) {
if (lore == null || lore.isEmpty()) {
item.removeComponent(ComponentKeys.LORE);
} else {
List<Object> loreTags = new ArrayList<>();
for (String json : lore) {
loreTags.add(ChatComponent.toTag(ComponentUtils.jsonToMinecraft(json)));
}
item.setComponent(ComponentKeys.LORE, TagList.newTag(loreTags));
}
}
}

View File

@@ -6,7 +6,9 @@ import com.saicone.rtag.item.ItemObject;
import com.saicone.rtag.tag.TagCompound;
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
import net.momirealms.craftengine.bukkit.item.CloneableConstantItem;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
import net.momirealms.craftengine.bukkit.util.KeyUtils;
import net.momirealms.craftengine.bukkit.util.MaterialUtils;
import net.momirealms.craftengine.bukkit.util.RecipeUtils;
import net.momirealms.craftengine.bukkit.util.Reflections;
@@ -125,8 +127,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
nmsRecipe = Reflections.constructor$RecipeHolder.newInstance(
Reflections.method$CraftRecipe$toMinecraft.invoke(null, new NamespacedKey(id.namespace(), id.value())), nmsRecipe);
} else if (VersionHelper.isVersionNewerThan1_20_2()) {
nmsRecipe = Reflections.constructor$RecipeHolder.newInstance(
Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, id.namespace(), id.value()), nmsRecipe);
nmsRecipe = Reflections.constructor$RecipeHolder.newInstance(KeyUtils.toResourceLocation(id), nmsRecipe);
} else {
return () -> {};
}
@@ -693,7 +694,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
List<Object> itemStacks = new ArrayList<>();
for (Holder<Key> holder : holders) {
ItemStack itemStack = BukkitItemManager.instance().getBuildableItem(holder.value()).get().buildItemStack(ItemBuildContext.EMPTY, 1);
Object nmsStack = Reflections.method$CraftItemStack$asNMSCopy.invoke(null, itemStack);
Object nmsStack = FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(itemStack);
itemStacks.add(nmsStack);
}
return itemStacks;
@@ -779,7 +780,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
}
return optional.get();
} else {
Object resourceLocation = Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, id.namespace(), id.value());
Object resourceLocation = KeyUtils.toResourceLocation(id);
@SuppressWarnings("unchecked")
Optional<Object> optional = (Optional<Object>) Reflections.method$RecipeManager$byKey.invoke(nmsRecipeManager, resourceLocation);
if (optional.isEmpty()) {
@@ -837,7 +838,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
// 1.21.5+
private static Object toTransmuteResult(ItemStack item) throws InvocationTargetException, IllegalAccessException, InstantiationException {
Object itemStack = Reflections.method$CraftItemStack$asNMSCopy.invoke(null, item);
Object itemStack = FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(item);
Object nmsItem = Reflections.method$ItemStack$getItem.invoke(itemStack);
return Reflections.constructor$TransmuteResult.newInstance(nmsItem);
}
@@ -856,22 +857,22 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
toOptionalMinecraftIngredient(recipe.template()),
toOptionalMinecraftIngredient(recipe.base()),
toOptionalMinecraftIngredient(recipe.addition()),
Reflections.method$CraftItemStack$asNMSCopy.invoke(null, recipe.result(ItemBuildContext.EMPTY))
FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(recipe.result(ItemBuildContext.EMPTY))
);
} else if (VersionHelper.isVersionNewerThan1_20_2()) {
return Reflections.constructor$SmithingTransformRecipe.newInstance(
toMinecraftIngredient(recipe.template()),
toMinecraftIngredient(recipe.base()),
toMinecraftIngredient(recipe.addition()),
Reflections.method$CraftItemStack$asNMSCopy.invoke(null, recipe.result(ItemBuildContext.EMPTY))
FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(recipe.result(ItemBuildContext.EMPTY))
);
} else {
return Reflections.constructor$SmithingTransformRecipe.newInstance(
Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, recipe.id().namespace(), recipe.id().value()),
KeyUtils.toResourceLocation(recipe.id()),
toMinecraftIngredient(recipe.template()),
toMinecraftIngredient(recipe.base()),
toMinecraftIngredient(recipe.addition()),
Reflections.method$CraftItemStack$asNMSCopy.invoke(null, recipe.result(ItemBuildContext.EMPTY))
FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(recipe.result(ItemBuildContext.EMPTY))
);
}
}

View File

@@ -347,7 +347,7 @@ public class RecipeEventListener implements Listener {
Optional<Object> optionalMCRecipe = (Optional<Object>) Reflections.method$RecipeManager$getRecipeFor1.invoke(
BukkitRecipeManager.nmsRecipeManager(),
Reflections.instance$RecipeType$CAMPFIRE_COOKING,
Reflections.constructor$SingleRecipeInput.newInstance(Reflections.method$CraftItemStack$asNMSCopy.invoke(null, itemStack)),
Reflections.constructor$SingleRecipeInput.newInstance(FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(itemStack)),
FastNMS.INSTANCE.field$CraftWorld$ServerLevel(event.getPlayer().getWorld()),
null
);
@@ -561,16 +561,16 @@ public class RecipeEventListener implements Listener {
String renameText;
int maxRepairCost;
int previousCost;
//int previousCost;
if (VersionHelper.isVersionNewerThan1_21_2()) {
AnvilView anvilView = event.getView();
renameText = anvilView.getRenameText();
maxRepairCost = anvilView.getMaximumRepairCost();
previousCost = anvilView.getRepairCost();
//previousCost = anvilView.getRepairCost();
} else {
renameText = LegacyInventoryUtils.getRenameText(inventory);
maxRepairCost = LegacyInventoryUtils.getMaxRepairCost(inventory);
previousCost = LegacyInventoryUtils.getRepairCost(inventory);
//previousCost = LegacyInventoryUtils.getRepairCost(inventory);
}
int repairCost = actualConsumedAmount;

View File

@@ -40,7 +40,7 @@ public class DebugItemDataCommand extends BukkitCommandFeature<CommandSender> {
for (String text : readableList) {
joiner.add(text);
}
plugin().senderFactory().wrap(context.sender()).sendMessage(AdventureHelper.miniMessage(joiner.toString()));
plugin().senderFactory().wrap(context.sender()).sendMessage(AdventureHelper.miniMessage().deserialize(joiner.toString()));
});
}

View File

@@ -537,10 +537,9 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
handleNMSPacket(user, event, packet);
}
@SuppressWarnings("unchecked")
private void onNMSPacketSend(NetWorkUser player, NMSPacketEvent event, Object packet) throws ReflectiveOperationException {
private void onNMSPacketSend(NetWorkUser player, NMSPacketEvent event, Object packet) {
if (Reflections.clazz$ClientboundBundlePacket.isInstance(packet)) {
Iterable<Object> packets = (Iterable<Object>) Reflections.field$BundlePacket$packets.get(packet);
Iterable<Object> packets = FastNMS.INSTANCE.method$ClientboundBundlePacket$subPackets(packet);
for (Object p : packets) {
onNMSPacketSend(player, event, p);
}

View File

@@ -251,10 +251,10 @@ public class PacketConsumers {
writeMethod = Reflections.method$Packet$write;
}
Object packet = Reflections.constructor$ClientboundLevelParticlesPacket.newInstance(mcByteBuf);
Object option = Reflections.field$ClientboundLevelParticlesPacket$particle.get(packet);
Object option = FastNMS.INSTANCE.field$ClientboundLevelParticlesPacket$particle(packet);
if (option == null) return;
if (!Reflections.clazz$BlockParticleOption.isInstance(option)) return;
Object blockState = Reflections.field$BlockParticleOption$blockState.get(option);
Object blockState = FastNMS.INSTANCE.field$BlockParticleOption$blockState(option);
int id = BlockStateUtils.blockStateToId(blockState);
int remapped = remap(id);
if (remapped == id) return;
@@ -274,7 +274,7 @@ public class PacketConsumers {
BukkitServerPlayer player = (BukkitServerPlayer) user;
Player platformPlayer = player.platformPlayer();
World world = platformPlayer.getWorld();
Object blockPos = Reflections.field$ServerboundPlayerActionPacket$pos.get(packet);
Object blockPos = FastNMS.INSTANCE.field$ServerboundPlayerActionPacket$pos(packet);
BlockPos pos = LocationUtils.fromBlockPos(blockPos);
if (VersionHelper.isFolia()) {
BukkitCraftEngine.instance().scheduler().sync().run(() -> {
@@ -293,7 +293,7 @@ public class PacketConsumers {
};
private static void handlePlayerActionPacketOnMainThread(BukkitServerPlayer player, World world, BlockPos pos, Object packet) throws Exception {
Object action = Reflections.field$ServerboundPlayerActionPacket$action.get(packet);
Object action = FastNMS.INSTANCE.field$ServerboundPlayerActionPacket$action(packet);
if (action == Reflections.instance$ServerboundPlayerActionPacket$Action$START_DESTROY_BLOCK) {
Object serverLevel = FastNMS.INSTANCE.field$CraftWorld$ServerLevel(world);
Object blockState = FastNMS.INSTANCE.method$BlockGetter$getBlockState(serverLevel, LocationUtils.toBlockPos(pos));
@@ -313,7 +313,7 @@ public class PacketConsumers {
return;
}
if (player.isAdventureMode()) {
Object itemStack = Reflections.method$CraftItemStack$asNMSCopy.invoke(null, player.platformPlayer().getInventory().getItemInMainHand());
Object itemStack = FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(player.platformPlayer().getInventory().getItemInMainHand());
Object blockPos = LocationUtils.toBlockPos(pos);
Object blockInWorld = Reflections.constructor$BlockInWorld.newInstance(serverLevel, blockPos, false);
if (VersionHelper.isVersionNewerThan1_20_5()) {
@@ -375,6 +375,7 @@ public class PacketConsumers {
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> RESPAWN = (user, event, packet) -> {
try {
BukkitServerPlayer player = (BukkitServerPlayer) user;
player.clearView();
Object dimensionKey;
if (!VersionHelper.isVersionNewerThan1_20_2()) {
dimensionKey = Reflections.field$ClientboundRespawnPacket$dimension.get(packet);
@@ -606,22 +607,22 @@ public class PacketConsumers {
}
assert Reflections.method$ServerGamePacketListenerImpl$tryPickItem != null;
Reflections.method$ServerGamePacketListenerImpl$tryPickItem.invoke(
Reflections.field$ServerPlayer$connection.get(FastNMS.INSTANCE.method$CraftPlayer$getHandle(player)), Reflections.method$CraftItemStack$asNMSCopy.invoke(null, itemStack));
Reflections.field$ServerPlayer$connection.get(FastNMS.INSTANCE.method$CraftPlayer$getHandle(player)), FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(itemStack));
}
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> ADD_ENTITY = (user, event, packet) -> {
try {
Object entityType = Reflections.field$ClientboundAddEntityPacket$type.get(packet);
Object entityType = FastNMS.INSTANCE.field$ClientboundAddEntityPacket$type(packet);
// Falling blocks
if (entityType == Reflections.instance$EntityType$FALLING_BLOCK) {
int data = Reflections.field$ClientboundAddEntityPacket$data.getInt(packet);
int data = FastNMS.INSTANCE.field$ClientboundAddEntityPacket$data(packet);
int remapped = remap(data);
if (remapped != data) {
Reflections.field$ClientboundAddEntityPacket$data.set(packet, remapped);
}
} else if (entityType == Reflections.instance$EntityType$ITEM_DISPLAY) {
// Furniture
int entityId = (int) Reflections.field$ClientboundAddEntityPacket$entityId.get(packet);
int entityId = FastNMS.INSTANCE.field$ClientboundAddEntityPacket$entityId(packet);
LoadedFurniture furniture = BukkitFurnitureManager.instance().loadedFurnitureByRealEntityId(entityId);
if (furniture != null) {
user.furnitureView().computeIfAbsent(furniture.baseEntityId(), k -> new ArrayList<>()).addAll(furniture.fakeEntityIds());
@@ -632,17 +633,21 @@ public class PacketConsumers {
}
} else if (entityType == Reflections.instance$EntityType$SHULKER) {
// Cancel collider entity packet
int entityId = (int) Reflections.field$ClientboundAddEntityPacket$entityId.get(packet);
int entityId = FastNMS.INSTANCE.field$ClientboundAddEntityPacket$entityId(packet);
LoadedFurniture furniture = BukkitFurnitureManager.instance().loadedFurnitureByRealEntityId(entityId);
if (furniture != null) {
event.setCancelled(true);
}
} else if (entityType == Reflections.instance$EntityType$BLOCK_DISPLAY) {
int entityId = FastNMS.INSTANCE.field$ClientboundAddEntityPacket$entityId(packet);
user.entityView().put(entityId, entityType);
}
} catch (Exception e) {
CraftEngine.instance().logger().warn("Failed to handle ClientboundAddEntityPacket", e);
}
};
// 1.21.3+
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> SYNC_ENTITY_POSITION = (user, event, packet) -> {
try {
int entityId = (int) Reflections.field$ClientboundEntityPositionSyncPacket$id.get(packet);
@@ -667,7 +672,7 @@ public class PacketConsumers {
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> REMOVE_ENTITY = (user, event, packet) -> {
try {
IntList intList = (IntList) Reflections.field$ClientboundRemoveEntitiesPacket$entityIds.get(packet);
IntList intList = FastNMS.INSTANCE.field$ClientboundRemoveEntitiesPacket$entityIds(packet);
for (int i = 0, size = intList.size(); i < size; i++) {
List<Integer> entities = user.furnitureView().remove(intList.getInt(i));
if (entities == null) continue;
@@ -686,16 +691,16 @@ public class PacketConsumers {
if (player == null) return;
int entityId;
if (BukkitNetworkManager.hasModelEngine()) {
int fakeId = (int) Reflections.field$ServerboundInteractPacket$entityId.get(packet);
int fakeId = FastNMS.INSTANCE.field$ServerboundInteractPacket$entityId(packet);
entityId = ModelEngineUtils.interactionToBaseEntity(fakeId);
} else {
entityId = Reflections.field$ServerboundInteractPacket$entityId.getInt(packet);
entityId = FastNMS.INSTANCE.field$ServerboundInteractPacket$entityId(packet);
}
LoadedFurniture furniture = BukkitFurnitureManager.instance().loadedFurnitureByEntityId(entityId);
if (furniture == null) return;
Object action = Reflections.field$ServerboundInteractPacket$action.get(packet);
Object actionType = Reflections.method$ServerboundInteractPacket$Action$getType.invoke(action);
if (actionType == null) return;
LoadedFurniture furniture = BukkitFurnitureManager.instance().loadedFurnitureByEntityId(entityId);
if (furniture == null) return;
Location location = furniture.baseEntity().getLocation();
BukkitServerPlayer serverPlayer = (BukkitServerPlayer) user;
if (serverPlayer.isSpectatorMode() || serverPlayer.isAdventureMode()) return;
@@ -718,9 +723,10 @@ public class PacketConsumers {
Object interactionHand = Reflections.field$ServerboundInteractPacket$InteractionAtLocationAction$hand.get(action);
hand = interactionHand == Reflections.instance$InteractionHand$MAIN_HAND ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND;
Object vec3 = Reflections.field$ServerboundInteractPacket$InteractionAtLocationAction$location.get(action);
double x = (double) Reflections.field$Vec3$x.get(vec3);
double y = (double) Reflections.field$Vec3$y.get(vec3);
double z = (double) Reflections.field$Vec3$z.get(vec3);
double x = FastNMS.INSTANCE.field$Vec3$x(vec3);
double y = FastNMS.INSTANCE.field$Vec3$y(vec3);
double z = FastNMS.INSTANCE.field$Vec3$z(vec3);
interactionPoint = new Location(location.getWorld(), x, y, z);
} catch (ReflectiveOperationException e) {
throw new RuntimeException("Failed to get interaction hand from interact packet", e);
@@ -745,25 +751,15 @@ public class PacketConsumers {
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> SOUND = (user, event, packet) -> {
try {
Object sound = Reflections.field$ClientboundSoundPacket$sound.get(packet);
Object soundEvent = Reflections.method$Holder$value.invoke(sound);
Key mapped = BukkitBlockManager.instance().replaceSoundIfExist(Key.of(Reflections.field$SoundEvent$location.get(soundEvent).toString()));
Object soundEvent = FastNMS.INSTANCE.field$ClientboundSoundPacket$soundEvent(packet);
Key mapped = BukkitBlockManager.instance().replaceSoundIfExist(Key.of(FastNMS.INSTANCE.field$SoundEvent$location(soundEvent).toString()));
if (mapped != null) {
event.setCancelled(true);
Object newId = Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, mapped.namespace(), mapped.value());
Object newId = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath(mapped.namespace(), mapped.value());
Object newSoundEvent = VersionHelper.isVersionNewerThan1_21_2() ?
Reflections.constructor$SoundEvent.newInstance(newId, Reflections.field$SoundEvent$fixedRange.get(soundEvent)) :
Reflections.constructor$SoundEvent.newInstance(newId, Reflections.field$SoundEvent$range.get(soundEvent), Reflections.field$SoundEvent$newSystem.get(soundEvent));
Object newSoundPacket = Reflections.constructor$ClientboundSoundPacket.newInstance(
Reflections.method$Holder$direct.invoke(null, newSoundEvent),
Reflections.field$ClientboundSoundPacket$source.get(packet),
(double) Reflections.field$ClientboundSoundPacket$x.getInt(packet) / 8,
(double) Reflections.field$ClientboundSoundPacket$y.getInt(packet) / 8,
(double) Reflections.field$ClientboundSoundPacket$z.getInt(packet) / 8,
Reflections.field$ClientboundSoundPacket$volume.get(packet),
Reflections.field$ClientboundSoundPacket$pitch.get(packet),
Reflections.field$ClientboundSoundPacket$seed.get(packet)
);
Object newSoundPacket = FastNMS.INSTANCE.fastConstructor$ClientboundSoundPacket(newSoundEvent, packet);
user.sendPacket(newSoundPacket, true);
}
} catch (Exception e) {
@@ -962,27 +958,19 @@ public class PacketConsumers {
}
};
@SuppressWarnings("unchecked")
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> SET_ENTITY_DATA = (user, event, packet) -> {
try {
int id = (int) Reflections.field$ClientboundSetEntityDataPacket$id.get(packet);
Object player = user.serverPlayer();
Object level = Reflections.method$Entity$level.invoke(player);
Object entityLookup = Reflections.method$Level$moonrise$getEntityLookup.invoke(level);
Object entity = Reflections.method$EntityLookup$get.invoke(entityLookup, id);
if (entity == null) return;
Object entityType = Reflections.method$Entity$getType.invoke(entity);
int id = FastNMS.INSTANCE.field$ClientboundSetEntityDataPacket$id(packet);
Object entityType = user.entityView().get(id);
if (entityType == Reflections.instance$EntityType$BLOCK_DISPLAY) {
List<Object> packedItems = (List<Object>) Reflections.field$ClientboundSetEntityDataPacket$packedItems.get(packet);
List<Object> packedItems = FastNMS.INSTANCE.field$ClientboundSetEntityDataPacket$packedItems(packet);
for (int i = 0; i < packedItems.size(); i++) {
Object packedItem = packedItems.get(i);
int entityDataId = (int) Reflections.field$SynchedEntityData$DataValue$id.get(packedItem);
if ((VersionHelper.isVersionNewerThan1_20_2() && entityDataId != 23)
|| (!VersionHelper.isVersionNewerThan1_20_2() && entityDataId != 22)) {
int entityDataId = FastNMS.INSTANCE.field$SynchedEntityData$DataValue$id(packedItem);
if (entityDataId != EntityDataUtils.BLOCK_STATE_DATA_ID) {
continue;
}
Object blockState = Reflections.field$SynchedEntityData$DataValue$value.get(packedItem);
Object serializer = Reflections.field$SynchedEntityData$DataValue$serializer.get(packedItem);
Object blockState = FastNMS.INSTANCE.field$SynchedEntityData$DataValue$value(packedItem);
int stateId = BlockStateUtils.blockStateToId(blockState);
int newStateId;
if (!user.clientModEnabled()) {
@@ -990,7 +978,8 @@ public class PacketConsumers {
} else {
newStateId = remapMOD(stateId);
}
packedItems.set(i, Reflections.constructor$SynchedEntityData$DataValue.newInstance(
Object serializer = FastNMS.INSTANCE.field$SynchedEntityData$DataValue$serializer(packedItem);
packedItems.set(i, FastNMS.INSTANCE.constructor$SynchedEntityData$DataValue(
entityDataId, serializer, BlockStateUtils.idToBlockState(newStateId)
));
break;

View File

@@ -69,7 +69,9 @@ public class BukkitServerPlayer extends Player {
private boolean hasClientMod = false;
// for better fake furniture visual sync
// TODO CLEAR ENTITY VIEW
private final Map<Integer, List<Integer>> furnitureView = new ConcurrentHashMap<>();
private final Map<Integer, Object> entityTypeView = new ConcurrentHashMap<>();
public BukkitServerPlayer(BukkitCraftEngine plugin, Channel channel) {
this.channel = channel;
@@ -343,7 +345,7 @@ public class BukkitServerPlayer extends Player {
} else {
if (VersionHelper.isVersionNewerThan1_20_5()) {
Object attributeModifier = VersionHelper.isVersionNewerThan1_21() ?
Reflections.constructor$AttributeModifier.newInstance(Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, "craftengine", "custom_hardness"), -9999d, Reflections.instance$AttributeModifier$Operation$ADD_VALUE) :
Reflections.constructor$AttributeModifier.newInstance(KeyUtils.toResourceLocation("craftengine", "custom_hardness"), -9999d, Reflections.instance$AttributeModifier$Operation$ADD_VALUE) :
Reflections.constructor$AttributeModifier.newInstance(UUID.randomUUID(), "craftengine:custom_hardness", -9999d, Reflections.instance$AttributeModifier$Operation$ADD_VALUE);
Object attributeSnapshot = Reflections.constructor$ClientboundUpdateAttributesPacket$AttributeSnapshot.newInstance(Reflections.instance$Holder$Attribute$block_break_speed, 1d, Lists.newArrayList(attributeModifier));
Object newPacket = Reflections.constructor$ClientboundUpdateAttributesPacket1.newInstance(entityID(), Lists.newArrayList(attributeSnapshot));
@@ -618,6 +620,11 @@ public class BukkitServerPlayer extends Player {
return this.furnitureView;
}
@Override
public Map<Integer, Object> entityView() {
return this.entityTypeView;
}
public void setResendSound() {
resentSoundTick = gameTicks();
}
@@ -649,4 +656,10 @@ public class BukkitServerPlayer extends Player {
public void setClientModState(boolean enable) {
this.hasClientMod = enable;
}
@Override
public void clearView() {
this.entityTypeView.clear();
this.furnitureView.clear();
}
}

View File

@@ -1,6 +1,7 @@
package net.momirealms.craftengine.bukkit.sound;
import net.momirealms.craftengine.bukkit.util.ComponentUtils;
import net.momirealms.craftengine.bukkit.util.KeyUtils;
import net.momirealms.craftengine.bukkit.util.Reflections;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.sound.AbstractSoundManager;
@@ -26,8 +27,8 @@ public class BukkitSoundManager extends AbstractSoundManager {
for (Map.Entry<Key, JukeboxSong> entry : songs.entrySet()) {
Key id = entry.getKey();
JukeboxSong jukeboxSong = entry.getValue();
Object resourceLocation = Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, id.namespace(), id.value());
Object soundId = Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, jukeboxSong.sound().namespace(), jukeboxSong.sound().value());
Object resourceLocation = KeyUtils.toResourceLocation(id);
Object soundId = KeyUtils.toResourceLocation(jukeboxSong.sound());
Object song = Reflections.method$Registry$get.invoke(Reflections.instance$InternalRegistries$JUKEBOX_SONG, resourceLocation);
Object soundEvent = VersionHelper.isVersionNewerThan1_21_2() ?

View File

@@ -63,7 +63,7 @@ public class BlockStateUtils {
@SuppressWarnings("unchecked")
public static List<Object> getAllVanillaBlockStates(Key block) {
try {
Object blockIns = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$BLOCK, Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, block.namespace(), block.value()));
Object blockIns = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$BLOCK, KeyUtils.toResourceLocation(block));
Object definition = Reflections.field$Block$StateDefinition.get(blockIns);
return (List<Object>) Reflections.field$StateDefinition$states.get(definition);
} catch (Exception e) {

View File

@@ -14,7 +14,7 @@ public class BlockTags {
Object value = CACHE.get(key);
if (value == null) {
try {
value = Reflections.method$TagKey$create.invoke(null, Reflections.instance$Registries$BLOCK, Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, key.namespace(), key.value()));
value = Reflections.method$TagKey$create.invoke(null, Reflections.instance$Registries$BLOCK, KeyUtils.toResourceLocation(key));
CACHE.put(key, value);
return value;
} catch (Exception e) {

View File

@@ -1,31 +1,27 @@
package net.momirealms.craftengine.bukkit.util;
import com.google.gson.JsonElement;
import net.kyori.adventure.text.Component;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.core.util.AdventureHelper;
import net.momirealms.craftengine.core.util.VersionHelper;
public class ComponentUtils {
private ComponentUtils() {}
public static Object adventureToMinecraft(Component component) {
String json = AdventureHelper.componentToJson(component);
return jsonToMinecraft(json);
return jsonElementToMinecraft(AdventureHelper.componentToJsonElement(component));
}
public static Object jsonElementToMinecraft(JsonElement json) {
return FastNMS.INSTANCE.method$Component$Serializer$fromJson(json);
}
public static Object jsonToMinecraft(String json) {
if (VersionHelper.isVersionNewerThan1_20_5()) {
try {
return Reflections.method$Component$Serializer$fromJson.invoke(null, json, Reflections.instance$MinecraftRegistry);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
} else {
try {
return Reflections.method$CraftChatMessage$fromJSON.invoke(null, json);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
return FastNMS.INSTANCE.method$Component$Serializer$fromJson(json);
}
public static String minecraftToJson(Object component) {
return FastNMS.INSTANCE.method$Component$Serializer$toJson(component);
}
}

View File

@@ -1,5 +1,7 @@
package net.momirealms.craftengine.bukkit.util;
import net.momirealms.craftengine.core.util.VersionHelper;
public class EntityDataUtils {
private EntityDataUtils() {}
@@ -9,6 +11,7 @@ public class EntityDataUtils {
private static final int USE_DEFAULT_BACKGROUND = 0x04; // 4
private static final int LEFT_ALIGNMENT = 0x08; // 8
private static final int RIGHT_ALIGNMENT = 0x10; // 16
public static final int BLOCK_STATE_DATA_ID = VersionHelper.isVersionNewerThan1_20_2() ? 23 : 22;
public static byte encodeTextDisplayMask(boolean hasShadow, boolean isSeeThrough, boolean useDefaultBackground, int alignment) {
int bitMask = 0;

View File

@@ -8,7 +8,7 @@ public class FeatureUtils {
public static Object createFeatureKey(Key id) {
try {
return Reflections.method$ResourceKey$create.invoke(null, Reflections.instance$Registries$CONFIGURED_FEATURE, Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, id.namespace(), id.value()));
return Reflections.method$ResourceKey$create.invoke(null, Reflections.instance$Registries$CONFIGURED_FEATURE, KeyUtils.toResourceLocation(id));
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}

View File

@@ -17,7 +17,7 @@ public class ItemTags {
Object value = CACHE.get(key);
if (value == null) {
try {
value = Reflections.method$TagKey$create.invoke(null, Reflections.instance$Registries$ITEM, Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, key.namespace(), key.value()));
value = Reflections.method$TagKey$create.invoke(null, Reflections.instance$Registries$ITEM, KeyUtils.toResourceLocation(key));
CACHE.put(key, value);
return value;
} catch (Exception e) {

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.bukkit.util;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.core.util.Key;
import org.bukkit.NamespacedKey;
@@ -14,4 +15,12 @@ public class KeyUtils {
public static Key adventureKey2Key(net.kyori.adventure.key.Key key) {
return Key.of(key.namespace(), key.value());
}
public static Object toResourceLocation(String namespace, String path) {
return FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath(namespace, path);
}
public static Object toResourceLocation(Key key) {
return toResourceLocation(key.namespace(), key.value());
}
}

View File

@@ -152,8 +152,8 @@ public class PlayerUtils {
ItemStack offhandItem = player.getInventory().getItemInOffHand();
List<Object> packets = new ArrayList<>();
try {
Object previousItem = Reflections.method$CraftItemStack$asNMSCopy.invoke(null, offhandItem);
Object totemItem = Reflections.method$CraftItemStack$asNMSCopy.invoke(null, totem);
Object previousItem = FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(offhandItem);
Object totemItem = FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(totem);
Object packet1 = Reflections.constructor$ClientboundSetEquipmentPacket
.newInstance(player.getEntityId(), List.of(Pair.of(Reflections.instance$EquipmentSlot$OFFHAND, totemItem)));

View File

@@ -404,12 +404,18 @@ public class Reflections {
BukkitReflectionUtils.assembleMCClass("core.HolderLookup$b")
);
public static final Method method$Component$Serializer$fromJson = ReflectionUtils.getMethod(
public static final Method method$Component$Serializer$fromJson0 = ReflectionUtils.getMethod(
clazz$Component$Serializer,
new String[] { "fromJson" },
String.class, clazz$HolderLookup$Provider
);
public static final Method method$Component$Serializer$fromJson1 = ReflectionUtils.getMethod(
clazz$Component$Serializer,
new String[] { "fromJson" },
JsonElement.class, clazz$HolderLookup$Provider
);
public static final Method method$Component$Serializer$toJson = ReflectionUtils.getMethod(
clazz$Component$Serializer,
new String[] { "toJson" },
@@ -564,11 +570,11 @@ public class Reflections {
)
);
public static final Field field$ClientboundRemoveEntitiesPacket$entityIds = requireNonNull(
ReflectionUtils.getInstanceDeclaredField(
clazz$ClientboundRemoveEntitiesPacket, 0
)
);
// public static final Field field$ClientboundRemoveEntitiesPacket$entityIds = requireNonNull(
// ReflectionUtils.getInstanceDeclaredField(
// clazz$ClientboundRemoveEntitiesPacket, 0
// )
// );
public static final Field field$ClientboundAddEntityPacket$entityId = requireNonNull(
ReflectionUtils.getDeclaredField(
@@ -792,35 +798,35 @@ public class Reflections {
}
}
public static final Field field$ClientboundSetEntityDataPacket$id = requireNonNull(
ReflectionUtils.getDeclaredField(
clazz$ClientboundSetEntityDataPacket, int.class, 0
)
);
// public static final Field field$ClientboundSetEntityDataPacket$id = requireNonNull(
// ReflectionUtils.getDeclaredField(
// clazz$ClientboundSetEntityDataPacket, int.class, 0
// )
// );
public static final Field field$ClientboundSetEntityDataPacket$packedItems = requireNonNull(
ReflectionUtils.getDeclaredField(
clazz$ClientboundSetEntityDataPacket, List.class, 0
)
);
// public static final Field field$ClientboundSetEntityDataPacket$packedItems = requireNonNull(
// ReflectionUtils.getDeclaredField(
// clazz$ClientboundSetEntityDataPacket, List.class, 0
// )
// );
public static final Field field$SynchedEntityData$DataValue$id = requireNonNull(
ReflectionUtils.getDeclaredField(
clazz$SynchedEntityData$DataValue, int.class, 0
)
);
// public static final Field field$SynchedEntityData$DataValue$id = requireNonNull(
// ReflectionUtils.getDeclaredField(
// clazz$SynchedEntityData$DataValue, int.class, 0
// )
// );
public static final Field field$SynchedEntityData$DataValue$serializer = requireNonNull(
ReflectionUtils.getDeclaredField(
clazz$SynchedEntityData$DataValue, 1
)
);
public static final Field field$SynchedEntityData$DataValue$value = requireNonNull(
ReflectionUtils.getDeclaredField(
clazz$SynchedEntityData$DataValue, 2
)
);
// public static final Field field$SynchedEntityData$DataValue$serializer = requireNonNull(
// ReflectionUtils.getDeclaredField(
// clazz$SynchedEntityData$DataValue, 1
// )
// );
//
// public static final Field field$SynchedEntityData$DataValue$value = requireNonNull(
// ReflectionUtils.getDeclaredField(
// clazz$SynchedEntityData$DataValue, 2
// )
// );
public static final Class<?> clazz$ClientboundUpdateAttributesPacket = requireNonNull(
ReflectionUtils.getClazz(
@@ -3140,11 +3146,11 @@ public class Reflections {
}
}
public static final Field field$ServerboundInteractPacket$entityId = requireNonNull(
ReflectionUtils.getInstanceDeclaredField(
clazz$ServerboundInteractPacket, int.class, 0
)
);
// public static final Field field$ServerboundInteractPacket$entityId = requireNonNull(
// ReflectionUtils.getInstanceDeclaredField(
// clazz$ServerboundInteractPacket, int.class, 0
// )
// );
public static final Field field$ServerboundInteractPacket$usingSecondaryAction = requireNonNull(
ReflectionUtils.getInstanceDeclaredField(
@@ -3354,11 +3360,11 @@ public class Reflections {
)
);
public static final Method method$CraftItemStack$asNMSCopy = requireNonNull(
ReflectionUtils.getStaticMethod(
clazz$CraftItemStack, clazz$ItemStack, new String[]{"asNMSCopy"}, ItemStack.class
)
);
// public static final Method method$CraftItemStack$asNMSCopy = requireNonNull(
// ReflectionUtils.getStaticMethod(
// clazz$CraftItemStack, clazz$ItemStack, new String[]{"asNMSCopy"}, ItemStack.class
// )
// );
public static final Field field$Holder$Reference$tags = requireNonNull(
ReflectionUtils.getDeclaredField(
@@ -6099,11 +6105,11 @@ public class Reflections {
)
);
public static final Constructor<?> constructor$SynchedEntityData$DataValue = requireNonNull(
ReflectionUtils.getConstructor(
clazz$SynchedEntityData$DataValue, int.class, clazz$EntityDataSerializer, Object.class
)
);
// public static final Constructor<?> constructor$SynchedEntityData$DataValue = requireNonNull(
// ReflectionUtils.getConstructor(
// clazz$SynchedEntityData$DataValue, int.class, clazz$EntityDataSerializer, Object.class
// )
// );
public static final Class<?> clazz$EntityLookup = requireNonNull(
ReflectionUtils.getClazz(

View File

@@ -19,8 +19,6 @@ public class SoundUtils {
}
public static Object getOrRegisterSoundEvent(Key key) throws ReflectiveOperationException {
return Reflections.method$SoundEvent$createVariableRangeEvent.invoke(null,
Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, key.namespace(), key.value())
);
return Reflections.method$SoundEvent$createVariableRangeEvent.invoke(null, KeyUtils.toResourceLocation(key));
}
}

View File

@@ -74,4 +74,6 @@ public abstract class Player extends Entity implements NetWorkUser {
public abstract void closeInventory();
public abstract BlockHitResult rayTrace(double distance, FluidCollisionRule collisionRule);
public abstract void clearView();
}

View File

@@ -200,6 +200,7 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
String name = obj.toString();
return new ItemNameModifier<>(name);
}, "item-name", "display-name");
registerDataFunction((obj) -> {
List<String> name = MiscUtils.getAsStringList(obj);
return new LoreModifier<>(name);

View File

@@ -28,7 +28,7 @@ public class MergePackMcMetaResolution implements Resolution {
}
}
public static void mergeMcMeta(Path file1, Path file2, JsonObject customDescription) throws IOException {
public static void mergeMcMeta(Path file1, Path file2, JsonElement customDescription) throws IOException {
JsonElement elem1 = GsonHelper.readJsonFile(file1);
JsonElement elem2 = GsonHelper.readJsonFile(file2);
@@ -193,7 +193,7 @@ public class MergePackMcMetaResolution implements Resolution {
@Override
public void run(Path existing, Path conflict) {
try {
mergeMcMeta(existing, conflict, JsonParser.parseString(AdventureHelper.miniMessageToJson(this.description)).getAsJsonObject());
mergeMcMeta(existing, conflict, AdventureHelper.componentToJsonElement(AdventureHelper.miniMessage().deserialize(this.description)));
} catch (IOException e) {
CraftEngine.instance().logger().severe("Failed to merge pack.mcmeta when resolving file conflicts", e);
}

View File

@@ -202,7 +202,7 @@ public class Config {
resource_pack$external_host$sha1 = config.getString("resource-pack.send.external-host.sha1", "");
String packUUIDStr = config.getString("resource-pack.send.external-host.uuid", "");
resource_pack$external_host$uuid = packUUIDStr.isEmpty() ? UUID.nameUUIDFromBytes(resource_pack$external_host$url.getBytes(StandardCharsets.UTF_8)) : UUID.fromString(packUUIDStr);
resource_pack$send$prompt = AdventureHelper.miniMessage(config.getString("resource-pack.send.prompt", "<yellow>To fully experience our server, please accept our custom resource pack.</yellow>"));
resource_pack$send$prompt = AdventureHelper.miniMessage().deserialize(config.getString("resource-pack.send.prompt", "<yellow>To fully experience our server, please accept our custom resource pack.</yellow>"));
resource_pack$send$self_host$rate_limit$reset_interval = config.getLong("resource-pack.send.self-host.rate-limit.reset-interval", 30L);
resource_pack$send$self_host$rate_limit$max_requests = config.getInt("resource-pack.send.self-host.rate-limit.max-requests", 3);
resource_pack$send$self_host$deny_non_minecraft_request = config.getBoolean("resource-pack.send.deny-non-minecraft-request", true);

View File

@@ -37,6 +37,8 @@ public interface NetWorkUser {
Map<Integer, List<Integer>> furnitureView();
Map<Integer, Object> entityView();
boolean clientModEnabled();
void setClientModState(boolean enable);

View File

@@ -25,7 +25,7 @@ public class PlaceholderTag implements TagResolver {
}
String placeholder = arguments.popOr("No argument placeholder provided").toString();
String parsed = CraftEngine.instance().parse(player, "%" + placeholder + "%");
return Tag.inserting(AdventureHelper.miniMessage(parsed));
return Tag.inserting(AdventureHelper.miniMessage().deserialize(parsed));
}
@Override

View File

@@ -25,7 +25,7 @@ public class ShiftTag implements TagResolver {
String shiftAmount = arguments.popOr("No argument shift provided").toString();
try {
int shift = Integer.parseInt(shiftAmount);
return Tag.inserting(AdventureHelper.miniMessage(CraftEngine.instance().imageManager().createMiniMessageOffsets(shift)));
return Tag.inserting(AdventureHelper.miniMessage().deserialize(CraftEngine.instance().imageManager().createMiniMessageOffsets(shift)));
} catch (NumberFormatException e) {
throw ctx.newException("Invalid shift value", arguments);
}

View File

@@ -80,7 +80,7 @@ public abstract class AbstractSoundManager implements SoundManager {
AbstractSoundManager.this.plugin.logger().warn(path, "No sound specified");
return;
}
Component description = AdventureHelper.miniMessage(section.getOrDefault("description", "").toString());
Component description = AdventureHelper.miniMessage().deserialize(section.getOrDefault("description", "").toString());
float length = MiscUtils.getAsFloat(section.get("length"));
int comparatorOutput = MiscUtils.getAsInt(section.getOrDefault("comparator-output", 15));
JukeboxSong song = new JukeboxSong(Key.of(sound), description, length, comparatorOutput, MiscUtils.getAsFloat(section.getOrDefault("range", 32f)));

View File

@@ -22,8 +22,6 @@ public class AdventureHelper {
private final MiniMessage miniMessage;
private final MiniMessage miniMessageStrict;
private final GsonComponentSerializer gsonComponentSerializer;
private final Cache<String, String> miniMessageToJsonCache = Caffeine.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build();
public static boolean legacySupport = false;
private AdventureHelper() {
this.miniMessage = MiniMessage.builder().build();
@@ -44,20 +42,6 @@ public class AdventureHelper {
return SingletonHolder.INSTANCE;
}
/**
* Converts a MiniMessage string to a Component.
*
* @param text the MiniMessage string
* @return the resulting Component
*/
public static Component miniMessage(String text) {
if (legacySupport) {
return miniMessage().deserialize(legacyToMiniMessage(text));
} else {
return miniMessage().deserialize(text);
}
}
/**
* Retrieves the MiniMessage instance.
*
@@ -76,41 +60,6 @@ public class AdventureHelper {
return getInstance().gsonComponentSerializer;
}
/**
* Converts a MiniMessage string to a JSON string.
*
* @param miniMessage the MiniMessage string
* @return the JSON string representation
*/
public static String miniMessageToJson(String miniMessage) {
AdventureHelper instance = getInstance();
return instance.miniMessageToJsonCache.get(miniMessage, (text) -> instance.gsonComponentSerializer.serialize(miniMessage(text)));
}
/**
* Sends a title to an audience.
*
* @param audience the audience to send the title to
* @param title the title component
* @param subtitle the subtitle component
* @param fadeIn the fade-in duration in ticks
* @param stay the stay duration in ticks
* @param fadeOut the fade-out duration in ticks
*/
public static void sendTitle(Audience audience, Component title, Component subtitle, int fadeIn, int stay, int fadeOut) {
audience.showTitle(Title.title(title, subtitle, Title.Times.times(Duration.ofMillis(fadeIn * 50L), Duration.ofMillis(stay * 50L), Duration.ofMillis(fadeOut * 50L))));
}
/**
* Sends an action bar message to an audience.
*
* @param audience the audience to send the action bar message to
* @param actionBar the action bar component
*/
public static void sendActionBar(Audience audience, Component actionBar) {
audience.sendActionBar(actionBar);
}
/**
* Sends a message to an audience.
*
@@ -173,6 +122,10 @@ public class AdventureHelper {
return getInstance().gsonComponentSerializer.deserialize(json);
}
public static Component jsonElementToComponent(JsonElement json) {
return getInstance().gsonComponentSerializer.deserializeFromTree(json);
}
/**
* Converts a Component to a JSON string.
*
@@ -183,22 +136,8 @@ public class AdventureHelper {
return getGson().serialize(component);
}
/**
* Converts a JsonElement to a Component.
* @param gson the JsonElement to convert
* @return the resulting Component
*/
public static Component jsonElementToComponent(JsonElement gson) {
return GsonComponentSerializer.gson().deserializeFromTree(gson);
}
/**
* Converts a JsonElement to a JSON string.
* @param jsonElement the JsonElement to convert
* @return the JSON string representation
*/
public static String jsonElementToStringJson(JsonElement jsonElement) {
return componentToJson(jsonElementToComponent(jsonElement));
public static JsonElement componentToJsonElement(Component component) {
return getGson().serializeToTree(component);
}
/**

View File

@@ -16,7 +16,10 @@ import java.util.List;
import java.util.Optional;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.IntUnaryOperator;
import java.util.function.Predicate;
import java.util.stream.LongStream;
public class PalettedContainer<T> implements PaletteResizeListener<T>, ReadableContainer<T> {

View File

@@ -2,10 +2,11 @@ org.gradle.jvmargs=-Xmx1G
# Project settings
# Rule: [major update].[feature update].[bug fix]
project_version=0.0.43
config_version=19
project_version=0.0.44
config_version=20
lang_version=4
project_group=net.momirealms
latest_supported_version=1.21.5
latest_minecraft_version=1.21.4
# Supported languages
@@ -40,7 +41,7 @@ geantyref_version=1.3.16
zstd_version=1.5.7-2
commons_io_version=2.18.0
sparrow_nbt_version=0.3
sparrow_util_version=0.36
sparrow_util_version=0.37
fastutil_version=8.5.15
netty_version=4.1.119.Final
joml_version=1.10.8
@@ -50,7 +51,7 @@ byte_buddy_version=1.17.5
ahocorasick_version=0.6.3
snake_yaml_version=2.4
anti_grief_version=0.13
nms_helper_version=0.34
nms_helper_version=0.40
# Ignite Dependencies
mixinextras_version=0.4.1
mixin_version=0.15.2+mixin.0.8.7