Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce client api
Browse files Browse the repository at this point in the history
raoulvdberge committed Dec 7, 2024
1 parent 478f78d commit ede58f4
Showing 44 changed files with 383 additions and 284 deletions.
Original file line number Diff line number Diff line change
@@ -7,14 +7,10 @@
import com.refinedmods.refinedstorage.api.network.energy.EnergyStorage;
import com.refinedmods.refinedstorage.api.network.node.NetworkNode;
import com.refinedmods.refinedstorage.api.network.security.SecurityPolicy;
import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.api.resource.ResourceKey;
import com.refinedmods.refinedstorage.common.api.constructordestructor.ConstructorStrategyFactory;
import com.refinedmods.refinedstorage.common.api.constructordestructor.DestructorStrategyFactory;
import com.refinedmods.refinedstorage.common.api.exporter.ExporterTransferStrategyFactory;
import com.refinedmods.refinedstorage.common.api.grid.Grid;
import com.refinedmods.refinedstorage.common.api.grid.GridInsertionHint;
import com.refinedmods.refinedstorage.common.api.grid.GridInsertionHints;
import com.refinedmods.refinedstorage.common.api.grid.GridSynchronizer;
import com.refinedmods.refinedstorage.common.api.grid.strategy.GridExtractionStrategy;
import com.refinedmods.refinedstorage.common.api.grid.strategy.GridExtractionStrategyFactory;
@@ -41,7 +37,6 @@
import com.refinedmods.refinedstorage.common.api.support.resource.RecipeModIngredientConverter;
import com.refinedmods.refinedstorage.common.api.support.resource.ResourceContainerInsertStrategy;
import com.refinedmods.refinedstorage.common.api.support.resource.ResourceFactory;
import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering;
import com.refinedmods.refinedstorage.common.api.support.resource.ResourceType;
import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReference;
import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReferenceFactory;
@@ -50,7 +45,6 @@
import com.refinedmods.refinedstorage.common.api.wirelesstransmitter.WirelessTransmitterRangeModifier;

