mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-25 00:18:34 +01:00
Added the ability to open the crafting table on a stick with a hotkey if the item is present in inventory, or in a curios slot. Closes #1417
This commit is contained in:
parent
276c2dbd95
commit
b5cb343492
17 changed files with 178 additions and 19 deletions
|
@ -80,6 +80,7 @@ repositories {
|
||||||
includeGroup "curse.maven"
|
includeGroup "curse.maven"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
maven { url = 'https://maven.octo-studios.com/releases' }
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -97,6 +98,8 @@ dependencies {
|
||||||
|
|
||||||
localRuntime "curse.maven:jade-324717:5803666"
|
localRuntime "curse.maven:jade-324717:5803666"
|
||||||
localRuntime "curse.maven:mekanism-268560:5680395"
|
localRuntime "curse.maven:mekanism-268560:5680395"
|
||||||
|
|
||||||
|
implementation "top.theillusivec4.curios:curios-neoforge:${curios_version}"
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
|
|
|
@ -18,3 +18,4 @@ jei_minecraft=1.21.1
|
||||||
jei_version=19.21.0.246
|
jei_version=19.21.0.246
|
||||||
patchouli_version=1.21-87-NEOFORGE
|
patchouli_version=1.21-87-NEOFORGE
|
||||||
patchouli_provider_version=1.21.1-1.0.11-Snapshot.3
|
patchouli_provider_version=1.21.1-1.0.11-Snapshot.3
|
||||||
|
curios_version=9.+
|
||||||
|
|
|
@ -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
|
87327118c2f16da245b76de4fdcaab149456d9b8 data/actuallyadditions/tags/item/coffee_beans.json
|
||||||
f3ee78cd8c9563bd1828de2b4b336735f289f9f2 data/actuallyadditions/tags/item/crystals.json
|
f3ee78cd8c9563bd1828de2b4b336735f289f9f2 data/actuallyadditions/tags/item/crystals.json
|
||||||
441008b49b4bab00125100fc969cb6582eff7271 data/actuallyadditions/tags/item/crystal_blocks.json
|
441008b49b4bab00125100fc969cb6582eff7271 data/actuallyadditions/tags/item/crystal_blocks.json
|
||||||
7e6e49c3eb5302af147a2d6ba439e83bd4831cbc data/actuallyadditions/tags/item/drills.json
|
7e6e49c3eb5302af147a2d6ba439e83bd4831cbc data/actuallyadditions/tags/item/drills.json
|
||||||
ae55da193b94fd6375c05d5aa46cafdda9d335cd data/actuallyadditions/tags/item/tiny_coals.json
|
ae55da193b94fd6375c05d5aa46cafdda9d335cd data/actuallyadditions/tags/item/tiny_coals.json
|
||||||
|
d0115caba2ef0aae6d1c07068d2b30819dfad612 data/curios/tags/item/charm.json
|
||||||
dc377437805c7c5696b88c17454da7b856b9055e data/c/tags/item/buckets.json
|
dc377437805c7c5696b88c17454da7b856b9055e data/c/tags/item/buckets.json
|
||||||
ea53bfe045e7e533a13fa2fa8793cd7741e92902 data/c/tags/item/bucket/canola_oil.json
|
ea53bfe045e7e533a13fa2fa8793cd7741e92902 data/c/tags/item/bucket/canola_oil.json
|
||||||
fb46ac4e564c749fcaa5ba1393ab33fcd91817f5 data/c/tags/item/bucket/crystallized_oil.json
|
fb46ac4e564c749fcaa5ba1393ab33fcd91817f5 data/c/tags/item/bucket/crystallized_oil.json
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
// 1.21.1 2024-10-19T11:22:45.6782191 Curios for actuallyadditions
|
||||||
|
42b9baaa8afba52b9f39f6830fc7620e3eb75c70 data/actuallyadditions/curios/entities/player.json
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"entities": [
|
||||||
|
"minecraft:player"
|
||||||
|
],
|
||||||
|
"slots": [
|
||||||
|
"charm"
|
||||||
|
]
|
||||||
|
}
|
5
src/generated/resources/data/curios/tags/item/charm.json
Normal file
5
src/generated/resources/data/curios/tags/item/charm.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"values": [
|
||||||
|
"actuallyadditions:crafter_on_a_stick"
|
||||||
|
]
|
||||||
|
}
|
|
@ -55,6 +55,9 @@ public final class ActuallyTags {
|
||||||
public static final TagKey<Item> BUCKET_CRYSTALLIZED_OIL = ItemTags.create(ResourceLocation.fromNamespaceAndPath("c", "bucket/crystallized_oil"));
|
public static final TagKey<Item> BUCKET_CRYSTALLIZED_OIL = ItemTags.create(ResourceLocation.fromNamespaceAndPath("c", "bucket/crystallized_oil"));
|
||||||
public static final TagKey<Item> BUCKET_EMPOWERED_OIL = ItemTags.create(ResourceLocation.fromNamespaceAndPath("c", "bucket/empowered_oil"));
|
public static final TagKey<Item> BUCKET_EMPOWERED_OIL = ItemTags.create(ResourceLocation.fromNamespaceAndPath("c", "bucket/empowered_oil"));
|
||||||
|
|
||||||
|
//curios:bracelet
|
||||||
|
public static final TagKey<Item> CURIOS_CHARM = TagKey.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath("curios", "charm"));
|
||||||
|
|
||||||
|
|
||||||
private static TagKey<Item> tag(String name) {
|
private static TagKey<Item> tag(String name) {
|
||||||
return TagKey.create(Registries.ITEM, ActuallyAdditions.modLoc(name));
|
return TagKey.create(Registries.ITEM, ActuallyAdditions.modLoc(name));
|
||||||
|
|
|
@ -72,6 +72,8 @@ public class ActuallyAdditionsData {
|
||||||
|
|
||||||
generator.addProvider(event.includeServer(), new DatapackBuiltinEntriesProvider(
|
generator.addProvider(event.includeServer(), new DatapackBuiltinEntriesProvider(
|
||||||
packOutput, patchedProvider, Set.of(ActuallyAdditions.MODID)));
|
packOutput, patchedProvider, Set.of(ActuallyAdditions.MODID)));
|
||||||
|
|
||||||
|
generator.addProvider(true, new Curios(packOutput, helper, lookupProvider));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static RegistrySetBuilder.PatchedRegistries getProvider() {
|
private static RegistrySetBuilder.PatchedRegistries getProvider() {
|
||||||
|
|
21
src/main/java/de/ellpeck/actuallyadditions/data/Curios.java
Normal file
21
src/main/java/de/ellpeck/actuallyadditions/data/Curios.java
Normal file
|
@ -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<HolderLookup.Provider> registries) {
|
||||||
|
super(ActuallyAdditions.MODID, output, fileHelper, registries);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generate(HolderLookup.Provider registries, ExistingFileHelper fileHelper) {
|
||||||
|
createEntities("player").addEntities(EntityType.PLAYER).addSlots("charm");
|
||||||
|
}
|
||||||
|
}
|
|
@ -88,5 +88,6 @@ public class ItemTagsGenerator extends ItemTagsProvider {
|
||||||
ActuallyTags.Items.BUCKET_CRYSTALLIZED_OIL, ActuallyTags.Items.BUCKET_EMPOWERED_OIL
|
ActuallyTags.Items.BUCKET_CRYSTALLIZED_OIL, ActuallyTags.Items.BUCKET_EMPOWERED_OIL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
tag(ActuallyTags.Items.CURIOS_CHARM).add(ActuallyItems.CRAFTER_ON_A_STICK.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ import de.ellpeck.actuallyadditions.mod.misc.apiimpl.MethodHandler;
|
||||||
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
|
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
|
||||||
import de.ellpeck.actuallyadditions.mod.particle.ActuallyParticles;
|
import de.ellpeck.actuallyadditions.mod.particle.ActuallyParticles;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.ResourceReloader;
|
import de.ellpeck.actuallyadditions.mod.util.ResourceReloader;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.Util;
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.Item;
|
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.api.distmarker.Dist;
|
||||||
import net.neoforged.bus.api.IEventBus;
|
import net.neoforged.bus.api.IEventBus;
|
||||||
import net.neoforged.fml.ModContainer;
|
import net.neoforged.fml.ModContainer;
|
||||||
|
import net.neoforged.fml.ModList;
|
||||||
import net.neoforged.fml.common.Mod;
|
import net.neoforged.fml.common.Mod;
|
||||||
import net.neoforged.fml.config.ModConfig;
|
import net.neoforged.fml.config.ModConfig;
|
||||||
import net.neoforged.fml.event.config.ModConfigEvent;
|
import net.neoforged.fml.event.config.ModConfigEvent;
|
||||||
|
@ -92,6 +94,7 @@ public class ActuallyAdditions {
|
||||||
ActuallyBiomeModifiers.init(eventBus);
|
ActuallyBiomeModifiers.init(eventBus);
|
||||||
ActuallyParticles.init(eventBus);
|
ActuallyParticles.init(eventBus);
|
||||||
ActuallyTags.init();
|
ActuallyTags.init();
|
||||||
|
ActuallyAdditionsClient.init(eventBus);
|
||||||
eventBus.addListener(this::onConfigReload);
|
eventBus.addListener(this::onConfigReload);
|
||||||
|
|
||||||
NeoForge.EVENT_BUS.addListener(this::serverStarted);
|
NeoForge.EVENT_BUS.addListener(this::serverStarted);
|
||||||
|
@ -114,6 +117,8 @@ public class ActuallyAdditions {
|
||||||
eventBus.addListener(ActuallyAdditionsClient::registerParticleFactories);
|
eventBus.addListener(ActuallyAdditionsClient::registerParticleFactories);
|
||||||
}
|
}
|
||||||
IFarmerBehavior.initBehaviors();
|
IFarmerBehavior.initBehaviors();
|
||||||
|
|
||||||
|
Util.curiosLoaded = ModList.get().isLoaded("curios");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void reloadEvent(AddReloadListenerEvent event) {
|
private static void reloadEvent(AddReloadListenerEvent event) {
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod;
|
package de.ellpeck.actuallyadditions.mod;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.InputConstants;
|
||||||
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
|
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
|
||||||
import de.ellpeck.actuallyadditions.mod.blocks.render.ReconstructorRenderer;
|
import de.ellpeck.actuallyadditions.mod.blocks.render.ReconstructorRenderer;
|
||||||
import de.ellpeck.actuallyadditions.mod.blocks.render.RenderBatteryBox;
|
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.inventory.gui.VoidSackGui;
|
||||||
import de.ellpeck.actuallyadditions.mod.items.ActuallyItems;
|
import de.ellpeck.actuallyadditions.mod.items.ActuallyItems;
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.special.SpecialRenderInit;
|
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.ActuallyParticles;
|
||||||
import de.ellpeck.actuallyadditions.mod.particle.ParticleBeam;
|
import de.ellpeck.actuallyadditions.mod.particle.ParticleBeam;
|
||||||
import de.ellpeck.actuallyadditions.mod.particle.ParticleLaserItem;
|
import de.ellpeck.actuallyadditions.mod.particle.ParticleLaserItem;
|
||||||
import de.ellpeck.actuallyadditions.mod.patchouli.PatchouliPages;
|
import de.ellpeck.actuallyadditions.mod.patchouli.PatchouliPages;
|
||||||
|
import net.minecraft.client.KeyMapping;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.multiplayer.ClientPacketListener;
|
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||||
import net.minecraft.client.renderer.ItemBlockRenderTypes;
|
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.core.BlockPos;
|
||||||
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
|
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
|
import net.neoforged.bus.api.IEventBus;
|
||||||
import net.neoforged.fml.ModList;
|
import net.neoforged.fml.ModList;
|
||||||
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
|
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
|
||||||
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
|
import net.neoforged.neoforge.client.event.*;
|
||||||
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;
|
import net.neoforged.neoforge.client.settings.KeyConflictContext;
|
||||||
import net.neoforged.neoforge.client.event.RegisterParticleProvidersEvent;
|
|
||||||
import net.neoforged.neoforge.common.NeoForge;
|
import net.neoforged.neoforge.common.NeoForge;
|
||||||
|
import net.neoforged.neoforge.network.PacketDistributor;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class ActuallyAdditionsClient {
|
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) {
|
public static void setupMenus(RegisterMenuScreensEvent evt) {
|
||||||
evt.register(ActuallyContainers.SACK_CONTAINER.get(), SackGui::new);
|
evt.register(ActuallyContainers.SACK_CONTAINER.get(), SackGui::new);
|
||||||
evt.register(ActuallyContainers.VOID_SACK_CONTAINER.get(), VoidSackGui::new);
|
evt.register(ActuallyContainers.VOID_SACK_CONTAINER.get(), VoidSackGui::new);
|
||||||
|
@ -158,4 +171,14 @@ public class ActuallyAdditionsClient {
|
||||||
assert Minecraft.getInstance().hitResult != null;
|
assert Minecraft.getInstance().hitResult != null;
|
||||||
connection.send(new ServerboundPlayerActionPacket(ServerboundPlayerActionPacket.Action.STOP_DESTROY_BLOCK, pos, ((BlockHitResult) Minecraft.getInstance().hitResult).getDirection()));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,16 +11,21 @@
|
||||||
package de.ellpeck.actuallyadditions.mod.items;
|
package de.ellpeck.actuallyadditions.mod.items;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
|
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.Util;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.InteractionResult;
|
import net.minecraft.world.InteractionResult;
|
||||||
import net.minecraft.world.InteractionResultHolder;
|
import net.minecraft.world.InteractionResultHolder;
|
||||||
import net.minecraft.world.SimpleMenuProvider;
|
import net.minecraft.world.SimpleMenuProvider;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.inventory.ContainerLevelAccess;
|
import net.minecraft.world.inventory.ContainerLevelAccess;
|
||||||
import net.minecraft.world.inventory.CraftingMenu;
|
import net.minecraft.world.inventory.CraftingMenu;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import top.theillusivec4.curios.api.CuriosApi;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
@ -35,13 +40,46 @@ public class ItemCrafterOnAStick extends ItemBase {
|
||||||
@Override
|
@Override
|
||||||
public InteractionResultHolder<ItemStack> use(Level world, @Nonnull Player player, @Nonnull InteractionHand hand) {
|
public InteractionResultHolder<ItemStack> use(Level world, @Nonnull Player player, @Nonnull InteractionHand hand) {
|
||||||
if (!world.isClientSide) {
|
if (!world.isClientSide) {
|
||||||
player.openMenu(new SimpleMenuProvider((windowId, playerInventory, playerEntity) -> new CraftingMenu(windowId, playerInventory, ContainerLevelAccess.create(world, player.blockPosition())){
|
openCraftingMenu(player);
|
||||||
@Override
|
|
||||||
public boolean stillValid(Player playerIn) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}, CONTAINER_TITLE));
|
|
||||||
}
|
}
|
||||||
return new InteractionResultHolder<>(InteractionResult.SUCCESS, player.getItemInHand(hand));
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,14 +13,7 @@ package de.ellpeck.actuallyadditions.mod.network;
|
||||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||||
import de.ellpeck.actuallyadditions.mod.network.handler.ClientPayloadHandler;
|
import de.ellpeck.actuallyadditions.mod.network.handler.ClientPayloadHandler;
|
||||||
import de.ellpeck.actuallyadditions.mod.network.handler.ServerPayloadHandler;
|
import de.ellpeck.actuallyadditions.mod.network.handler.ServerPayloadHandler;
|
||||||
import de.ellpeck.actuallyadditions.mod.network.packet.ButtonToContainerPacket;
|
import de.ellpeck.actuallyadditions.mod.network.packet.*;
|
||||||
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 net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
|
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
|
||||||
import net.neoforged.neoforge.network.handling.DirectionalPayloadHandler;
|
import net.neoforged.neoforge.network.handling.DirectionalPayloadHandler;
|
||||||
import net.neoforged.neoforge.network.registration.PayloadRegistrar;
|
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(StringToTilePacket.ID, StringToTilePacket.CODEC, ServerPayloadHandler.getInstance()::handleStringToTile);
|
||||||
registrar.playToServer(NumberToTilePacket.ID, NumberToTilePacket.CODEC, ServerPayloadHandler.getInstance()::handleNumberToTile);
|
registrar.playToServer(NumberToTilePacket.ID, NumberToTilePacket.CODEC, ServerPayloadHandler.getInstance()::handleNumberToTile);
|
||||||
registrar.playToServer(ButtonToContainerPacket.ID, ButtonToContainerPacket.CODEC, ServerPayloadHandler.getInstance()::handleButtonToContainer);
|
registrar.playToServer(ButtonToContainerPacket.ID, ButtonToContainerPacket.CODEC, ServerPayloadHandler.getInstance()::handleButtonToContainer);
|
||||||
|
registrar.playToServer(HotkeyPacket.TYPE, HotkeyPacket.CODEC, HotkeyPacket::handle);
|
||||||
|
|
||||||
registrar.playBidirectional(SyncPlayerPacket.ID, SyncPlayerPacket.CODEC,
|
registrar.playBidirectional(SyncPlayerPacket.ID, SyncPlayerPacket.CODEC,
|
||||||
new DirectionalPayloadHandler<>(ClientPayloadHandler.getInstance()::handleSyncPlayer, ServerPayloadHandler.getInstance()::handleSyncPlayer));
|
new DirectionalPayloadHandler<>(ClientPayloadHandler.getInstance()::handleSyncPlayer, ServerPayloadHandler.getInstance()::handleSyncPlayer));
|
||||||
|
|
|
@ -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<HotkeyPacket> TYPE = new CustomPacketPayload.Type<>(ResourceLocation.fromNamespaceAndPath(ActuallyAdditions.MODID, "hotkey"));
|
||||||
|
|
||||||
|
public HotkeyPacket(byte type) {
|
||||||
|
this(HotKey.values()[type]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Type<? extends CustomPacketPayload> type() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum HotKey {
|
||||||
|
OPEN_CRAFTING_STICK
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final StreamCodec<FriendlyByteBuf, HotkeyPacket> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -48,4 +48,6 @@ public final class Util {
|
||||||
AttributeInstance attribute = player.getAttribute(Attributes.BLOCK_INTERACTION_RANGE);
|
AttributeInstance attribute = player.getAttribute(Attributes.BLOCK_INTERACTION_RANGE);
|
||||||
return attribute == null ? 4.5d : attribute.getValue();
|
return attribute == null ? 4.5d : attribute.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean curiosLoaded = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -992,5 +992,8 @@
|
||||||
"jei.actuallyadditions.coffee.extra.milk": "+01:00, -1 Level",
|
"jei.actuallyadditions.coffee.extra.milk": "+01:00, -1 Level",
|
||||||
"jei.actuallyadditions.mining_lens": "Lens of the Miner",
|
"jei.actuallyadditions.mining_lens": "Lens of the Miner",
|
||||||
"jei.actuallyadditions.mining_lens.weight": "Weight:",
|
"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"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue