2024/11/11
優化了彩蛋物品的獲取方式
This commit is contained in:
parent
6c9f27041d
commit
db41f395f7
|
|
@ -18,6 +18,7 @@ import com.r3944realms.leashedplayer.modInterface.PlayerLeashable;
|
||||||
import com.r3944realms.leashedplayer.utils.Util;
|
import com.r3944realms.leashedplayer.utils.Util;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
|
import net.minecraft.tags.ItemTags;
|
||||||
import net.minecraft.world.effect.MobEffectInstance;
|
import net.minecraft.world.effect.MobEffectInstance;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.EquipmentSlot;
|
import net.minecraft.world.entity.EquipmentSlot;
|
||||||
|
|
@ -56,11 +57,13 @@ public class CommonEventHandler {
|
||||||
ChatCommand.register(dispatcher);
|
ChatCommand.register(dispatcher);
|
||||||
TickCommand.register(dispatcher);
|
TickCommand.register(dispatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void OnRegisterPotionBrewing(RegisterBrewingRecipesEvent event) {
|
public static void OnRegisterPotionBrewing(RegisterBrewingRecipesEvent event) {
|
||||||
PotionBrewing.Builder builder = event.getBuilder();
|
PotionBrewing.Builder builder = event.getBuilder();
|
||||||
builder.addMix(Potions.WATER, Items.SLIME_BALL, ModPotionRegister.NO_LEASH);
|
builder.addMix(Potions.WATER, Items.SLIME_BALL, ModPotionRegister.NO_LEASH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void OnLivingTickEvent(EntityTickEvent.Post event) {
|
public static void OnLivingTickEvent(EntityTickEvent.Post event) {
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
|
|
@ -70,7 +73,7 @@ public class CommonEventHandler {
|
||||||
}
|
}
|
||||||
if (entity instanceof LivingEntity living) {
|
if (entity instanceof LivingEntity living) {
|
||||||
MobEffectInstance effect = living.getEffect(ModEffectRegister.NO_LEASH_EFFECT);
|
MobEffectInstance effect = living.getEffect(ModEffectRegister.NO_LEASH_EFFECT);
|
||||||
if(effect != null && effect.getDuration() != 0){
|
if (effect != null && effect.getDuration() != 0) {
|
||||||
if (entity instanceof PlayerLeashable player) {
|
if (entity instanceof PlayerLeashable player) {
|
||||||
if (player.getLeashHolder() != null) {
|
if (player.getLeashHolder() != null) {
|
||||||
if (player.getLeashHolder() instanceof LeashRopeArrow arrow)
|
if (player.getLeashHolder() instanceof LeashRopeArrow arrow)
|
||||||
|
|
@ -86,46 +89,60 @@ public class CommonEventHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (entity instanceof Fox fox) {
|
if (entity instanceof Fox fox) {
|
||||||
if (fox.getMainHandItem().is(Items.ANVIL)) {
|
if (fox.getMainHandItem().is(ItemTags.ANVIL)) {
|
||||||
fox.setItemSlot(EquipmentSlot.MAINHAND, ItemStack.EMPTY);
|
fox.setItemSlot(EquipmentSlot.MAINHAND, ItemStack.EMPTY);
|
||||||
Util.throwItemTowardsLook(fox, ModItemRegister.NEOFORGE.get(), 1.0f, 0.1f);
|
Util.throwItemTowardsLook(fox, ModItemRegister.NEOFORGE.get(), 0.3f, 0.1f);
|
||||||
fox.playSound(fox.getEatingSound(ItemStack.EMPTY));
|
fox.playSound(fox.getEatingSound(ItemStack.EMPTY));
|
||||||
|
} else if (fox.getMainHandItem().is(ModItemRegister.NEOFORGE.get())) {
|
||||||
|
// 繞圈參數
|
||||||
|
float rotationSpeed = 10.0f; // 每 tick 旋轉的角度
|
||||||
|
// 計算新的旋轉角度
|
||||||
|
fox.yBodyRot += rotationSpeed; // 身體旋轉
|
||||||
|
fox.yHeadRot += rotationSpeed; // 頭部旋轉
|
||||||
|
fox.yRotO += rotationSpeed; // 當前旋轉角度
|
||||||
|
fox.yHeadRotO += rotationSpeed; // 頭部的當前旋轉角度
|
||||||
|
|
||||||
|
// 確保旋轉角度不超出 360 度,重置為 0 以便持續旋轉
|
||||||
|
if (fox.yBodyRot >= 360) fox.yBodyRot -= 360;
|
||||||
|
if (fox.yHeadRot >= 360) fox.yHeadRot -= 360;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@EventBusSubscriber(modid = LeashedPlayer.MOD_ID, bus = EventBusSubscriber.Bus.MOD)
|
|
||||||
public static class Mod extends CommonEventHandler {
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void onCommonSetup(FMLCommonSetupEvent event) {
|
|
||||||
DispenserBlock.registerProjectileBehavior(ModItemRegister.LEASH_ROPE_ARROW.get());
|
|
||||||
DispenserBlock.registerProjectileBehavior(ModItemRegister.TIPPED_LEASH_ROPE_ARROW.get());
|
|
||||||
DispenserBlock.registerProjectileBehavior(ModItemRegister.SPECTRAL_LEASH_ROPE_ARROW.get());
|
|
||||||
DispenserBlock.registerBehavior(ModItemRegister.AMETHYST_SHEARS.get(), new LeadBreakItemBehavior());
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
@EventBusSubscriber(modid = LeashedPlayer.MOD_ID, bus = EventBusSubscriber.Bus.MOD)
|
||||||
public static void onEntityAttributeEvent(EntityAttributeCreationEvent event) {
|
public static class Mod extends CommonEventHandler {
|
||||||
event.put(ModEntityRegister.KID.get(), LittlePlayer.createAttributes().build());
|
@SubscribeEvent
|
||||||
}
|
public static void onCommonSetup(FMLCommonSetupEvent event) {
|
||||||
@SubscribeEvent
|
DispenserBlock.registerProjectileBehavior(ModItemRegister.LEASH_ROPE_ARROW.get());
|
||||||
public static void onRegisterEvent(RegisterEvent event) {
|
DispenserBlock.registerProjectileBehavior(ModItemRegister.TIPPED_LEASH_ROPE_ARROW.get());
|
||||||
if (event.getRegistry() == BuiltInRegistries.RECIPE_SERIALIZER) {
|
DispenserBlock.registerProjectileBehavior(ModItemRegister.SPECTRAL_LEASH_ROPE_ARROW.get());
|
||||||
ModRecipeSerializer.TIPPED_LEASH_ROPE_ARROW_A_RECIPE =
|
DispenserBlock.registerBehavior(ModItemRegister.AMETHYST_SHEARS.get(), new LeadBreakItemBehavior());
|
||||||
RecipeSerializer.register(
|
|
||||||
"tipped_leash_rope_arrow_a_recipe",
|
|
||||||
new SimpleCraftingRecipeSerializer<>(TippedLeashRopeArrowRecipe.TippedLeashRopeArrowARecipe::new)
|
|
||||||
);
|
|
||||||
ModRecipeSerializer.TIPPED_LEASH_ROPE_ARROW_B_RECIPE =
|
|
||||||
RecipeSerializer.register("tipped_leash_rope_arrow_b_recipe",
|
|
||||||
new SimpleCraftingRecipeSerializer<>(TippedLeashRopeArrowRecipe.TippedLeashRopeArrowBRecipe::new)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onEntityAttributeEvent(EntityAttributeCreationEvent event) {
|
||||||
|
event.put(ModEntityRegister.KID.get(), LittlePlayer.createAttributes().build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onRegisterEvent(RegisterEvent event) {
|
||||||
|
if (event.getRegistry() == BuiltInRegistries.RECIPE_SERIALIZER) {
|
||||||
|
ModRecipeSerializer.TIPPED_LEASH_ROPE_ARROW_A_RECIPE =
|
||||||
|
RecipeSerializer.register(
|
||||||
|
"tipped_leash_rope_arrow_a_recipe",
|
||||||
|
new SimpleCraftingRecipeSerializer<>(TippedLeashRopeArrowRecipe.TippedLeashRopeArrowARecipe::new)
|
||||||
|
);
|
||||||
|
ModRecipeSerializer.TIPPED_LEASH_ROPE_ARROW_B_RECIPE =
|
||||||
|
RecipeSerializer.register("tipped_leash_rope_arrow_b_recipe",
|
||||||
|
new SimpleCraftingRecipeSerializer<>(TippedLeashRopeArrowRecipe.TippedLeashRopeArrowBRecipe::new)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ public class Util {
|
||||||
thrower.getZ(),
|
thrower.getZ(),
|
||||||
new ItemStack(itemToThrow)
|
new ItemStack(itemToThrow)
|
||||||
);
|
);
|
||||||
|
thrownItem.setPickUpDelay(40);
|
||||||
Vec3 lookDirection = thrower.getLookAngle();
|
Vec3 lookDirection = thrower.getLookAngle();
|
||||||
|
|
||||||
thrownItem.setDeltaMovement(
|
thrownItem.setDeltaMovement(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user