Skip to content

Commit

Permalink
Merge pull request #524 from jaquadro/capabilities2
Browse files Browse the repository at this point in the history
Capabilities2
  • Loading branch information
jaquadro authored Jul 6, 2017
2 parents 450ab80 + ad8aa3a commit 54b7934
Show file tree
Hide file tree
Showing 78 changed files with 3,522 additions and 2,957 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx3G

minecraft_base_version=1.12
minecraft_version=1.12
mod_version=5.1.3
mod_version=5.2.0
chameleon_version=4.0.1
chameleon_max_version=5.0.0

Expand Down
2 changes: 2 additions & 0 deletions resources/assets/storagedrawers/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ item.storagedrawers.upgradeStatus.level2.name=Status Upgrade (II)
item.storagedrawers.upgradeStatus.level2.description=Shows fill level
item.storagedrawers.upgradeVoid.name=Void Upgrade
item.storagedrawers.upgradeVoid.description=Destroys excess items
item.storagedrawers.upgradeConversion.name=Conversion Upgrade
item.storagedrawers.upgradeConversion.description=Auto-converts compatible items
item.storagedrawers.upgradeCreative.store.name=Creative Storage Upgrade
item.storagedrawers.upgradeCreative.store.description=Near-infinite storage
item.storagedrawers.upgradeCreative.vend.name=Creative Vending Upgrade
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "storagedrawers:items/upgrade_conversion"
}
}
18 changes: 18 additions & 0 deletions resources/assets/storagedrawers/recipes/upgrade_conversion.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"conditions": [{
"type": "minecraft:item_exists",
"item": "storagedrawers:upgrade_conversion"
}],
"type": "minecraft:crafting_shaped",
"pattern": [
"#/#",
"/X/",
"#/#"
],
"key": {
"/": { "ore": "stickWood", "type": "forge:ore_dict" },
"#": { "item": "minecraft:dye", "data": 4 },
"X": { "item": "storagedrawers:upgrade_template" }
},
"result": { "item": "storagedrawers:upgrade_conversion" }
}
Binary file modified resources/assets/storagedrawers/textures/gui/drawers_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/assets/storagedrawers/textures/gui/drawers_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/assets/storagedrawers/textures/gui/drawers_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/assets/storagedrawers/textures/gui/drawers_comp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/com/jaquadro/minecraft/storagedrawers/StorageDrawers.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.jaquadro.minecraft.storagedrawers;

import com.jaquadro.minecraft.storagedrawers.capabilities.CapabilityDrawerGroup;
import com.jaquadro.minecraft.storagedrawers.capabilities.CapabilityItemRepository;
import com.jaquadro.minecraft.storagedrawers.config.*;
import com.jaquadro.minecraft.storagedrawers.core.*;
import com.jaquadro.minecraft.storagedrawers.capabilities.CapabilityDrawerAttributes;
import com.jaquadro.minecraft.storagedrawers.core.handlers.GuiHandler;
import com.jaquadro.minecraft.storagedrawers.integration.LocalIntegrationRegistry;
import com.jaquadro.minecraft.storagedrawers.network.BoolConfigUpdateMessage;
Expand All @@ -21,6 +24,7 @@
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.relauncher.Side;
import org.apache.logging.log4j.Logger;

import java.io.File;

Expand All @@ -37,6 +41,7 @@ public class StorageDrawers

public static final Api api = new Api();

public static Logger log;
public static SimpleNetworkWrapper network;
public static ConfigManager config;
public static CompTierRegistry compRegistry;
Expand All @@ -54,8 +59,13 @@ public class StorageDrawers

