mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 01:49:30 +00:00
添加摩擦力,跳跃、移动系数
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
);
|
||||
|
||||
@@ -38,6 +38,9 @@ public class BlockSettings {
|
||||
LazyReference<Set<Key>> correctTools = LazyReference.lazyReference(Set::of);
|
||||
String name;
|
||||
String supportShapeBlockState;
|
||||
float friction = 0.6f;
|
||||
float speedFactor = 1f;
|
||||
float jumpFactor = 1f;
|
||||
|
||||
private BlockSettings() {}
|
||||
|
||||
@@ -101,6 +104,9 @@ public class BlockSettings {
|
||||
newSettings.supportShapeBlockState = settings.supportShapeBlockState;
|
||||
newSettings.propagatesSkylightDown = settings.propagatesSkylightDown;
|
||||
newSettings.useShapeForLightOcclusion = settings.useShapeForLightOcclusion;
|
||||
newSettings.speedFactor = settings.speedFactor;
|
||||
newSettings.jumpFactor = settings.jumpFactor;
|
||||
newSettings.friction = settings.friction;
|
||||
return newSettings;
|
||||
}
|
||||
|
||||
@@ -140,6 +146,18 @@ public class BlockSettings {
|
||||
return hardness;
|
||||
}
|
||||
|
||||
public float friction() {
|
||||
return friction;
|
||||
}
|
||||
|
||||
public float jumpFactor() {
|
||||
return jumpFactor;
|
||||
}
|
||||
|
||||
public float speedFactor() {
|
||||
return speedFactor;
|
||||
}
|
||||
|
||||
public Tristate canOcclude() {
|
||||
return canOcclude;
|
||||
}
|
||||
@@ -236,6 +254,21 @@ public class BlockSettings {
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockSettings friction(float friction) {
|
||||
this.friction = friction;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockSettings speedFactor(float speedFactor) {
|
||||
this.speedFactor = speedFactor;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockSettings jumpFactor(float jumpFactor) {
|
||||
this.jumpFactor = jumpFactor;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockSettings tags(Set<Key> tags) {
|
||||
this.tags = tags;
|
||||
return this;
|
||||
@@ -384,6 +417,18 @@ public class BlockSettings {
|
||||
float floatValue = ResourceConfigUtils.getAsFloat(value, "hardness");
|
||||
return settings -> settings.hardness(floatValue);
|
||||
}));
|
||||
registerFactory("friction", (value -> {
|
||||
float floatValue = ResourceConfigUtils.getAsFloat(value, "friction");
|
||||
return settings -> settings.friction(floatValue);
|
||||
}));
|
||||
registerFactory("speed-factor", (value -> {
|
||||
float floatValue = ResourceConfigUtils.getAsFloat(value, "speed-factor");
|
||||
return settings -> settings.speedFactor(floatValue);
|
||||
}));
|
||||
registerFactory("jump-factor", (value -> {
|
||||
float floatValue = ResourceConfigUtils.getAsFloat(value, "jump-factor");
|
||||
return settings -> settings.jumpFactor(floatValue);
|
||||
}));
|
||||
registerFactory("resistance", (value -> {
|
||||
float floatValue = ResourceConfigUtils.getAsFloat(value, "resistance");
|
||||
return settings -> settings.resistance(floatValue);
|
||||
|
||||
Reference in New Issue
Block a user