Skip to content

Commit 94cc56b

Browse files
committed
Cake sounds and particles
1 parent 17b926c commit 94cc56b

File tree

6 files changed

+86
-3
lines changed

6 files changed

+86
-3
lines changed

src/main/java/com/therandomlabs/randomtweaks/RandomTweaks.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ public final class RandomTweaks {
3636
public static final Logger LOGGER = LogManager.getLogger(MOD_ID);
3737

3838
public static final boolean APPLECORE_LOADED = Loader.isModLoaded("applecore");
39+
public static final boolean CAKE_CHOMPS_LOADED = Loader.isModLoaded("cakechomps");
40+
public static final boolean CALM_DOWN_ZOMBIE_GUY_LOADED =
41+
Loader.isModLoaded("calmdownzombieguy");
3942
public static final boolean COLORFUL_SHEEP_LOADED = Loader.isModLoaded("colorful-sheep");
4043
public static final boolean DING_LOADED = Loader.isModLoaded("ding");
4144
public static final boolean DYNAMIC_SURROUNDINGS_LOADED = Loader.isModLoaded("dsurround");
45+
public static final boolean ENTITY_NAN_HEALTH_FIX_LOADED = Loader.isModLoaded("nanfix");
4246
public static final boolean EXPANDED_BONEMEAL_LOADED = Loader.isModLoaded("expandedbonemeal");
4347
public static final boolean HEADCRUMBS_LOADED = Loader.isModLoaded("headcrumbs");
4448
public static final boolean HELPFIXER_LOADED = Loader.isModLoaded("helpfixer");

src/main/java/com/therandomlabs/randomtweaks/common/MiscEventHandler.java

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import java.util.UUID;
55
import com.therandomlabs.randomtweaks.RandomTweaks;
66
import com.therandomlabs.randomtweaks.config.RTConfig;
7+
import net.minecraft.block.Block;
8+
import net.minecraft.block.BlockCake;
9+
import net.minecraft.block.state.IBlockState;
710
import net.minecraft.enchantment.EnchantmentHelper;
811
import net.minecraft.entity.Entity;
912
import net.minecraft.entity.EntityAgeable;
@@ -17,10 +20,15 @@
1720
import net.minecraft.entity.player.EntityPlayer;
1821
import net.minecraft.init.Enchantments;
1922
import net.minecraft.init.Items;
23+
import net.minecraft.init.SoundEvents;
24+
import net.minecraft.item.Item;
2025
import net.minecraft.item.ItemStack;
2126
import net.minecraft.util.ActionResult;
2227
import net.minecraft.util.DamageSource;
2328
import net.minecraft.util.EnumActionResult;
29+
import net.minecraft.util.EnumParticleTypes;
30+
import net.minecraft.util.math.BlockPos;
31+
import net.minecraft.util.math.Vec3d;
2432
import net.minecraft.world.World;
2533
import net.minecraft.world.WorldServer;
2634
import net.minecraftforge.common.util.FakePlayerFactory;
@@ -33,6 +41,7 @@
3341
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
3442
import net.minecraftforge.event.entity.player.ArrowNockEvent;
3543
import net.minecraftforge.event.entity.player.AttackEntityEvent;
44+
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
3645
import net.minecraftforge.fml.common.Mod;
3746
import net.minecraftforge.fml.common.eventhandler.Event;
3847
import 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
}

src/main/java/com/therandomlabs/randomtweaks/common/ZombieAIHandler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.ArrayList;
44
import java.util.Iterator;
55
import java.util.List;
6+
import com.therandomlabs.randomtweaks.RandomTweaks;
67
import com.therandomlabs.randomtweaks.config.RTConfig;
78
import net.minecraft.entity.EntityLivingBase;
89
import net.minecraft.entity.ai.EntityAITasks;
@@ -44,7 +45,8 @@ public boolean shouldExecute() {
4445
}
4546

