diff --git a/common/src/main/java/io/github/gregtechintergalactical/gtcore/mixin/MixinHoneycombItem.java b/common/src/main/java/io/github/gregtechintergalactical/gtcore/mixin/MixinHoneycombItem.java index 1ab975d..f445103 100644 --- a/common/src/main/java/io/github/gregtechintergalactical/gtcore/mixin/MixinHoneycombItem.java +++ b/common/src/main/java/io/github/gregtechintergalactical/gtcore/mixin/MixinHoneycombItem.java @@ -3,6 +3,7 @@ import io.github.gregtechintergalactical.gtcore.GTCoreConfig; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.HoneycombItem; +import net.minecraft.world.item.Items; import net.minecraft.world.item.context.UseOnContext; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -14,7 +15,7 @@ public class MixinHoneycombItem { @Inject(method = "useOn", at = @At("HEAD"), cancellable = true) private void injectUseOn(UseOnContext context, CallbackInfoReturnable cir){ - if (GTCoreConfig.HONEYCOMB_REPLACEMENT.get()){ + if (GTCoreConfig.HONEYCOMB_REPLACEMENT.get() && context.getItemInHand().getItem() == Items.HONEYCOMB){ cir.setReturnValue(InteractionResult.PASS); } } diff --git a/fabric/src/main/java/io/github/gregtechintergalactical/gtcore/fabric/GTCoreFabric.java b/fabric/src/main/java/io/github/gregtechintergalactical/gtcore/fabric/GTCoreFabric.java index 2799d45..af6bcbd 100644 --- a/fabric/src/main/java/io/github/gregtechintergalactical/gtcore/fabric/GTCoreFabric.java +++ b/fabric/src/main/java/io/github/gregtechintergalactical/gtcore/fabric/GTCoreFabric.java @@ -5,6 +5,14 @@ import muramasa.antimatter.event.fabric.LoaderEvents; import muramasa.antimatter.event.fabric.ProviderEvents; import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.event.player.UseBlockCallback; +import net.fabricmc.fabric.api.event.player.UseItemCallback; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.context.UseOnContext; + +import static io.github.gregtechintergalactical.gtcore.data.GTCoreMaterials.Beeswax; +import static muramasa.antimatter.data.AntimatterMaterialTypes.DUST; //initializer class for non antimatter related stuff public class GTCoreFabric implements ModInitializer { @@ -13,5 +21,11 @@ public void onInitialize() { ProviderEvents.PROVIDERS.register(GTCore::onProviders); CraftingEvents.CRAFTING.register(GTCore::onCrafting); LoaderEvents.LOADER.register(GTCore::registerRecipeLoaders); + UseBlockCallback.EVENT.register((player, level, interactionHand, hitResult) -> { + if (player.getItemInHand(interactionHand).is(DUST.getMaterialTag(Beeswax))){ + return Items.HONEYCOMB.useOn(new UseOnContext(player, interactionHand, hitResult)); + } + return InteractionResult.PASS; + }); } } diff --git a/forge/src/main/java/io/github/gregtechintergalactical/gtcore/forge/GTCoreForge.java b/forge/src/main/java/io/github/gregtechintergalactical/gtcore/forge/GTCoreForge.java index 141742f..58c2cc3 100644 --- a/forge/src/main/java/io/github/gregtechintergalactical/gtcore/forge/GTCoreForge.java +++ b/forge/src/main/java/io/github/gregtechintergalactical/gtcore/forge/GTCoreForge.java @@ -9,18 +9,26 @@ import muramasa.antimatter.event.forge.AntimatterLoaderEvent; import muramasa.antimatter.event.forge.AntimatterProvidersEvent; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacerType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.event.entity.item.ItemEvent; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.world.ChunkWatchEvent; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import static io.github.gregtechintergalactical.gtcore.data.GTCoreMaterials.Beeswax; +import static muramasa.antimatter.data.AntimatterMaterialTypes.DUST; + // The value here should match an entry in the META-INF/mods.toml file @Mod(GTCore.ID) public class GTCoreForge extends GTCore { @@ -29,6 +37,7 @@ public GTCoreForge(){ FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onCraftingEvent); MinecraftForge.EVENT_BUS.addListener(GTCoreForge::registerRecipeLoaders); MinecraftForge.EVENT_BUS.addListener(this::onChunkWatch); + MinecraftForge.EVENT_BUS.addListener(this::onItemUse); FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(FoliagePlacerType.class, this::onRegistration); DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup); @@ -45,6 +54,13 @@ private void onChunkWatch(ChunkWatchEvent.Watch event){ });*/ } + private void onItemUse(PlayerInteractEvent.RightClickBlock event){ + if (event.getPlayer().getItemInHand(event.getHand()).is(DUST.getMaterialTag(Beeswax))){ + event.setCancellationResult(Items.HONEYCOMB.useOn(new UseOnContext(event.getPlayer(), event.getHand(), event.getHitVec()))); + event.setCanceled(true); + } + } + @OnlyIn(Dist.CLIENT) private void clientSetup(FMLClientSetupEvent event){ ClientHandler.init();