-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
common/src/main/java/xyz/faewulf/diversity/event/shearDefusesTnt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
common/src/main/resources/data/diversity/tags/item/tnt_defuser.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"replace": false, | ||
"values": [ | ||
"minecraft:shears" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
fabric/src/main/java/xyz/faewulf/diversity/event_handler/shearDefusesTnt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
neoforge/src/main/java/xyz/faewulf/diversity/event_handler/shearDefusesTnt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |