Implement the Crafting Grid
This commit is contained in:
@@ -12,6 +12,7 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.event.ModelBakeEvent;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
@@ -38,6 +39,11 @@ public class ClientSetup {
|
||||
new ResourceLocation(RS.ID, "block/grid/cutouts/front_connected")
|
||||
));
|
||||
|
||||
bakedModelOverrideRegistry.add(new ResourceLocation(RS.ID, "crafting_grid"), (base, registry) -> new FullbrightBakedModel(
|
||||
base,
|
||||
new ResourceLocation(RS.ID, "block/grid/cutouts/crafting_front_connected")
|
||||
));
|
||||
|
||||
bakedModelOverrideRegistry.add(new ResourceLocation(RS.ID, "disk_drive"), (base, registry) -> new FullbrightBakedModel(
|
||||
new DiskDriveBakedModel(
|
||||
base,
|
||||
@@ -65,7 +71,8 @@ public class ClientSetup {
|
||||
ScreenManager.registerFactory(RSContainers.DISK_DRIVE, DiskDriveScreen::new);
|
||||
ScreenManager.registerFactory(RSContainers.GRID, new GridScreenFactory());
|
||||
|
||||
RSKeyBindings.init();
|
||||
ClientRegistry.registerKeyBinding(RSKeyBindings.FOCUS_SEARCH_BAR);
|
||||
ClientRegistry.registerKeyBinding(RSKeyBindings.CLEAR_GRID_CRAFTING_MATRIX);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.NetworkNodeListener;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.GridFactoryGridBlock;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.factory.GridBlockGridFactory;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.CableNetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.GridNetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNode;
|
||||
@@ -94,8 +94,9 @@ public final class RS {
|
||||
API.instance().getNetworkNodeRegistry().add(DiskDriveNetworkNode.ID, (tag, world, pos) -> readAndReturn(tag, new DiskDriveNetworkNode(world, pos)));
|
||||
API.instance().getNetworkNodeRegistry().add(CableNetworkNode.ID, (tag, world, pos) -> readAndReturn(tag, new CableNetworkNode(world, pos)));
|
||||
API.instance().getNetworkNodeRegistry().add(GridNetworkNode.ID, (tag, world, pos) -> readAndReturn(tag, new GridNetworkNode(world, pos, GridType.NORMAL)));
|
||||
API.instance().getNetworkNodeRegistry().add(GridNetworkNode.CRAFTING_ID, (tag, world, pos) -> readAndReturn(tag, new GridNetworkNode(world, pos, GridType.CRAFTING)));
|
||||
|
||||
API.instance().getGridManager().add(GridFactoryGridBlock.ID, new GridFactoryGridBlock());
|
||||
API.instance().getGridManager().add(GridBlockGridFactory.ID, new GridBlockGridFactory());
|
||||
}
|
||||
|
||||
private INetworkNode readAndReturn(CompoundNBT tag, NetworkNode node) {
|
||||
@@ -118,26 +119,17 @@ public final class RS {
|
||||
e.getRegistry().register(new CableBlock());
|
||||
e.getRegistry().register(new DiskDriveBlock());
|
||||
e.getRegistry().register(new GridBlock(GridType.NORMAL));
|
||||
e.getRegistry().register(new GridBlock(GridType.CRAFTING));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRegisterTiles(RegistryEvent.Register<TileEntityType<?>> e) {
|
||||
e.getRegistry().register(registerTileDataParameters(
|
||||
TileEntityType.Builder.create(() -> new ControllerTile(ControllerBlock.Type.NORMAL), RSBlocks.CONTROLLER).build(null).setRegistryName(RS.ID, "controller")
|
||||
));
|
||||
|
||||
e.getRegistry().register(registerTileDataParameters(
|
||||
TileEntityType.Builder.create(() -> new ControllerTile(ControllerBlock.Type.CREATIVE), RSBlocks.CREATIVE_CONTROLLER).build(null).setRegistryName(RS.ID, "creative_controller")
|
||||
));
|
||||
|
||||
e.getRegistry().register(registerTileDataParameters(TileEntityType.Builder.create(() -> new ControllerTile(ControllerBlock.Type.NORMAL), RSBlocks.CONTROLLER).build(null).setRegistryName(RS.ID, "controller")));
|
||||
e.getRegistry().register(registerTileDataParameters(TileEntityType.Builder.create(() -> new ControllerTile(ControllerBlock.Type.CREATIVE), RSBlocks.CREATIVE_CONTROLLER).build(null).setRegistryName(RS.ID, "creative_controller")));
|
||||
e.getRegistry().register(TileEntityType.Builder.create(CableTile::new, RSBlocks.CABLE).build(null).setRegistryName(RS.ID, "cable"));
|
||||
e.getRegistry().register(registerTileDataParameters(
|
||||
TileEntityType.Builder.create(DiskDriveTile::new, RSBlocks.DISK_DRIVE).build(null).setRegistryName(RS.ID, "disk_drive")
|
||||
));
|
||||
|
||||
e.getRegistry().register(registerTileDataParameters(
|
||||
TileEntityType.Builder.create(() -> new GridTile(GridType.NORMAL), RSBlocks.GRID).build(null).setRegistryName(RS.ID, "grid")
|
||||
));
|
||||
e.getRegistry().register(registerTileDataParameters(TileEntityType.Builder.create(DiskDriveTile::new, RSBlocks.DISK_DRIVE).build(null).setRegistryName(RS.ID, "disk_drive")));
|
||||
e.getRegistry().register(registerTileDataParameters(TileEntityType.Builder.create(() -> new GridTile(GridType.NORMAL), RSBlocks.GRID).build(null).setRegistryName(RS.ID, "grid")));
|
||||
e.getRegistry().register(registerTileDataParameters(TileEntityType.Builder.create(() -> new GridTile(GridType.CRAFTING), RSBlocks.CRAFTING_GRID).build(null).setRegistryName(RS.ID, "crafting_grid")));
|
||||
}
|
||||
|
||||
private <T extends TileEntity> TileEntityType<T> registerTileDataParameters(TileEntityType<T> t) {
|
||||
@@ -206,6 +198,7 @@ public final class RS {
|
||||
e.getRegistry().register(BlockUtils.createBlockItemFor(RSBlocks.CABLE));
|
||||
e.getRegistry().register(BlockUtils.createBlockItemFor(RSBlocks.DISK_DRIVE));
|
||||
e.getRegistry().register(BlockUtils.createBlockItemFor(RSBlocks.GRID));
|
||||
e.getRegistry().register(BlockUtils.createBlockItemFor(RSBlocks.CRAFTING_GRID));
|
||||
}
|
||||
|
||||
/* TODO
|
||||
|
||||
@@ -44,6 +44,8 @@ public final class RSBlocks {
|
||||
|
||||
@ObjectHolder(RS.ID + ":grid")
|
||||
public static final GridBlock GRID = null;
|
||||
@ObjectHolder(RS.ID + ":crafting_grid")
|
||||
public static final GridBlock CRAFTING_GRID = null;
|
||||
|
||||
public static final BlockStorageMonitor STORAGE_MONITOR = new BlockStorageMonitor();
|
||||
public static final BlockPortableGrid PORTABLE_GRID = new BlockPortableGrid();
|
||||
|
||||
@@ -3,28 +3,37 @@ package com.raoulvdberge.refinedstorage;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
import net.minecraftforge.client.settings.KeyConflictContext;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.client.settings.KeyModifier;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
public final class RSKeyBindings {
|
||||
/*
|
||||
public static final KeyBinding CLEAR_GRID_CRAFTING_MATRIX = new KeyBinding("key.refinedstorage.clearGridCraftingMatrix", KeyConflictContext.GUI, KeyModifier.CONTROL, Keyboard.KEY_X, "Refined Storage");
|
||||
public static final KeyBinding OPEN_WIRELESS_GRID = new KeyBinding("key.refinedstorage.openWirelessGrid", KeyConflictContext.IN_GAME, 0, "Refined Storage");
|
||||
public static final KeyBinding OPEN_WIRELESS_FLUID_GRID = new KeyBinding("key.refinedstorage.openWirelessFluidGrid", KeyConflictContext.IN_GAME, 0, "Refined Storage");
|
||||
public static final KeyBinding OPEN_PORTABLE_GRID = new KeyBinding("key.refinedstorage.openPortableGrid", KeyConflictContext.IN_GAME, 0, "Refined Storage");
|
||||
public static final KeyBinding OPEN_WIRELESS_CRAFTING_MONITOR = new KeyBinding("key.refinedstorage.openWirelessCraftingMonitor", KeyConflictContext.IN_GAME, 0, "Refined Storage");
|
||||
|
||||
public static void init() {
|
||||
ClientRegistry.registerKeyBinding(CLEAR_GRID_CRAFTING_MATRIX);
|
||||
ClientRegistry.registerKeyBinding(OPEN_WIRELESS_GRID);
|
||||
ClientRegistry.registerKeyBinding(OPEN_WIRELESS_FLUID_GRID);
|
||||
ClientRegistry.registerKeyBinding(OPEN_PORTABLE_GRID);
|
||||
ClientRegistry.registerKeyBinding(OPEN_WIRELESS_CRAFTING_MONITOR);
|
||||
}*/
|
||||
|
||||
public static final KeyBinding FOCUS_SEARCH_BAR = new KeyBinding("key.refinedstorage.focusSearchBar", KeyConflictContext.GUI, InputMappings.Type.KEYSYM, GLFW.GLFW_KEY_TAB, "Refined Storage");
|
||||
public static final KeyBinding FOCUS_SEARCH_BAR = new KeyBinding(
|
||||
"key.refinedstorage.focusSearchBar",
|
||||
KeyConflictContext.GUI,
|
||||
InputMappings.Type.KEYSYM,
|
||||
GLFW.GLFW_KEY_TAB,
|
||||
"Refined Storage"
|
||||
);
|
||||
|
||||
public static void init() {
|
||||
ClientRegistry.registerKeyBinding(FOCUS_SEARCH_BAR);
|
||||
}
|
||||
public static final KeyBinding CLEAR_GRID_CRAFTING_MATRIX = new KeyBinding(
|
||||
"key.refinedstorage.clearGridCraftingMatrix",
|
||||
KeyConflictContext.GUI,
|
||||
KeyModifier.CONTROL,
|
||||
InputMappings.Type.KEYSYM,
|
||||
GLFW.GLFW_KEY_X,
|
||||
"Refined Storage"
|
||||
);
|
||||
}
|
||||
@@ -19,7 +19,6 @@ public class RSOldConfig {
|
||||
public int storageUsage;
|
||||
public int fluidStorageUsage;
|
||||
public int wirelessTransmitterUsage;
|
||||
public int craftingGridUsage;
|
||||
public int patternGridUsage;
|
||||
public int fluidGridUsage;
|
||||
public int networkTransmitterUsage;
|
||||
@@ -111,7 +110,6 @@ public class RSOldConfig {
|
||||
storageUsage = config.getInt("storage", ENERGY, 1, 0, Integer.MAX_VALUE, "The energy used by Storage Blocks");
|
||||
fluidStorageUsage = config.getInt("fluidStorage", ENERGY, 1, 0, Integer.MAX_VALUE, "The energy used by Fluid Storage Blocks");
|
||||
wirelessTransmitterUsage = config.getInt("wirelessTransmitter", ENERGY, 8, 0, Integer.MAX_VALUE, "The energy used by Wireless Transmitters");
|
||||
craftingGridUsage = config.getInt("craftingGrid", ENERGY, 4, 0, Integer.MAX_VALUE, "The energy used by Crafting Grids");
|
||||
patternGridUsage = config.getInt("patternGrid", ENERGY, 3, 0, Integer.MAX_VALUE, "The energy used by Pattern Grids");
|
||||
fluidGridUsage = config.getInt("fluidGrid", ENERGY, 2, 0, Integer.MAX_VALUE, "The energy used by Fluid Grids");
|
||||
networkTransmitterUsage = config.getInt("networkTransmitter", ENERGY, 64, 0, Integer.MAX_VALUE, "The energy used by Network Transmitters");
|
||||
|
||||
@@ -44,6 +44,8 @@ public class RSTiles {
|
||||
|
||||
@ObjectHolder(RS.ID + ":grid")
|
||||
public static final TileEntityType<GridTile> GRID = null;
|
||||
@ObjectHolder(RS.ID + ":crafting_grid")
|
||||
public static final TileEntityType<GridTile> CRAFTING_GRID = null;
|
||||
|
||||
//@ObjectHolder(RS.ID + ":importer")
|
||||
public static final TileEntityType<TileImporter> IMPORTER = null;
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.raoulvdberge.refinedstorage.api.autocrafting.registry.ICraftingTaskRe
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.task.CraftingTaskReadException;
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingRequestInfo;
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.ICraftingGridBehavior;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridManager;
|
||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeManager;
|
||||
@@ -121,6 +122,12 @@ public interface IRSAPI {
|
||||
@Nonnull
|
||||
IGridManager getGridManager();
|
||||
|
||||
/**
|
||||
* @return the default crafting grid behavior
|
||||
*/
|
||||
@Nonnull
|
||||
ICraftingGridBehavior getCraftingGridBehavior();
|
||||
|
||||
/**
|
||||
* @return the storage disk registry
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.raoulvdberge.refinedstorage.api.network.grid;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.crafting.ICraftingRecipe;
|
||||
|
||||
/**
|
||||
* Defines default behavior of crafting grids.
|
||||
*/
|
||||
public interface ICraftingGridBehavior {
|
||||
/**
|
||||
* Default logic for regular crafting.
|
||||
*
|
||||
* @param grid the grid
|
||||
* @param recipe the recipe
|
||||
* @param player the player
|
||||
*/
|
||||
void onCrafted(IGridNetworkAware grid, ICraftingRecipe recipe, PlayerEntity player);
|
||||
|
||||
/**
|
||||
* Default logic for crafting with shift click (mass crafting).
|
||||
*
|
||||
* @param grid the grid
|
||||
* @param player the layer
|
||||
*/
|
||||
void onCraftedShift(IGridNetworkAware grid, PlayerEntity player);
|
||||
}
|
||||
@@ -3,10 +3,11 @@ package com.raoulvdberge.refinedstorage.api.network.grid;
|
||||
/**
|
||||
* A crafting listener for the grid.
|
||||
*/
|
||||
public interface IGridCraftingListener {
|
||||
public interface ICraftingGridListener {
|
||||
/**
|
||||
* Called when the crafting matrix was changed.
|
||||
* Usually you'd send slot updates for the crafting slots (and output slot) here, so that all clients get an actual view.
|
||||
* This listener exists so the crafting result slot is only calculated on the server.
|
||||
*/
|
||||
void onCraftingMatrixChanged();
|
||||
}
|
||||
@@ -77,13 +77,13 @@ public interface IGrid {
|
||||
/**
|
||||
* @param listener the listener
|
||||
*/
|
||||
default void addCraftingListener(IGridCraftingListener listener) {
|
||||
default void addCraftingListener(ICraftingGridListener listener) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param listener the listener
|
||||
*/
|
||||
default void removeCraftingListener(IGridCraftingListener listener) {
|
||||
default void removeCraftingListener(ICraftingGridListener listener) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,6 +205,11 @@ public interface IGrid {
|
||||
*/
|
||||
void onCrafted(PlayerEntity player);
|
||||
|
||||
/**
|
||||
* Called when the clear button is pressed in the pattern grid or crafting grid.
|
||||
*/
|
||||
void onClear(PlayerEntity player);
|
||||
|
||||
/**
|
||||
* Called when an item is crafted with shift click (up to 64 items) in a crafting grid.
|
||||
*
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.raoulvdberge.refinedstorage.api.autocrafting.registry.ICraftingTaskRe
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.task.CraftingTaskReadException;
|
||||
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingRequestInfo;
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.ICraftingGridBehavior;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridManager;
|
||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeManager;
|
||||
@@ -33,6 +34,7 @@ import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPrev
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.registry.CraftingTaskRegistry;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.NetworkNodeManager;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.NetworkNodeRegistry;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.CraftingGridBehavior;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.GridManager;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.readerwriter.ReaderWriterChannel;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.readerwriter.ReaderWriterHandlerRegistry;
|
||||
@@ -60,18 +62,19 @@ import java.util.*;
|
||||
public class API implements IRSAPI {
|
||||
private static final IRSAPI INSTANCE = new API();
|
||||
|
||||
private IComparer comparer = new Comparer();
|
||||
private IQuantityFormatter quantityFormatter = new QuantityFormatter();
|
||||
private INetworkNodeRegistry networkNodeRegistry = new NetworkNodeRegistry();
|
||||
private ICraftingTaskRegistry craftingTaskRegistry = new CraftingTaskRegistry();
|
||||
private ICraftingMonitorElementRegistry craftingMonitorElementRegistry = new CraftingMonitorElementRegistry();
|
||||
private ICraftingPreviewElementRegistry craftingPreviewElementRegistry = new CraftingPreviewElementRegistry();
|
||||
private IReaderWriterHandlerRegistry readerWriterHandlerRegistry = new ReaderWriterHandlerRegistry();
|
||||
private IGridManager gridManager = new GridManager();
|
||||
private IStorageDiskRegistry storageDiskRegistry = new StorageDiskRegistry();
|
||||
private IStorageDiskSync storageDiskSync = new StorageDiskSync();
|
||||
private Map<StorageType, TreeSet<IExternalStorageProvider>> externalStorageProviders = new HashMap<>();
|
||||
private List<ICraftingPatternRenderHandler> patternRenderHandlers = new LinkedList<>();
|
||||
private final IComparer comparer = new Comparer();
|
||||
private final IQuantityFormatter quantityFormatter = new QuantityFormatter();
|
||||
private final INetworkNodeRegistry networkNodeRegistry = new NetworkNodeRegistry();
|
||||
private final ICraftingTaskRegistry craftingTaskRegistry = new CraftingTaskRegistry();
|
||||
private final ICraftingMonitorElementRegistry craftingMonitorElementRegistry = new CraftingMonitorElementRegistry();
|
||||
private final ICraftingPreviewElementRegistry craftingPreviewElementRegistry = new CraftingPreviewElementRegistry();
|
||||
private final IReaderWriterHandlerRegistry readerWriterHandlerRegistry = new ReaderWriterHandlerRegistry();
|
||||
private final IGridManager gridManager = new GridManager();
|
||||
private final ICraftingGridBehavior craftingGridBehavior = new CraftingGridBehavior();
|
||||
private final IStorageDiskRegistry storageDiskRegistry = new StorageDiskRegistry();
|
||||
private final IStorageDiskSync storageDiskSync = new StorageDiskSync();
|
||||
private final Map<StorageType, TreeSet<IExternalStorageProvider>> externalStorageProviders = new HashMap<>();
|
||||
private final List<ICraftingPatternRenderHandler> patternRenderHandlers = new LinkedList<>();
|
||||
|
||||
public static IRSAPI instance() {
|
||||
return INSTANCE;
|
||||
@@ -175,6 +178,12 @@ public class API implements IRSAPI {
|
||||
return gridManager;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ICraftingGridBehavior getCraftingGridBehavior() {
|
||||
return craftingGridBehavior;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IStorageDiskRegistry getStorageDiskRegistry() {
|
||||
|
||||
@@ -11,7 +11,6 @@ import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.ICraftingRecipe;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.IRecipeType;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.util.NonNullList;
|
||||
@@ -20,6 +19,7 @@ import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class CraftingPattern implements ICraftingPattern {
|
||||
private ICraftingPatternContainer container;
|
||||
@@ -27,7 +27,7 @@ public class CraftingPattern implements ICraftingPattern {
|
||||
private boolean processing;
|
||||
private boolean oredict;
|
||||
private boolean valid;
|
||||
private IRecipe recipe;
|
||||
private ICraftingRecipe recipe;
|
||||
private List<NonNullList<ItemStack>> inputs = new ArrayList<>();
|
||||
private NonNullList<ItemStack> outputs = NonNullList.create();
|
||||
private NonNullList<ItemStack> byproducts = NonNullList.create();
|
||||
@@ -108,34 +108,30 @@ public class CraftingPattern implements ICraftingPattern {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: better way of collecting recipes
|
||||
for (ICraftingRecipe r : world.getRecipeManager().getRecipes(IRecipeType.CRAFTING, inv, world)) {
|
||||
if (r.matches(inv, world)) {
|
||||
this.recipe = r;
|
||||
Optional<ICraftingRecipe> potentialRecipe = world.getRecipeManager().getRecipe(IRecipeType.CRAFTING, inv, world);
|
||||
if (potentialRecipe.isPresent()) {
|
||||
this.recipe = potentialRecipe.get();
|
||||
|
||||
this.byproducts = recipe.getRemainingItems(inv);
|
||||
this.byproducts = recipe.getRemainingItems(inv);
|
||||
|
||||
ItemStack output = recipe.getCraftingResult(inv);
|
||||
ItemStack output = recipe.getCraftingResult(inv);
|
||||
|
||||
if (!output.isEmpty()) {
|
||||
this.valid = true;
|
||||
if (!output.isEmpty()) {
|
||||
this.valid = true;
|
||||
|
||||
outputs.add(output);
|
||||
outputs.add(output);
|
||||
|
||||
if (oredict) {
|
||||
if (recipe.getIngredients().size() > 0) {
|
||||
inputs.clear();
|
||||
if (oredict) {
|
||||
if (recipe.getIngredients().size() > 0) {
|
||||
inputs.clear();
|
||||
|
||||
for (int i = 0; i < recipe.getIngredients().size(); ++i) {
|
||||
inputs.add(i, NonNullList.from(ItemStack.EMPTY, ((Ingredient) recipe.getIngredients().get(i)).getMatchingStacks()));
|
||||
}
|
||||
} else {
|
||||
this.valid = false;
|
||||
for (int i = 0; i < recipe.getIngredients().size(); ++i) {
|
||||
inputs.add(i, NonNullList.from(ItemStack.EMPTY, ((Ingredient) recipe.getIngredients().get(i)).getMatchingStacks()));
|
||||
}
|
||||
} else {
|
||||
this.valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.grid;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.ICraftingGridBehavior;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridNetworkAware;
|
||||
import com.raoulvdberge.refinedstorage.api.util.Action;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.ICraftingRecipe;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraftforge.fml.hooks.BasicEventHooks;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CraftingGridBehavior implements ICraftingGridBehavior {
|
||||
@Override
|
||||
public void onCrafted(IGridNetworkAware grid, ICraftingRecipe recipe, PlayerEntity player) {
|
||||
NonNullList<ItemStack> remainder = recipe.getRemainingItems(grid.getCraftingMatrix());
|
||||
|
||||
INetwork network = grid.getNetwork();
|
||||
|
||||
CraftingInventory matrix = grid.getCraftingMatrix();
|
||||
|
||||
for (int i = 0; i < grid.getCraftingMatrix().getSizeInventory(); ++i) {
|
||||
ItemStack slot = matrix.getStackInSlot(i);
|
||||
|
||||
// Do we have a remainder?
|
||||
if (i < remainder.size() && !remainder.get(i).isEmpty()) {
|
||||
// If there is no space for the remainder, dump it in the player inventory.
|
||||
if (!slot.isEmpty() && slot.getCount() > 1) {
|
||||
if (!player.inventory.addItemStackToInventory(remainder.get(i).copy())) { // If there is no space in the player inventory, try to dump it in the network.
|
||||
ItemStack remainderStack = network == null ? remainder.get(i).copy() : network.insertItem(remainder.get(i).copy(), remainder.get(i).getCount(), Action.PERFORM);
|
||||
|
||||
// If there is no space in the network, just dump it in the world.
|
||||
if (remainderStack != null) {
|
||||
InventoryHelper.spawnItemStack(player.getEntityWorld(), player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), remainderStack);
|
||||
}
|
||||
}
|
||||
|
||||
matrix.decrStackSize(i, 1);
|
||||
} else {
|
||||
matrix.setInventorySlotContents(i, remainder.get(i).copy());
|
||||
}
|
||||
} else if (!slot.isEmpty()) { // We don't have a remainder, but the slot is not empty.
|
||||
if (slot.getCount() == 1 && network != null) { // Attempt to refill the slot with the same item from the network, only if we have a network and only if it's the last item.
|
||||
ItemStack refill = StackUtils.nullToEmpty(network.extractItem(slot, 1, Action.PERFORM));
|
||||
|
||||
matrix.setInventorySlotContents(i, refill);
|
||||
|
||||
if (!refill.isEmpty()) {
|
||||
network.getItemStorageTracker().changed(player, refill.copy());
|
||||
}
|
||||
} else { // We don't have a network, or, the slot still has more than 1 items in it. Just decrement then.
|
||||
matrix.decrStackSize(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
grid.onCraftingMatrixChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCraftedShift(IGridNetworkAware grid, PlayerEntity player) {
|
||||
List<ItemStack> craftedItemsList = new ArrayList<>();
|
||||
int amountCrafted = 0;
|
||||
ItemStack crafted = grid.getCraftingResult().getStackInSlot(0);
|
||||
|
||||
// Do while the item is still craftable (aka is the result slot still the same as the original item?) and we don't exceed the max stack size.
|
||||
do {
|
||||
grid.onCrafted(player);
|
||||
|
||||
craftedItemsList.add(crafted.copy());
|
||||
|
||||
amountCrafted += crafted.getCount();
|
||||
} while (API.instance().getComparer().isEqual(crafted, grid.getCraftingResult().getStackInSlot(0)) && amountCrafted + crafted.getCount() < crafted.getMaxStackSize());
|
||||
|
||||
INetwork network = grid.getNetwork();
|
||||
|
||||
for (ItemStack craftedItem : craftedItemsList) {
|
||||
if (!player.inventory.addItemStackToInventory(craftedItem.copy())) {
|
||||
ItemStack remainder = network == null ? craftedItem : network.insertItem(craftedItem, craftedItem.getCount(), Action.PERFORM);
|
||||
|
||||
if (remainder != null) {
|
||||
InventoryHelper.spawnItemStack(player.getEntityWorld(), player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), remainder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @Volatile: This is some logic copied from CraftingResultSlot#onCrafting. We call this manually for shift clicking because
|
||||
// otherwise it's not being called.
|
||||
// For regular crafting, this is already called in ResultCraftingGridSlot#onTake -> onCrafting(stack)
|
||||
crafted.onCrafting(player.world, player, amountCrafted);
|
||||
BasicEventHooks.firePlayerCraftingEvent(player, ItemHandlerHelper.copyStackWithSize(crafted, amountCrafted), grid.getCraftingMatrix());
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.grid;
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.grid.factory;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridFactoryType;
|
||||
@@ -14,7 +14,7 @@ import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class GridFactoryGridBlock implements IGridFactory {
|
||||
public class GridBlockGridFactory implements IGridFactory {
|
||||
public static final ResourceLocation ID = new ResourceLocation(RS.ID, "grid");
|
||||
|
||||
@Override
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.grid;
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.grid.factory;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridFactoryType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
@@ -12,7 +12,7 @@ import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class GridFactoryPortableGridBlock implements IGridFactory {
|
||||
public class PortableGridBlockGridFactory implements IGridFactory {
|
||||
@Override
|
||||
@Nullable
|
||||
public IGrid createFromStack(PlayerEntity player, ItemStack stack) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.grid;
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.grid.factory;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridFactoryType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
@@ -12,7 +12,7 @@ import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class GridFactoryPortableGrid implements IGridFactory {
|
||||
public class PortableGridGridFactory implements IGridFactory {
|
||||
@Nullable
|
||||
@Override
|
||||
public IGrid createFromStack(PlayerEntity player, ItemStack stack) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.grid;
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.grid.factory;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridFactoryType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
@@ -12,7 +12,7 @@ import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class GridFactoryWirelessFluidGrid implements IGridFactory {
|
||||
public class WirelessFluidGridGridFactory implements IGridFactory {
|
||||
@Nullable
|
||||
@Override
|
||||
public IGrid createFromStack(PlayerEntity player, ItemStack stack) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.grid;
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.grid.factory;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridFactoryType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
@@ -12,7 +12,7 @@ import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class GridFactoryWirelessGrid implements IGridFactory {
|
||||
public class WirelessGridGridFactory implements IGridFactory {
|
||||
@Nullable
|
||||
@Override
|
||||
public IGrid createFromStack(PlayerEntity player, ItemStack stack) {
|
||||
@@ -19,10 +19,10 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.UUID;
|
||||
|
||||
public class FluidGridHandlerPortable implements IFluidGridHandler {
|
||||
public class PortableFluidGridHandler implements IFluidGridHandler {
|
||||
private IPortableGrid portableGrid;
|
||||
|
||||
public FluidGridHandlerPortable(IPortableGrid portableGrid) {
|
||||
public PortableFluidGridHandler(IPortableGrid portableGrid) {
|
||||
this.portableGrid = portableGrid;
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ItemGridHandlerPortable implements IItemGridHandler {
|
||||
public class PortableItemGridHandler implements IItemGridHandler {
|
||||
private IPortableGrid portableGrid;
|
||||
private IGrid grid;
|
||||
|
||||
public ItemGridHandlerPortable(IPortableGrid portableGrid, IGrid grid) {
|
||||
public PortableItemGridHandler(IPortableGrid portableGrid, IGrid grid) {
|
||||
this.portableGrid = portableGrid;
|
||||
this.grid = grid;
|
||||
}
|
||||
@@ -31,14 +31,12 @@ import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.CraftResultInventory;
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.ICraftingRecipe;
|
||||
import net.minecraft.item.crafting.IRecipeType;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
@@ -61,6 +59,7 @@ import java.util.Set;
|
||||
|
||||
public class GridNetworkNode extends NetworkNode implements IGridNetworkAware, IType {
|
||||
public static final ResourceLocation ID = new ResourceLocation(RS.ID, "grid");
|
||||
public static final ResourceLocation CRAFTING_ID = new ResourceLocation(RS.ID, "crafting_grid");
|
||||
|
||||
public static final String NBT_VIEW_TYPE = "ViewType";
|
||||
public static final String NBT_SORTING_DIRECTION = "SortingDirection";
|
||||
@@ -87,13 +86,13 @@ public class GridNetworkNode extends NetworkNode implements IGridNetworkAware, I
|
||||
}
|
||||
}
|
||||
};
|
||||
private IRecipe currentRecipe;
|
||||
private ICraftingRecipe currentRecipe;
|
||||
private CraftingInventory matrix = new CraftingInventory(craftingContainer, 3, 3);
|
||||
private CraftResultInventory result = new CraftResultInventory();
|
||||
private ItemHandlerBase processingMatrix = new ItemHandlerBase(9 * 2, new ListenerNetworkNode(this));
|
||||
private FluidInventory processingMatrixFluids = new FluidInventory(9 * 2, FluidAttributes.BUCKET_VOLUME * 64, new ListenerNetworkNode(this));
|
||||
|
||||
private Set<IGridCraftingListener> craftingListeners = new HashSet<>();
|
||||
private Set<ICraftingGridListener> craftingListeners = new HashSet<>();
|
||||
|
||||
private ItemHandlerBase patterns = new ItemHandlerBase(2, new ListenerNetworkNode(this), new ItemValidatorBasic(RSItems.PATTERN)) {
|
||||
@Override
|
||||
@@ -146,7 +145,7 @@ public class GridNetworkNode extends NetworkNode implements IGridNetworkAware, I
|
||||
private List<IGridTab> tabs = new ArrayList<>();
|
||||
private ItemHandlerFilter filter = new ItemHandlerFilter(filters, tabs, new ListenerNetworkNode(this));
|
||||
|
||||
private GridType type;
|
||||
private final GridType type;
|
||||
|
||||
private int viewType = VIEW_TYPE_NORMAL;
|
||||
private int sortingDirection = SORTING_DIRECTION_DESCENDING;
|
||||
@@ -161,21 +160,19 @@ public class GridNetworkNode extends NetworkNode implements IGridNetworkAware, I
|
||||
private boolean processingPattern = false;
|
||||
private int processingType = IType.ITEMS;
|
||||
|
||||
private final GridType gridType;
|
||||
|
||||
public GridNetworkNode(World world, BlockPos pos, GridType gridType) {
|
||||
public GridNetworkNode(World world, BlockPos pos, GridType type) {
|
||||
super(world, pos);
|
||||
|
||||
this.gridType = gridType;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyUsage() {
|
||||
switch (getGridType()) {
|
||||
switch (type) {
|
||||
case NORMAL:
|
||||
return RS.SERVER_CONFIG.getGrid().getUsage();
|
||||
return RS.SERVER_CONFIG.getGrid().getGridUsage();
|
||||
case CRAFTING:
|
||||
return 0;
|
||||
return RS.SERVER_CONFIG.getGrid().getCraftingGridUsage();
|
||||
case PATTERN:
|
||||
return 0;
|
||||
case FLUID:
|
||||
@@ -231,18 +228,18 @@ public class GridNetworkNode extends NetworkNode implements IGridNetworkAware, I
|
||||
|
||||
@Override
|
||||
public GridType getGridType() {
|
||||
return gridType;
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageCacheListener createListener(ServerPlayerEntity player) {
|
||||
return getGridType() == GridType.FLUID ? new FluidGridStorageCacheListener(player, network) : new ItemGridStorageCacheListener(player, network);
|
||||
return type == GridType.FLUID ? new FluidGridStorageCacheListener(player, network) : new ItemGridStorageCacheListener(player, network);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IStorageCache getStorageCache() {
|
||||
return network != null ? (getGridType() == GridType.FLUID ? network.getFluidStorageCache() : network.getItemStorageCache()) : null;
|
||||
return network != null ? (type == GridType.FLUID ? network.getFluidStorageCache() : network.getItemStorageCache()) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -258,19 +255,17 @@ public class GridNetworkNode extends NetworkNode implements IGridNetworkAware, I
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCraftingListener(IGridCraftingListener listener) {
|
||||
public void addCraftingListener(ICraftingGridListener listener) {
|
||||
craftingListeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCraftingListener(IGridCraftingListener listener) {
|
||||
public void removeCraftingListener(ICraftingGridListener listener) {
|
||||
craftingListeners.remove(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getTitle() {
|
||||
GridType type = getGridType();
|
||||
|
||||
switch (type) {
|
||||
case CRAFTING:
|
||||
return new TranslationTextComponent("gui.refinedstorage.crafting_grid");
|
||||
@@ -323,7 +318,7 @@ public class GridNetworkNode extends NetworkNode implements IGridNetworkAware, I
|
||||
@Override
|
||||
public void onCraftingMatrixChanged() {
|
||||
if (currentRecipe == null || !currentRecipe.matches(matrix, world)) {
|
||||
currentRecipe = world.getRecipeManager().getRecipe(IRecipeType.CRAFTING, matrix, world).orElse(null); // TODO: does this work?
|
||||
currentRecipe = world.getRecipeManager().getRecipe(IRecipeType.CRAFTING, matrix, world).orElse(null);
|
||||
}
|
||||
|
||||
if (currentRecipe == null) {
|
||||
@@ -332,7 +327,7 @@ public class GridNetworkNode extends NetworkNode implements IGridNetworkAware, I
|
||||
result.setInventorySlotContents(0, currentRecipe.getCraftingResult(matrix));
|
||||
}
|
||||
|
||||
craftingListeners.forEach(IGridCraftingListener::onCraftingMatrixChanged);
|
||||
craftingListeners.forEach(ICraftingGridListener::onCraftingMatrixChanged);
|
||||
|
||||
markDirty();
|
||||
}
|
||||
@@ -457,88 +452,29 @@ public class GridNetworkNode extends NetworkNode implements IGridNetworkAware, I
|
||||
|
||||
@Override
|
||||
public void onCrafted(PlayerEntity player) {
|
||||
onCrafted(this, world, player);
|
||||
API.instance().getCraftingGridBehavior().onCrafted(this, currentRecipe, player);
|
||||
}
|
||||
|
||||
public static void onCrafted(IGridNetworkAware grid, World world, PlayerEntity player) {
|
||||
// TODO: NonNullList<ItemStack> remainder = CraftingManager.getRemainingItems(grid.getCraftingMatrix(), world);
|
||||
NonNullList<ItemStack> remainder = NonNullList.create();
|
||||
@Override
|
||||
public void onClear(PlayerEntity player) {
|
||||
if (type == GridType.CRAFTING && network != null && network.getSecurityManager().hasPermission(Permission.INSERT, player)) {
|
||||
for (int i = 0; i < matrix.getSizeInventory(); ++i) {
|
||||
ItemStack slot = matrix.getStackInSlot(i);
|
||||
|
||||
INetwork network = grid.getNetwork();
|
||||
if (!slot.isEmpty()) {
|
||||
matrix.setInventorySlotContents(i, StackUtils.nullToEmpty(network.insertItem(slot, slot.getCount(), Action.PERFORM)));
|
||||
|
||||
CraftingInventory matrix = grid.getCraftingMatrix();
|
||||
|
||||
for (int i = 0; i < grid.getCraftingMatrix().getSizeInventory(); ++i) {
|
||||
ItemStack slot = matrix.getStackInSlot(i);
|
||||
|
||||
if (i < remainder.size() && !remainder.get(i).isEmpty()) {
|
||||
// If there is no space for the remainder, dump it in the player inventory
|
||||
if (!slot.isEmpty() && slot.getCount() > 1) {
|
||||
if (!player.inventory.addItemStackToInventory(remainder.get(i).copy())) {
|
||||
ItemStack remainderStack = network == null ? remainder.get(i).copy() : network.insertItem(remainder.get(i).copy(), remainder.get(i).getCount(), Action.PERFORM);
|
||||
|
||||
if (remainderStack != null) {
|
||||
InventoryHelper.spawnItemStack(player.getEntityWorld(), player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), remainderStack);
|
||||
}
|
||||
}
|
||||
|
||||
matrix.decrStackSize(i, 1);
|
||||
} else {
|
||||
matrix.setInventorySlotContents(i, remainder.get(i).copy());
|
||||
}
|
||||
} else if (!slot.isEmpty()) {
|
||||
if (slot.getCount() == 1 && network != null) {
|
||||
ItemStack refill = StackUtils.nullToEmpty(network.extractItem(slot, 1, Action.PERFORM));
|
||||
|
||||
matrix.setInventorySlotContents(i, refill);
|
||||
|
||||
if (!refill.isEmpty()) {
|
||||
network.getItemStorageTracker().changed(player, refill.copy());
|
||||
}
|
||||
} else {
|
||||
matrix.decrStackSize(i, 1);
|
||||
network.getItemStorageTracker().changed(player, slot.copy());
|
||||
}
|
||||
}
|
||||
} else if (type == GridType.PATTERN) {
|
||||
clearMatrix();
|
||||
}
|
||||
|
||||
grid.onCraftingMatrixChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCraftedShift(PlayerEntity player) {
|
||||
onCraftedShift(this, player);
|
||||
}
|
||||
|
||||
public static void onCraftedShift(IGridNetworkAware grid, PlayerEntity player) {
|
||||
List<ItemStack> craftedItemsList = new ArrayList<>();
|
||||
int craftedItems = 0;
|
||||
ItemStack crafted = grid.getCraftingResult().getStackInSlot(0);
|
||||
|
||||
while (true) {
|
||||
grid.onCrafted(player);
|
||||
|
||||
craftedItemsList.add(crafted.copy());
|
||||
|
||||
craftedItems += crafted.getCount();
|
||||
|
||||
if (!API.instance().getComparer().isEqual(crafted, grid.getCraftingResult().getStackInSlot(0)) || craftedItems + crafted.getCount() > crafted.getMaxStackSize()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
INetwork network = grid.getNetwork();
|
||||
|
||||
for (ItemStack craftedItem : craftedItemsList) {
|
||||
if (!player.inventory.addItemStackToInventory(craftedItem.copy())) {
|
||||
ItemStack remainder = network == null ? craftedItem : network.insertItem(craftedItem, craftedItem.getCount(), Action.PERFORM);
|
||||
|
||||
if (remainder != null) {
|
||||
InventoryHelper.spawnItemStack(player.getEntityWorld(), player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), remainder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO FMLCommonHandler.instance().firePlayerCraftingEvent(player, ItemHandlerHelper.copyStackWithSize(crafted, craftedItems), grid.getCraftingMatrix());
|
||||
API.instance().getCraftingGridBehavior().onCraftedShift(this, player);
|
||||
}
|
||||
|
||||
public void onCreatePattern() {
|
||||
@@ -753,7 +689,7 @@ public class GridNetworkNode extends NetworkNode implements IGridNetworkAware, I
|
||||
|
||||
@Override
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
return type == GridType.NORMAL ? ID : CRAFTING_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -828,7 +764,7 @@ public class GridNetworkNode extends NetworkNode implements IGridNetworkAware, I
|
||||
|
||||
@Override
|
||||
public IItemHandler getDrops() {
|
||||
switch (getGridType()) {
|
||||
switch (type) {
|
||||
case CRAFTING:
|
||||
return new CombinedInvWrapper(filter, new InvWrapper(matrix));
|
||||
case PATTERN:
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.raoulvdberge.refinedstorage.block;
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.GridFactoryGridBlock;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.factory.GridBlockGridFactory;
|
||||
import com.raoulvdberge.refinedstorage.block.info.BlockDirection;
|
||||
import com.raoulvdberge.refinedstorage.tile.grid.GridTile;
|
||||
import com.raoulvdberge.refinedstorage.util.BlockUtils;
|
||||
@@ -62,7 +62,7 @@ public class GridBlock extends NodeBlock {
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
|
||||
if (!worldIn.isRemote) {
|
||||
return NetworkUtils.attemptModify(worldIn, pos, hit.getFace(), player, () -> API.instance().getGridManager().openGrid(GridFactoryGridBlock.ID, (ServerPlayerEntity) player, pos));
|
||||
return NetworkUtils.attemptModify(worldIn, pos, hit.getFace(), player, () -> API.instance().getGridManager().openGrid(GridBlockGridFactory.ID, (ServerPlayerEntity) player, pos));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -119,18 +119,24 @@ public class ServerConfig {
|
||||
}
|
||||
|
||||
public class Grid {
|
||||
private final ForgeConfigSpec.IntValue usage;
|
||||
private final ForgeConfigSpec.IntValue gridUsage;
|
||||
private final ForgeConfigSpec.IntValue craftingGridUsage;
|
||||
|
||||
public Grid() {
|
||||
builder.push("grid");
|
||||
|
||||
usage = builder.comment("The energy used by Grids").defineInRange("usage", 2, 0, Integer.MAX_VALUE);
|
||||
gridUsage = builder.comment("The energy used by Grids").defineInRange("gridUsage", 2, 0, Integer.MAX_VALUE);
|
||||
craftingGridUsage = builder.comment("The energy used by Crafting Grids").defineInRange("craftingGridUsage", 4, 0, Integer.MAX_VALUE);
|
||||
|
||||
builder.pop();
|
||||
}
|
||||
|
||||
public int getUsage() {
|
||||
return usage.get();
|
||||
public int getGridUsage() {
|
||||
return gridUsage.get();
|
||||
}
|
||||
|
||||
public int getCraftingGridUsage() {
|
||||
return craftingGridUsage.get();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.raoulvdberge.refinedstorage.container;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RSContainers;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.ICraftingGridListener;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridCraftingListener;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IFluidGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.cache.IStorageCache;
|
||||
@@ -31,9 +31,8 @@ import net.minecraft.network.play.server.SSetSlotPacket;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class GridContainer extends BaseContainer implements IGridCraftingListener {
|
||||
public class GridContainer extends BaseContainer implements ICraftingGridListener {
|
||||
private IGrid grid;
|
||||
private IStorageCache cache;
|
||||
private IStorageCacheListener listener;
|
||||
@@ -56,7 +55,7 @@ public class GridContainer extends BaseContainer implements IGridCraftingListene
|
||||
|
||||
public void initSlots() {
|
||||
this.inventorySlots.clear();
|
||||
// this.inventoryItemStacks.clear(); // TODO at
|
||||
this.inventoryItemStacks.clear();
|
||||
|
||||
this.transferManager.clearTransfers();
|
||||
|
||||
@@ -215,8 +214,8 @@ public class GridContainer extends BaseContainer implements IGridCraftingListene
|
||||
Slot slot = inventorySlots.get(i);
|
||||
|
||||
if (slot instanceof CraftingGridSlot || slot == craftingResultSlot || slot == patternResultSlot) {
|
||||
for (IContainerListener listener : new ArrayList<IContainerListener>()) { // TODO AT for listeners
|
||||
// @Volatile: We can't use IContainerListener#sendSlotContents since ServerPlayerEntity blocks SlotCrafting changes...
|
||||
for (IContainerListener listener : listeners) {
|
||||
// @Volatile: We can't use IContainerListener#sendSlotContents since ServerPlayerEntity blocks CraftingResultSlot changes...
|
||||
if (listener instanceof ServerPlayerEntity) {
|
||||
((ServerPlayerEntity) listener).connection.sendPacket(new SSetSlotPacket(windowId, i, slot.getStack()));
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ public class ResultCraftingGridSlot extends CraftingResultSlot {
|
||||
this.grid = grid;
|
||||
}
|
||||
|
||||
// @Volatile: Overriding logic from the super onTake method for Grid behaviors like refilling stacks from the network
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack onTake(PlayerEntity player, @Nonnull ItemStack stack) {
|
||||
|
||||
@@ -42,17 +42,18 @@ public class FilterUpdateMessage {
|
||||
}
|
||||
|
||||
public static void handle(FilterUpdateMessage message, Supplier<NetworkEvent.Context> ctx) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
PlayerEntity player = ctx.get().getSender();
|
||||
PlayerEntity player = ctx.get().getSender();
|
||||
|
||||
if (player != null && player.openContainer instanceof FilterContainer) {
|
||||
if (player != null && player.openContainer instanceof FilterContainer) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
FilterItem.setCompare(((FilterContainer) player.openContainer).getStack(), message.compare);
|
||||
FilterItem.setMode(((FilterContainer) player.openContainer).getStack(), message.mode);
|
||||
FilterItem.setModFilter(((FilterContainer) player.openContainer).getStack(), message.modFilter);
|
||||
FilterItem.setName(((FilterContainer) player.openContainer).getStack(), message.name);
|
||||
FilterItem.setType(((FilterContainer) player.openContainer).getStack(), message.type);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.raoulvdberge.refinedstorage.network;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridNetworkAware;
|
||||
import com.raoulvdberge.refinedstorage.api.network.security.Permission;
|
||||
import com.raoulvdberge.refinedstorage.api.util.Action;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeGrid;
|
||||
import com.raoulvdberge.refinedstorage.container.GridContainer;
|
||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
|
||||
public class MessageGridClear extends MessageHandlerPlayerToServer<MessageGridClear> implements IMessage {
|
||||
public MessageGridClear() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(MessageGridClear message, ServerPlayerEntity player) {
|
||||
Container container = player.openContainer;
|
||||
|
||||
if (container instanceof ContainerGrid && ((ContainerGrid) container).getGrid() instanceof IGridNetworkAware) {
|
||||
IGridNetworkAware grid = (IGridNetworkAware) ((ContainerGrid) container).getGrid();
|
||||
|
||||
if (grid.getGridType() == GridType.CRAFTING && grid.getNetwork() != null && grid.getNetwork().getSecurityManager().hasPermission(Permission.INSERT, player)) {
|
||||
InventoryCrafting matrix = grid.getCraftingMatrix();
|
||||
|
||||
for (int i = 0; i < matrix.getSizeInventory(); ++i) {
|
||||
ItemStack slot = matrix.getStackInSlot(i);
|
||||
|
||||
if (!slot.isEmpty()) {
|
||||
matrix.setInventorySlotContents(i, StackUtils.nullToEmpty(grid.getNetwork().insertItem(slot, slot.getCount(), Action.PERFORM)));
|
||||
|
||||
grid.getNetwork().getItemStorageTracker().changed(player, slot.copy());
|
||||
}
|
||||
}
|
||||
} else if (grid.getGridType() == GridType.PATTERN) {
|
||||
((NetworkNodeGrid) grid).clearMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,7 @@ package com.raoulvdberge.refinedstorage.network;
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.network.disk.StorageDiskSizeRequestMessage;
|
||||
import com.raoulvdberge.refinedstorage.network.disk.StorageDiskSizeResponseMessage;
|
||||
import com.raoulvdberge.refinedstorage.network.grid.GridItemDeltaMessage;
|
||||
import com.raoulvdberge.refinedstorage.network.grid.GridItemInsertHeldMessage;
|
||||
import com.raoulvdberge.refinedstorage.network.grid.GridItemPullMessage;
|
||||
import com.raoulvdberge.refinedstorage.network.grid.GridItemUpdateMessage;
|
||||
import com.raoulvdberge.refinedstorage.network.grid.*;
|
||||
import com.raoulvdberge.refinedstorage.network.tiledata.TileDataParameterMessage;
|
||||
import com.raoulvdberge.refinedstorage.network.tiledata.TileDataParameterUpdateMessage;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
@@ -38,6 +35,7 @@ public class NetworkHandler {
|
||||
handler.registerMessage(id++, GridItemDeltaMessage.class, GridItemDeltaMessage::encode, GridItemDeltaMessage::decode, GridItemDeltaMessage::handle);
|
||||
handler.registerMessage(id++, GridItemPullMessage.class, GridItemPullMessage::encode, GridItemPullMessage::decode, GridItemPullMessage::handle);
|
||||
handler.registerMessage(id++, GridItemInsertHeldMessage.class, GridItemInsertHeldMessage::encode, GridItemInsertHeldMessage::decode, GridItemInsertHeldMessage::handle);
|
||||
handler.registerMessage(id++, GridClearMessage.class, GridClearMessage::encode, GridClearMessage::decode, GridClearMessage::handle);
|
||||
}
|
||||
|
||||
public void sendToServer(Object message) {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.raoulvdberge.refinedstorage.network.grid;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.container.GridContainer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class GridClearMessage {
|
||||
public static GridClearMessage decode(PacketBuffer buf) {
|
||||
return new GridClearMessage();
|
||||
}
|
||||
|
||||
public static void encode(GridClearMessage message, PacketBuffer buf) {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
public static void handle(GridClearMessage message, Supplier<NetworkEvent.Context> ctx) {
|
||||
PlayerEntity player = ctx.get().getSender();
|
||||
|
||||
if (player != null) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
Container container = player.openContainer;
|
||||
|
||||
if (container instanceof GridContainer) {
|
||||
((GridContainer) container).getGrid().onClear(player);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
@@ -27,8 +27,8 @@ public class GridItemInsertHeldMessage {
|
||||
public static void handle(GridItemInsertHeldMessage message, Supplier<NetworkEvent.Context> ctx) {
|
||||
ServerPlayerEntity player = ctx.get().getSender();
|
||||
|
||||
ctx.get().enqueueWork(() -> {
|
||||
if (player != null) {
|
||||
if (player != null) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
Container container = player.openContainer;
|
||||
|
||||
if (container instanceof GridContainer) {
|
||||
@@ -38,8 +38,8 @@ public class GridItemInsertHeldMessage {
|
||||
grid.getItemHandler().onInsertHeldItem(player, message.single);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ public class GridItemPullMessage {
|
||||
public static void handle(GridItemPullMessage message, Supplier<NetworkEvent.Context> ctx) {
|
||||
ServerPlayerEntity player = ctx.get().getSender();
|
||||
|
||||
ctx.get().enqueueWork(() -> {
|
||||
if (player != null) {
|
||||
if (player != null) {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
Container container = player.openContainer;
|
||||
|
||||
if (container instanceof GridContainer) {
|
||||
@@ -42,8 +42,9 @@ public class GridItemPullMessage {
|
||||
grid.getItemHandler().onExtract(player, message.id, message.flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,12 @@ import com.raoulvdberge.refinedstorage.render.FluidRenderer;
|
||||
import com.raoulvdberge.refinedstorage.screen.widget.CheckBoxWidget;
|
||||
import com.raoulvdberge.refinedstorage.screen.widget.sidebutton.SideButton;
|
||||
import com.raoulvdberge.refinedstorage.util.RenderUtils;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
@@ -324,6 +327,12 @@ public abstract class BaseScreen<T extends Container> extends ContainerScreen<T>
|
||||
// NO OP
|
||||
}
|
||||
|
||||
public static boolean isKeyDown(KeyBinding keybinding) {
|
||||
return InputMappings.isKeyDown(Minecraft.getInstance().mainWindow.getHandle(), keybinding.getKey().getKeyCode()) &&
|
||||
keybinding.getKeyConflictContext().isActive() &&
|
||||
keybinding.getKeyModifier().isActive(keybinding.getKeyConflictContext());
|
||||
}
|
||||
|
||||
public abstract void onPostInit(int x, int y);
|
||||
|
||||
public abstract void tick(int x, int y);
|
||||
|
||||
@@ -91,6 +91,8 @@ public class FilterScreen extends BaseScreen<FilterContainer> {
|
||||
public boolean keyPressed(int key, int scanCode, int modifiers) {
|
||||
if (key == GLFW.GLFW_KEY_ESCAPE) {
|
||||
minecraft.player.closeScreen();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (nameField.keyPressed(key, scanCode, modifiers) || nameField.func_212955_f()) {
|
||||
|
||||
@@ -115,7 +115,7 @@ public class GuiCrafterManager extends BaseScreen<CrafterManagerContainer> imple
|
||||
|
||||
if (searchField == null) {
|
||||
searchField = new SearchWidget(font, sx, sy, 88 - 6);
|
||||
searchField.addListener(() -> container.initSlots(null));
|
||||
searchField.func_212954_a(value -> container.initSlots(null));
|
||||
searchField.setMode(crafterManager.getSearchBoxMode());
|
||||
} else {
|
||||
searchField.x = sx;
|
||||
|
||||
@@ -3,13 +3,14 @@ package com.raoulvdberge.refinedstorage.screen.grid;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.RSKeyBindings;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridNetworkAware;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.GridNetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.render.ElementDrawers;
|
||||
import com.raoulvdberge.refinedstorage.container.GridContainer;
|
||||
import com.raoulvdberge.refinedstorage.network.grid.GridClearMessage;
|
||||
import com.raoulvdberge.refinedstorage.network.grid.GridItemInsertHeldMessage;
|
||||
import com.raoulvdberge.refinedstorage.network.grid.GridItemPullMessage;
|
||||
import com.raoulvdberge.refinedstorage.screen.BaseScreen;
|
||||
@@ -40,6 +41,7 @@ import net.minecraft.util.SoundEvents;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraftforge.fml.client.config.GuiCheckBox;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -104,7 +106,7 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
|
||||
|
||||
if (searchField == null) {
|
||||
searchField = new SearchWidget(font, sx, sy, 88 - 6);
|
||||
searchField.addListener(() -> {
|
||||
searchField.func_212954_a(value -> {
|
||||
this.getView().sort(); // Use getter since this view can be replaced.
|
||||
});
|
||||
searchField.setMode(grid.getSearchBoxMode());
|
||||
@@ -171,6 +173,10 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
|
||||
view.sort();
|
||||
}
|
||||
|
||||
if (isKeyDown(RSKeyBindings.CLEAR_GRID_CRAFTING_MATRIX)) {
|
||||
RS.NETWORK_HANDLER.sendToServer(new GridClearMessage());
|
||||
}
|
||||
|
||||
tabs.update();
|
||||
}
|
||||
|
||||
@@ -429,12 +435,16 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
|
||||
if (clickedCreatePattern) {
|
||||
BlockPos gridPos = ((GridNetworkNode) grid).getPos();
|
||||
|
||||
minecraft.getSoundHandler().play(SimpleSound.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
|
||||
|
||||
// @TODO RS.INSTANCE.network.sendToServer(new MessageGridPatternCreate(gridPos.getX(), gridPos.getY(), gridPos.getZ()));
|
||||
|
||||
return true;
|
||||
} else if (grid.isActive()) {
|
||||
if (clickedClear && grid instanceof IGridNetworkAware) {
|
||||
// @TODO RS.INSTANCE.network.sendToServer(new MessageGridClear());
|
||||
if (clickedClear) {
|
||||
RS.NETWORK_HANDLER.sendToServer(new GridClearMessage());
|
||||
|
||||
minecraft.getSoundHandler().play(SimpleSound.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -442,10 +452,10 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
|
||||
ItemStack held = container.getPlayer().inventory.getItemStack();
|
||||
|
||||
if (isOverSlotArea(mouseX - guiLeft, mouseY - guiTop) && !held.isEmpty() && (clickedButton == 0 || clickedButton == 1)) {
|
||||
if (grid.getGridType() == GridType.NORMAL) {
|
||||
RS.NETWORK_HANDLER.sendToServer(new GridItemInsertHeldMessage(clickedButton == 1));
|
||||
} else if (grid.getGridType() == GridType.FLUID) {
|
||||
if (grid.getGridType() == GridType.FLUID) {
|
||||
// @TODO RS.INSTANCE.network.sendToServer(new MessageGridFluidInsertHeld());
|
||||
} else {
|
||||
RS.NETWORK_HANDLER.sendToServer(new GridItemInsertHeldMessage(clickedButton == 1));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -485,12 +495,6 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
|
||||
}
|
||||
}
|
||||
|
||||
if (clickedClear || clickedCreatePattern) {
|
||||
minecraft.getSoundHandler().play(SimpleSound.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.mouseClicked(mouseX, mouseY, clickedButton);
|
||||
}
|
||||
|
||||
@@ -511,8 +515,23 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
|
||||
return this.scrollbar.mouseScrolled(x, y, delta) || super.mouseScrolled(x, y, delta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char p_charTyped_1_, int p_charTyped_2_) {
|
||||
if (searchField.charTyped(p_charTyped_1_, p_charTyped_2_)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.charTyped(p_charTyped_1_, p_charTyped_2_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int key, int scanCode, int modifiers) {
|
||||
if (key == GLFW.GLFW_KEY_ESCAPE) {
|
||||
minecraft.player.closeScreen();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (searchField.keyPressed(key, scanCode, modifiers) || searchField.func_212955_f()) {
|
||||
return true;
|
||||
}
|
||||
@@ -520,16 +539,6 @@ public class GridScreen extends BaseScreen<GridContainer> implements IScreenInfo
|
||||
return super.keyPressed(key, scanCode, modifiers);
|
||||
}
|
||||
|
||||
/* TODO
|
||||
@Override
|
||||
protected void keyTyped(char character, int keyCode) throws IOException {
|
||||
if (keyCode == RSKeyBindings.CLEAR_GRID_CRAFTING_MATRIX.getKeyCode()) {
|
||||
RS.INSTANCE.network.sendToServer(new MessageGridClear());
|
||||
} else {
|
||||
super.keyTyped(character, keyCode);
|
||||
}
|
||||
}*/
|
||||
|
||||
public SearchWidget getSearchField() {
|
||||
return searchField;
|
||||
}
|
||||
|
||||
@@ -2,13 +2,12 @@ package com.raoulvdberge.refinedstorage.screen.widget;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RSKeyBindings;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
import com.raoulvdberge.refinedstorage.screen.BaseScreen;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class SearchWidget extends TextFieldWidget {
|
||||
@@ -17,8 +16,6 @@ public class SearchWidget extends TextFieldWidget {
|
||||
private int mode;
|
||||
private int historyIndex = -1;
|
||||
|
||||
private List<Runnable> listeners = new LinkedList<>();
|
||||
|
||||
public SearchWidget(FontRenderer fontRenderer, int x, int y, int width) {
|
||||
super(fontRenderer, x, y, width, fontRenderer.FONT_HEIGHT, "");
|
||||
|
||||
@@ -33,23 +30,17 @@ public class SearchWidget extends TextFieldWidget {
|
||||
});*/
|
||||
}
|
||||
|
||||
public void addListener(Runnable listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
|
||||
boolean wasFocused = isFocused();
|
||||
|
||||
boolean result = super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
|
||||
boolean flag = mouseX >= this.x && mouseX < this.x + this.width && mouseY >= this.y && mouseY < this.y + this.height;
|
||||
boolean clickedWidget = mouseX >= this.x && mouseX < this.x + this.width && mouseY >= this.y && mouseY < this.y + this.height;
|
||||
|
||||
if (flag && mouseButton == 1) {
|
||||
if (clickedWidget && mouseButton == 1) {
|
||||
setText("");
|
||||
setFocused(true);
|
||||
|
||||
listeners.forEach(Runnable::run);
|
||||
} else if (wasFocused != isFocused()) {
|
||||
saveHistory();
|
||||
}
|
||||
@@ -59,17 +50,15 @@ public class SearchWidget extends TextFieldWidget {
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifier) {
|
||||
@SuppressWarnings("deprecation") boolean canLoseFocus = ObfuscationReflectionHelper.getPrivateValue(TextFieldWidget.class, this, 6);
|
||||
|
||||
boolean result = super.keyPressed(keyCode, scanCode, modifier);
|
||||
|
||||
if (isFocused()) {
|
||||
if (keyCode == GLFW.GLFW_KEY_UP) {
|
||||
updateSearchHistory(-1);
|
||||
updateHistory(-1);
|
||||
|
||||
result = true;
|
||||
} else if (keyCode == GLFW.GLFW_KEY_DOWN) {
|
||||
updateSearchHistory(1);
|
||||
updateHistory(1);
|
||||
|
||||
result = true;
|
||||
} else if (keyCode == GLFW.GLFW_KEY_ENTER || keyCode == GLFW.GLFW_KEY_KP_ENTER) {
|
||||
@@ -83,7 +72,7 @@ public class SearchWidget extends TextFieldWidget {
|
||||
}
|
||||
}
|
||||
|
||||
if (keyCode == RSKeyBindings.FOCUS_SEARCH_BAR.getKey().getKeyCode() && canLoseFocus) {
|
||||
if (BaseScreen.isKeyDown(RSKeyBindings.FOCUS_SEARCH_BAR) && canLoseFocus) {
|
||||
setFocused(!isFocused());
|
||||
|
||||
saveHistory();
|
||||
@@ -91,14 +80,10 @@ public class SearchWidget extends TextFieldWidget {
|
||||
result = true;
|
||||
}
|
||||
|
||||
if (result) {
|
||||
listeners.forEach(Runnable::run);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void updateSearchHistory(int delta) {
|
||||
private void updateHistory(int delta) {
|
||||
if (HISTORY.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@@ -117,15 +102,11 @@ public class SearchWidget extends TextFieldWidget {
|
||||
if (delta == 1) {
|
||||
setText("");
|
||||
|
||||
listeners.forEach(Runnable::run);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
setText(HISTORY.get(historyIndex));
|
||||
|
||||
listeners.forEach(Runnable::run);
|
||||
}
|
||||
|
||||
private void saveHistory() {
|
||||
|
||||
@@ -76,7 +76,7 @@ public class GridTile extends NetworkNodeTile<GridNetworkNode> {
|
||||
private final GridType gridType;
|
||||
|
||||
public GridTile(GridType gridType) {
|
||||
super(RSTiles.GRID);
|
||||
super(gridType == GridType.NORMAL ? RSTiles.GRID : RSTiles.CRAFTING_GRID);
|
||||
|
||||
this.gridType = gridType;
|
||||
|
||||
|
||||
@@ -130,12 +130,12 @@ public class WirelessFluidGrid implements IGridNetworkAware {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCraftingListener(IGridCraftingListener listener) {
|
||||
public void addCraftingListener(ICraftingGridListener listener) {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCraftingListener(IGridCraftingListener listener) {
|
||||
public void removeCraftingListener(ICraftingGridListener listener) {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@@ -278,6 +278,11 @@ public class WirelessFluidGrid implements IGridNetworkAware {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClear(PlayerEntity player) {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCraftedShift(PlayerEntity player) {
|
||||
// NO OP
|
||||
|
||||
@@ -131,12 +131,12 @@ public class WirelessGrid implements IGridNetworkAware {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCraftingListener(IGridCraftingListener listener) {
|
||||
public void addCraftingListener(ICraftingGridListener listener) {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCraftingListener(IGridCraftingListener listener) {
|
||||
public void removeCraftingListener(ICraftingGridListener listener) {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@@ -283,6 +283,11 @@ public class WirelessGrid implements IGridNetworkAware {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClear(PlayerEntity player) {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCraftedShift(PlayerEntity player) {
|
||||
// NO OP
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.raoulvdberge.refinedstorage.tile.grid.portable;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.ICraftingGridListener;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridCraftingListener;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridTab;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IFluidGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
||||
@@ -16,8 +16,8 @@ import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskContainerCon
|
||||
import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskProvider;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IFilter;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.handler.FluidGridHandlerPortable;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.handler.ItemGridHandlerPortable;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.handler.PortableFluidGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.handler.PortableItemGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive.DiskDriveNetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.cache.PortableFluidStorageCache;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.cache.PortableItemStorageCache;
|
||||
@@ -61,8 +61,8 @@ public class PortableGrid implements IGrid, IPortableGrid, IStorageDiskContainer
|
||||
@Nullable
|
||||
private IStorageCache cache;
|
||||
|
||||
private ItemGridHandlerPortable itemHandler = new ItemGridHandlerPortable(this, this);
|
||||
private FluidGridHandlerPortable fluidHandler = new FluidGridHandlerPortable(this);
|
||||
private PortableItemGridHandler itemHandler = new PortableItemGridHandler(this, this);
|
||||
private PortableFluidGridHandler fluidHandler = new PortableFluidGridHandler(this);
|
||||
|
||||
private PlayerEntity player;
|
||||
private ItemStack stack;
|
||||
@@ -240,12 +240,12 @@ public class PortableGrid implements IGrid, IPortableGrid, IStorageDiskContainer
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCraftingListener(IGridCraftingListener listener) {
|
||||
public void addCraftingListener(ICraftingGridListener listener) {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCraftingListener(IGridCraftingListener listener) {
|
||||
public void removeCraftingListener(ICraftingGridListener listener) {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@@ -398,6 +398,11 @@ public class PortableGrid implements IGrid, IPortableGrid, IStorageDiskContainer
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClear(PlayerEntity player) {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCraftedShift(PlayerEntity player) {
|
||||
// NO OP
|
||||
|
||||
@@ -4,8 +4,8 @@ import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.RSBlocks;
|
||||
import com.raoulvdberge.refinedstorage.RSTiles;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.ICraftingGridListener;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridCraftingListener;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGridTab;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IFluidGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
||||
@@ -19,8 +19,8 @@ import com.raoulvdberge.refinedstorage.api.storage.disk.IStorageDiskProvider;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.tracker.IStorageTracker;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IFilter;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.handler.FluidGridHandlerPortable;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.handler.ItemGridHandlerPortable;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.handler.PortableFluidGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.grid.handler.PortableItemGridHandler;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.GridNetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.diskdrive.DiskDriveNetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.cache.PortableFluidStorageCache;
|
||||
@@ -155,8 +155,8 @@ public class TilePortableGrid extends BaseTile implements IGrid, IPortableGrid,
|
||||
@Nullable
|
||||
private IStorageCache cache;
|
||||
|
||||
private ItemGridHandlerPortable itemHandler = new ItemGridHandlerPortable(this, this);
|
||||
private FluidGridHandlerPortable fluidHandler = new FluidGridHandlerPortable(this);
|
||||
private PortableItemGridHandler itemHandler = new PortableItemGridHandler(this, this);
|
||||
private PortableFluidGridHandler fluidHandler = new PortableFluidGridHandler(this);
|
||||
private PortableGridDiskState diskState = PortableGridDiskState.NONE;
|
||||
private boolean connected;
|
||||
|
||||
@@ -344,12 +344,12 @@ public class TilePortableGrid extends BaseTile implements IGrid, IPortableGrid,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCraftingListener(IGridCraftingListener listener) {
|
||||
public void addCraftingListener(ICraftingGridListener listener) {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCraftingListener(IGridCraftingListener listener) {
|
||||
public void removeCraftingListener(ICraftingGridListener listener) {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@@ -504,6 +504,11 @@ public class TilePortableGrid extends BaseTile implements IGrid, IPortableGrid,
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClear(PlayerEntity player) {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCraftedShift(PlayerEntity player) {
|
||||
// NO OP
|
||||
|
||||
3
src/main/resources/META-INF/accesstransformer.cfg
Normal file
3
src/main/resources/META-INF/accesstransformer.cfg
Normal file
@@ -0,0 +1,3 @@
|
||||
protected net.minecraft.inventory.container.Container field_75153_a # inventoryItemStacks
|
||||
protected net.minecraft.inventory.container.Container field_75149_d # listeners
|
||||
protected net.minecraft.client.gui.widget.TextFieldWidget field_146212_n # canLoseFocus
|
||||
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"variants": {
|
||||
"connected=true,direction=north": {
|
||||
"model": "refinedstorage:block/grid/crafting/connected",
|
||||
"y": 0
|
||||
},
|
||||
"connected=true,direction=east": {
|
||||
"model": "refinedstorage:block/grid/crafting/connected",
|
||||
"y": 90
|
||||
},
|
||||
"connected=true,direction=south": {
|
||||
"model": "refinedstorage:block/grid/crafting/connected",
|
||||
"y": 180
|
||||
},
|
||||
"connected=true,direction=west": {
|
||||
"model": "refinedstorage:block/grid/crafting/connected",
|
||||
"y": 270
|
||||
},
|
||||
"connected=false,direction=north": {
|
||||
"model": "refinedstorage:block/grid/crafting/disconnected",
|
||||
"y": 0
|
||||
},
|
||||
"connected=false,direction=east": {
|
||||
"model": "refinedstorage:block/grid/crafting/disconnected",
|
||||
"y": 90
|
||||
},
|
||||
"connected=false,direction=south": {
|
||||
"model": "refinedstorage:block/grid/crafting/disconnected",
|
||||
"y": 180
|
||||
},
|
||||
"connected=false,direction=west": {
|
||||
"model": "refinedstorage:block/grid/crafting/disconnected",
|
||||
"y": 270
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"parent": "refinedstorage:block/cube_north_cutout",
|
||||
"textures": {
|
||||
"particle": "refinedstorage:block/side",
|
||||
"east": "refinedstorage:block/grid/left",
|
||||
"south": "refinedstorage:block/grid/back",
|
||||
"west": "refinedstorage:block/grid/right",
|
||||
"up": "refinedstorage:block/grid/top",
|
||||
"down": "refinedstorage:block/bottom",
|
||||
"north": "refinedstorage:block/grid/front",
|
||||
"cutout": "refinedstorage:block/grid/cutouts/crafting_front_connected"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"parent": "refinedstorage:block/cube_north_cutout",
|
||||
"textures": {
|
||||
"particle": "refinedstorage:block/side",
|
||||
"east": "refinedstorage:block/grid/left",
|
||||
"south": "refinedstorage:block/grid/back",
|
||||
"west": "refinedstorage:block/grid/right",
|
||||
"up": "refinedstorage:block/grid/top",
|
||||
"down": "refinedstorage:block/bottom",
|
||||
"north": "refinedstorage:block/grid/front",
|
||||
"cutout": "refinedstorage:block/grid/cutouts/crafting_front_disconnected"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"parent": "refinedstorage:block/grid/crafting/disconnected"
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
{
|
||||
"type": "forge:ore_shapeless",
|
||||
"ingredients": [
|
||||
{
|
||||
"item": "refinedstorage:grid",
|
||||
"data": 0
|
||||
},
|
||||
{
|
||||
"item": "#advanced_processor"
|
||||
},
|
||||
{
|
||||
"type": "forge:ore_dict",
|
||||
"ore": "workbench"
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"item": "refinedstorage:grid",
|
||||
"data": 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{
|
||||
"type": "minecraft:item",
|
||||
"name": "refinedstorage:crafting_grid"
|
||||
}
|
||||
],
|
||||
"conditions": [
|
||||
{
|
||||
"condition": "minecraft:survives_explosion"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{
|
||||
"type": "minecraft:item",
|
||||
"name": "refinedstorage:grid"
|
||||
}
|
||||
],
|
||||
"conditions": [
|
||||
{
|
||||
"condition": "minecraft:survives_explosion"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"type": "minecraft:crafting_shapeless",
|
||||
"ingredients": [
|
||||
{
|
||||
"item": "refinedstorage:grid"
|
||||
},
|
||||
{
|
||||
"item": "refinedstorage:advanced_processor"
|
||||
},
|
||||
{
|
||||
"tag": "refinedstorage:crafting_tables"
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"item": "refinedstorage:crafting_grid"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user