44import java .util .UUID ;
55import com .therandomlabs .randomtweaks .RandomTweaks ;
66import com .therandomlabs .randomtweaks .config .RTConfig ;
7+ import net .minecraft .block .Block ;
8+ import net .minecraft .block .BlockCake ;
9+ import net .minecraft .block .state .IBlockState ;
710import net .minecraft .enchantment .EnchantmentHelper ;
811import net .minecraft .entity .Entity ;
912import net .minecraft .entity .EntityAgeable ;
1720import net .minecraft .entity .player .EntityPlayer ;
1821import net .minecraft .init .Enchantments ;
1922import net .minecraft .init .Items ;
23+ import net .minecraft .init .SoundEvents ;
24+ import net .minecraft .item .Item ;
2025import net .minecraft .item .ItemStack ;
2126import net .minecraft .util .ActionResult ;
2227import net .minecraft .util .DamageSource ;
2328import net .minecraft .util .EnumActionResult ;
29+ import net .minecraft .util .EnumParticleTypes ;
30+ import net .minecraft .util .math .BlockPos ;
31+ import net .minecraft .util .math .Vec3d ;
2432import net .minecraft .world .World ;
2533import net .minecraft .world .WorldServer ;
2634import net .minecraftforge .common .util .FakePlayerFactory ;
3341import net .minecraftforge .event .entity .living .LivingSpawnEvent ;
3442import net .minecraftforge .event .entity .player .ArrowNockEvent ;
3543import net .minecraftforge .event .entity .player .AttackEntityEvent ;
44+ import net .minecraftforge .event .entity .player .PlayerInteractEvent ;
3645import net .minecraftforge .fml .common .Mod ;
3746import net .minecraftforge .fml .common .eventhandler .Event ;
3847import net .minecraftforge .fml .common .eventhandler .EventPriority ;
@@ -112,7 +121,8 @@ public static void onLivingUpdate(LivingEvent.LivingUpdateEvent event) {
112121 return ;
113122 }
114123
115- if (RTConfig .Misc .entityNaNHealthFix && Float .isNaN (entity .getHealth ())) {
124+ if (RTConfig .Misc .entityNaNHealthFix && !RandomTweaks .ENTITY_NAN_HEALTH_FIX_LOADED &&
125+ Float .isNaN (entity .getHealth ())) {
116126 entity .setHealth (0.0F );
117127 return ;
118128 }
@@ -128,7 +138,8 @@ public static void onLivingHurt(LivingHurtEvent event) {
128138 final DamageSource source = event .getSource ();
129139 final float amount = event .getAmount ();
130140
131- if (RTConfig .Misc .entityNaNHealthFix && Float .isNaN (amount )) {
141+ if (RTConfig .Misc .entityNaNHealthFix && !RandomTweaks .ENTITY_NAN_HEALTH_FIX_LOADED &&
142+ Float .isNaN (amount )) {
132143 RandomTweaks .LOGGER .error ("{} was damaged by a NaN value." , entity );
133144 RandomTweaks .LOGGER .error ("Immediate source: " + source );
134145 RandomTweaks .LOGGER .error ("True source: " + source .getTrueSource ());
@@ -328,4 +339,61 @@ public static void onArrowNock(ArrowNockEvent event) {
328339 event .setAction (new ActionResult <>(EnumActionResult .SUCCESS , bow ));
329340 }
330341 }
342+
343+ @ SubscribeEvent
344+ public static void onBlockRightClick (PlayerInteractEvent .RightClickBlock event ) {
345+ if (!RTConfig .Misc .cakeSoundsAndParticles || RandomTweaks .CAKE_CHOMPS_LOADED ) {
346+ return ;
347+ }
348+
349+ final World world = event .getWorld ();
350+ final EntityPlayer player = event .getEntityPlayer ();
351+ final BlockPos pos = event .getPos ();
352+ final IBlockState state = world .getBlockState (pos );
353+ final Block block = state .getBlock ();
354+
355+ if (!(block instanceof BlockCake ) || !player .canEat (false )) {
356+ return ;
357+ }
358+
359+ final Random random = player .getRNG ();
360+
361+ final ItemStack stack = block .getPickBlock (state , null , world , pos , player );
362+ final int id = Item .getIdFromItem (stack .getItem ());
363+ final int meta = stack .getMetadata ();
364+
365+ //Taken from EntityLivingBase#updateItemUse
366+ for (int i = 0 ; i < 5 ; i ++) {
367+ final Vec3d particlePos = new Vec3d (
368+ (random .nextFloat () - 0.5 ) * 0.3 , (-random .nextFloat ()) * 0.6 - 0.3 , 0.6
369+ ).rotatePitch (
370+ -player .rotationPitch * 0.017453292F
371+ ).rotateYaw (
372+ -player .rotationYaw * 0.017453292F
373+ ).add (
374+ player .posX , player .posY + player .getEyeHeight () + 0.05 , player .posZ
375+ );
376+
377+ final Vec3d particleSpeed = new Vec3d (
378+ (random .nextFloat () - 0.5 ) * 0.1 , Math .random () * 0.1 + 0.1 , 0.0
379+ ).rotatePitch (
380+ -player .rotationPitch * 0.017453292F
381+ ).rotateYaw (
382+ -player .rotationYaw * 0.017453292F
383+ );
384+
385+ world .spawnParticle (
386+ EnumParticleTypes .ITEM_CRACK ,
387+ particlePos .x , particlePos .y , particlePos .z ,
388+ particleSpeed .x , particleSpeed .y , particleSpeed .z ,
389+ id , meta
390+ );
391+ }
392+
393+ player .playSound (
394+ SoundEvents .ENTITY_GENERIC_EAT ,
395+ 0.5F + 0.5F * random .nextInt (2 ),
396+ (random .nextFloat () - random .nextFloat ()) * 0.2F + 1.0F
397+ );
398+ }
331399}
0 commit comments