Curio support (#3013)
* update gradle, mappings and dependencies * fix dependencies * add curio support for wireless items * Update Forge * Speed up pattern validation by using now-fixed cache (#3011) * fix dependencies * remove weird imports * whoops doubled dependency * improve code quality * found out there is an Api method Co-authored-by: raoulvdberge <raoulvdberge@gmail.com> Co-authored-by: Anton Bulakh <self@necauqua.dev>
This commit is contained in:
@@ -22,6 +22,9 @@ repositories {
|
||||
includeGroup "curse.maven"
|
||||
}
|
||||
}
|
||||
maven {
|
||||
url = "https://maven.theillusivec4.top/"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'net.minecraftforge.gradle'
|
||||
@@ -118,6 +121,9 @@ dependencies {
|
||||
|
||||
compileOnly fg.deobf('curse.maven:crafting-tweaks-233071:3330406')
|
||||
|
||||
runtimeOnly fg.deobf("top.theillusivec4.curios:curios-forge:1.16.5-4.0.5.2")
|
||||
compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:1.16.5-4.0.5.2:api")
|
||||
|
||||
testImplementation('org.junit.jupiter:junit-jupiter-api:5.6.2')
|
||||
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.6.2')
|
||||
testCompile group: 'org.assertj', name: 'assertj-core', version: '3.16.1'
|
||||
|
@@ -4,6 +4,7 @@ import com.refinedmods.refinedstorage.apiimpl.API;
|
||||
import com.refinedmods.refinedstorage.config.ClientConfig;
|
||||
import com.refinedmods.refinedstorage.config.ServerConfig;
|
||||
import com.refinedmods.refinedstorage.datageneration.DataGenerators;
|
||||
import com.refinedmods.refinedstorage.integration.curios.CuriosIntegration;
|
||||
import com.refinedmods.refinedstorage.item.group.MainItemGroup;
|
||||
import com.refinedmods.refinedstorage.network.NetworkHandler;
|
||||
import com.refinedmods.refinedstorage.setup.ClientSetup;
|
||||
@@ -49,6 +50,7 @@ public final class RS {
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(IRecipeSerializer.class, commonSetup::onRegisterRecipeSerializers);
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(ContainerType.class, commonSetup::onRegisterContainers);
|
||||
FMLJavaModLoadingContext.get().getModEventBus().register(new DataGenerators());
|
||||
FMLJavaModLoadingContext.get().getModEventBus().register(new CuriosIntegration());
|
||||
|
||||
API.deliver();
|
||||
}
|
||||
|
@@ -0,0 +1,25 @@
|
||||
package com.refinedmods.refinedstorage.integration.curios;
|
||||
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.InterModComms;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
|
||||
import top.theillusivec4.curios.api.SlotTypeMessage;
|
||||
import top.theillusivec4.curios.api.SlotTypePreset;
|
||||
|
||||
public class CuriosIntegration {
|
||||
private static final String ID = "curios";
|
||||
|
||||
public CuriosIntegration() {
|
||||
}
|
||||
|
||||
public static boolean isLoaded() {
|
||||
return ModList.get().isLoaded(ID);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void registerSlots(InterModEnqueueEvent event){
|
||||
InterModComms.sendTo(ID, SlotTypeMessage.REGISTER_TYPE,()-> SlotTypePreset.BELT.getMessageBuilder().build());
|
||||
InterModComms.sendTo(ID, SlotTypeMessage.REGISTER_TYPE,()-> SlotTypePreset.BODY.getMessageBuilder().build());
|
||||
}
|
||||
}
|
@@ -4,26 +4,35 @@ import com.refinedmods.refinedstorage.apiimpl.API;
|
||||
import com.refinedmods.refinedstorage.apiimpl.network.grid.factory.PortableGridGridFactory;
|
||||
import com.refinedmods.refinedstorage.item.NetworkItem;
|
||||
import com.refinedmods.refinedstorage.item.blockitem.PortableGridBlockItem;
|
||||
import com.refinedmods.refinedstorage.util.PacketBufferUtils;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
import top.theillusivec4.curios.api.CuriosApi;
|
||||
import top.theillusivec4.curios.api.type.capability.ICuriosItemHandler;
|
||||
import top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class OpenNetworkItemMessage {
|
||||
private final int slotId;
|
||||
private final String curioSlot;
|
||||
|
||||
public OpenNetworkItemMessage(int slotId) {
|
||||
public OpenNetworkItemMessage(int slotId, String curioSlot) {
|
||||
this.slotId = slotId;
|
||||
this.curioSlot = curioSlot;
|
||||
}
|
||||
|
||||
public static OpenNetworkItemMessage decode(PacketBuffer buf) {
|
||||
return new OpenNetworkItemMessage(buf.readInt());
|
||||
return new OpenNetworkItemMessage(buf.readInt(), PacketBufferUtils.readString(buf));
|
||||
}
|
||||
|
||||
public static void encode(OpenNetworkItemMessage message, PacketBuffer buf) {
|
||||
buf.writeInt(message.slotId);
|
||||
buf.writeString(message.curioSlot);
|
||||
}
|
||||
|
||||
public static void handle(OpenNetworkItemMessage message, Supplier<NetworkEvent.Context> ctx) {
|
||||
@@ -31,7 +40,11 @@ public class OpenNetworkItemMessage {
|
||||
|
||||
if (player != null) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
ItemStack stack = player.inventory.getStackInSlot(message.slotId);
|
||||
ItemStack stack = getStackFromSlot(player, message.slotId, message.curioSlot);
|
||||
|
||||
if (stack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (stack.getItem() instanceof NetworkItem) {
|
||||
((NetworkItem) stack.getItem()).applyNetwork(player.getServer(), stack, n -> n.getNetworkItemManager().open(player, stack, message.slotId), err -> player.sendMessage(err, player.getUniqueID()));
|
||||
@@ -43,4 +56,24 @@ public class OpenNetworkItemMessage {
|
||||
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
|
||||
private static ItemStack getStackFromSlot(ServerPlayerEntity player, int slotId, String curioSlot) {
|
||||
if (curioSlot.isEmpty()) {
|
||||
return player.inventory.getStackInSlot(slotId);
|
||||
} else {
|
||||
|
||||
LazyOptional<ICuriosItemHandler> curiosHandler = CuriosApi.getCuriosHelper().getCuriosHandler(player);
|
||||
|
||||
Optional<ICurioStacksHandler> stacksHandler = curiosHandler.resolve().flatMap((handler ->
|
||||
handler.getStacksHandler(curioSlot)
|
||||
));
|
||||
|
||||
Optional<ItemStack> stack = stacksHandler.map(handler -> handler.getStacks().getStackInSlot(slotId));
|
||||
if (stack.isPresent()) {
|
||||
return stack.get();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -3,44 +3,43 @@ package com.refinedmods.refinedstorage.screen;
|
||||
import com.refinedmods.refinedstorage.RS;
|
||||
import com.refinedmods.refinedstorage.RSItems;
|
||||
import com.refinedmods.refinedstorage.RSKeyBindings;
|
||||
import com.refinedmods.refinedstorage.integration.curios.CuriosIntegration;
|
||||
import com.refinedmods.refinedstorage.network.OpenNetworkItemMessage;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraftforge.client.event.InputEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import org.apache.commons.lang3.tuple.ImmutableTriple;
|
||||
import top.theillusivec4.curios.api.CuriosApi;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class KeyInputListener {
|
||||
@SubscribeEvent
|
||||
public void onKeyInput(InputEvent.KeyInputEvent e) {
|
||||
if (Minecraft.getInstance().player != null) {
|
||||
PlayerInventory inv = Minecraft.getInstance().player.inventory;
|
||||
|
||||
if (RSKeyBindings.OPEN_WIRELESS_GRID.isKeyDown()) {
|
||||
findAndOpen(inv, error -> Minecraft.getInstance().player.sendMessage(error, Util.DUMMY_UUID), RSItems.WIRELESS_GRID.get(), RSItems.CREATIVE_WIRELESS_GRID.get());
|
||||
findAndOpen(RSItems.WIRELESS_GRID.get(), RSItems.CREATIVE_WIRELESS_GRID.get());
|
||||
} else if (RSKeyBindings.OPEN_WIRELESS_FLUID_GRID.isKeyDown()) {
|
||||
findAndOpen(inv, error -> Minecraft.getInstance().player.sendMessage(error, Util.DUMMY_UUID), RSItems.WIRELESS_FLUID_GRID.get(), RSItems.CREATIVE_WIRELESS_FLUID_GRID.get());
|
||||
findAndOpen(RSItems.WIRELESS_FLUID_GRID.get(), RSItems.CREATIVE_WIRELESS_FLUID_GRID.get());
|
||||
} else if (RSKeyBindings.OPEN_PORTABLE_GRID.isKeyDown()) {
|
||||
findAndOpen(inv, error -> Minecraft.getInstance().player.sendMessage(error, Util.DUMMY_UUID), RSItems.PORTABLE_GRID.get(), RSItems.CREATIVE_PORTABLE_GRID.get());
|
||||
findAndOpen(RSItems.PORTABLE_GRID.get(), RSItems.CREATIVE_PORTABLE_GRID.get());
|
||||
} else if (RSKeyBindings.OPEN_WIRELESS_CRAFTING_MONITOR.isKeyDown()) {
|
||||
findAndOpen(inv, error -> Minecraft.getInstance().player.sendMessage(error, Util.DUMMY_UUID), RSItems.WIRELESS_CRAFTING_MONITOR.get(), RSItems.CREATIVE_WIRELESS_CRAFTING_MONITOR.get());
|
||||
findAndOpen(RSItems.WIRELESS_CRAFTING_MONITOR.get(), RSItems.CREATIVE_WIRELESS_CRAFTING_MONITOR.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void findAndOpen(IInventory inv, Consumer<ITextComponent> onError, Item... items) {
|
||||
public void findAndOpen(Item... items) {
|
||||
Set<Item> validItems = new HashSet<>(Arrays.asList(items));
|
||||
|
||||
IInventory inv = Minecraft.getInstance().player.inventory;
|
||||
int slotFound = -1;
|
||||
|
||||
for (int i = 0; i < inv.getSizeInventory(); ++i) {
|
||||
@@ -48,7 +47,7 @@ public class KeyInputListener {
|
||||
|
||||
if (validItems.contains(slot.getItem())) {
|
||||
if (slotFound != -1) {
|
||||
onError.accept(new TranslationTextComponent("misc.refinedstorage.network_item.shortcut_duplicate", new TranslationTextComponent(items[0].getTranslationKey())));
|
||||
sendError(new TranslationTextComponent("misc.refinedstorage.network_item.shortcut_duplicate", new TranslationTextComponent(items[0].getTranslationKey())));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -56,10 +55,25 @@ public class KeyInputListener {
|
||||
}
|
||||
}
|
||||
|
||||
if (CuriosIntegration.isLoaded() && slotFound == -1) {
|
||||
Optional<ImmutableTriple<String, Integer, ItemStack>> curio = CuriosApi.getCuriosHelper().findEquippedCurio(stack -> validItems.contains(stack.getItem()), Minecraft.getInstance().player);
|
||||
|
||||
if (curio.isPresent()) {
|
||||
RS.NETWORK_HANDLER.sendToServer(new OpenNetworkItemMessage(curio.get().getMiddle(), curio.get().getLeft()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (slotFound == -1) {
|
||||
onError.accept(new TranslationTextComponent("misc.refinedstorage.network_item.shortcut_not_found", new TranslationTextComponent(items[0].getTranslationKey())));
|
||||
sendError(new TranslationTextComponent("misc.refinedstorage.network_item.shortcut_not_found", new TranslationTextComponent(items[0].getTranslationKey())));
|
||||
} else {
|
||||
RS.NETWORK_HANDLER.sendToServer(new OpenNetworkItemMessage(slotFound));
|
||||
RS.NETWORK_HANDLER.sendToServer(new OpenNetworkItemMessage(slotFound, ""));
|
||||
}
|
||||
}
|
||||
|
||||
public void sendError(TranslationTextComponent error) {
|
||||
Minecraft.getInstance().player.sendMessage(error, Util.DUMMY_UUID);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
11
src/main/resources/data/curios/tags/items/curio.json
Normal file
11
src/main/resources/data/curios/tags/items/curio.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"refinedstorage:wireless_grid",
|
||||
"refinedstorage:creative_wireless_grid",
|
||||
"refinedstorage:wireless_fluid_grid",
|
||||
"refinedstorage:creative_wireless_fluid_grid",
|
||||
"refinedstorage:wireless_crafting_monitor",
|
||||
"refinedstorage:creative_wireless_crafting_monitor"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user