4647
public static void onZombieJoinWorld(EntityZombie zombie) {
47-
if(!RTConfig.Misc.zombieTargetDetectionImprovements) {
48+
if(!RTConfig.Misc.zombieTargetDetectionImprovements ||
49+
RandomTweaks.CALM_DOWN_ZOMBIE_GUY_LOADED) {
4850
return;
4951
}
5052

src/main/java/com/therandomlabs/randomtweaks/config/RTConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,11 @@ public static final class Misc {
405405
@Config.Property("Allows players to sleep near mobs with custom names.")
406406
public static boolean allowSleepNearMobsWithCustomNames = true;
407407

408+
@Config.Property(
409+
"Whether to play eating sounds and display crumb particles when eating cakes."
410+
)
411+
public static boolean cakeSoundsAndParticles = true;
412+
408413
@Config.Property("Whether attacks should be disabled during the attack cooldown.")
409414
public static boolean disableAttacksDuringAttackCooldown = TRLUtils.IS_DEOBFUSCATED;
410415

src/main/resources/assets/randomtweaks/lang/de_de.lang

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ randomtweaks.config.misc.allowSleepNearMobsWithCustomNames=Allow sleep near mobs
162162
randomtweaks.config.misc.attackSpeed=Attack speed
163163
randomtweaks.config.misc.betterButtonNames=Better button names
164164
randomtweaks.config.misc.bowInfinityFix=Bow Infinity fix
165+
randomtweaks.config.misc.cakeSoundsAndParticles=Cake sounds and particles
165166
randomtweaks.config.misc.disableAttacksDuringAttackCooldown=Disable attacks during attack cooldown
166167
randomtweaks.config.misc.deathPunishmentMode=Death punishment mode
167168
randomtweaks.config.misc.deathPunishmentMode.enabled=Enabled
@@ -170,6 +171,7 @@ randomtweaks.config.misc.deathPunishmentMode.disabled=Disabled
170171
randomtweaks.config.misc.disableBedProximityRequirement=Disable bed proximity requirement
171172
randomtweaks.config.misc.disableCumulativeAnvilCosts=Disable cumulative anvil cost
172173
randomtweaks.config.misc.entitiesDropNameTags=Enable living entities with custom names dropping nametags
174+
randomtweaks.config.misc.entityNaNHealthFix=Entity NaN Health Fix
173175
randomtweaks.config.misc.farmlandTrampleBehavior=Farmland trample behavior
174176
randomtweaks.config.misc.farmlandTrampleBehavior.vanilla=Vanilla
175177
randomtweaks.config.misc.farmlandTrampleBehavior.dontTrampleIfFeatherFalling=Don't trample if Feather Falling
@@ -188,6 +190,7 @@ randomtweaks.config.playerHeadDrops.chanceWhenKilledByPlayer=Drop chance when ki
188190
randomtweaks.config.playerHeadDrops.normalChance=Normal drop chance
189191

190192
randomtweaks.config.world=World
193+
randomtweaks.config.world.cactusSpawnRate=Cactus spawn rate
191194
randomtweaks.config.world.fixDuplicateEntityUUIDs=Fix duplicate entity UUIDs
192195
randomtweaks.config.world.logEntityUUIDReassignments=Log entity UUID reassignments
193196
randomtweaks.config.world.realisticWorldType=Enable Realistic world type

src/main/resources/assets/randomtweaks/lang/en_us.lang

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ randomtweaks.config.misc.allowSleepNearMobsWithCustomNames=Allow sleep near mobs
162162
randomtweaks.config.misc.attackSpeed=Attack speed
163163
randomtweaks.config.misc.betterButtonNames=Better button names
164164
randomtweaks.config.misc.bowInfinityFix=Bow Infinity fix
165+
randomtweaks.config.misc.cakeSoundsAndParticles=Cake sounds and particles
165166
randomtweaks.config.misc.disableAttacksDuringAttackCooldown=Disable attacks during attack cooldown
166167
randomtweaks.config.misc.deathPunishmentMode=Death punishment mode
167168
randomtweaks.config.misc.deathPunishmentMode.enabled=Enabled

0 commit comments

Comments
 (0)