From f337faa0850cc2cd002b42fa45805168ec9d8e6e Mon Sep 17 00:00:00 2001 From: Leclowndu93150 Date: Sat, 12 Oct 2024 22:52:30 +0200 Subject: [PATCH] ingot yeah ingot yeah yeah --- .../com/leclowndu93150/carbort/Carbort.java | 12 ++++++--- .../content/items/PartyPickaxeItem.java | 3 ++- .../content/items/UnstableIngotItem.java | 11 +++++++- .../carbort/datagen/DataGatherer.java | 2 +- .../carbort/events/CarbortClientEvents.java | 15 +++++++++++ .../carbort/events/CarbortEvents.java | 26 +++++++++++++++++++ 6 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/leclowndu93150/carbort/events/CarbortClientEvents.java diff --git a/src/main/java/com/leclowndu93150/carbort/Carbort.java b/src/main/java/com/leclowndu93150/carbort/Carbort.java index b094c36..c115b5e 100644 --- a/src/main/java/com/leclowndu93150/carbort/Carbort.java +++ b/src/main/java/com/leclowndu93150/carbort/Carbort.java @@ -1,12 +1,18 @@ package com.leclowndu93150.carbort; +import com.leclowndu93150.carbort.content.items.UnstableIngotItem; import com.leclowndu93150.carbort.registries.*; import com.mojang.logging.LogUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.world.item.ItemStack; import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.ModContainer; import net.neoforged.fml.common.Mod; import net.neoforged.fml.config.ModConfig; import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; +import net.neoforged.neoforge.client.event.ClientTickEvent; +import net.neoforged.neoforge.event.tick.PlayerTickEvent; +import net.neoforged.neoforge.event.tick.ServerTickEvent; import org.slf4j.Logger; @Mod(Carbort.MODID) @@ -29,8 +35,8 @@ public Carbort(IEventBus modEventBus, ModContainer modContainer) { modContainer.registerConfig(ModConfig.Type.COMMON, CarbortConfig.SPEC); } - private void commonSetup(final FMLCommonSetupEvent event) - { - LOGGER.info("[Carbort]: I hope i did things right."); + + private void commonSetup(final FMLCommonSetupEvent event) { + LOGGER.info("I hope i did things right."); } } diff --git a/src/main/java/com/leclowndu93150/carbort/content/items/PartyPickaxeItem.java b/src/main/java/com/leclowndu93150/carbort/content/items/PartyPickaxeItem.java index 387f3c1..dc5a822 100644 --- a/src/main/java/com/leclowndu93150/carbort/content/items/PartyPickaxeItem.java +++ b/src/main/java/com/leclowndu93150/carbort/content/items/PartyPickaxeItem.java @@ -1,6 +1,7 @@ package com.leclowndu93150.carbort.content.items; import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; import net.minecraft.core.Direction; import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionResult; @@ -18,7 +19,6 @@ public class PartyPickaxeItem extends PickaxeItem { public PartyPickaxeItem(Properties p_42964_) { - super(ToolTiers.PARTY, p_42964_); } @@ -48,6 +48,7 @@ public int getMaxStackSize(ItemStack stack) { return super.useOn(context); } + @Override public void appendHoverText(ItemStack stack, TooltipContext context, List tooltipComponents, TooltipFlag tooltipFlag) { super.appendHoverText(stack, context, tooltipComponents, tooltipFlag); diff --git a/src/main/java/com/leclowndu93150/carbort/content/items/UnstableIngotItem.java b/src/main/java/com/leclowndu93150/carbort/content/items/UnstableIngotItem.java index f87d9df..afd6677 100644 --- a/src/main/java/com/leclowndu93150/carbort/content/items/UnstableIngotItem.java +++ b/src/main/java/com/leclowndu93150/carbort/content/items/UnstableIngotItem.java @@ -4,6 +4,7 @@ import com.leclowndu93150.carbort.registries.CBDataComponents; import com.leclowndu93150.carbort.utils.RandomFunctions; import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; @@ -45,10 +46,18 @@ public void onCraftedBy(ItemStack stack, Level level, Player player) { @Override public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) { + if(entity instanceof Player player){ + if(!(player.containerMenu instanceof CraftingMenu)){ + stack.set(CBDataComponents.TIMER, 0); + } + } if (stack.has(CBDataComponents.TIMER)){ stack.set(CBDataComponents.TIMER, stack.get(CBDataComponents.TIMER) - 1); if (stack.get(CBDataComponents.TIMER) <= 0){ - stack.shrink(1); + if(entity instanceof Player player && !player.isCreative() && !level.isClientSide()){ + stack.shrink(1); + level.explode(entity, entity.getX(), entity.getY(), entity.getZ(),3, Level.ExplosionInteraction.TNT); + } } } super.inventoryTick(stack, level, entity, slotId, isSelected); diff --git a/src/main/java/com/leclowndu93150/carbort/datagen/DataGatherer.java b/src/main/java/com/leclowndu93150/carbort/datagen/DataGatherer.java index 7b6664a..02d7ea3 100644 --- a/src/main/java/com/leclowndu93150/carbort/datagen/DataGatherer.java +++ b/src/main/java/com/leclowndu93150/carbort/datagen/DataGatherer.java @@ -11,7 +11,7 @@ import java.util.concurrent.CompletableFuture; -@EventBusSubscriber(modid = Carbort.MODID) +@EventBusSubscriber(modid = Carbort.MODID, bus = EventBusSubscriber.Bus.MOD) public final class DataGatherer { @SubscribeEvent public static void gatherData(GatherDataEvent event) { diff --git a/src/main/java/com/leclowndu93150/carbort/events/CarbortClientEvents.java b/src/main/java/com/leclowndu93150/carbort/events/CarbortClientEvents.java new file mode 100644 index 0000000..0314dac --- /dev/null +++ b/src/main/java/com/leclowndu93150/carbort/events/CarbortClientEvents.java @@ -0,0 +1,15 @@ +package com.leclowndu93150.carbort.events; + +import com.leclowndu93150.carbort.content.items.UnstableIngotItem; +import com.leclowndu93150.carbort.registries.DataComponentRegistry; +import net.minecraft.client.Minecraft; +import net.minecraft.world.item.ItemStack; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.client.event.ClientTickEvent; + +//@EventBusSubscriber(modid = "carbort", bus = EventBusSubscriber.Bus.GAME, value = Dist.CLIENT) +public class CarbortClientEvents { + +} diff --git a/src/main/java/com/leclowndu93150/carbort/events/CarbortEvents.java b/src/main/java/com/leclowndu93150/carbort/events/CarbortEvents.java index 716a178..ac116db 100644 --- a/src/main/java/com/leclowndu93150/carbort/events/CarbortEvents.java +++ b/src/main/java/com/leclowndu93150/carbort/events/CarbortEvents.java @@ -4,16 +4,21 @@ import com.leclowndu93150.carbort.content.energy.ItemStackEnergyStorage; import com.leclowndu93150.carbort.content.items.HealingAxeItem; import com.leclowndu93150.carbort.content.energy.IEnergyItem; +import com.leclowndu93150.carbort.content.items.UnstableIngotItem; import com.leclowndu93150.carbort.content.screen.ChunkAnalyzerScreen; import com.leclowndu93150.carbort.networking.ChunkAnalyzerDataPayload; import com.leclowndu93150.carbort.networking.ChunkAnalyzerTogglePayload; import com.leclowndu93150.carbort.networking.PayloadActions; +import com.leclowndu93150.carbort.registries.CBDataComponents; import com.leclowndu93150.carbort.registries.CBMenus; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.monster.Monster; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.CraftingMenu; import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; import net.neoforged.bus.api.EventPriority; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.EventBusSubscriber; @@ -21,6 +26,7 @@ import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent; import net.neoforged.neoforge.event.entity.player.AttackEntityEvent; +import net.neoforged.neoforge.event.tick.PlayerTickEvent; import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; import net.neoforged.neoforge.network.registration.PayloadRegistrar; @@ -44,6 +50,26 @@ public static void healingAxeHitEntity(AttackEntityEvent event) { } } + @SubscribeEvent(priority = EventPriority.LOW) + public static void holdingUnstableIngot(PlayerTickEvent.Post event){ + Player player = event.getEntity(); + if(player.containerMenu.getCarried().getItem() instanceof UnstableIngotItem && !player.level().isClientSide()){ + ItemStack item = player.containerMenu.getCarried(); + if(!(player.containerMenu instanceof CraftingMenu)){ + item.set(CBDataComponents.TIMER, 0); + } + if(item.has(CBDataComponents.TIMER)){ + item.set(CBDataComponents.TIMER, item.get(CBDataComponents.TIMER) - 1); + if(item.get(CBDataComponents.TIMER) <= 0){ + if(!player.isCreative()){ + item.shrink(1); + player.level().explode(player, player.getX(), player.getY(), player.getZ(),3, Level.ExplosionInteraction.TNT); + } + } + } + } + } + @EventBusSubscriber(modid = Carbort.MODID, bus = EventBusSubscriber.Bus.MOD) public static class ModEvents { @SubscribeEvent