1010import huix .infinity .util .IFWEnchantmentHelper ;
1111import huix .infinity .util .WorldHelper ;
1212import net .minecraft .ChatFormatting ;
13+ import net .minecraft .client .Minecraft ;
1314import net .minecraft .client .gui .screens .Screen ;
15+ import net .minecraft .client .player .LocalPlayer ;
1416import net .minecraft .core .BlockPos ;
1517import net .minecraft .core .component .DataComponents ;
1618import net .minecraft .network .chat .Component ;
1719import net .minecraft .resources .ResourceKey ;
1820import net .minecraft .resources .ResourceLocation ;
1921import net .minecraft .server .level .ServerLevel ;
2022import net .minecraft .tags .ItemTags ;
21- import net .minecraft .world .effect .MobEffectInstance ;
2223import net .minecraft .world .effect .MobEffects ;
2324import net .minecraft .world .entity .EquipmentSlotGroup ;
24- import net .minecraft .world .entity .LivingEntity ;
25- import net .minecraft .world .entity .ai .attributes .AttributeInstance ;
2625import net .minecraft .world .entity .ai .attributes .AttributeModifier ;
2726import net .minecraft .world .entity .ai .attributes .Attributes ;
2827import net .minecraft .world .entity .player .Player ;
4039import net .minecraft .world .level .storage .loot .providers .number .ConstantValue ;
4140import net .neoforged .bus .api .IEventBus ;
4241import net .neoforged .bus .api .SubscribeEvent ;
42+ import net .neoforged .neoforge .client .event .CalculatePlayerTurnEvent ;
4343import net .neoforged .neoforge .common .Tags ;
4444import net .neoforged .neoforge .event .ItemAttributeModifierEvent ;
4545import net .neoforged .neoforge .event .LootTableLoadEvent ;
6161public class IFWEvents {
6262
6363 public static void init (IEventBus bus ) {
64- bus .addListener (IFWEvents ::armorModify );
65- bus .addListener (IFWEvents ::playerBreakSpeed );
66- bus .addListener (IFWEvents ::playerAttacklHit );
67- bus .addListener (IFWEvents ::playerDie );
68- bus .addListener (IFWEvents ::playerClone );
69- bus .addListener (IFWEvents ::daySleep );
70- bus .addListener (IFWEvents ::addFoodInfo );
71- bus .addListener (IFWEvents ::nonRemoveUnClearEffect );
72- bus .addListener (IFWEvents ::injectFuel );
73- bus .addListener (IFWEvents ::injectItem );
74- bus .addListener (IFWEvents ::serverTick );
75- bus .addListener (IFWEvents ::playerLoggedIn );
76- bus .addListener (IFWEvents ::onLootTableLoad );
77- bus .addListener (IFWEvents ::onCropGrow );
78- bus .addListener (IFWEvents ::onMobEffectApplied );
79- bus .addListener (IFWEvents ::onMobEffectRemoved );
64+ // Register this class to receive forge bus events
65+ bus .register (IFWEvents .class );
66+
8067 }
8168
69+ @ SubscribeEvent
8270 public static void injectItem (final DataMapsUpdatedEvent event ) {
8371 IFWLoading .rebuildStackSize ();
8472 IFWLoading .injectCookingLevel ();
8573 IFWLoading .injectAnvil ();
8674 }
8775
88-
76+ @ SubscribeEvent
8977 public static void serverTick (final ServerTickEvent .Post event ) {
9078 for (Map .Entry <ResourceKey <Level >, Map <BlockPos , Integer >> entry : WorldHelper .DELAYED_BLOCKS .entrySet ()) {
9179 ResourceKey <Level > dimension = entry .getKey ();
@@ -110,6 +98,7 @@ public static void serverTick(final ServerTickEvent.Post event) {
11098 }
11199 }
112100
101+ @ SubscribeEvent
113102 public static void armorModify (final ItemAttributeModifierEvent event ) {
114103 if (event .getItemStack ().getItem () instanceof ArmorItem armorItem ) {
115104 ArmorItem .Type type = armorItem .getType ();
@@ -120,22 +109,26 @@ public static void armorModify(final ItemAttributeModifierEvent event) {
120109 }
121110
122111 }
112+
113+ @ SubscribeEvent
123114 public static void playerLoggedIn (final PlayerEvent .PlayerLoggedInEvent event ) {
124115 Player entity = event .getEntity ();
125116 }
126117
127-
118+ @ SubscribeEvent
128119 public static void playerBreakSpeed (final PlayerEvent .BreakSpeed event ) {
129120 event .setNewSpeed (event .getOriginalSpeed () + LevelBonusStats .HARVESTING .calcBonusFor (event .getEntity ()));
130121 }
131122
123+ @ SubscribeEvent
132124 public static void playerAttacklHit (final CriticalHitEvent event ) {
133125 if (!event .getEntity ().getFoodData ().ifw_hasAnyEnergy ()) {
134126 event .setDamageMultiplier (0.5F );
135127 }
136128 event .setDamageMultiplier (1.0F + LevelBonusStats .MELEE_DAMAGE .calcBonusFor (event .getEntity ()));
137129 }
138130
131+ @ SubscribeEvent
139132 public static void playerDie (final LivingDeathEvent event ) {
140133 if (event .getEntity () instanceof Player entity ) {
141134 int respawn_experience = entity .getData (IFWAttachments .respawn_xp );
@@ -149,22 +142,26 @@ public static void playerDie(final LivingDeathEvent event) {
149142 }
150143 }
151144
145+ @ SubscribeEvent
152146 public static void playerClone (final PlayerEvent .Clone event ) {
153147 final Player cloned = event .getEntity ();
154148 cloned .giveExperiencePoints (event .getOriginal ().getData (IFWAttachments .respawn_xp ));
155149 }
156150
151+ @ SubscribeEvent
157152 public static void daySleep (final CanContinueSleepingEvent event ) {
158153 event .setContinueSleeping (true );
159154 }
160155
156+ @ SubscribeEvent
161157 public static void addFoodInfo (final ItemTooltipEvent event ) {
162158 ItemStack stack = event .getItemStack ();
163159 if (stack .getItem ().ifw_isFood ()) {
164160 showFoodInfo (stack .get (DataComponents .FOOD ), event .getToolTip ());
165161 showMoreFoodInfo (stack .get (IFWDataComponents .ifw_food_data ), event .getToolTip ());
166162 }
167163 }
164+
168165 private static void showFoodInfo (final FoodProperties food , final List <Component > list ) {
169166 if (food != null && Screen .hasShiftDown ()) {
170167 if (food .nutrition () != 0 )
@@ -173,6 +170,7 @@ private static void showFoodInfo(final FoodProperties food, final List<Component
173170 list .add (Component .translatable ("foodtips.saturation" , food .saturation ()).withStyle (ChatFormatting .AQUA ));
174171 }
175172 }
173+
176174 private static void showMoreFoodInfo (final IFWFoodProperties extraFood , final List <Component > list ) {
177175 if (extraFood != null && Screen .hasAltDown ()) {
178176 if (extraFood .protein () != 0 )
@@ -184,11 +182,13 @@ private static void showMoreFoodInfo(final IFWFoodProperties extraFood, final Li
184182 }
185183 }
186184
185+ @ SubscribeEvent
187186 public static void nonRemoveUnClearEffect (final MobEffectEvent .Remove event ) {
188187 if (event .getEffect ().value () instanceof UnClearEffect )
189188 event .setCanceled (true );
190189 }
191190
191+ @ SubscribeEvent
192192 public static void injectFuel (final FurnaceFuelBurnTimeEvent event ) {
193193 if (event .getItemStack ().is (Items .TORCH ))
194194 event .setBurnTime (800 );
@@ -204,6 +204,7 @@ public static void injectFuel(final FurnaceFuelBurnTimeEvent event) {
204204 event .setBurnTime (3200 );
205205 }
206206
207+ @ SubscribeEvent
207208 public static void onLootTableLoad (final LootTableLoadEvent event ) {
208209 if (event .getName ().equals (BuiltInLootTables .SPAWN_BONUS_CHEST .location ())) {
209210 event .setTable (LootTable .lootTable ()
@@ -228,41 +229,6 @@ public static void onLootTableLoad(final LootTableLoadEvent event) {
228229 }
229230
230231 @ SubscribeEvent
231- public static void onMobEffectApplied (MobEffectEvent .Added event ) {
232- MobEffectInstance effectInstance = event .getEffectInstance ();
233- if (effectInstance != null && effectInstance .getEffect () == MobEffects .MOVEMENT_SLOWDOWN ) {
234- LivingEntity living = event .getEntity ();
235- int amplifier = effectInstance .getAmplifier ();
236-
237- AttributeInstance speedAttribute = living .getAttribute (Attributes .MOVEMENT_SPEED );
238- if (speedAttribute != null ) {
239- ResourceLocation modifierId = ResourceLocation .fromNamespaceAndPath (InfinityWay .MOD_ID , "ifw_slowness" );
240- speedAttribute .removeModifier (modifierId );
241-
242- double reduction = -0.2 * (amplifier + 1 );
243- speedAttribute .addTransientModifier (new AttributeModifier (
244- modifierId ,
245- reduction ,
246- AttributeModifier .Operation .ADD_MULTIPLIED_BASE
247- ));
248- }
249- }
250- }
251-
252- @ SubscribeEvent
253- public static void onMobEffectRemoved (MobEffectEvent .Remove event ) {
254- MobEffectInstance effectInstance = event .getEffectInstance ();
255- if (effectInstance != null && effectInstance .getEffect () == MobEffects .MOVEMENT_SLOWDOWN ) {
256- LivingEntity living = event .getEntity ();
257-
258- AttributeInstance speedAttribute = living .getAttribute (Attributes .MOVEMENT_SPEED );
259- if (speedAttribute != null ) {
260- ResourceLocation modifierId = ResourceLocation .fromNamespaceAndPath (InfinityWay .MOD_ID , "ifw_slowness" );
261- speedAttribute .removeModifier (modifierId );
262- }
263- }
264- }
265-
266232 public static void onCropGrow (final CropGrowEvent .Pre event ) {
267233 LevelAccessor world = event .getLevel ();
268234
@@ -272,6 +238,24 @@ public static void onCropGrow(final CropGrowEvent.Pre event) {
272238 }
273239 }
274240
241+ @ SubscribeEvent
242+ public static void onCalculatePlayerTurn (CalculatePlayerTurnEvent event ) {
243+ // 获取玩家
244+ LocalPlayer player = Minecraft .getInstance ().player ;
245+
246+ if (player != null && player .hasEffect (MobEffects .MOVEMENT_SLOWDOWN )) {
247+ // 获取缓慢效果等级
248+ int amplifier = player .getEffect (MobEffects .MOVEMENT_SLOWDOWN ).getAmplifier ();
249+ // 获取当前灵敏度
250+ double sensitivity = event .getMouseSensitivity ();
251+ // 根据缓慢等级降低灵敏度 (每级减少20%)
252+ double reduction = 1.0 - ((amplifier + 1 ) * 0.2 );
253+ // 设置新的灵敏度
254+ event .setMouseSensitivity (sensitivity * reduction );
255+ }
256+ }
257+
258+ // @SubscribeEvent
275259// public static void onSleepFinished(final SleepFinishedTimeEvent event) {
276260//
277261// }
0 commit comments