Skip to content

Commit

Permalink
+ Add: Shears defuses TNT.
Browse files Browse the repository at this point in the history
  • Loading branch information
FaeWulf committed Nov 14, 2024
1 parent b5e271c commit ee7bf1d
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package xyz.faewulf.diversity.event;

import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.HitResult;
import xyz.faewulf.diversity.inter.ICustomSniffer;
import xyz.faewulf.diversity.inter.typeSnort;
import xyz.faewulf.diversity.util.compare;
import xyz.faewulf.diversity.util.config.ModConfigs;

import java.util.ArrayList;
import java.util.List;

public class shearDefusesTnt {
public static InteractionResult run(Level level, Player player, InteractionHand hand, Entity entity, HitResult hitResult) {


//if not enable in config file
if (!ModConfigs.shear_defuses_tnt)
return InteractionResult.PASS;

Item item = player.getItemInHand(hand).getItem();

//if not mainhand
if ((entity.getType() == EntityType.TNT)
&& hand == InteractionHand.MAIN_HAND
&& hitResult == null
&& level instanceof ServerLevel serverLevel
&& compare.isHasTag(item, "diversity:tnt_defuser")
) {

if (entity.getRandom().nextFloat() < 0.15f)
entity.remove(Entity.RemovalReason.KILLED);

// ItemStack itemStack = new ItemStack(Items.TNT, 1);
// ItemEntity item1 = new ItemEntity(level, entity.getX(), entity.getY(), entity.getZ(), itemStack);
// item1.setDefaultPickUpDelay();
// level.addFreshEntity(item1);

player.swing(hand, true);
player.getItemInHand(hand).hurtAndBreak(1, player, LivingEntity.getSlotForHand(hand));
entity.playSound(SoundEvents.SHEEP_SHEAR, 1.0f, 1.0f);

//game event
level.gameEvent(player, GameEvent.ITEM_INTERACT_FINISH, entity.position());

return InteractionResult.SUCCESS;
}

return InteractionResult.PASS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ public class ModConfigs {
@Entry(category = "item", name = "Shear can pickpocket villager")
public static boolean shear_can_pickpocket_villager = true;

@Entry(category = "item", name = "Shear can defuse TNT")
public static boolean shear_defuses_tnt = true;

@Entry(category = "item", name = "Shear prevents plant from growing")
public static boolean shear_prevent_growing = true;

Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/assets/diversity/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"diversity.config.clock_shows_time.tooltip": "- Use Clock to show current time.",
"diversity.config.shear_prevent_growing.tooltip": "- Shear can be used on Saplings, Bamboo, Vine and Sugar cane to prevent it from growing",
"diversity.config.shear_can_pickpocket_villager.tooltip": "- Pickpocket villager using Shear while sneaking.\n- Pickpocket from the front has a high chance of making them angry; reduce it by pickpocketing from behind, or completely nullify it with invisibility potion.\n- Pickpocketing has a chance to reset their profession. The higher the profession level, the lower the chance of it resetting.",
"diversity.config.shear_defuses_tnt.tooltip": "- Shears can be used on primed TNT to give a chance to defuse it.",
"diversity.config.spyglass_what_is_that.tooltip": "- See additional block/entity information with a Spyglass, default radius is 5 blocks.\n- Zoom with Spyglass will extend to 32 blocks.",
"diversity.config.invisible_frame.tooltip": "- Make item frames invisible by sneak + right-clicking a non-dyed glass pane into them.\n- They stay invisible when holding an item, otherwise, they emit particles as indicators.",
"diversity.config.faster_minecart.tooltip": "- Rail placed on `Gravel` will make Minecart and its variants travel faster.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"minecraft:shears"
]
}
1 change: 1 addition & 0 deletions fabric/src/main/java/xyz/faewulf/diversity/Diversity.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ private void loadEvent() {
useClockOnBlock.register();
useShearOnBlock.register();
onRightClickCropBlocks.register();
shearDefusesTnt.register();
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package xyz.faewulf.diversity.event_handler;

import net.fabricmc.fabric.api.event.player.UseEntityCallback;

public class shearDefusesTnt {

public static void register() {
UseEntityCallback.EVENT.register(((player, world, hand, entity, hitResult) -> xyz.faewulf.diversity.event.shearDefusesTnt.run(world, player, hand, entity, hitResult)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package xyz.faewulf.diversity.event_handler;

import net.minecraft.world.InteractionResult;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
import xyz.faewulf.diversity.Constants;

@EventBusSubscriber(modid = Constants.MOD_ID)
public class shearDefusesTnt {
@SubscribeEvent
public static void onEntityInteract(PlayerInteractEvent.EntityInteract event) {
InteractionResult interactionResult = xyz.faewulf.diversity.event.shearDefusesTnt.run(event.getLevel(), event.getEntity(), event.getHand(), event.getTarget(), null);

if (interactionResult.consumesAction())
event.setCanceled(true);
}
}

0 comments on commit ee7bf1d

Please sign in to comment.