@Mod.EventHandler
public void preInit (FMLPreInitializationEvent event) {
log = event.getModLog();
config = new ConfigManager(new File(event.getModConfigurationDirectory(), MOD_ID + ".cfg"));

CapabilityDrawerGroup.register();
CapabilityItemRepository.register();
CapabilityDrawerAttributes.register();

network = NetworkRegistry.INSTANCE.newSimpleChannel(MOD_ID);
network.registerMessage(BoolConfigUpdateMessage.Handler.class, BoolConfigUpdateMessage.class, 0, Side.SERVER);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class StorageDrawersApi
{
private static IStorageDrawersApi instance;

public static final String VERSION = "1.10.2-1.3.0";
public static final String VERSION = "2.0.0";

/**
* API entry point.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.jaquadro.minecraft.storagedrawers.api.capabilities;

import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;

import javax.annotation.Nonnull;

public interface IItemRepository
{
/**
* Gets a list of all items in the inventory. The same item may appear multiple times with varying counts.
*
* @return A list of zero or more items in the inventory.
*/
@Nonnull
NonNullList<ItemRecord> getAllItems ();

/**
* Inserts an ItemStack into the inventory and returns the remainder.
*
* @param stack ItemStack to insert.
* @param simulate If true, the insertion is only simulated
* @return The remaining ItemStack that was not inserted. If the entire stack was accepted, returns
* ItemStack.EMPTY instead.
*/
@Nonnull
ItemStack insertItem (@Nonnull ItemStack stack, boolean simulate);

/**
* Tries to extract the given ItemStack from the inventory. The returned value will be a matching ItemStack
* with a stack size equal to or less than amount, or the empty ItemStack if the item could not be found at all.
* The returned stack size may exceed the itemstack's getMaxStackSize() value.
*
* @param stack The item to extract. The stack size is ignored.
* @param amount Amount to extract (may be greater than the stacks max limit)
* @param simulate If true, the extraction is only simulated
* @return ItemStack extracted from the inventory, or ItemStack.EMPTY if nothing could be extracted.
*/
@Nonnull
ItemStack extractItem (@Nonnull ItemStack stack, int amount, boolean simulate);

/**
* An item record representing an item and the amount stored.
*
* The ItemStack held by itemPrototype always reports a stack size of 1.
* IT IS IMPORTANT THAT YOU NEVER MODIFY itemPrototype.
*/
class ItemRecord
{
@Nonnull
public final ItemStack itemPrototype;
public final int count;

public ItemRecord (@Nonnull ItemStack itemPrototype, int count) {
this.itemPrototype = itemPrototype;
this.count = count;
}
}
}
84 changes: 84 additions & 0 deletions src/com/jaquadro/minecraft/storagedrawers/api/storage/Drawers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.jaquadro.minecraft.storagedrawers.api.storage;

import net.minecraft.item.ItemStack;

import javax.annotation.Nonnull;

public class Drawers
{
public static final IDrawer DISABLED = new DisabledDrawer();
public static final IFractionalDrawer DISABLED_FRACTIONAL = new DisabledFractionalDrawer();

private static class DisabledDrawer implements IDrawer
{
@Nonnull
@Override
public ItemStack getStoredItemPrototype () {
return ItemStack.EMPTY;
}

@Nonnull
@Override
public IDrawer setStoredItem (@Nonnull ItemStack itemPrototype) {
return this;
}

@Override
public int getStoredItemCount () {
return 0;
}

@Override
public void setStoredItemCount (int amount) {

}

@Override
public int getMaxCapacity (@Nonnull ItemStack itemPrototype) {
return 0;
}

@Override
public int getRemainingCapacity () {
return 0;
}

@Override
public boolean canItemBeStored (@Nonnull ItemStack itemPrototype) {
return false;
}

@Override
public boolean canItemBeExtracted (@Nonnull ItemStack itemPrototype) {
return false;
}

@Override
public boolean isEmpty () {
return true;
}

@Override
public boolean isEnabled () {
return false;
}
}

private static class DisabledFractionalDrawer extends DisabledDrawer implements IFractionalDrawer
{
@Override
public int getConversionRate () {
return 0;
}

@Override
public int getStoredItemRemainder () {
return 0;
}

@Override
public boolean isSmallestUnit () {
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.jaquadro.minecraft.storagedrawers.api.storage;

public class EmptyDrawerAttributes implements IDrawerAttributes
{
public EmptyDrawerAttributes () { }
}
97 changes: 62 additions & 35 deletions src/com/jaquadro/minecraft/storagedrawers/api/storage/IDrawer.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.jaquadro.minecraft.storagedrawers.api.storage;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

import javax.annotation.Nonnull;

Expand All @@ -14,14 +13,28 @@ public interface IDrawer
@Nonnull
ItemStack getStoredItemPrototype ();

/**
* Sets the type of the stored item and initializes it to 0. Any existing item will be replaced.
*
* @param itemPrototype An ItemStack representing the type, metadata, and tags of the item to store.
* @return The IDrawer actually set with the prototype. Some drawer groups can redirect a set operation to another member.
*/
@Nonnull
IDrawer setStoredItem (@Nonnull ItemStack itemPrototype);

/**
* Sets the type of the stored item and initializes it to the given amount. Any existing item will be replaced.
*
* @param itemPrototype An ItemStack representing the type, metadata, and tags of the item to store.
* @param amount The amount to initialize the stored item count to.
* @param amount The amount of items stored in this drawer.
* @return The IDrawer actually set with the prototype. Some drawer groups can redirect a set operation to another member.
*/
IDrawer setStoredItem (@Nonnull ItemStack itemPrototype, int amount);
@Nonnull
default IDrawer setStoredItem (@Nonnull ItemStack itemPrototype, int amount) {
IDrawer drawer = setStoredItem(itemPrototype);
drawer.setStoredItemCount(amount);
return drawer;
}

/**
* Gets the number of items stored in this drawer.
Expand All @@ -36,34 +49,68 @@ public interface IDrawer
*/
void setStoredItemCount (int amount);

/**
* Adds or removes a given amount from the number of items stored in this drawer.
*
* @param amount The amount to add (positive) or subtract (negative).
* @return 0 if the full adjustment was committed, or a positive value representing the remainder if the full
* amount couldn't be added or subtracted.
*/
default int adjustStoredItemCount (int amount) {
if (amount > 0) {
int insert = Math.min(amount, getRemainingCapacity());
setStoredItemCount(getStoredItemCount() + insert);
return amount - insert;
} else if (amount < 0) {
int stored = getStoredItemCount();
int destroy = Math.min(Math.abs(amount), getStoredItemCount());
setStoredItemCount(stored - destroy);
return amount + destroy;
} else {
return 0;
}
}

/**
* Gets the maximum number of items that can be stored in this drawer.
* This value will vary depending on the max stack size of the stored item type.
*/
int getMaxCapacity ();
default int getMaxCapacity () {
return getMaxCapacity(getStoredItemPrototype());
}

/**
* Gets the maximum number of items that could be stored in this drawer if it held the given item.
*
* @param itemPrototype The item type to query.
* @param itemPrototype The item type to query. Pass the empty stack to get the max capacity for an empty slot.
*/
int getMaxCapacity (@Nonnull ItemStack itemPrototype);

/**
* Gets the maxmimum number of items that could be stored in this drawer for a standard item stack size
* of 64.
* Gets the number of items that could still be added to this drawer before it is full.
*/
int getDefaultMaxCapacity ();
int getRemainingCapacity ();

/**
* Gets the number of items that could still be added to this drawer before it is full.
* Gets the number of additional items that would be accepted by this drawer.
*
* Because a drawer may be able to handle items in excess of its full capacity, this value may be larger than
* the result of getRemainingCapacity().
*/
int getRemainingCapacity ();
default int getAcceptingRemainingCapacity () {
return getRemainingCapacity();
}

/**
* Gets the max stack size of the item type stored in this drawer. Convenience method.
* Gets the max stack size of the item type stored in this drawer.
*/
int getStoredItemStackSize ();
default int getStoredItemStackSize () {
@Nonnull ItemStack protoStack = getStoredItemPrototype();
if (protoStack.isEmpty())
return 0;

return protoStack.getItem().getItemStackLimit(protoStack);
}

/**
* Gets whether or not an item of the given type and data can be stored in this drawer.
Expand Down Expand Up @@ -93,27 +140,7 @@ public interface IDrawer
*/
boolean isEmpty ();

/**
* Gets auxiliary data that has been associated with this drawer.
*
* @param key The key used to identify the data.
* @return An opaque object that was previously stored.
*/
Object getExtendedData (String key);

/**
* Stores auxiliary data with this drawer, mainly for use in integration.
* @param key The key to identify the data with.
* @param data The data to store.
*/
void setExtendedData (String key, Object data);

/**
* Called when a component attribute of a drawer (such as lock or void) changes state.
*/
void attributeChanged ();

void writeToNBT (NBTTagCompound tag);

void readFromNBT (NBTTagCompound tag);
default boolean isEnabled () {
return true;
}
}
Loading

0 comments on commit 54b7934

Please sign in to comment.