diff --git a/build.gradle b/build.gradle index bbc37615b..c5317a761 100644 --- a/build.gradle +++ b/build.gradle @@ -80,6 +80,7 @@ repositories { includeGroup "curse.maven" } } + maven { url = 'https://maven.octo-studios.com/releases' } } dependencies { @@ -97,6 +98,8 @@ dependencies { localRuntime "curse.maven:jade-324717:5803666" localRuntime "curse.maven:mekanism-268560:5680395" + + implementation "top.theillusivec4.curios:curios-neoforge:${curios_version}" } jar { diff --git a/gradle.properties b/gradle.properties index c4d59e7d2..4f9a59bfa 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,3 +18,4 @@ jei_minecraft=1.21.1 jei_version=19.21.0.246 patchouli_version=1.21-87-NEOFORGE patchouli_provider_version=1.21.1-1.0.11-Snapshot.3 +curios_version=9.+ diff --git a/src/generated/resources/.cache/74807d958079a027731c973b9550985af6711175 b/src/generated/resources/.cache/74807d958079a027731c973b9550985af6711175 index 9ccb674aa..aa0b87f4b 100644 --- a/src/generated/resources/.cache/74807d958079a027731c973b9550985af6711175 +++ b/src/generated/resources/.cache/74807d958079a027731c973b9550985af6711175 @@ -1,9 +1,10 @@ -// 1.21.1 2024-10-19T16:16:57.3701064 Tags for minecraft:item mod id actuallyadditions +// 1.21.1 2024-10-19T11:22:45.676221 Tags for minecraft:item mod id actuallyadditions 87327118c2f16da245b76de4fdcaab149456d9b8 data/actuallyadditions/tags/item/coffee_beans.json f3ee78cd8c9563bd1828de2b4b336735f289f9f2 data/actuallyadditions/tags/item/crystals.json 441008b49b4bab00125100fc969cb6582eff7271 data/actuallyadditions/tags/item/crystal_blocks.json 7e6e49c3eb5302af147a2d6ba439e83bd4831cbc data/actuallyadditions/tags/item/drills.json ae55da193b94fd6375c05d5aa46cafdda9d335cd data/actuallyadditions/tags/item/tiny_coals.json +d0115caba2ef0aae6d1c07068d2b30819dfad612 data/curios/tags/item/charm.json dc377437805c7c5696b88c17454da7b856b9055e data/c/tags/item/buckets.json ea53bfe045e7e533a13fa2fa8793cd7741e92902 data/c/tags/item/bucket/canola_oil.json fb46ac4e564c749fcaa5ba1393ab33fcd91817f5 data/c/tags/item/bucket/crystallized_oil.json diff --git a/src/generated/resources/.cache/87e2907469db955f8ddefa188042c5da18eb27f7 b/src/generated/resources/.cache/87e2907469db955f8ddefa188042c5da18eb27f7 new file mode 100644 index 000000000..10d2ccd74 --- /dev/null +++ b/src/generated/resources/.cache/87e2907469db955f8ddefa188042c5da18eb27f7 @@ -0,0 +1,2 @@ +// 1.21.1 2024-10-19T11:22:45.6782191 Curios for actuallyadditions +42b9baaa8afba52b9f39f6830fc7620e3eb75c70 data/actuallyadditions/curios/entities/player.json diff --git a/src/generated/resources/data/actuallyadditions/curios/entities/player.json b/src/generated/resources/data/actuallyadditions/curios/entities/player.json new file mode 100644 index 000000000..d509c0819 --- /dev/null +++ b/src/generated/resources/data/actuallyadditions/curios/entities/player.json @@ -0,0 +1,8 @@ +{ + "entities": [ + "minecraft:player" + ], + "slots": [ + "charm" + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/curios/tags/item/charm.json b/src/generated/resources/data/curios/tags/item/charm.json new file mode 100644 index 000000000..5f310e5f6 --- /dev/null +++ b/src/generated/resources/data/curios/tags/item/charm.json @@ -0,0 +1,5 @@ +{ + "values": [ + "actuallyadditions:crafter_on_a_stick" + ] +} \ No newline at end of file diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyTags.java b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyTags.java index fc0f59425..a4ad5a6ab 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyTags.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyTags.java @@ -55,6 +55,9 @@ public final class ActuallyTags { public static final TagKey BUCKET_CRYSTALLIZED_OIL = ItemTags.create(ResourceLocation.fromNamespaceAndPath("c", "bucket/crystallized_oil")); public static final TagKey BUCKET_EMPOWERED_OIL = ItemTags.create(ResourceLocation.fromNamespaceAndPath("c", "bucket/empowered_oil")); + //curios:bracelet + public static final TagKey CURIOS_CHARM = TagKey.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath("curios", "charm")); + private static TagKey tag(String name) { return TagKey.create(Registries.ITEM, ActuallyAdditions.modLoc(name)); diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/ActuallyAdditionsData.java b/src/main/java/de/ellpeck/actuallyadditions/data/ActuallyAdditionsData.java index 6b0c8331e..d0779d836 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/ActuallyAdditionsData.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/ActuallyAdditionsData.java @@ -72,6 +72,8 @@ public class ActuallyAdditionsData { generator.addProvider(event.includeServer(), new DatapackBuiltinEntriesProvider( packOutput, patchedProvider, Set.of(ActuallyAdditions.MODID))); + + generator.addProvider(true, new Curios(packOutput, helper, lookupProvider)); } private static RegistrySetBuilder.PatchedRegistries getProvider() { diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/Curios.java b/src/main/java/de/ellpeck/actuallyadditions/data/Curios.java new file mode 100644 index 000000000..0621b25f9 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/data/Curios.java @@ -0,0 +1,21 @@ +package de.ellpeck.actuallyadditions.data; + +import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; +import net.minecraft.core.HolderLookup; +import net.minecraft.data.PackOutput; +import net.minecraft.world.entity.EntityType; +import net.neoforged.neoforge.common.data.ExistingFileHelper; +import top.theillusivec4.curios.api.CuriosDataProvider; + +import java.util.concurrent.CompletableFuture; + +public class Curios extends CuriosDataProvider { + public Curios(PackOutput output, ExistingFileHelper fileHelper, CompletableFuture registries) { + super(ActuallyAdditions.MODID, output, fileHelper, registries); + } + + @Override + public void generate(HolderLookup.Provider registries, ExistingFileHelper fileHelper) { + createEntities("player").addEntities(EntityType.PLAYER).addSlots("charm"); + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/ItemTagsGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/ItemTagsGenerator.java index 947d3fc1b..8f4e988f4 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/ItemTagsGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/ItemTagsGenerator.java @@ -88,5 +88,6 @@ public class ItemTagsGenerator extends ItemTagsProvider { ActuallyTags.Items.BUCKET_CRYSTALLIZED_OIL, ActuallyTags.Items.BUCKET_EMPOWERED_OIL ); + tag(ActuallyTags.Items.CURIOS_CHARM).add(ActuallyItems.CRAFTER_ON_A_STICK.get()); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java index 5fc889bea..7ebc43653 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java @@ -36,6 +36,7 @@ import de.ellpeck.actuallyadditions.mod.misc.apiimpl.MethodHandler; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; import de.ellpeck.actuallyadditions.mod.particle.ActuallyParticles; import de.ellpeck.actuallyadditions.mod.util.ResourceReloader; +import de.ellpeck.actuallyadditions.mod.util.Util; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; @@ -43,6 +44,7 @@ import net.minecraft.world.item.Items; import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.ModContainer; +import net.neoforged.fml.ModList; import net.neoforged.fml.common.Mod; import net.neoforged.fml.config.ModConfig; import net.neoforged.fml.event.config.ModConfigEvent; @@ -92,6 +94,7 @@ public class ActuallyAdditions { ActuallyBiomeModifiers.init(eventBus); ActuallyParticles.init(eventBus); ActuallyTags.init(); + ActuallyAdditionsClient.init(eventBus); eventBus.addListener(this::onConfigReload); NeoForge.EVENT_BUS.addListener(this::serverStarted); @@ -114,6 +117,8 @@ public class ActuallyAdditions { eventBus.addListener(ActuallyAdditionsClient::registerParticleFactories); } IFarmerBehavior.initBehaviors(); + + Util.curiosLoaded = ModList.get().isLoaded("curios"); } private static void reloadEvent(AddReloadListenerEvent event) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditionsClient.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditionsClient.java index f34d663ed..f71d87909 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditionsClient.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditionsClient.java @@ -10,6 +10,7 @@ package de.ellpeck.actuallyadditions.mod; +import com.mojang.blaze3d.platform.InputConstants; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.mod.blocks.render.ReconstructorRenderer; import de.ellpeck.actuallyadditions.mod.blocks.render.RenderBatteryBox; @@ -50,10 +51,12 @@ import de.ellpeck.actuallyadditions.mod.inventory.gui.SackGui; import de.ellpeck.actuallyadditions.mod.inventory.gui.VoidSackGui; import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; import de.ellpeck.actuallyadditions.mod.misc.special.SpecialRenderInit; +import de.ellpeck.actuallyadditions.mod.network.packet.HotkeyPacket; import de.ellpeck.actuallyadditions.mod.particle.ActuallyParticles; import de.ellpeck.actuallyadditions.mod.particle.ParticleBeam; import de.ellpeck.actuallyadditions.mod.particle.ParticleLaserItem; import de.ellpeck.actuallyadditions.mod.patchouli.PatchouliPages; +import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.client.renderer.ItemBlockRenderTypes; @@ -62,14 +65,24 @@ import net.minecraft.client.renderer.item.ItemProperties; import net.minecraft.core.BlockPos; import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket; import net.minecraft.world.phys.BlockHitResult; +import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.ModList; import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; -import net.neoforged.neoforge.client.event.EntityRenderersEvent; -import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent; -import net.neoforged.neoforge.client.event.RegisterParticleProvidersEvent; +import net.neoforged.neoforge.client.event.*; +import net.neoforged.neoforge.client.settings.KeyConflictContext; import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.neoforge.network.PacketDistributor; + +import java.util.Optional; public class ActuallyAdditionsClient { + private static final KeyMapping OPEN_CRAFTING_KEY = new KeyMapping("key.actualladditions.crafting_stick_open.desc", KeyConflictContext.IN_GAME, InputConstants.Type.KEYSYM, -1, "key.actuallyadditions.category"); + + public static void init(IEventBus modBus) { + NeoForge.EVENT_BUS.addListener(ActuallyAdditionsClient::onClientTick); + modBus.addListener(ActuallyAdditionsClient::registerKeyBinding); + } + public static void setupMenus(RegisterMenuScreensEvent evt) { evt.register(ActuallyContainers.SACK_CONTAINER.get(), SackGui::new); evt.register(ActuallyContainers.VOID_SACK_CONTAINER.get(), VoidSackGui::new); @@ -158,4 +171,14 @@ public class ActuallyAdditionsClient { assert Minecraft.getInstance().hitResult != null; connection.send(new ServerboundPlayerActionPacket(ServerboundPlayerActionPacket.Action.STOP_DESTROY_BLOCK, pos, ((BlockHitResult) Minecraft.getInstance().hitResult).getDirection())); } + + private static void onClientTick(ClientTickEvent.Post event) { + if (OPEN_CRAFTING_KEY.consumeClick()) { + PacketDistributor.sendToServer(new HotkeyPacket(HotkeyPacket.HotKey.OPEN_CRAFTING_STICK)); + } + } + + private static void registerKeyBinding(final RegisterKeyMappingsEvent event) { + event.register(OPEN_CRAFTING_KEY); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemCrafterOnAStick.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemCrafterOnAStick.java index 4e7a2fea7..9ce03000e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemCrafterOnAStick.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemCrafterOnAStick.java @@ -11,16 +11,21 @@ package de.ellpeck.actuallyadditions.mod.items; import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; +import de.ellpeck.actuallyadditions.mod.util.Util; import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.SimpleMenuProvider; +import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.ContainerLevelAccess; import net.minecraft.world.inventory.CraftingMenu; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; +import org.jetbrains.annotations.NotNull; +import top.theillusivec4.curios.api.CuriosApi; import javax.annotation.Nonnull; @@ -35,13 +40,46 @@ public class ItemCrafterOnAStick extends ItemBase { @Override public InteractionResultHolder use(Level world, @Nonnull Player player, @Nonnull InteractionHand hand) { if (!world.isClientSide) { - player.openMenu(new SimpleMenuProvider((windowId, playerInventory, playerEntity) -> new CraftingMenu(windowId, playerInventory, ContainerLevelAccess.create(world, player.blockPosition())){ - @Override - public boolean stillValid(Player playerIn) { - return true; - } - }, CONTAINER_TITLE)); + openCraftingMenu(player); } return new InteractionResultHolder<>(InteractionResult.SUCCESS, player.getItemInHand(hand)); } + + public static void openCraftingMenu(Player player) { + if (!(player instanceof ServerPlayer)) + return; + player.openMenu(new SimpleMenuProvider((windowId, playerInventory, playerEntity) -> new CraftingMenu(windowId, playerInventory, ContainerLevelAccess.create(player.level(), player.blockPosition())){ + @Override + public boolean stillValid(@NotNull Player playerIn) { + return true; + } + }, CONTAINER_TITLE)); + } + + public static boolean hasCrafterOnAStick(@Nonnull Player player) { + if (player.getMainHandItem().getItem() instanceof ItemCrafterOnAStick || player.getOffhandItem().getItem() instanceof ItemCrafterOnAStick) { + return true; + } + + if (Util.curiosLoaded) { + var curiosInv = CuriosApi.getCuriosInventory(player); + if (curiosInv.isPresent()) { + if(curiosInv.get().findFirstCurio(ItemCrafterOnAStick::isCrafterOnAStick).isPresent()) + return true; + } + } + + Inventory inventory = player.getInventory(); + for (int i = 0; i <= 35; i++) { + ItemStack stack = inventory.getItem(i); + if (stack.getItem() instanceof ItemCrafterOnAStick) + return true; + } + + return false; + } + + public static boolean isCrafterOnAStick(@Nonnull ItemStack stack) { + return stack.getItem() instanceof ItemCrafterOnAStick; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java index 56720c113..743945763 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java @@ -13,14 +13,7 @@ package de.ellpeck.actuallyadditions.mod.network; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.network.handler.ClientPayloadHandler; import de.ellpeck.actuallyadditions.mod.network.handler.ServerPayloadHandler; -import de.ellpeck.actuallyadditions.mod.network.packet.ButtonToContainerPacket; -import de.ellpeck.actuallyadditions.mod.network.packet.ButtonToTilePacket; -import de.ellpeck.actuallyadditions.mod.network.packet.NumberToTilePacket; -import de.ellpeck.actuallyadditions.mod.network.packet.SpawnLaserPacket; -import de.ellpeck.actuallyadditions.mod.network.packet.SpawnLaserParticlePacket; -import de.ellpeck.actuallyadditions.mod.network.packet.StringToTilePacket; -import de.ellpeck.actuallyadditions.mod.network.packet.SyncPlayerPacket; -import de.ellpeck.actuallyadditions.mod.network.packet.TileUpdatePacket; +import de.ellpeck.actuallyadditions.mod.network.packet.*; import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; import net.neoforged.neoforge.network.handling.DirectionalPayloadHandler; import net.neoforged.neoforge.network.registration.PayloadRegistrar; @@ -39,6 +32,7 @@ public final class PacketHandler { registrar.playToServer(StringToTilePacket.ID, StringToTilePacket.CODEC, ServerPayloadHandler.getInstance()::handleStringToTile); registrar.playToServer(NumberToTilePacket.ID, NumberToTilePacket.CODEC, ServerPayloadHandler.getInstance()::handleNumberToTile); registrar.playToServer(ButtonToContainerPacket.ID, ButtonToContainerPacket.CODEC, ServerPayloadHandler.getInstance()::handleButtonToContainer); + registrar.playToServer(HotkeyPacket.TYPE, HotkeyPacket.CODEC, HotkeyPacket::handle); registrar.playBidirectional(SyncPlayerPacket.ID, SyncPlayerPacket.CODEC, new DirectionalPayloadHandler<>(ClientPayloadHandler.getInstance()::handleSyncPlayer, ServerPayloadHandler.getInstance()::handleSyncPlayer)); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/packet/HotkeyPacket.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/packet/HotkeyPacket.java new file mode 100644 index 000000000..e0037c4db --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/network/packet/HotkeyPacket.java @@ -0,0 +1,47 @@ +package de.ellpeck.actuallyadditions.mod.network.packet; + +import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; +import de.ellpeck.actuallyadditions.mod.items.ItemCrafterOnAStick; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Player; +import net.neoforged.neoforge.network.handling.IPayloadContext; + +public record HotkeyPacket(HotKey hotKey) implements CustomPacketPayload { + public static final Type TYPE = new CustomPacketPayload.Type<>(ResourceLocation.fromNamespaceAndPath(ActuallyAdditions.MODID, "hotkey")); + + public HotkeyPacket(byte type) { + this(HotKey.values()[type]); + } + + @Override + public Type type() { + return TYPE; + } + + public enum HotKey { + OPEN_CRAFTING_STICK + } + + public static final StreamCodec CODEC = StreamCodec.composite( + ByteBufCodecs.BYTE, packet -> ((byte) packet.hotKey.ordinal()), + HotkeyPacket::new + ); + + public static void handle(final HotkeyPacket packet, IPayloadContext ctx) { + switch (packet.hotKey) { + case OPEN_CRAFTING_STICK -> ctx.enqueueWork(() -> open(ctx)); + } + } + + private static void open(IPayloadContext ctx) { + Player player = ctx.player(); + + if (ItemCrafterOnAStick.hasCrafterOnAStick(player)) { + ItemCrafterOnAStick.openCraftingMenu(player); + } + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/Util.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/Util.java index 913fb00f7..5b735a217 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/Util.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/Util.java @@ -48,4 +48,6 @@ public final class Util { AttributeInstance attribute = player.getAttribute(Attributes.BLOCK_INTERACTION_RANGE); return attribute == null ? 4.5d : attribute.getValue(); } + + public static boolean curiosLoaded = false; } diff --git a/src/main/resources/assets/actuallyadditions/lang/en_us.json b/src/main/resources/assets/actuallyadditions/lang/en_us.json index ce74a8050..6ac635a8b 100644 --- a/src/main/resources/assets/actuallyadditions/lang/en_us.json +++ b/src/main/resources/assets/actuallyadditions/lang/en_us.json @@ -992,5 +992,8 @@ "jei.actuallyadditions.coffee.extra.milk": "+01:00, -1 Level", "jei.actuallyadditions.mining_lens": "Lens of the Miner", "jei.actuallyadditions.mining_lens.weight": "Weight:", - "container.actuallyadditions.item_tag": "Item Tag" + "container.actuallyadditions.item_tag": "Item Tag", + + "key.actualladditions.crafting_stick_open.desc": "Open the Crafting Stick", + "key.actuallyadditions.category": "Actually Additions" }