import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Nullable;
@@ -62,7 +56,6 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
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;
@@ -141,10 +134,6 @@ GridInsertionStrategy createGridInsertionStrategy(AbstractContainerMenu containe

Collection<ResourceContainerInsertStrategy> getResourceContainerInsertStrategies();

void addAlternativeGridInsertionHint(GridInsertionHint hint);

GridInsertionHints getGridInsertionHints();

GridExtractionStrategy createGridExtractionStrategy(AbstractContainerMenu containerMenu,
ServerPlayer player,
Grid grid);
@@ -169,10 +158,6 @@ GridScrollingStrategy createGridScrollingStrategy(AbstractContainerMenu containe

Set<ResourceFactory> getAlternativeResourceFactories();

<T extends ResourceKey> void registerResourceRendering(Class<T> resourceClass, ResourceRendering rendering);

<T extends ResourceKey> ResourceRendering getResourceRendering(Class<T> resourceClass);

void addIngredientConverter(RecipeModIngredientConverter converter);

RecipeModIngredientConverter getIngredientConverter();
@@ -215,8 +200,6 @@ EnergyStorage asBlockItemEnergyStorage(

Optional<Pattern> getPattern(ItemStack stack, Level level);

void openAutocraftingPreview(List<ResourceAmount> requests, @Nullable Object parentScreen);

ResourceLocation getCreativeModeTabId();

AbstractNetworkNodeContainerBlockEntity<?> createStorageBlockEntity(BlockPos pos,
@@ -232,9 +215,4 @@ AbstractContainerMenu createStorageBlockContainerMenu(int syncId,
MenuType<?> menuType);

StreamCodec<RegistryFriendlyByteBuf, StorageBlockData> getStorageBlockDataStreamCodec();

Object createStorageBlockScreen(AbstractContainerMenu menu,
Inventory inventory,
Component title,
Class<? extends ResourceKey> resourceClass);
}
Original file line number Diff line number Diff line change
@@ -7,14 +7,10 @@
import com.refinedmods.refinedstorage.api.network.energy.EnergyStorage;
import com.refinedmods.refinedstorage.api.network.node.NetworkNode;
import com.refinedmods.refinedstorage.api.network.security.SecurityPolicy;
import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.api.resource.ResourceKey;
import com.refinedmods.refinedstorage.common.api.constructordestructor.ConstructorStrategyFactory;
import com.refinedmods.refinedstorage.common.api.constructordestructor.DestructorStrategyFactory;
import com.refinedmods.refinedstorage.common.api.exporter.ExporterTransferStrategyFactory;
import com.refinedmods.refinedstorage.common.api.grid.Grid;
import com.refinedmods.refinedstorage.common.api.grid.GridInsertionHint;
import com.refinedmods.refinedstorage.common.api.grid.GridInsertionHints;
import com.refinedmods.refinedstorage.common.api.grid.GridSynchronizer;
import com.refinedmods.refinedstorage.common.api.grid.strategy.GridExtractionStrategy;
import com.refinedmods.refinedstorage.common.api.grid.strategy.GridExtractionStrategyFactory;
@@ -41,7 +37,6 @@
import com.refinedmods.refinedstorage.common.api.support.resource.RecipeModIngredientConverter;
import com.refinedmods.refinedstorage.common.api.support.resource.ResourceContainerInsertStrategy;
import com.refinedmods.refinedstorage.common.api.support.resource.ResourceFactory;
import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering;
import com.refinedmods.refinedstorage.common.api.support.resource.ResourceType;
import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReference;
import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReferenceFactory;
@@ -50,7 +45,6 @@
import com.refinedmods.refinedstorage.common.api.wirelesstransmitter.WirelessTransmitterRangeModifier;

import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Nullable;
@@ -62,7 +56,6 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
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;
@@ -237,16 +230,6 @@ public Collection<ResourceContainerInsertStrategy> getResourceContainerInsertStr
return ensureLoaded().getResourceContainerInsertStrategies();
}

@Override
public void addAlternativeGridInsertionHint(final GridInsertionHint hint) {
ensureLoaded().addAlternativeGridInsertionHint(hint);
}

@Override
public GridInsertionHints getGridInsertionHints() {
return ensureLoaded().getGridInsertionHints();
}

@Override
public GridExtractionStrategy createGridExtractionStrategy(final AbstractContainerMenu containerMenu,
final ServerPlayer player,
@@ -301,17 +284,6 @@ public Set<ResourceFactory> getAlternativeResourceFactories() {
return ensureLoaded().getAlternativeResourceFactories();
}

@Override
public <T extends ResourceKey> void registerResourceRendering(final Class<T> resourceClass,
final ResourceRendering rendering) {
ensureLoaded().registerResourceRendering(resourceClass, rendering);
}

@Override
public <T extends ResourceKey> ResourceRendering getResourceRendering(final Class<T> resourceClass) {
return ensureLoaded().getResourceRendering(resourceClass);
}

@Override
public void addIngredientConverter(final RecipeModIngredientConverter converter) {
ensureLoaded().addIngredientConverter(converter);
@@ -412,11 +384,6 @@ public Optional<Pattern> getPattern(final ItemStack stack, final Level level) {
return ensureLoaded().getPattern(stack, level);
}

@Override
public void openAutocraftingPreview(final List<ResourceAmount> requests, @Nullable final Object parentScreen) {
ensureLoaded().openAutocraftingPreview(requests, parentScreen);
}

@Override
public ResourceLocation getCreativeModeTabId() {
return ensureLoaded().getCreativeModeTabId();
@@ -448,14 +415,6 @@ public StreamCodec<RegistryFriendlyByteBuf, StorageBlockData> getStorageBlockDat
return ensureLoaded().getStorageBlockDataStreamCodec();
}

@Override
public Object createStorageBlockScreen(final AbstractContainerMenu menu,
final Inventory inventory,
final Component title,
final Class<? extends ResourceKey> resourceClass) {
return ensureLoaded().createStorageBlockScreen(menu, inventory, title, resourceClass);
}

private RefinedStorageApi ensureLoaded() {
if (delegate == null) {
throw new IllegalStateException("API not loaded yet");
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.refinedmods.refinedstorage.common.api;

import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.api.resource.ResourceKey;
import com.refinedmods.refinedstorage.common.api.grid.GridInsertionHint;
import com.refinedmods.refinedstorage.common.api.grid.GridInsertionHints;
import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering;

import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;

import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.Item;
import org.apiguardian.api.API;

@API(status = API.Status.STABLE, since = "2.0.0-milestone.4.11")
public interface RefinedStorageClientApi {
RefinedStorageClientApi INSTANCE = new RefinedStorageClientApiProxy();

AbstractContainerScreen<AbstractContainerMenu> createStorageBlockScreen(
AbstractContainerMenu menu,
Inventory inventory,
Component title,
Class<? extends ResourceKey> resourceClass
);

void openAutocraftingPreview(List<ResourceAmount> requests, @Nullable Screen parentScreen);

<T extends ResourceKey> void registerResourceRendering(Class<T> resourceClass, ResourceRendering rendering);

<T extends ResourceKey> ResourceRendering getResourceRendering(Class<T> resourceClass);

void addAlternativeGridInsertionHint(GridInsertionHint hint);

GridInsertionHints getGridInsertionHints();

void registerDiskModel(Item item, ResourceLocation model);

Set<ResourceLocation> getDiskModels();

Map<Item, ResourceLocation> getDiskModelsByItem();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.refinedmods.refinedstorage.common.api;

import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.api.resource.ResourceKey;
import com.refinedmods.refinedstorage.common.api.grid.GridInsertionHint;
import com.refinedmods.refinedstorage.common.api.grid.GridInsertionHints;
import com.refinedmods.refinedstorage.common.api.support.resource.ResourceRendering;

import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;

import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.Item;

public class RefinedStorageClientApiProxy implements RefinedStorageClientApi {
@Nullable
private RefinedStorageClientApi delegate;

public void setDelegate(final RefinedStorageClientApi delegate) {
if (this.delegate != null) {
throw new IllegalStateException("Client API already injected");
}
this.delegate = delegate;
}

@Override
public AbstractContainerScreen<AbstractContainerMenu> createStorageBlockScreen(
final AbstractContainerMenu menu,
final Inventory inventory,
final Component title,
final Class<? extends ResourceKey> resourceClass
) {
return ensureLoaded().createStorageBlockScreen(menu, inventory, title, resourceClass);
}

@Override
public void openAutocraftingPreview(final List<ResourceAmount> requests, @Nullable final Screen parentScreen) {
ensureLoaded().openAutocraftingPreview(requests, parentScreen);
}

@Override
public <T extends ResourceKey> void registerResourceRendering(final Class<T> resourceClass,
final ResourceRendering rendering) {
ensureLoaded().registerResourceRendering(resourceClass, rendering);
}

@Override
public <T extends ResourceKey> ResourceRendering getResourceRendering(final Class<T> resourceClass) {
return ensureLoaded().getResourceRendering(resourceClass);
}

@Override
public void addAlternativeGridInsertionHint(final GridInsertionHint hint) {
ensureLoaded().addAlternativeGridInsertionHint(hint);
}

@Override
public GridInsertionHints getGridInsertionHints() {
return ensureLoaded().getGridInsertionHints();
}

@Override
public void registerDiskModel(final Item item, final ResourceLocation model) {
ensureLoaded().registerDiskModel(item, model);
}

@Override
public Set<ResourceLocation> getDiskModels() {
return ensureLoaded().getDiskModels();
}

@Override
public Map<Item, ResourceLocation> getDiskModelsByItem() {
return ensureLoaded().getDiskModelsByItem();
}

private RefinedStorageClientApi ensureLoaded() {
if (delegate == null) {
throw new IllegalStateException("API not loaded yet");
}
return delegate;
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package com.refinedmods.refinedstorage.common.api.storage;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.function.LongFunction;
import javax.annotation.Nullable;

import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
@@ -52,11 +48,5 @@ void appendToTooltip(ItemStack stack,

void transferFromBlockEntity(ItemStack stack, StorageBlockEntity blockEntity);

void registerDiskModel(Item item, ResourceLocation model);

Set<ResourceLocation> getDiskModels();

Map<Item, ResourceLocation> getDiskModelsByItem();

void markAsToTransfer(ItemStack from, ItemStack to);
}
Loading

0 comments on commit ede58f4

Please sign in to comment.