diff --git a/README.md b/README.md index bdcd850a..e37c983a 100644 --- a/README.md +++ b/README.md @@ -222,6 +222,7 @@ All changes are toggleable via config files. * **Prevent Mob Eggs from Changing Spawners:** Prevents using Mob Spawner Eggs to change what a Spawner is spawning * **Prevent Observer Activating on Placement:** Controls if the observer activates itself on the first tick when it is placed * **Prevent Placing Buckets in Portals:** Prevents placing of liquid source blocks overriding portal blocks +* **Projectiles Bounce Off Slime Blocks:** Lets projectiles like arrows bounce off slime blocks * **Pumpkin Placing:** Allows placing Pumpkins and Jack'O'Lanterns without a supporting block * **Rabbit Killer Spawning:** Configurable chance for rabbits to spawn as the killer bunny variant * **Rabbit Toast Spawning:** Configurable chance for rabbits to spawn as the Toast variant diff --git a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java index aa9b8fd2..963dc3a4 100644 --- a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java +++ b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java @@ -200,6 +200,10 @@ public static class BlocksCategory @Config.Comment("Allows placing End Crystals without requiring Obsidian or Bedrock below") public boolean utEndCrystalAnywherePlacing = false; + @Config.Name("Projectiles Bounce Off Slime Blocks") + @Config.Comment("Lets projectiles like arrows bounce off slime blocks") + public boolean utSlimeBlockProjectiles = false; + @Config.RequiresMcRestart @Config.Name("Sugar Cane Size") @Config.Comment("Determines how tall sugar cane can grow") diff --git a/src/main/java/mod/acgaming/universaltweaks/tweaks/blocks/slimeblock/UTSlimeBlockProjectiles.java b/src/main/java/mod/acgaming/universaltweaks/tweaks/blocks/slimeblock/UTSlimeBlockProjectiles.java new file mode 100644 index 00000000..32047672 --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/tweaks/blocks/slimeblock/UTSlimeBlockProjectiles.java @@ -0,0 +1,45 @@ +package mod.acgaming.universaltweaks.tweaks.blocks.slimeblock; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockSlime; +import net.minecraft.init.SoundEvents; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.RayTraceResult; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.ProjectileImpactEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +import mod.acgaming.universaltweaks.UniversalTweaks; +import mod.acgaming.universaltweaks.config.UTConfigGeneral; +import mod.acgaming.universaltweaks.config.UTConfigTweaks; + +// Courtesy of CAS-ual-TY +@Mod.EventBusSubscriber(modid = UniversalTweaks.MODID) +public class UTSlimeBlockProjectiles +{ + @SubscribeEvent + public static void utSlimeBlockProjectiles(ProjectileImpactEvent event) + { + if (!UTConfigTweaks.BLOCKS.utSlimeBlockProjectiles) return; + if (UTConfigGeneral.DEBUG.utDebugToggle) UniversalTweaks.LOGGER.debug("UTSlimeBlockProjectiles ::: Projectile impact event"); + RayTraceResult rayTraceResult = event.getRayTraceResult(); + if (rayTraceResult.typeOfHit == RayTraceResult.Type.BLOCK) + { + BlockPos pos = rayTraceResult.getBlockPos(); + World world = event.getEntity().world; + Block block = world.getBlockState(pos).getBlock(); + if (block instanceof BlockSlime) + { + EnumFacing direction = rayTraceResult.sideHit; + if (direction.getXOffset() != 0) event.getEntity().motionX *= -0.1D; + else if (direction.getYOffset() != 0) event.getEntity().motionY *= -0.1D; + else if (direction.getZOffset() != 0) event.getEntity().motionZ *= -0.1D; + world.playSound(null, pos, SoundEvents.BLOCK_SLIME_HIT, SoundCategory.BLOCKS, 1.0F, (world.rand.nextFloat() - world.rand.nextFloat()) * 0.2F + 1.0F); + event.setCanceled(true); + } + } + } +}