Skip to content

Commit

Permalink
Implement Projectiles Bounce Off Slime Blocks tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
ACGaming committed Oct 18, 2024
1 parent 9adde32 commit 9abd329
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}

0 comments on commit 9abd329

Please sign in to comment.