Skip to content

Commit

Permalink
Merge pull request #434 from refinedmods/feat/GH-110/curios
Browse files Browse the repository at this point in the history
Curios and Trinkets support
  • Loading branch information
raoulvdberge authored Sep 2, 2023
2 parents f7c71e1 + 522bda5 commit 08463b3
Show file tree
Hide file tree
Showing 64 changed files with 892 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ on:
types: [ opened, synchronize, reopened ]
jobs:
build:
uses: refinedmods/refinedarchitect/.github/workflows/build.yml@v0.8.2
uses: refinedmods/refinedarchitect/.github/workflows/build.yml@v0.9.0
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/draft-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
type: string
jobs:
draft:
uses: refinedmods/refinedarchitect/.github/workflows/draft-release.yml@v0.8.2
uses: refinedmods/refinedarchitect/.github/workflows/draft-release.yml@v0.9.0
with:
release-type: ${{ inputs.release-type }}
version-number-override: ${{ inputs.version-number-override }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/issue-for-unsupported-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ on:
types: [ labeled, unlabeled, reopened ]
jobs:
unsupported-labeler:
uses: refinedmods/refinedarchitect/.github/workflows/issue-for-unsupported-version.yml@v0.8.2
uses: refinedmods/refinedarchitect/.github/workflows/issue-for-unsupported-version.yml@v0.9.0
2 changes: 1 addition & 1 deletion .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- closed
jobs:
publish-release:
uses: refinedmods/refinedarchitect/.github/workflows/publish-release.yml@v0.8.2
uses: refinedmods/refinedarchitect/.github/workflows/publish-release.yml@v0.9.0
secrets: inherit
with:
project-name: 'Refined Storage'
2 changes: 1 addition & 1 deletion .github/workflows/resolved-issue-locking.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ on:
- cron: '0 0 * * *'
jobs:
lock:
uses: refinedmods/refinedarchitect/.github/workflows/resolved-issue-locking.yml@v0.8.2
uses: refinedmods/refinedarchitect/.github/workflows/resolved-issue-locking.yml@v0.9.0
2 changes: 1 addition & 1 deletion .github/workflows/validate-branch-name.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ name: Validate branch name
on: [ pull_request ]
jobs:
validate-branch-name:
uses: refinedmods/refinedarchitect/.github/workflows/validate-branch-name.yml@v0.8.2
uses: refinedmods/refinedarchitect/.github/workflows/validate-branch-name.yml@v0.9.0
2 changes: 1 addition & 1 deletion .github/workflows/validate-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ on:
types: [ opened, synchronize, reopened, ready_for_review, labeled, unlabeled ]
jobs:
validate-changelog:
uses: refinedmods/refinedarchitect/.github/workflows/validate-changelog.yml@v0.8.2
uses: refinedmods/refinedarchitect/.github/workflows/validate-changelog.yml@v0.9.0
2 changes: 1 addition & 1 deletion .github/workflows/validate-commit-messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ name: Validate commit messages
on: [ pull_request ]
jobs:
validate-commit-messages:
uses: refinedmods/refinedarchitect/.github/workflows/validate-commit-messages.yml@v0.8.2
uses: refinedmods/refinedarchitect/.github/workflows/validate-commit-messages.yml@v0.9.0
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- "Open Wireless Grid" keybinding.
- Curios integration on Forge.
- Trinkets integration on Fabric.

### Changed

- You can now recharge the Controller in item form.
- You can now recharge the Controller in item form.

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import com.refinedmods.refinedstorage2.platform.api.integration.recipemod.IngredientConverter;
import com.refinedmods.refinedstorage2.platform.api.item.EnergyItemHelper;
import com.refinedmods.refinedstorage2.platform.api.item.NetworkBoundItemHelper;
import com.refinedmods.refinedstorage2.platform.api.item.SlotReference;
import com.refinedmods.refinedstorage2.platform.api.item.SlotReferenceFactory;
import com.refinedmods.refinedstorage2.platform.api.item.SlotReferenceProvider;
import com.refinedmods.refinedstorage2.platform.api.item.StorageContainerItemHelper;
import com.refinedmods.refinedstorage2.platform.api.network.node.exporter.ExporterTransferStrategyFactory;
import com.refinedmods.refinedstorage2.platform.api.network.node.externalstorage.PlatformExternalStorageProviderFactory;
Expand All @@ -40,9 +43,12 @@
import java.util.Optional;
import java.util.Set;

import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import org.apiguardian.api.API;
Expand Down Expand Up @@ -148,4 +154,16 @@ GridScrollingStrategy createGridScrollingStrategy(AbstractContainerMenu containe
EnergyStorage asItemEnergyStorage(EnergyStorage energyStorage, ItemStack stack);

NetworkBoundItemHelper getNetworkBoundItemHelper();

PlatformRegistry<SlotReferenceFactory> getSlotReferenceFactoryRegistry();

void writeSlotReference(SlotReference slotReference, FriendlyByteBuf buf);

Optional<SlotReference> getSlotReference(FriendlyByteBuf buf);

void addSlotReferenceProvider(SlotReferenceProvider slotReferenceProvider);

SlotReference createInventorySlotReference(Player player, InteractionHand hand);

void useNetworkBoundItem(Player player, Item... items);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import com.refinedmods.refinedstorage2.platform.api.integration.recipemod.IngredientConverter;
import com.refinedmods.refinedstorage2.platform.api.item.EnergyItemHelper;
import com.refinedmods.refinedstorage2.platform.api.item.NetworkBoundItemHelper;
import com.refinedmods.refinedstorage2.platform.api.item.SlotReference;
import com.refinedmods.refinedstorage2.platform.api.item.SlotReferenceFactory;
import com.refinedmods.refinedstorage2.platform.api.item.SlotReferenceProvider;
import com.refinedmods.refinedstorage2.platform.api.item.StorageContainerItemHelper;
import com.refinedmods.refinedstorage2.platform.api.network.node.exporter.ExporterTransferStrategyFactory;
import com.refinedmods.refinedstorage2.platform.api.network.node.externalstorage.PlatformExternalStorageProviderFactory;
Expand All @@ -41,9 +44,12 @@
import java.util.Set;
import javax.annotation.Nullable;

import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;

Expand Down Expand Up @@ -296,6 +302,36 @@ public NetworkBoundItemHelper getNetworkBoundItemHelper() {
return ensureLoaded().getNetworkBoundItemHelper();
}

@Override
public PlatformRegistry<SlotReferenceFactory> getSlotReferenceFactoryRegistry() {
return ensureLoaded().getSlotReferenceFactoryRegistry();
}

@Override
public void writeSlotReference(final SlotReference slotReference, final FriendlyByteBuf buf) {
ensureLoaded().writeSlotReference(slotReference, buf);
}

@Override
public Optional<SlotReference> getSlotReference(final FriendlyByteBuf buf) {
return ensureLoaded().getSlotReference(buf);
}

@Override
public void addSlotReferenceProvider(final SlotReferenceProvider slotReferenceProvider) {
ensureLoaded().addSlotReferenceProvider(slotReferenceProvider);
}

@Override
public SlotReference createInventorySlotReference(final Player player, final InteractionHand hand) {
return ensureLoaded().createInventorySlotReference(player, hand);
}

@Override
public void useNetworkBoundItem(final Player player, final Item... items) {
ensureLoaded().useNetworkBoundItem(player, items);
}

private PlatformApi ensureLoaded() {
if (delegate == null) {
throw new IllegalStateException("Platform API not loaded yet");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package com.refinedmods.refinedstorage2.platform.api.item;

import com.refinedmods.refinedstorage2.platform.api.PlatformApi;

import java.util.List;
import java.util.Optional;
import javax.annotation.Nullable;

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.entity.player.Player;
import net.minecraft.world.inventory.tooltip.TooltipComponent;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
Expand Down Expand Up @@ -43,6 +49,23 @@ public void appendHoverText(final ItemStack stack,
networkBoundItemHelper.addTooltip(stack, tooltip);
}

@Override
public InteractionResultHolder<ItemStack> use(final Level level, final Player player, final InteractionHand hand) {
final ItemStack stack = player.getItemInHand(hand);
if (player instanceof ServerPlayer serverPlayer && level.getServer() != null) {
final SlotReference slotReference = PlatformApi.INSTANCE.createInventorySlotReference(player, hand);
final NetworkBoundItemSession session = networkBoundItemHelper.openSession(
stack,
serverPlayer,
slotReference
);
use(serverPlayer, slotReference, session);
}
return InteractionResultHolder.consume(stack);
}

public abstract void use(ServerPlayer player, SlotReference slotReference, NetworkBoundItemSession session);

public boolean isBound(final ItemStack stack) {
return networkBoundItemHelper.isBound(stack);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

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.inventory.tooltip.TooltipComponent;
import net.minecraft.world.item.ItemStack;
Expand All @@ -20,7 +19,7 @@ public interface NetworkBoundItemHelper {

Optional<TooltipComponent> getTooltipImage(ItemStack stack);

NetworkBoundItemSession openSession(ItemStack stack, ServerPlayer player, InteractionHand hand);
NetworkBoundItemSession openSession(ItemStack stack, ServerPlayer player, SlotReference slotReference);

boolean isBound(ItemStack stack);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.refinedmods.refinedstorage2.platform.api.item;

import java.util.Optional;

import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import org.apiguardian.api.API;

@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.1")
public interface SlotReference {
boolean isDisabledSlot(int playerSlotIndex);

void writeToBuffer(FriendlyByteBuf buf);

Optional<ItemStack> resolve(Player player);

SlotReferenceFactory getFactory();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.refinedmods.refinedstorage2.platform.api.item;

import net.minecraft.network.FriendlyByteBuf;
import org.apiguardian.api.API;

@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.1")
public interface SlotReferenceFactory {
SlotReference create(FriendlyByteBuf buf);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.refinedmods.refinedstorage2.platform.api.item;

import java.util.List;
import java.util.Set;

import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import org.apiguardian.api.API;

@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.1")
public interface SlotReferenceProvider {
List<SlotReference> find(Player player, Set<Item> validItems);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource;
import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.GridContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.WirelessGridContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.content.Items;
import com.refinedmods.refinedstorage2.platform.common.content.KeyMappings;
import com.refinedmods.refinedstorage2.platform.common.content.Menus;
import com.refinedmods.refinedstorage2.platform.common.internal.resource.FluidResourceRendering;
import com.refinedmods.refinedstorage2.platform.common.internal.resource.ItemResourceRendering;
Expand All @@ -25,10 +27,13 @@
import com.refinedmods.refinedstorage2.platform.common.screen.grid.GridScreen;
import com.refinedmods.refinedstorage2.platform.common.screen.grid.hint.FluidGridInsertionHint;

import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.MenuAccess;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.MenuType;

Expand Down Expand Up @@ -61,6 +66,21 @@ protected static void registerResourceRendering() {
PlatformApi.INSTANCE.registerResourceRendering(FluidResource.class, new FluidResourceRendering());
}

protected static void handleInputEvents() {
final Player player = Minecraft.getInstance().player;
if (player == null) {
return;
}
final KeyMapping openWirelessGrid = KeyMappings.INSTANCE.getOpenWirelessGrid();
while (openWirelessGrid != null && openWirelessGrid.consumeClick()) {
PlatformApi.INSTANCE.useNetworkBoundItem(
player,
Items.INSTANCE.getWirelessGrid(),
Items.INSTANCE.getCreativeWirelessGrid()
);
}
}

@FunctionalInterface
public interface ScreenRegistration {
<M extends AbstractContainerMenu, U extends Screen & MenuAccess<M>> void register(MenuType<? extends M> type,
Expand Down
Loading

0 comments on commit 08463b3

Please sign in to comment.