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

添加摩擦力,跳跃、移动系数

This commit is contained in:
XiaoMoMi
2025-08-22 21:50:07 +08:00
parent 6f6bb4c9da
commit 6061216628
4 changed files with 76 additions and 16 deletions

View File

@@ -128,6 +128,9 @@ public final class BukkitCustomBlock extends AbstractCustomBlock {
behaviorHolder.bindValue(super.behavior);
// set block side properties
CoreReflections.field$BlockBehaviour$explosionResistance.set(nmsBlock, settings.resistance());
CoreReflections.field$BlockBehaviour$friction.set(nmsBlock, settings.friction());
CoreReflections.field$BlockBehaviour$speedFactor.set(nmsBlock, settings.speedFactor());
CoreReflections.field$BlockBehaviour$jumpFactor.set(nmsBlock, settings.jumpFactor());
CoreReflections.field$BlockBehaviour$soundType.set(nmsBlock, SoundUtils.toSoundType(settings.sounds()));
// init cache
CoreReflections.method$BlockStateBase$initCache.invoke(nmsState);

View File

@@ -68,22 +68,6 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
return recipe;
};
static {
try {
Key dyeRecipeId = Key.from("armor_dye");
MINECRAFT_RECIPE_REMOVER.accept(dyeRecipeId);
MINECRAFT_RECIPE_ADDER.apply(dyeRecipeId, RecipeInjector.createCustomDyeRecipe(dyeRecipeId));
Key repairRecipeId = Key.from("repair_item");
MINECRAFT_RECIPE_REMOVER.accept(repairRecipeId);
MINECRAFT_RECIPE_ADDER.apply(repairRecipeId, RecipeInjector.createRepairItemRecipe(repairRecipeId));
Key fireworkStarFadeRecipeId = Key.from("firework_star_fade");
MINECRAFT_RECIPE_REMOVER.accept(fireworkStarFadeRecipeId);
MINECRAFT_RECIPE_ADDER.apply(fireworkStarFadeRecipeId, RecipeInjector.createFireworkStarFadeRecipe(fireworkStarFadeRecipeId));
} catch (ReflectiveOperationException e) {
throw new ReflectionInitException("Failed to inject special recipes", e);
}
}
private static final Map<Key, Function<Recipe<ItemStack>, Object>> ADD_RECIPE_FOR_MINECRAFT_RECIPE_HOLDER = Map.of(
RecipeSerializers.SHAPED, recipe -> {
CustomShapedRecipe<ItemStack> shapedRecipe = (CustomShapedRecipe<ItemStack>) recipe;
@@ -481,6 +465,22 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
this.plugin.logger().warn("Failed to register recipe " + recipe.id().toString(), e);
}
}
// 重新注入特殊配方
try {
Key dyeRecipeId = Key.from("armor_dye");
MINECRAFT_RECIPE_REMOVER.accept(dyeRecipeId);
MINECRAFT_RECIPE_ADDER.apply(dyeRecipeId, RecipeInjector.createCustomDyeRecipe(dyeRecipeId));
Key repairRecipeId = Key.from("repair_item");
MINECRAFT_RECIPE_REMOVER.accept(repairRecipeId);
MINECRAFT_RECIPE_ADDER.apply(repairRecipeId, RecipeInjector.createRepairItemRecipe(repairRecipeId));
Key fireworkStarFadeRecipeId = Key.from("firework_star_fade");
MINECRAFT_RECIPE_REMOVER.accept(fireworkStarFadeRecipeId);
MINECRAFT_RECIPE_ADDER.apply(fireworkStarFadeRecipeId, RecipeInjector.createFireworkStarFadeRecipe(fireworkStarFadeRecipeId));
} catch (ReflectiveOperationException e) {
throw new ReflectionInitException("Failed to inject special recipes", e);
}
try {
// give flags back on 1.21.2+
if (VersionHelper.isOrAbove1_21_2() && this.stolenFeatureFlagSet != null) {

View File

@@ -1451,6 +1451,18 @@ public final class CoreReflections {
ReflectionUtils.getInstanceDeclaredField(clazz$BlockBehaviour, float.class, 0)
);
public static final Field field$BlockBehaviour$friction = requireNonNull(
ReflectionUtils.getInstanceDeclaredField(clazz$BlockBehaviour, float.class, 1)
);
public static final Field field$BlockBehaviour$speedFactor = requireNonNull(
ReflectionUtils.getInstanceDeclaredField(clazz$BlockBehaviour, float.class, 2)
);
public static final Field field$BlockBehaviour$jumpFactor = requireNonNull(
ReflectionUtils.getInstanceDeclaredField(clazz$BlockBehaviour, float.class, 3)
);
public static final Field field$BlockBehaviour$soundType = requireNonNull(
ReflectionUtils.getInstanceDeclaredField(clazz$BlockBehaviour, clazz$SoundType, 0)
);