Merge pull request #3 from raoulvdberge/mc1.10

Update to master
This commit is contained in:
Mikael Rozee
2016-08-20 12:34:03 +01:00
committed by GitHub
316 changed files with 10105 additions and 3995 deletions

21
.github/ISSUE_TEMPLATE.md vendored Executable file
View File

@@ -0,0 +1,21 @@
#### Issue description:
#### What happens:
#### What you expected to happen:
#### Steps to reproduce:
1.
2.
3.
...
#### Version (Make sure you are on the latest version before reporting):
- Minecraft: 1.10.2
- Forge:
- Refined Storage:
#### If a (crash)log is relevant for this issue, link it here:
[pastebin/gist/etc link here]

1
.gitignore vendored
View File

@@ -13,3 +13,4 @@ run/
*.iws
.idea/
out/
translation-diff.diff

View File

@@ -1,13 +1,101 @@
# Refined Storage Changelog
### 0.9
**Bugfixes**
- Fixed crash with Grid
- Fixed Grid Filter only updating the Grid when reopening the GUI
- Priority field and detector amount field can now display 4 digits at a time
**Features**
- Added fluid storage
- Energy usage of Wireless Grid is now configurable
### 0.8.20
**Bugfixes**
- Fixed crash with Grid
### 0.8.19
**Bugfixes**
- Fixed item duplication bug with External Storage
- Fixed External Storage taking too long to update storage
- Fixed crash with Grid
- Fixed crash when shift clicking unsupported item in a slot
### 0.8.18
**Bugfixes**
- Fixed Detector mode not persisting
- Fixed bug where scrollbar didn't scroll correctly and thus hiding some items
- Fixed Network Transmitter not dropping inventory when broken
### 0.8.17
**Bugfixes**
- Fixed Grid causing sorting lag on the client
### 0.8.16
**Bugfixes**
- Fixed issue with IC2 integration causing console spam
- Slight performance increase and network efficiency improvement in all GUI's
- Slight performance increase in Grid GUI
- Fixed not being able to change some configs in blocks
- Fixed serverside configs not syncing up with clientside
- Fixed not being able to move inventory items in Grid GUI's to hotbar via the number keys
- Fixed Relays when being in "Ignore Redstone" mode using up energy
- Fixed Crafter facing bottom side on placement
- Improved collisions of Cable parts
- You now have to click the actual cable part head in order to get the GUI open
**Features**
- Added German translation by ChillUpX
- Grid Filters can now only filter 9 items, but, Grids take 4 filters now instead
- Grid Filters can now be configured to compare on NBT and/ or damage
- It is now possible to shift click items to the Storage Device filters
- Updated to Forge 2046
- Updated Tesla
- Java 8 is now a requirement
- Added MCMultiPart integration for Cable Parts
### 0.8.15
**Bugfixes**
- Fixed server startup crash
### 0.8.14
**Features**
- Added Interdimensional Upgrade so the Network Transmitter can work over different dimensions
### 0.8.13
**Bugfixes**
- Fixed rendering crash with Disk Drive
- Fixed crash when quickly toggling sorting direction in Grid
- Fixed not being able to clear exporter row in interface
**Features**
- Added config option to set the base energy usage of the Controller (default is 0)
- Added Grid Filter item to filter items in any Grid
- Added support for processing patterns with big stacksizes
- Added Network Transmitter, Network Receiver and Network Cards
- The slot where the Wireless Grid is in in the Wireless Grid GUI is now disabled, so the item can't be thrown out of the inventory by accident
- Changed Relay recipe to use redstone torch instead of Basic Processor
- Placed machines now face the block they are placed on, like hoppers
**NOTE:** Config change: the config options for the energy capacity of the Controller and wether the Controller uses energy are now in a different config category called "controller", if you changed these config options, don't forget the change it under the new category.
### 0.8.12
**Bugfixes**
- Fixed dupe bug when shift clicking output slot in grid
### 0.8.11
**Bugfixes**
- Fixed minor dupe bug with JEI transferring
- Fixed exporter crafting upgrades taking priority over other tasks
- Solderer upgrades go to upgrades slots first now when shift clicking
- Fixed NPE with incorrectly initialized disks
- Fixed not being able to take out items of Grid 2K16
- Fixed not being able to start autocrafting for certain items (most notably IC2 items)
**Features**
- Added X button to Processing Pattern Encoder to clear configuration of inputs and outputs
- Added Grid view toggle buttons (regular, craftable items only, no craftable items)
- Added ability to shift click items into Importer, Exporter, Constructor, Destructor and Detector to set up whitelist / blacklist configurations easier
- Re-added opposite facing on shift click functionality
- Updated to Forge 2014

View File

@@ -10,3 +10,4 @@
## Translations
- ChaoticTabris (Portuguese (Brazilian) translation)
- Leventovitch (French translation)
- ChillUpX (German translation)

View File

@@ -12,12 +12,15 @@ buildscript {
}
apply plugin: 'net.minecraftforge.gradle.forge'
version = "0.8.11"
version = "0.9"
group = "refinedstorage"
archivesBaseName = "refinedstorage"
sourceCompatibility = 1.8
targetCompatibility = 1.8
minecraft {
version = "1.10.2-12.18.1.2014"
version = "1.10.2-12.18.1.2065"
runDir = "run"
useDepAts = true
mappings = "snapshot_20160518"
@@ -34,12 +37,16 @@ repositories {
name = "ic2"
url = "http://maven.ic2.player.to/"
}
maven {
url "http://maven.amadornes.com/"
}
}
dependencies {
deobfCompile "mezz.jei:jei_1.10.2:3.7.+"
compile "net.darkhax.tesla:Tesla:1.10-1.2.0.34"
compile "net.industrial-craft:industrialcraft-2:2.6.9-ex110:api"
deobfCompile "mezz.jei:jei_1.10.2:3.9.+"
compile "net.darkhax.tesla:Tesla:1.10-1.2.+"
compile "net.industrial-craft:industrialcraft-2:2.6.41-ex110:api"
deobfCompile "MCMultiPart:MCMultiPart:1.2.1+:universal"
}
processResources {

BIN
screenshots/wireless_networks.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 233 KiB

View File

@@ -4,7 +4,7 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
@@ -14,16 +14,13 @@ import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import refinedstorage.apiimpl.storage.ClientStack;
import refinedstorage.proxy.CommonProxy;
import java.util.ArrayList;
import java.util.List;
@Mod(modid = RefinedStorage.ID, version = RefinedStorage.VERSION)
@Mod(modid = RefinedStorage.ID, version = RefinedStorage.VERSION, dependencies = RefinedStorage.DEPENDENCIES)
public final class RefinedStorage {
public static final String ID = "refinedstorage";
public static final String VERSION = "0.8.11";
public static final String VERSION = "0.9";
public static final String DEPENDENCIES = "required-after:mcmultipart@[1.2.1,);";
@SidedProxy(clientSide = "refinedstorage.proxy.ClientProxy", serverSide = "refinedstorage.proxy.ServerProxy")
public static CommonProxy PROXY;
@@ -45,8 +42,11 @@ public final class RefinedStorage {
}
};
public List<ClientStack> items = new ArrayList<ClientStack>();
static {
FluidRegistry.enableUniversalBucket();
}
public int controllerBaseUsage;
public int cableUsage;
public int constructorUsage;
public int crafterUsage;
@@ -61,24 +61,38 @@ public final class RefinedStorage {
public int exporterUsage;
public int importerUsage;
public int interfaceUsage;
public int fluidInterfaceUsage;
public int relayUsage;
public int soldererUsage;
public int storageUsage;
public int fluidStorageUsage;
public int wirelessTransmitterUsage;
public int gridUsage;
public int craftingGridUsage;
public int patternGridUsage;
public int fluidGridUsage;
public int networkTransmitterUsage;
public float networkTransmitterPerBlockUsage;
public int networkReceiverUsage;
public int controller;
public int controllerCapacity;
public boolean controllerUsesEnergy;
public int wirelessTransmitterBaseRange;
public int wirelessTransmitterRangePerUpgrade;
public boolean wirelessGridUsesEnergy;
public int wirelessGridOpenUsage;
public int wirelessGridExtractUsage;
public int wirelessGridInsertUsage;
public int rangeUpgradeUsage;
public int speedUpgradeUsage;
public int craftingUpgradeUsage;
public int stackUpgradeUsage;
public int wirelessTransmitterRangePerUpgrade;
public int interdimensionalUpgradeUsage;
public boolean translucentCables;
@EventHandler
public void preInit(FMLPreInitializationEvent e) {
@@ -86,6 +100,7 @@ public final class RefinedStorage {
Configuration config = new Configuration(e.getSuggestedConfigurationFile());
controllerBaseUsage = config.getInt("controllerBase", "energy", 0, 0, Integer.MAX_VALUE, "The base energy used by the Controller");
cableUsage = config.getInt("cable", "energy", 0, 0, Integer.MAX_VALUE, "The energy used by Cables");
constructorUsage = config.getInt("constructor", "energy", 1, 0, Integer.MAX_VALUE, "The energy used by Constructors");
crafterUsage = config.getInt("crafter", "energy", 2, 0, Integer.MAX_VALUE, "The base energy used by Crafters");
@@ -100,24 +115,38 @@ public final class RefinedStorage {
exporterUsage = config.getInt("exporter", "energy", 1, 0, Integer.MAX_VALUE, "The energy used by Exporters");
importerUsage = config.getInt("importer", "energy", 1, 0, Integer.MAX_VALUE, "The energy used by Importers");
interfaceUsage = config.getInt("interface", "energy", 3, 0, Integer.MAX_VALUE, "The energy used by Interfaces");
fluidInterfaceUsage = config.getInt("fluidInterface", "energy", 3, 0, Integer.MAX_VALUE, "The energy used by Fluid Interfaces");
relayUsage = config.getInt("relay", "energy", 1, 0, Integer.MAX_VALUE, "The energy used by Relays");
soldererUsage = config.getInt("solderer", "energy", 3, 0, Integer.MAX_VALUE, "The energy used by Solderers");
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");
gridUsage = config.getInt("grid", "energy", 2, 0, Integer.MAX_VALUE, "The energy used by Grids");
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", 50, 0, Integer.MAX_VALUE, "The base energy used by Network Transmitters");
networkTransmitterPerBlockUsage = config.getFloat("networkTransmitterPerBlock", "energy", 4, 0, Float.MAX_VALUE, "The additional energy per block that the Network Transmitter uses, gets rounded up");
networkReceiverUsage = config.getInt("networkReceiver", "energy", 15, 0, Integer.MAX_VALUE, "The energy used by Network Receivers");
controller = config.getInt("controller", "energy", 32000, 0, Integer.MAX_VALUE, "The energy capacity of the controller");
controllerUsesEnergy = config.getBoolean("controllerUsesEnergy", "energy", true, "Whether the controller uses RF");
controllerCapacity = config.getInt("capacity", "controller", 32000, 0, Integer.MAX_VALUE, "The energy capacity of the Controller");
controllerUsesEnergy = config.getBoolean("usesEnergy", "controller", true, "Whether the Controller uses energy");
wirelessTransmitterBaseRange = config.getInt("range", "wirelessTransmitter", 16, 0, Integer.MAX_VALUE, "The base range of the Wireless Transmitter");
wirelessTransmitterRangePerUpgrade = config.getInt("rangePerUpgrade", "wirelessTransmitter", 8, 0, Integer.MAX_VALUE, "The additional range per Range Upgrade in the Wireless Transmitter");
wirelessGridUsesEnergy = config.getBoolean("usesEnergy", "wirelessGrid", true, "Whether the Wireless Grid uses energy");
wirelessGridOpenUsage = config.getInt("open", "wirelessGrid", 30, 0, Integer.MAX_VALUE, "The energy used by the Wireless Grid to open");
wirelessGridInsertUsage = config.getInt("insert", "wirelessGrid", 3, 0, Integer.MAX_VALUE, "The energy used by the Wireless Grid to insert items");
wirelessGridExtractUsage = config.getInt("extract", "wirelessGrid", 3, 0, Integer.MAX_VALUE, "The energy used by the Wireless Grid to extract items");
rangeUpgradeUsage = config.getInt("range", "upgrades", 8, 0, Integer.MAX_VALUE, "The additional energy used per Range Upgrade");
speedUpgradeUsage = config.getInt("speed", "upgrades", 2, 0, Integer.MAX_VALUE, "The additional energy used per Speed Upgrade");
craftingUpgradeUsage = config.getInt("crafting", "upgrades", 5, 0, Integer.MAX_VALUE, "The additional energy used per Crafting Upgrade");
stackUpgradeUsage = config.getInt("stack", "upgrades", 12, 0, Integer.MAX_VALUE, "The additional energy used per Stack Upgrade");
interdimensionalUpgradeUsage = config.getInt("interdimensional", "upgrades", 1000, 0, Integer.MAX_VALUE, "The additional energy used by the Interdimensional Upgrade");
translucentCables = config.getBoolean("translucentCables", "misc", false, "For resource pack makers that want a translucent cable");
config.save();
}
@@ -131,16 +160,4 @@ public final class RefinedStorage {
public void postInit(FMLPostInitializationEvent e) {
PROXY.postInit(e);
}
public static boolean hasJei() {
return Loader.isModLoaded("JEI");
}
public static boolean hasIC2() {
return Loader.isModLoaded("IC2");
}
public static boolean hasTesla() {
return Loader.isModLoaded("Tesla");
}
}

View File

@@ -22,4 +22,8 @@ public final class RefinedStorageBlocks {
public static final BlockWirelessTransmitter WIRELESS_TRANSMITTER = new BlockWirelessTransmitter();
public static final BlockCrafter CRAFTER = new BlockCrafter();
public static final BlockProcessingPatternEncoder PROCESSING_PATTERN_ENCODER = new BlockProcessingPatternEncoder();
public static final BlockNetworkTransmitter NETWORK_TRANSMITTER = new BlockNetworkTransmitter();
public static final BlockNetworkReceiver NETWORK_RECEIVER = new BlockNetworkReceiver();
public static final BlockFluidInterface FLUID_INTERFACE = new BlockFluidInterface();
public static final BlockFluidStorage FLUID_STORAGE = new BlockFluidStorage();
}

View File

@@ -18,4 +18,9 @@ public final class RefinedStorageGui {
public static final int WIRELESS_TRANSMITTER = 14;
public static final int CRAFTER = 15;
public static final int PROCESSING_PATTERN_ENCODER = 16;
public static final int GRID_FILTER = 17;
public static final int NETWORK_TRANSMITTER = 18;
public static final int FLUID_INTERFACE = 19;
public static final int EXTERNAL_STORAGE = 20;
public static final int FLUID_STORAGE = 21;
}

View File

@@ -13,4 +13,8 @@ public final class RefinedStorageItems {
public static final ItemPattern PATTERN = new ItemPattern();
public static final ItemUpgrade UPGRADE = new ItemUpgrade();
public static final ItemStorageHousing STORAGE_HOUSING = new ItemStorageHousing();
public static final ItemGridFilter GRID_FILTER = new ItemGridFilter();
public static final ItemNetworkCard NETWORK_CARD = new ItemNetworkCard();
public static final ItemFluidStorageDisk FLUID_STORAGE_DISK = new ItemFluidStorageDisk();
public static final ItemFluidStoragePart FLUID_STORAGE_PART = new ItemFluidStoragePart();
}

View File

@@ -1,348 +0,0 @@
package refinedstorage;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagIntArray;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.InvWrapper;
import net.minecraftforge.items.wrapper.SidedInvWrapper;
import net.minecraftforge.oredict.OreDictionary;
import org.apache.commons.lang3.ArrayUtils;
import refinedstorage.api.autocrafting.ICraftingPattern;
import refinedstorage.api.network.INetworkMaster;
import refinedstorage.api.storage.CompareFlags;
import refinedstorage.item.ItemUpgrade;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public final class RefinedStorageUtils {
private static final String NBT_INVENTORY = "Inventory_%d";
private static final String NBT_SLOT = "Slot";
public static void writeItems(IItemHandler handler, int id, NBTTagCompound nbt) {
NBTTagList tagList = new NBTTagList();
for (int i = 0; i < handler.getSlots(); i++) {
if (handler.getStackInSlot(i) != null) {
NBTTagCompound compoundTag = new NBTTagCompound();
compoundTag.setInteger(NBT_SLOT, i);
handler.getStackInSlot(i).writeToNBT(compoundTag);
tagList.appendTag(compoundTag);
}
}
nbt.setTag(String.format(NBT_INVENTORY, id), tagList);
}
public static void readItems(IItemHandler handler, int id, NBTTagCompound nbt) {
String name = String.format(NBT_INVENTORY, id);
if (nbt.hasKey(name)) {
NBTTagList tagList = nbt.getTagList(name, Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < tagList.tagCount(); i++) {
int slot = tagList.getCompoundTagAt(i).getInteger(NBT_SLOT);
ItemStack stack = ItemStack.loadItemStackFromNBT(tagList.getCompoundTagAt(i));
handler.insertItem(slot, stack, false);
}
}
}
public static void writeItemsLegacy(IInventory inventory, int id, NBTTagCompound nbt) {
NBTTagList tagList = new NBTTagList();
for (int i = 0; i < inventory.getSizeInventory(); i++) {
if (inventory.getStackInSlot(i) != null) {
NBTTagCompound compoundTag = new NBTTagCompound();
compoundTag.setInteger(NBT_SLOT, i);
inventory.getStackInSlot(i).writeToNBT(compoundTag);
tagList.appendTag(compoundTag);
}
}
nbt.setTag(String.format(NBT_INVENTORY, id), tagList);
}
public static void readItemsLegacy(IInventory inventory, int id, NBTTagCompound nbt) {
String name = String.format(NBT_INVENTORY, id);
if (nbt.hasKey(name)) {
NBTTagList tagList = nbt.getTagList(name, Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < tagList.tagCount(); i++) {
int slot = tagList.getCompoundTagAt(i).getInteger(NBT_SLOT);
ItemStack stack = ItemStack.loadItemStackFromNBT(tagList.getCompoundTagAt(i));
inventory.setInventorySlotContents(slot, stack);
}
}
}
public static boolean compareStack(ItemStack left, ItemStack right) {
return compareStack(left, right, CompareFlags.COMPARE_NBT | CompareFlags.COMPARE_DAMAGE | CompareFlags.COMPARE_QUANTITY);
}
public static boolean compareStack(ItemStack left, ItemStack right, int flags) {
if (left == null && right == null) {
return true;
}
if ((left == null && right != null) || (left != null && right == null)) {
return false;
}
if (left.getItem() != right.getItem()) {
return false;
}
if ((flags & CompareFlags.COMPARE_DAMAGE) == CompareFlags.COMPARE_DAMAGE) {
if (left.getItemDamage() != right.getItemDamage()) {
return false;
}
}
if ((flags & CompareFlags.COMPARE_NBT) == CompareFlags.COMPARE_NBT) {
if (!compareNbt(left, right)) {
return false;
}
}
if ((flags & CompareFlags.COMPARE_QUANTITY) == CompareFlags.COMPARE_QUANTITY) {
if (left.stackSize != right.stackSize) {
return false;
}
}
return true;
}
public static boolean compareNbt(ItemStack left, ItemStack right) {
if (!ItemStack.areItemStackTagsEqual(left, right)) {
if (left.hasTagCompound() && !right.hasTagCompound() && left.getTagCompound().hasNoTags()) {
return true;
} else if (!left.hasTagCompound() && right.hasTagCompound() && right.getTagCompound().hasNoTags()) {
return true;
}
return false;
}
return true;
}
public static boolean compareStackNoQuantity(ItemStack left, ItemStack right) {
return compareStack(left, right, CompareFlags.COMPARE_NBT | CompareFlags.COMPARE_DAMAGE);
}
public static boolean compareStackOreDict(ItemStack left, ItemStack right) {
if (left == null && right == null) {
return true;
}
if ((left == null && right != null) || (left != null && right == null)) {
return false;
}
int[] leftIds = OreDictionary.getOreIDs(left);
int[] rightIds = OreDictionary.getOreIDs(right);
for (int i : rightIds) {
if (ArrayUtils.contains(leftIds, i)) {
return true;
}
}
return false;
}
public static int getSpeed(IItemHandler handler) {
return getSpeed(handler, 9, 2);
}
public static int getSpeed(IItemHandler handler, int speed, int speedIncrease) {
for (int i = 0; i < handler.getSlots(); ++i) {
if (handler.getStackInSlot(i) != null && handler.getStackInSlot(i).getMetadata() == ItemUpgrade.TYPE_SPEED) {
speed -= speedIncrease;
}
}
return speed;
}
public static boolean hasUpgrade(IItemHandler handler, int type) {
return getUpgradeCount(handler, type) > 0;
}
public static int getUpgradeCount(IItemHandler handler, int type) {
int upgrades = 0;
for (int i = 0; i < handler.getSlots(); ++i) {
if (handler.getStackInSlot(i) != null && handler.getStackInSlot(i).getMetadata() == type) {
upgrades++;
}
}
return upgrades;
}
public static int getUpgradeEnergyUsage(IItemHandler handler) {
int usage = 0;
for (int i = 0; i < handler.getSlots(); ++i) {
if (handler.getStackInSlot(i) != null) {
usage += ItemUpgrade.getEnergyUsage(handler.getStackInSlot(i).getMetadata());
}
}
return usage;
}
public static void writeBooleanArray(NBTTagCompound tag, String name, boolean[] array) {
int[] intArray = new int[array.length];
for (int i = 0; i < intArray.length; ++i) {
intArray[i] = array[i] ? 1 : 0;
}
tag.setTag(name, new NBTTagIntArray(intArray));
}
public static boolean[] readBooleanArray(NBTTagCompound tag, String name) {
int[] intArray = tag.getIntArray(name);
boolean array[] = new boolean[intArray.length];
for (int i = 0; i < intArray.length; ++i) {
array[i] = intArray[i] == 1 ? true : false;
}
return array;
}
public static EnumHand getHandById(int id) {
switch (id) {
case 0:
return EnumHand.MAIN_HAND;
case 1:
return EnumHand.OFF_HAND;
default:
return EnumHand.MAIN_HAND;
}
}
public static int getIdFromHand(EnumHand hand) {
switch (hand) {
case MAIN_HAND:
return 0;
case OFF_HAND:
return 1;
default:
return 0;
}
}
public static void updateBlock(World world, BlockPos pos) {
world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 1 | 2);
}
public static IItemHandler getItemHandler(TileEntity tile, EnumFacing side) {
if (tile == null) {
return null;
}
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
if (handler == null) {
if (side != null && tile instanceof ISidedInventory) {
handler = new SidedInvWrapper((ISidedInventory) tile, side);
} else if (tile instanceof IInventory) {
handler = new InvWrapper((IInventory) tile);
}
}
return handler;
}
public static int calculateOffsetOnScale(int pos, float scale) {
float multiplier = (pos / scale);
return (int) multiplier;
}
public static void combineMultipleItemsInTooltip(List<String> lines, ItemStack... stacks) {
Set<Integer> combinedIndices = new HashSet<Integer>();
for (int i = 0; i < stacks.length; ++i) {
if (!combinedIndices.contains(i)) {
String data = stacks[i].getDisplayName();
int amount = stacks[i].stackSize;
for (int j = i + 1; j < stacks.length; ++j) {
if (RefinedStorageUtils.compareStack(stacks[i], stacks[j])) {
amount += stacks[j].stackSize;
combinedIndices.add(j);
}
}
if (amount != 1) {
data += " (" + amount + "x)";
}
lines.add(data);
}
}
}
// Keep this on par with the Forestry generators (1 EU is worth 4 RF)
public static int convertIC2ToRF(double amount) {
// IC2 passes infinity sometimes as a simulate test
if (amount >= Double.POSITIVE_INFINITY) {
return Integer.MAX_VALUE;
}
return (int) Math.floor(amount) * 4;
}
public static double convertRFToIC2(int amount) {
return Math.floor(amount / 4);
}
public static ItemStack extractItem(INetworkMaster network, ItemStack stack, int size) {
return network.extractItem(stack, size, CompareFlags.COMPARE_DAMAGE | CompareFlags.COMPARE_NBT);
}
public static ICraftingPattern getPattern(INetworkMaster network, ItemStack stack) {
return network.getPattern(stack, CompareFlags.COMPARE_DAMAGE | CompareFlags.COMPARE_NBT);
}
public static boolean hasPattern(INetworkMaster network, ItemStack stack) {
return RefinedStorageUtils.getPattern(network, stack) != null;
}
public static int getItemStackHashCode(ItemStack stack) {
return stack.getItem().hashCode() * (stack.getItemDamage() + 1) * (stack.hasTagCompound() ? stack.getTagCompound().hashCode() : 1);
}
}

View File

@@ -4,7 +4,7 @@ import refinedstorage.api.solderer.ISoldererRegistry;
public final class RefinedStorageAPI {
/**
* The solderer registry, set in pre-initialization.
* The solderer registry, set in pre-initialization
*/
public static ISoldererRegistry SOLDERER_REGISTRY;
}

View File

@@ -9,7 +9,7 @@ public interface ICraftingPatternContainer {
/**
* This usually corresponds to the amount of speed upgrades in a crafter.
*
* @return The speed of this pattern
* @return The speed of this container
*/
int getSpeed();

View File

@@ -1,10 +0,0 @@
package refinedstorage.api.network;
/**
* Flags for knowing what extract action the player is performing, these can be combined.
*/
public class GridExtractFlags {
public static final int EXTRACT_HALF = 1;
public static final int EXTRACT_SINGLE = 2;
public static final int EXTRACT_SHIFT = 4;
}

View File

@@ -4,10 +4,14 @@ import cofh.api.energy.EnergyStorage;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fluids.FluidStack;
import refinedstorage.api.autocrafting.ICraftingPattern;
import refinedstorage.api.autocrafting.ICraftingTask;
import refinedstorage.api.storage.CompareFlags;
import refinedstorage.api.storage.IGroupedStorage;
import refinedstorage.api.network.grid.IFluidGridHandler;
import refinedstorage.api.network.grid.IItemGridHandler;
import refinedstorage.api.storage.CompareUtils;
import refinedstorage.api.storage.fluid.IGroupedFluidStorage;
import refinedstorage.api.storage.item.IGroupedItemStorage;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -38,14 +42,19 @@ public interface INetworkMaster {
boolean canRun();
/**
* @return A list with all the network nodes
* @return A graph of connected nodes to this network
*/
List<INetworkNode> getNodes();
INetworkNodeGraph getNodeGraph();
/**
* @return The {@link IGridHandler} for this network
* @return The {@link IItemGridHandler} for this network
*/
IGridHandler getGridHandler();
IItemGridHandler getItemGridHandler();
/**
* @return The {@link IFluidGridHandler} for this network
*/
IFluidGridHandler getFluidGridHandler();
/**
* @return The {@link IWirelessGridHandler} for this network
@@ -53,9 +62,14 @@ public interface INetworkMaster {
IWirelessGridHandler getWirelessGridHandler();
/**
* @return The {@link IGroupedStorage} of this network
* @return The {@link IGroupedItemStorage} of this network
*/
IGroupedStorage getStorage();
IGroupedItemStorage getItemStorage();
/**
* @return The {@link IGroupedFluidStorage} of this network
*/
IGroupedFluidStorage getFluidStorage();
/**
* @return The crafting tasks in this network, do NOT modify this list
@@ -101,23 +115,18 @@ public interface INetworkMaster {
*/
void rebuildPatterns();
/**
* Rebuilds the network node list.
*/
void rebuildNodes();
/**
* Returns crafting patterns from an item stack.
*
* @param pattern The {@link ItemStack} to get a pattern for
* @param flags The flags to compare on, see {@link CompareFlags}
* @param flags The flags to compare on, see {@link CompareUtils}
* @return A list of crafting patterns where the given pattern is one of the outputs
*/
List<ICraftingPattern> getPatterns(ItemStack pattern, int flags);
/**
* @param pattern The {@link ItemStack} to get a pattern for
* @param flags The flags to compare on, see {@link CompareFlags}
* @param flags The flags to compare on, see {@link CompareUtils}
* @return The pattern, or null if the pattern is not found
*/
@Nullable
@@ -126,20 +135,38 @@ public interface INetworkMaster {
/**
* Sends a grid packet with all the items to all clients that are watching a grid.
*/
void sendStorageToClient();
void sendItemStorageToClient();
/**
* Sends a grid packet with all the items to a specific player.
*/
void sendStorageToClient(EntityPlayerMP player);
void sendItemStorageToClient(EntityPlayerMP player);
/**
* Sends a storage change to all clients that are watching a grid.
* Sends a item storage change to all clients that are watching a grid.
*
* @param stack The stack
* @param delta The delta
*/
void sendStorageDeltaToClient(ItemStack stack, int delta);
void sendItemStorageDeltaToClient(ItemStack stack, int delta);
/**
* Sends a grid packet with all the fluids to all clients that are watching a grid.
*/
void sendFluidStorageToClient();
/**
* Sends a grid packet with all the fluids to a specific player.
*/
void sendFluidStorageToClient(EntityPlayerMP player);
/**
* Sends a fluids storage change to all clients that are watching a grid.
*
* @param stack The stack
* @param delta The delta
*/
void sendFluidStorageDeltaToClient(FluidStack stack, int delta);
/**
* Inserts an item to this network.
@@ -157,9 +184,31 @@ public interface INetworkMaster {
*
* @param stack The prototype of the stack to extract, do NOT modify
* @param size The amount of that prototype that has to be extracted
* @param flags The flags to compare on, see {@link CompareFlags}
* @param flags The flags to compare on, see {@link CompareUtils}
* @return null if we didn't extract anything, or a {@link ItemStack} with the result
*/
@Nullable
ItemStack extractItem(@Nonnull ItemStack stack, int size, int flags);
/**
* Inserts a fluid to this network.
*
* @param stack The stack prototype to insert, do NOT modify
* @param size The amount of that prototype that has to be inserted
* @param simulate If we are simulating
* @return null if the insert was successful, or an {@link FluidStack} with the remainder
*/
@Nullable
FluidStack insertFluid(@Nonnull FluidStack stack, int size, boolean simulate);
/**
* Extracts a fluid from this network.
*
* @param stack The prototype of the stack to extract, do NOT modify
* @param size The amount of that prototype that has to be extracted
* @param flags The flags to compare on, see {@link CompareUtils}
* @return null if we didn't extract anything, or a {@link FluidStack} with the result
*/
@Nullable
FluidStack extractFluid(@Nonnull FluidStack stack, int size, int flags);
}

View File

@@ -1,6 +1,8 @@
package refinedstorage.api.network;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
* Represents a node in the storage network.
@@ -37,7 +39,7 @@ public interface INetworkNode {
/**
* Called when the connection state of this node changes.
* This is also called when redstone mode is updated, as opposed to {@link INetworkNode#onConnected(INetworkMaster)} and {@link INetworkNode#onDisconnected()}.
* This is also called when redstone mode is updated, as opposed to {@link INetworkNode#onConnected(INetworkMaster)} and {@link INetworkNode#onDisconnected(INetworkMaster)}.
*
* @param network The network
* @param state The state
@@ -50,17 +52,23 @@ public interface INetworkNode {
boolean isConnected();
/**
* @return If {@link INetworkNode#canUpdate()} can get called, typically checks for connection status and redstone mode
* @return If {@link INetworkNode#updateNode()} can get called, typically checks for connection status and redstone mode
*/
boolean canUpdate();
/**
* @param direction The direction to conduct to
* @return Whether this node can conduct a network signal
*/
boolean canConduct();
boolean canConduct(EnumFacing direction);
/**
* @return The network
*/
INetworkMaster getNetwork();
/**
* @return The world where this node is in
*/
World getNodeWorld();
}

View File

@@ -0,0 +1,35 @@
package refinedstorage.api.network;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.List;
import java.util.Set;
/**
* A graph of all the nodes connected to a network.
*/
public interface INetworkNodeGraph {
/**
* Rebuilds the node graph.
*
* @param start The starting position to start looking for nodes
* @param notify Whether to notify nodes of a connection change
*/
void rebuild(BlockPos start, boolean notify);
/**
* @return A list of all connected nodes
*/
List<INetworkNode> all();
/**
* @return A set of hashes of all connected nodes, see {@link NetworkUtils#getNodeHashCode(World, INetworkNode)}
*/
Set<Integer> allHashes();
/**
* Disconnects and notifies all connected nodes.
*/
void disconnectAll();
}

View File

@@ -2,17 +2,11 @@ package refinedstorage.api.network;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
/**
* Represents a player using a wireless grid.
*/
public interface IWirelessGridConsumer {
/**
* @return The hand this wireless grid is opened with
*/
EnumHand getHand();
/**
* @return The player using the wireless grid
*/

View File

@@ -0,0 +1,46 @@
package refinedstorage.api.network;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
import refinedstorage.api.autocrafting.ICraftingPattern;
import refinedstorage.api.storage.CompareUtils;
/**
* Utilities for network manipulation.
*/
public final class NetworkUtils {
public static ItemStack extractItem(INetworkMaster network, ItemStack stack, int size) {
return network.extractItem(stack, size, CompareUtils.COMPARE_DAMAGE | CompareUtils.COMPARE_NBT);
}
public static FluidStack extractFluid(INetworkMaster network, FluidStack stack, int size) {
return network.extractFluid(stack, size, CompareUtils.COMPARE_NBT);
}
public static ICraftingPattern getPattern(INetworkMaster network, ItemStack stack) {
return network.getPattern(stack, CompareUtils.COMPARE_DAMAGE | CompareUtils.COMPARE_NBT);
}
public static boolean hasPattern(INetworkMaster network, ItemStack stack) {
return getPattern(network, stack) != null;
}
public static void rebuildGraph(INetworkMaster network) {
network.getNodeGraph().rebuild(network.getPosition(), true);
}
public static int getItemStackHashCode(ItemStack stack) {
return stack.getItem().hashCode() * (stack.getItemDamage() + 1) * (stack.hasTagCompound() ? stack.getTagCompound().hashCode() : 1);
}
public static int getFluidStackHashCode(FluidStack stack) {
return stack.getFluid().hashCode() * (stack.tag != null ? stack.tag.hashCode() : 1);
}
public static int getNodeHashCode(World world, INetworkNode node) {
int result = node.getPosition().hashCode();
result = 31 * result + world.provider.getDimension();
return result;
}
}

View File

@@ -0,0 +1,36 @@
package refinedstorage.api.network.grid;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import javax.annotation.Nullable;
/**
* Defines the behavior of item grids.
*/
public interface IFluidGridHandler {
/**
* Called when a player tries to extract a fluid from the grid.
*
* @param hash The hash of the fluid we're trying to extract, see {@link refinedstorage.api.network.NetworkUtils#getFluidStackHashCode(net.minecraftforge.fluids.FluidStack)}
* @param shift If we're shift clicking
* @param player The player that is attempting the extraction
*/
void onExtract(int hash, boolean shift, EntityPlayerMP player);
/**
* Called when a player tries to insert fluids to the grid.
*
* @param container A stack with a container we're trying to insert
* @return The remainder, or null if there is no remainder
*/
@Nullable
ItemStack onInsert(ItemStack container);
/**
* Called when a player is trying to insert a fluid that it is holding in their hand in the GUI.
*
* @param player The player that is attempting the insert
*/
void onInsertHeldContainer(EntityPlayerMP player);
}

View File

@@ -1,4 +1,4 @@
package refinedstorage.api.network;
package refinedstorage.api.network.grid;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
@@ -6,42 +6,47 @@ import net.minecraft.item.ItemStack;
import javax.annotation.Nullable;
/**
* Defines the behavior of grids.
* Defines the behavior of item grids.
*/
public interface IGridHandler {
public interface IItemGridHandler {
int EXTRACT_HALF = 1;
int EXTRACT_SINGLE = 2;
int EXTRACT_SHIFT = 4;
/**
* Called when a player tries to extract an item from the grid.
*
* @param id The ID of the item we're trying to extract
* @param flags How we are extracting, see {@link GridExtractFlags}
* @param hash The hash of the item we're trying to extract, see {@link refinedstorage.api.network.NetworkUtils#getItemStackHashCode(ItemStack)}
* @param flags How we are extracting
* @param player The player that is attempting the extraction
*/
void onExtract(int id, int flags, EntityPlayerMP player);
void onExtract(int hash, int flags, EntityPlayerMP player);
/**
* Called when a player tries to insert an item to the grid.
*
* @param stack The item we're trying to insert
* @param player The player that is attempting the insert
* @param stack The item we're trying to insert
* @return The remainder, or null if there is no remainder
*/
@Nullable
ItemStack onInsert(ItemStack stack);
ItemStack onInsert(EntityPlayerMP player, ItemStack stack);
/**
* Called when a player is trying to insert an item that it is holding in their hand in the GUI.
*
* @param single If we are only inserting 1 item
* @param player The player that is attempting the insert
* @param single If we are only inserting 1 item
*/
void onInsertHeldItem(boolean single, EntityPlayerMP player);
void onInsertHeldItem(EntityPlayerMP player, boolean single);
/**
* Called when a player requested crafting for an item.
*
* @param id The ID of the item we're requesting crafting for
* @param hash The hash of the item we're requesting crafting for, see {@link refinedstorage.api.network.NetworkUtils#getItemStackHashCode(ItemStack)}
* @param quantity The amount of that item that has to be crafted
*/
void onCraftingRequested(int id, int quantity);
void onCraftingRequested(int hash, int quantity);
/**
* Called when a player wants to cancel a crafting task.

View File

@@ -1,10 +0,0 @@
package refinedstorage.api.storage;
/**
* Comparison flags.
*/
public final class CompareFlags {
public static final int COMPARE_DAMAGE = 1;
public static final int COMPARE_NBT = 2;
public static final int COMPARE_QUANTITY = 4;
}

View File

@@ -0,0 +1,158 @@
package refinedstorage.api.storage;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
import org.apache.commons.lang3.ArrayUtils;
/**
* Utilities for comparing.
*/
public final class CompareUtils {
public static final int COMPARE_DAMAGE = 1;
public static final int COMPARE_NBT = 2;
public static final int COMPARE_QUANTITY = 4;
/**
* Compares two stacks by NBT, damage and quantity.
*
* @param left The left stack
* @param right The right stack
* @return Whether the left and right stack are equal
*/
public static boolean compareStack(ItemStack left, ItemStack right) {
return compareStack(left, right, COMPARE_NBT | COMPARE_DAMAGE | COMPARE_QUANTITY);
}
/**
* Compares two stacks by NBT and damage.
*
* @param left The left stack
* @param right The right stack
* @return Whether the left and right stack are equal
*/
public static boolean compareStackNoQuantity(ItemStack left, ItemStack right) {
return compareStack(left, right, COMPARE_NBT | COMPARE_DAMAGE);
}
/**
* Compares two stacks by the given flags.
*
* @param left The left stack
* @param right The right stack
* @param flags The flags to compare with
* @return Whether the left and right stack are equal
*/
public static boolean compareStack(ItemStack left, ItemStack right, int flags) {
if (left == null && right == null) {
return true;
}
if ((left == null && right != null) || (left != null && right == null)) {
return false;
}
if (left.getItem() != right.getItem()) {
return false;
}
if ((flags & COMPARE_DAMAGE) == COMPARE_DAMAGE) {
if (left.getItemDamage() != right.getItemDamage()) {
return false;
}
}
if ((flags & COMPARE_NBT) == COMPARE_NBT) {
if (!compareNbt(left, right)) {
return false;
}
}
if ((flags & COMPARE_QUANTITY) == COMPARE_QUANTITY) {
if (left.stackSize != right.stackSize) {
return false;
}
}
return true;
}
/**
* Compares two stacks by the given flags.
*
* @param left The left stack
* @param right The right stack
* @param flags The flags to compare with
* @return Whether the left and right stack are equal
*/
public static boolean compareStack(FluidStack left, FluidStack right, int flags) {
if (left == null && right == null) {
return true;
}
if ((left == null && right != null) || (left != null && right == null)) {
return false;
}
if (left.getFluid() != right.getFluid()) {
return false;
}
if ((flags & COMPARE_NBT) == COMPARE_NBT) {
if (left.tag != null && !left.tag.equals(right)) {
return false;
}
}
return true;
}
/**
* Compares the NBT tags of two stacks.
*
* @param left The left stack
* @param right The right stack
* @return Whether the NBT tags are equal
*/
public static boolean compareNbt(ItemStack left, ItemStack right) {
if (!ItemStack.areItemStackTagsEqual(left, right)) {
if (left.hasTagCompound() && !right.hasTagCompound() && left.getTagCompound().hasNoTags()) {
return true;
} else if (!left.hasTagCompound() && right.hasTagCompound() && right.getTagCompound().hasNoTags()) {
return true;
}
return false;
}
return true;
}
/**
* Compares two stacks and checks if they share the same ore dictionary entry.
*
* @param left The left stack
* @param right The right stack
* @return Whether the stacks share the same ore dictionary entry
*/
public static boolean compareStackOreDict(ItemStack left, ItemStack right) {
if (left == null && right == null) {
return true;
}
if ((left == null && right != null) || (left != null && right == null)) {
return false;
}
int[] leftIds = OreDictionary.getOreIDs(left);
int[] rightIds = OreDictionary.getOreIDs(right);
for (int i : rightIds) {
if (ArrayUtils.contains(leftIds, i)) {
return true;
}
}
return false;
}
}

View File

@@ -1,59 +0,0 @@
package refinedstorage.api.storage;
import net.minecraft.item.ItemStack;
import refinedstorage.api.network.INetworkMaster;
import java.util.Collection;
import java.util.List;
/**
* This holds all items from all the connected storages from a {@link INetworkMaster}.
*/
public interface IGroupedStorage {
/**
* Rebuilds the storages and items for a network. Typically called when a {@link IStorageProvider} is
* added or removed from the network.
*/
void rebuild();
/**
* Adds an item to the network. Will merge it with another item if it already exists.
*
* @param stack The stack to add, do NOT modify
* @param rebuilding Whether this method is called while the storage is rebuilding
*/
void add(ItemStack stack, boolean rebuilding);
/**
* Removes a item from the network.
*
* @param stack The item to remove, do NOT modify
*/
void remove(ItemStack stack);
/**
* Gets an item from the network, does not decrement its count like {@link IGroupedStorage#remove(ItemStack)} does.
*
* @param stack The stack to find
* @param flags The flags to compare on, see {@link CompareFlags}
* @return The {@link ItemStack}, do NOT modify
*/
ItemStack get(ItemStack stack, int flags);
/**
* Gets an item from the network by ID.
*
* @return The {@link ItemStack}, do NOT modify
*/
ItemStack get(int id);
/**
* @return All items in this storage network
*/
Collection<ItemStack> getStacks();
/**
* @return The storages connected to this network
*/
List<IStorage> getStorages();
}

View File

@@ -1,15 +0,0 @@
package refinedstorage.api.storage;
import java.util.List;
/**
* Implement this interface on the tile that has a {@link refinedstorage.api.RefinedStorageCapabilities#NETWORK_NODE_CAPABILITY} capability.
*/
public interface IStorageProvider {
/**
* Adds the storages that this storage provider provides.
*
* @param storages The previously added storages
*/
void addStorages(List<IStorage> storages);
}

View File

@@ -0,0 +1,54 @@
package refinedstorage.api.storage.fluid;
import net.minecraftforge.fluids.FluidStack;
import refinedstorage.api.storage.CompareUtils;
import refinedstorage.api.storage.item.IItemStorageProvider;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
/**
* Represents a fluid storage sink for the storage network.
* Provide this through an {@link IItemStorageProvider}.
*/
public interface IFluidStorage {
/**
* @return Fluids stored in this storage
*/
List<FluidStack> getStacks();
/**
* Inserts a fluid to this storage.
*
* @param stack The fluid prototype to insert, do NOT modify
* @param size The amount of that prototype that has to be inserted
* @param simulate If we are simulating
* @return null if the insert was successful, or a {@link FluidStack} with the remainder
*/
@Nullable
FluidStack insertFluid(@Nonnull FluidStack stack, int size, boolean simulate);
/**
* Extracts a fluid from this storage.
* <p>
* If the fluid we found in the system is smaller than the requested size, return that fluid anyway.
*
* @param stack A prototype of the fluid to extract, do NOT modify
* @param size The amount of that fluid that has to be extracted
* @param flags On what we are comparing to extract this fluid, see {@link CompareUtils}
* @return null if we didn't extract anything, or an {@link FluidStack} with the result
*/
@Nullable
FluidStack extractFluid(@Nonnull FluidStack stack, int size, int flags);
/**
* @return The amount of fluids stored in this storage
*/
int getStored();
/**
* @return The priority of this storage
*/
int getPriority();
}

View File

@@ -0,0 +1,15 @@
package refinedstorage.api.storage.fluid;
import java.util.List;
/**
* Represents a tile that provides item storage to the network. Implement this on a tile that is a {@link refinedstorage.api.network.INetworkNode}.
*/
public interface IFluidStorageProvider {
/**
* Adds the fluid storages that this storage provider provides.
*
* @param storages The previously added fluid storages
*/
void addFluidStorages(List<IFluidStorage> storages);
}

View File

@@ -0,0 +1,76 @@
package refinedstorage.api.storage.fluid;
import net.minecraftforge.fluids.FluidStack;
import refinedstorage.api.network.INetworkMaster;
import refinedstorage.api.storage.CompareUtils;
import refinedstorage.api.storage.item.IItemStorageProvider;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.List;
/**
* This holds all fluids from all the connected storages from a {@link INetworkMaster}.
* <p>
* Refined Storage uses this class mainly for use in Grids and Detectors to avoid querying
* individual {@link IFluidStorage} constantly (performance impact) and to send and detect storage changes
* more efficiently.
*/
public interface IGroupedFluidStorage {
/**
* Rebuilds the global fluid list. Typically called when a {@link IItemStorageProvider} is added or removed from the network.
*/
void rebuild();
/**
* Adds an item to the global fluid list.
* <p>
* Note that this doesn't modify any of the connected storages, but just modifies the global fluid list.
* Use {@link INetworkMaster#insertFluid(FluidStack, int, boolean)} to add a fluid to an actual storage.
* <p>
* Will merge it with another fluid if it already exists.
*
* @param stack The fluid to add, do NOT modify
* @param rebuilding Whether this method is called while the storage is rebuilding
*/
void add(@Nonnull FluidStack stack, boolean rebuilding);
/**
* Removes a fluid from the global fluid list.
* <p>
* Note that this doesn't modify any of the connected storages, but just modifies the global fluid list.
* Use {@link INetworkMaster#extractFluid(FluidStack, int, int)} to remove an fluid from an actual storage.
*
* @param stack The fluid to remove, do NOT modify
*/
void remove(@Nonnull FluidStack stack);
/**
* Gets a fluid from the network.
*
* @param stack The stack to find
* @param flags The flags to compare on, see {@link CompareUtils}
* @return Null if no fluid is found, or the {@link FluidStack}, do NOT modify
*/
@Nullable
FluidStack get(@Nonnull FluidStack stack, int flags);
/**
* Gets a fluid from the network by hash, see {@link refinedstorage.api.network.NetworkUtils#getFluidStackHashCode(FluidStack)}.
*
* @return Null if no fluid is found matching the hash, or the {@link FluidStack}, do NOT modify
*/
@Nullable
FluidStack get(int hash);
/**
* @return All fluids in this storage network
*/
Collection<FluidStack> getStacks();
/**
* @return The fluid storages connected to this network
*/
List<IFluidStorage> getStorages();
}

View File

@@ -0,0 +1,75 @@
package refinedstorage.api.storage.item;
import net.minecraft.item.ItemStack;
import refinedstorage.api.network.INetworkMaster;
import refinedstorage.api.storage.CompareUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.List;
/**
* This holds all items from all the connected storages from a {@link INetworkMaster}.
* <p>
* Refined Storage uses this class mainly for use in Grids and Detectors to avoid querying
* individual {@link IItemStorage} constantly (performance impact) and to send and detect storage changes
* more efficiently.
*/
public interface IGroupedItemStorage {
/**
* Rebuilds the global item list. Typically called when a {@link IItemStorageProvider} is added or removed from the network.
*/
void rebuild();
/**
* Adds an item to the global item list.
* <p>
* Note that this doesn't modify any of the connected storages, but just modifies the global item list.
* Use {@link INetworkMaster#insertItem(ItemStack, int, boolean)} to add an item to an actual storage.
* <p>
* Will merge it with another item if it already exists.
*
* @param stack The stack to add, do NOT modify
* @param rebuilding Whether this method is called while the storage is rebuilding
*/
void add(@Nonnull ItemStack stack, boolean rebuilding);
/**
* Removes a item from global item list.
* <p>
* Note that this doesn't modify any of the connected storages, but just modifies the global item list.
* Use {@link INetworkMaster#extractItem(ItemStack, int, int)} to remove an item from an actual storage.
*
* @param stack The item to remove, do NOT modify
*/
void remove(@Nonnull ItemStack stack);
/**
* Gets an item from the network.
*
* @param stack The stack to find
* @param flags The flags to compare on, see {@link CompareUtils}
* @return Null if no item is found, or the {@link ItemStack}, do NOT modify
*/
@Nullable
ItemStack get(@Nonnull ItemStack stack, int flags);
/**
* Gets an item from the network by hash, see {@link refinedstorage.api.network.NetworkUtils#getItemStackHashCode(ItemStack)}.
*
* @return Null if no item is found matching the hash, or the {@link ItemStack}, do NOT modify
*/
@Nullable
ItemStack get(int hash);
/**
* @return All items in this storage network
*/
Collection<ItemStack> getStacks();
/**
* @return The item storages connected to this network
*/
List<IItemStorage> getStorages();
}

View File

@@ -1,16 +1,17 @@
package refinedstorage.api.storage;
package refinedstorage.api.storage.item;
import net.minecraft.item.ItemStack;
import refinedstorage.api.storage.CompareUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
/**
* Represents a storage sink for the storage network.
* Provide this through an {@link IStorageProvider}.
* Represents an item storage sink for the storage network.
* Provide this through an {@link IItemStorageProvider}.
*/
public interface IStorage {
public interface IItemStorage {
/**
* @return Items stored in this storage
*/
@@ -28,14 +29,13 @@ public interface IStorage {
ItemStack insertItem(@Nonnull ItemStack stack, int size, boolean simulate);
/**
* Extracts an item from storage.
*
* If the stack we found in the system is smaller than the requested size, return the stack anyway.
* For example: if this method is called for dirt (64x) while there is only dirt (32x), return the dirt (32x) anyway.
* Extracts an item from this storage.
* <p>
* If the stack we found in the system is smaller than the requested size, return that stack anyway.
*
* @param stack A prototype of the stack to extract, do NOT modify
* @param size The amount of that prototype that has to be extracted
* @param flags On what we are comparing to extract this item, see {@link CompareFlags}
* @param flags On what we are comparing to extract this item, see {@link CompareUtils}
* @return null if we didn't extract anything, or an {@link ItemStack} with the result
*/
@Nullable

View File

@@ -0,0 +1,15 @@
package refinedstorage.api.storage.item;
import java.util.List;
/**
* Represents a tile that provides item storage to the network. Implement this on a tile that is a {@link refinedstorage.api.network.INetworkNode}.
*/
public interface IItemStorageProvider {
/**
* Adds the item storages that this storage provider provides.
*
* @param storages The previously added item storages
*/
void addItemStorages(List<IItemStorage> storages);
}

View File

@@ -2,13 +2,15 @@ package refinedstorage.apiimpl.autocrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagIntArray;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import refinedstorage.RefinedStorageUtils;
import refinedstorage.api.autocrafting.ICraftingPattern;
import refinedstorage.api.autocrafting.ICraftingTask;
import refinedstorage.api.network.INetworkMaster;
import refinedstorage.api.network.NetworkUtils;
import refinedstorage.apiimpl.storage.fluid.FluidUtils;
import java.util.ArrayList;
import java.util.List;
@@ -25,7 +27,7 @@ public class BasicCraftingTask implements ICraftingTask {
private boolean satisfied[];
private boolean checked[];
private boolean childTasks[];
private List<ItemStack> itemsTook = new ArrayList<ItemStack>();
private List<ItemStack> itemsTook = new ArrayList<>();
private boolean updatedOnce;
public BasicCraftingTask(ICraftingPattern pattern) {
@@ -37,9 +39,9 @@ public class BasicCraftingTask implements ICraftingTask {
public BasicCraftingTask(NBTTagCompound tag, ICraftingPattern pattern) {
this.pattern = pattern;
this.satisfied = RefinedStorageUtils.readBooleanArray(tag, NBT_SATISFIED);
this.checked = RefinedStorageUtils.readBooleanArray(tag, NBT_CHECKED);
this.childTasks = RefinedStorageUtils.readBooleanArray(tag, NBT_CHILD_TASKS);
this.satisfied = readBooleanArray(tag, NBT_SATISFIED);
this.checked = readBooleanArray(tag, NBT_CHECKED);
this.childTasks = readBooleanArray(tag, NBT_CHILD_TASKS);
NBTTagList tookList = tag.getTagList(NBT_TOOK, Constants.NBT.TAG_COMPOUND);
@@ -67,14 +69,14 @@ public class BasicCraftingTask implements ICraftingTask {
if (!satisfied[i]) {
done = false;
ItemStack took = RefinedStorageUtils.extractItem(network, input, 1);
ItemStack took = FluidUtils.extractItemOrIfBucketLookInFluids(network, input, 1);
if (took != null) {
itemsTook.add(took);
satisfied[i] = true;
} else if (!childTasks[i]) {
ICraftingPattern pattern = RefinedStorageUtils.getPattern(network, input);
ICraftingPattern pattern = NetworkUtils.getPattern(network, input);
if (pattern != null) {
network.addCraftingTask(network.createCraftingTask(pattern));
@@ -92,7 +94,7 @@ public class BasicCraftingTask implements ICraftingTask {
return done;
}
// @todo: handle no space
// @TODO: Handle no space
@Override
public void onDone(INetworkMaster network) {
for (ItemStack output : pattern.getOutputs()) {
@@ -106,7 +108,7 @@ public class BasicCraftingTask implements ICraftingTask {
}
}
// @todo: handle no space
// @TODO: Handle no space
@Override
public void onCancelled(INetworkMaster network) {
for (ItemStack took : itemsTook) {
@@ -120,9 +122,9 @@ public class BasicCraftingTask implements ICraftingTask {
pattern.writeToNBT(patternTag);
tag.setTag(CraftingPattern.NBT, patternTag);
RefinedStorageUtils.writeBooleanArray(tag, NBT_SATISFIED, satisfied);
RefinedStorageUtils.writeBooleanArray(tag, NBT_CHECKED, checked);
RefinedStorageUtils.writeBooleanArray(tag, NBT_CHILD_TASKS, childTasks);
writeBooleanArray(tag, NBT_SATISFIED, satisfied);
writeBooleanArray(tag, NBT_CHECKED, checked);
writeBooleanArray(tag, NBT_CHILD_TASKS, childTasks);
NBTTagList tookList = new NBTTagList();
@@ -177,4 +179,26 @@ public class BasicCraftingTask implements ICraftingTask {
return builder.toString();
}
public static void writeBooleanArray(NBTTagCompound tag, String name, boolean[] array) {
int[] intArray = new int[array.length];
for (int i = 0; i < intArray.length; ++i) {
intArray[i] = array[i] ? 1 : 0;
}
tag.setTag(name, new NBTTagIntArray(intArray));
}
public static boolean[] readBooleanArray(NBTTagCompound tag, String name) {
int[] intArray = tag.getIntArray(name);
boolean array[] = new boolean[intArray.length];
for (int i = 0; i < intArray.length; ++i) {
array[i] = intArray[i] == 1 ? true : false;
}
return array;
}
}

View File

@@ -3,9 +3,9 @@ package refinedstorage.apiimpl.autocrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import refinedstorage.RefinedStorageUtils;
import refinedstorage.api.autocrafting.ICraftingPattern;
import refinedstorage.api.network.INetworkMaster;
import refinedstorage.api.storage.CompareUtils;
public class CraftingTaskScheduler {
private static final String NBT_SCHEDULED = "CraftingTaskScheduled";
@@ -18,7 +18,7 @@ public class CraftingTaskScheduler {
}
public boolean canSchedule(int compare, ItemStack item) {
return scheduledItem == null || !RefinedStorageUtils.compareStack(scheduledItem, item, compare);
return scheduledItem == null || !CompareUtils.compareStack(scheduledItem, item, compare);
}
public void schedule(INetworkMaster network, int compare, ItemStack item) {
@@ -39,7 +39,7 @@ public class CraftingTaskScheduler {
tile.markDirty();
}
public void writeToNBT(NBTTagCompound tag) {
public void write(NBTTagCompound tag) {
if (scheduledItem != null) {
tag.setTag(NBT_SCHEDULED, scheduledItem.serializeNBT());
} else {

View File

@@ -4,11 +4,13 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.items.ItemHandlerHelper;
import refinedstorage.RefinedStorageUtils;
import refinedstorage.api.autocrafting.ICraftingPattern;
import refinedstorage.api.autocrafting.ICraftingPatternContainer;
import refinedstorage.api.autocrafting.ICraftingTask;
import refinedstorage.api.network.INetworkMaster;
import refinedstorage.api.network.NetworkUtils;
import refinedstorage.api.storage.CompareUtils;
import refinedstorage.apiimpl.storage.fluid.FluidUtils;
public class ProcessingCraftingTask implements ICraftingTask {
public static final int ID = 1;
@@ -32,9 +34,9 @@ public class ProcessingCraftingTask implements ICraftingTask {
public ProcessingCraftingTask(NBTTagCompound tag, ICraftingPattern pattern) {
this.pattern = pattern;
this.inserted = RefinedStorageUtils.readBooleanArray(tag, NBT_INSERTED);
this.childTasks = RefinedStorageUtils.readBooleanArray(tag, NBT_CHILD_TASKS);
this.satisfied = RefinedStorageUtils.readBooleanArray(tag, NBT_SATISFIED);
this.inserted = BasicCraftingTask.readBooleanArray(tag, NBT_INSERTED);
this.childTasks = BasicCraftingTask.readBooleanArray(tag, NBT_CHILD_TASKS);
this.satisfied = BasicCraftingTask.readBooleanArray(tag, NBT_SATISFIED);
}
@Override
@@ -52,7 +54,7 @@ public class ProcessingCraftingTask implements ICraftingTask {
for (int i = 0; i < inserted.length; ++i) {
if (!inserted[i]) {
ItemStack input = pattern.getInputs()[i];
ItemStack took = RefinedStorageUtils.extractItem(network, input, 1);
ItemStack took = FluidUtils.extractItemOrIfBucketLookInFluids(network, input, 1);
if (took != null) {
if (ItemHandlerHelper.insertItem(container.getConnectedItems(), took, true) == null) {
@@ -63,7 +65,7 @@ public class ProcessingCraftingTask implements ICraftingTask {
network.insertItem(took, took.stackSize, false);
}
} else if (!childTasks[i]) {
ICraftingPattern pattern = RefinedStorageUtils.getPattern(network, input);
ICraftingPattern pattern = NetworkUtils.getPattern(network, input);
if (pattern != null) {
childTasks[i] = true;
@@ -92,7 +94,7 @@ public class ProcessingCraftingTask implements ICraftingTask {
public boolean onInserted(ItemStack stack) {
for (int i = 0; i < pattern.getOutputs().length; ++i) {
if (!satisfied[i] && RefinedStorageUtils.compareStackNoQuantity(stack, pattern.getOutputs()[i])) {
if (!satisfied[i] && CompareUtils.compareStackNoQuantity(stack, pattern.getOutputs()[i])) {
satisfied[i] = true;
return true;
@@ -118,9 +120,9 @@ public class ProcessingCraftingTask implements ICraftingTask {
pattern.writeToNBT(patternTag);
tag.setTag(CraftingPattern.NBT, patternTag);
RefinedStorageUtils.writeBooleanArray(tag, NBT_INSERTED, inserted);
RefinedStorageUtils.writeBooleanArray(tag, NBT_CHILD_TASKS, childTasks);
RefinedStorageUtils.writeBooleanArray(tag, NBT_SATISFIED, satisfied);
BasicCraftingTask.writeBooleanArray(tag, NBT_INSERTED, inserted);
BasicCraftingTask.writeBooleanArray(tag, NBT_CHILD_TASKS, childTasks);
BasicCraftingTask.writeBooleanArray(tag, NBT_SATISFIED, satisfied);
tag.setInteger("Type", ID);
}

View File

@@ -0,0 +1,166 @@
package refinedstorage.apiimpl.network;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import refinedstorage.api.network.INetworkNode;
import refinedstorage.api.network.INetworkNodeGraph;
import refinedstorage.api.network.NetworkUtils;
import refinedstorage.tile.TileController;
import refinedstorage.tile.TileNetworkTransmitter;
import java.util.*;
public class NetworkNodeGraph implements INetworkNodeGraph {
private TileController controller;
private List<INetworkNode> nodes = new ArrayList<>();
private Set<Integer> nodeHashes = new HashSet<>();
public NetworkNodeGraph(TileController controller) {
this.controller = controller;
}
@Override
public void rebuild(BlockPos start, boolean notify) {
if (!controller.canRun()) {
if (!nodes.isEmpty()) {
disconnectAll();
}
return;
}
World world = getWorld();
List<INetworkNode> newNodes = new ArrayList<>();
Set<Integer> newNodeHashes = new HashSet<>();
Set<BlockPos> checked = new HashSet<>();
Queue<BlockPos> toCheck = new ArrayDeque<>();
checked.add(start);
toCheck.add(start);
for (EnumFacing facing : EnumFacing.VALUES) {
BlockPos pos = start.offset(facing);
checked.add(pos);
toCheck.add(pos);
}
BlockPos currentPos;
while ((currentPos = toCheck.poll()) != null) {
TileEntity tile = world.getTileEntity(currentPos);
if (tile instanceof TileController && !controller.getPos().equals(tile.getPos())) {
world.createExplosion(null, tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ(), 4.5f, true);
}
if (!(tile instanceof INetworkNode)) {
continue;
}
INetworkNode node = (INetworkNode) tile;
newNodes.add(node);
newNodeHashes.add(NetworkUtils.getNodeHashCode(world, node));
if (tile instanceof TileNetworkTransmitter) {
final TileNetworkTransmitter transmitter = (TileNetworkTransmitter) tile;
if (transmitter.canTransmit()) {
if (!transmitter.isSameDimension()) {
NetworkNodeGraph dimensionGraph = new NetworkNodeGraph(controller) {
@Override
public World getWorld() {
return DimensionManager.getWorld(transmitter.getReceiverDimension());
}
};
dimensionGraph.rebuild(transmitter.getReceiver(), false);
newNodes.addAll(dimensionGraph.all());
newNodeHashes.addAll(dimensionGraph.allHashes());
} else {
BlockPos receiver = transmitter.getReceiver();
if (checked.add(receiver)) {
toCheck.add(receiver);
}
}
}
}
for (EnumFacing facing : EnumFacing.VALUES) {
if (node.canConduct(facing)) {
BlockPos pos = currentPos.offset(facing);
if (checked.add(pos)) {
toCheck.add(pos);
}
}
}
}
List<INetworkNode> oldNodes = new ArrayList<>(nodes);
Set<Integer> oldNodeHashes = new HashSet<>(nodeHashes);
this.nodes = newNodes;
this.nodeHashes = newNodeHashes;
if (notify) {
boolean changed = false;
for (INetworkNode newNode : nodes) {
if (!oldNodeHashes.contains(NetworkUtils.getNodeHashCode(newNode.getNodeWorld(), newNode))) {
newNode.onConnected(controller);
changed = true;
}
}
for (INetworkNode oldNode : oldNodes) {
if (!nodeHashes.contains(NetworkUtils.getNodeHashCode(oldNode.getNodeWorld(), oldNode))) {
oldNode.onDisconnected(controller);
changed = true;
}
}
if (changed) {
controller.getDataManager().sendParameterToWatchers(TileController.NODES);
}
}
}
@Override
public List<INetworkNode> all() {
return nodes;
}
@Override
public Set<Integer> allHashes() {
return nodeHashes;
}
@Override
public void disconnectAll() {
for (INetworkNode node : nodes) {
if (node.isConnected()) {
node.onDisconnected(controller);
}
}
nodes.clear();
nodeHashes.clear();
controller.getDataManager().sendParameterToWatchers(TileController.NODES);
}
public World getWorld() {
return controller.getWorld();
}
}

View File

@@ -2,25 +2,17 @@ package refinedstorage.apiimpl.network;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import refinedstorage.api.network.IWirelessGridConsumer;
public class WirelessGridConsumer implements IWirelessGridConsumer {
private EntityPlayer player;
private EnumHand hand;
private ItemStack stack;
public WirelessGridConsumer(EntityPlayer player, EnumHand hand, ItemStack stack) {
public WirelessGridConsumer(EntityPlayer player, ItemStack stack) {
this.player = player;
this.hand = hand;
this.stack = stack;
}
@Override
public EnumHand getHand() {
return hand;
}
@Override
public EntityPlayer getPlayer() {
return player;

View File

@@ -7,7 +7,6 @@ import net.minecraft.util.EnumHand;
import refinedstorage.RefinedStorage;
import refinedstorage.RefinedStorageGui;
import refinedstorage.RefinedStorageItems;
import refinedstorage.RefinedStorageUtils;
import refinedstorage.api.network.*;
import refinedstorage.item.ItemWirelessGrid;
@@ -16,14 +15,10 @@ import java.util.Iterator;
import java.util.List;
public class WirelessGridHandler implements IWirelessGridHandler {
public static final int USAGE_OPEN = 30;
public static final int USAGE_EXTRACT = 3;
public static final int USAGE_INSERT = 3;
private INetworkMaster network;
private List<IWirelessGridConsumer> consumers = new ArrayList<IWirelessGridConsumer>();
private List<IWirelessGridConsumer> consumersToRemove = new ArrayList<IWirelessGridConsumer>();
private List<IWirelessGridConsumer> consumers = new ArrayList<>();
private List<IWirelessGridConsumer> consumersToRemove = new ArrayList<>();
public WirelessGridHandler(INetworkMaster network) {
this.network = network;
@@ -33,26 +28,13 @@ public class WirelessGridHandler implements IWirelessGridHandler {
public void update() {
consumers.removeAll(consumersToRemove);
consumersToRemove.clear();
Iterator<IWirelessGridConsumer> it = consumers.iterator();
while (it.hasNext()) {
IWirelessGridConsumer consumer = it.next();
if (!RefinedStorageUtils.compareStack(consumer.getStack(), consumer.getPlayer().getHeldItem(consumer.getHand()))) {
/**
* This will call {@link net.minecraft.inventory.Container#onContainerClosed(EntityPlayer)} so the consumer is removed from the list.
*/
consumer.getPlayer().closeScreen();
}
}
}
@Override
public boolean onOpen(EntityPlayer player, EnumHand hand) {
boolean inRange = false;
for (INetworkNode node : network.getNodes()) {
for (INetworkNode node : network.getNodeGraph().all()) {
if (node instanceof IWirelessTransmitter) {
IWirelessTransmitter transmitter = (IWirelessTransmitter) node;
@@ -70,13 +52,19 @@ public class WirelessGridHandler implements IWirelessGridHandler {
return false;
}
consumers.add(new WirelessGridConsumer(player, hand, player.getHeldItem(hand)));
ItemStack stack = player.getHeldItem(hand);
player.openGui(RefinedStorage.INSTANCE, RefinedStorageGui.WIRELESS_GRID, player.worldObj, RefinedStorageUtils.getIdFromHand(hand), 0, 0);
if (RefinedStorage.INSTANCE.wirelessGridUsesEnergy && stack.getItemDamage() != ItemWirelessGrid.TYPE_CREATIVE && RefinedStorageItems.WIRELESS_GRID.getEnergyStored(stack) <= RefinedStorage.INSTANCE.wirelessGridOpenUsage) {
return true;
}
network.sendStorageToClient((EntityPlayerMP) player);
consumers.add(new WirelessGridConsumer(player, stack));
drainEnergy(player, USAGE_OPEN);
player.openGui(RefinedStorage.INSTANCE, RefinedStorageGui.WIRELESS_GRID, player.worldObj, hand.ordinal(), 0, 0);
network.sendItemStorageToClient((EntityPlayerMP) player);
drainEnergy(player, RefinedStorage.INSTANCE.wirelessGridOpenUsage);
return true;
}
@@ -94,15 +82,15 @@ public class WirelessGridHandler implements IWirelessGridHandler {
public void drainEnergy(EntityPlayer player, int energy) {
IWirelessGridConsumer consumer = getConsumer(player);
if (consumer != null) {
if (consumer != null && RefinedStorage.INSTANCE.wirelessGridUsesEnergy) {
ItemWirelessGrid item = RefinedStorageItems.WIRELESS_GRID;
ItemStack held = consumer.getPlayer().getHeldItem(consumer.getHand());
if (held.getItemDamage() != ItemWirelessGrid.TYPE_CREATIVE) {
item.extractEnergy(held, energy, false);
if (consumer.getStack().getItemDamage() != ItemWirelessGrid.TYPE_CREATIVE) {
item.extractEnergy(consumer.getStack(), energy, false);
if (item.getEnergyStored(held) <= 0) {
if (item.getEnergyStored(consumer.getStack()) <= 0) {
onClose(player);
consumer.getPlayer().closeScreen();
}
}

View File

@@ -0,0 +1,80 @@
package refinedstorage.apiimpl.network.grid;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import refinedstorage.api.network.INetworkMaster;
import refinedstorage.api.network.NetworkUtils;
import refinedstorage.api.network.grid.IFluidGridHandler;
import refinedstorage.api.storage.CompareUtils;
import refinedstorage.apiimpl.storage.fluid.FluidUtils;
import javax.annotation.Nullable;
public class FluidGridHandler implements IFluidGridHandler {
private INetworkMaster network;
public FluidGridHandler(INetworkMaster network) {
this.network = network;
}
@Override
public void onExtract(int hash, boolean shift, EntityPlayerMP player) {
FluidStack stack = network.getFluidStorage().get(hash);
if (stack != null && FluidUtils.hasFluidBucket(stack)) {
ItemStack bucket = FluidUtils.extractBucket(network);
if (bucket == null) {
for (int i = 0; i < player.inventory.getSizeInventory(); ++i) {
ItemStack slot = player.inventory.getStackInSlot(i);
if (CompareUtils.compareStackNoQuantity(FluidUtils.EMPTY_BUCKET, slot)) {
bucket = FluidUtils.EMPTY_BUCKET.copy();
player.inventory.decrStackSize(i, 1);
break;
}
}
}
if (bucket != null) {
bucket.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null).fill(NetworkUtils.extractFluid(network, stack, Fluid.BUCKET_VOLUME), true);
if (shift) {
if (!player.inventory.addItemStackToInventory(bucket.copy())) {
InventoryHelper.spawnItemStack(player.worldObj, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), bucket);
}
} else {
player.inventory.setItemStack(bucket);
player.updateHeldItem();
}
}
}
}
@Nullable
@Override
public ItemStack onInsert(ItemStack container) {
FluidStack stack = FluidUtils.getFluidFromStack(container, true);
if (stack != null && network.insertFluid(stack, stack.amount, true) == null) {
FluidStack drained = FluidUtils.getFluidFromStack(container, false);
network.insertFluid(drained, drained.amount, false);
}
return container;
}
@Override
public void onInsertHeldContainer(EntityPlayerMP player) {
onInsert(player.inventory.getItemStack());
player.updateHeldItem();
}
}

View File

@@ -1,27 +1,28 @@
package refinedstorage.apiimpl.network;
package refinedstorage.apiimpl.network.grid;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.ItemStack;
import refinedstorage.RefinedStorageUtils;
import refinedstorage.RefinedStorage;
import refinedstorage.api.autocrafting.ICraftingPattern;
import refinedstorage.api.autocrafting.ICraftingTask;
import refinedstorage.api.network.GridExtractFlags;
import refinedstorage.api.network.IGridHandler;
import refinedstorage.api.network.INetworkMaster;
import refinedstorage.api.network.NetworkUtils;
import refinedstorage.api.network.grid.IItemGridHandler;
import refinedstorage.api.storage.CompareUtils;
public class GridHandler implements IGridHandler {
public class ItemGridHandler implements IItemGridHandler {
public static final int MAX_CRAFTING_PER_REQUEST = 500;
private INetworkMaster network;
public GridHandler(INetworkMaster network) {
public ItemGridHandler(INetworkMaster network) {
this.network = network;
}
@Override
public void onExtract(int id, int flags, EntityPlayerMP player) {
ItemStack item = network.getStorage().get(id);
public void onExtract(int hash, int flags, EntityPlayerMP player) {
ItemStack item = network.getItemStorage().get(hash);
if (item == null) {
return;
@@ -29,12 +30,12 @@ public class GridHandler implements IGridHandler {
int itemSize = item.stackSize;
boolean single = (flags & GridExtractFlags.EXTRACT_SINGLE) == GridExtractFlags.EXTRACT_SINGLE;
boolean single = (flags & EXTRACT_SINGLE) == EXTRACT_SINGLE;
ItemStack held = player.inventory.getItemStack();
if (single) {
if (held != null && (!RefinedStorageUtils.compareStackNoQuantity(item, held) || held.stackSize + 1 > held.getMaxStackSize())) {
if (held != null && (!CompareUtils.compareStackNoQuantity(item, held) || held.stackSize + 1 > held.getMaxStackSize())) {
return;
}
} else if (player.inventory.getItemStack() != null) {
@@ -43,7 +44,7 @@ public class GridHandler implements IGridHandler {
int size = 64;
if ((flags & GridExtractFlags.EXTRACT_HALF) == GridExtractFlags.EXTRACT_HALF && itemSize > 1) {
if ((flags & EXTRACT_HALF) == EXTRACT_HALF && itemSize > 1) {
size = itemSize / 2;
if (size > 32) {
@@ -51,16 +52,16 @@ public class GridHandler implements IGridHandler {
}
} else if (single) {
size = 1;
} else if ((flags & GridExtractFlags.EXTRACT_SHIFT) == GridExtractFlags.EXTRACT_SHIFT) {
} else if ((flags & EXTRACT_SHIFT) == EXTRACT_SHIFT) {
// NO OP, the quantity already set (64) is needed for shift
}
size = Math.min(size, item.getItem().getItemStackLimit(item));
ItemStack took = RefinedStorageUtils.extractItem(network, item, size);
ItemStack took = NetworkUtils.extractItem(network, item, size);
if (took != null) {
if ((flags & GridExtractFlags.EXTRACT_SHIFT) == GridExtractFlags.EXTRACT_SHIFT) {
if ((flags & EXTRACT_SHIFT) == EXTRACT_SHIFT) {
if (!player.inventory.addItemStackToInventory(took.copy())) {
InventoryHelper.spawnItemStack(player.worldObj, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), took);
}
@@ -74,17 +75,21 @@ public class GridHandler implements IGridHandler {
player.updateHeldItem();
}
network.getWirelessGridHandler().drainEnergy(player, WirelessGridHandler.USAGE_EXTRACT);
network.getWirelessGridHandler().drainEnergy(player, RefinedStorage.INSTANCE.wirelessGridExtractUsage);
}
}
@Override
public ItemStack onInsert(ItemStack stack) {
return network.insertItem(stack, stack.stackSize, false);
public ItemStack onInsert(EntityPlayerMP player, ItemStack stack) {
ItemStack remainder = network.insertItem(stack, stack.stackSize, false);
network.getWirelessGridHandler().drainEnergy(player, RefinedStorage.INSTANCE.wirelessGridInsertUsage);
return remainder;
}
@Override
public void onInsertHeldItem(boolean single, EntityPlayerMP player) {
public void onInsertHeldItem(EntityPlayerMP player, boolean single) {
if (player.inventory.getItemStack() == null) {
return;
}
@@ -108,16 +113,16 @@ public class GridHandler implements IGridHandler {
player.updateHeldItem();
network.getWirelessGridHandler().drainEnergy(player, WirelessGridHandler.USAGE_INSERT);
network.getWirelessGridHandler().drainEnergy(player, RefinedStorage.INSTANCE.wirelessGridInsertUsage);
}
@Override
public void onCraftingRequested(int id, int quantity) {
public void onCraftingRequested(int hash, int quantity) {
if (quantity <= 0 || quantity > MAX_CRAFTING_PER_REQUEST) {
return;
}
ItemStack stack = network.getStorage().get(id);
ItemStack stack = network.getItemStorage().get(hash);
if (stack == null) {
return;
@@ -125,11 +130,11 @@ public class GridHandler implements IGridHandler {
int quantityPerRequest = 0;
ICraftingPattern pattern = RefinedStorageUtils.getPattern(network, stack);
ICraftingPattern pattern = NetworkUtils.getPattern(network, stack);
if (pattern != null) {
for (ItemStack output : pattern.getOutputs()) {
if (RefinedStorageUtils.compareStackNoQuantity(stack, output)) {
if (CompareUtils.compareStackNoQuantity(stack, output)) {
quantityPerRequest += output.stackSize;
if (!pattern.isProcessing()) {

View File

@@ -0,0 +1,38 @@
package refinedstorage.apiimpl.solderer;
import net.minecraft.item.ItemStack;
import refinedstorage.RefinedStorageBlocks;
import refinedstorage.RefinedStorageItems;
import refinedstorage.api.solderer.ISoldererRecipe;
import refinedstorage.block.EnumFluidStorageType;
import refinedstorage.item.ItemBlockFluidStorage;
import refinedstorage.item.ItemProcessor;
public class SoldererRecipeFluidStorage implements ISoldererRecipe {
private EnumFluidStorageType type;
private ItemStack[] rows;
public SoldererRecipeFluidStorage(EnumFluidStorageType type, int storagePart) {
this.type = type;
this.rows = new ItemStack[]{
new ItemStack(RefinedStorageItems.PROCESSOR, 1, ItemProcessor.TYPE_BASIC),
new ItemStack(RefinedStorageBlocks.MACHINE_CASING),
new ItemStack(RefinedStorageItems.FLUID_STORAGE_PART, 1, storagePart)
};
}
@Override
public ItemStack getRow(int row) {
return rows[row];
}
@Override
public ItemStack getResult() {
return ItemBlockFluidStorage.initNBT(new ItemStack(RefinedStorageBlocks.FLUID_STORAGE, 1, type.getId()));
}
@Override
public int getDuration() {
return 200;
}
}

View File

@@ -4,15 +4,15 @@ import net.minecraft.item.ItemStack;
import refinedstorage.RefinedStorageBlocks;
import refinedstorage.RefinedStorageItems;
import refinedstorage.api.solderer.ISoldererRecipe;
import refinedstorage.block.EnumStorageType;
import refinedstorage.block.EnumItemStorageType;
import refinedstorage.item.ItemBlockStorage;
import refinedstorage.item.ItemProcessor;
public class SoldererRecipeStorage implements ISoldererRecipe {
private EnumStorageType type;
private EnumItemStorageType type;
private ItemStack[] rows;
public SoldererRecipeStorage(EnumStorageType type, int storagePart) {
public SoldererRecipeStorage(EnumItemStorageType type, int storagePart) {
this.type = type;
this.rows = new ItemStack[]{
new ItemStack(RefinedStorageItems.PROCESSOR, 1, ItemProcessor.TYPE_BASIC),

View File

@@ -1,7 +1,5 @@
package refinedstorage.apiimpl.solderer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import refinedstorage.RefinedStorageItems;
import refinedstorage.api.solderer.ISoldererRecipe;
@@ -12,25 +10,11 @@ public class SoldererRecipeUpgrade implements ISoldererRecipe {
private ItemStack result;
public SoldererRecipeUpgrade(int type) {
ItemStack requirement = null;
switch (type) {
case ItemUpgrade.TYPE_RANGE:
requirement = new ItemStack(Items.ENDER_PEARL);
break;
case ItemUpgrade.TYPE_SPEED:
requirement = new ItemStack(Items.SUGAR);
break;
case ItemUpgrade.TYPE_CRAFTING:
requirement = new ItemStack(Blocks.CRAFTING_TABLE);
break;
}
this.result = new ItemStack(RefinedStorageItems.UPGRADE, 1, type);
this.rows = new ItemStack[]{
requirement,
ItemUpgrade.getRequirement(type),
new ItemStack(RefinedStorageItems.UPGRADE, 1, 0),
requirement
ItemUpgrade.getRequirement(type)
};
}

View File

@@ -1,9 +1,9 @@
package refinedstorage.apiimpl.solderer;
import net.minecraftforge.items.IItemHandler;
import refinedstorage.RefinedStorageUtils;
import refinedstorage.api.solderer.ISoldererRecipe;
import refinedstorage.api.solderer.ISoldererRegistry;
import refinedstorage.api.storage.CompareUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -11,7 +11,7 @@ import java.util.ArrayList;
import java.util.List;
public class SoldererRegistry implements ISoldererRegistry {
private List<ISoldererRecipe> recipes = new ArrayList<ISoldererRecipe>();
private List<ISoldererRecipe> recipes = new ArrayList<>();
@Override
public void addRecipe(@Nonnull ISoldererRecipe recipe) {
@@ -30,7 +30,7 @@ public class SoldererRegistry implements ISoldererRegistry {
boolean found = true;
for (int i = 0; i < 3; ++i) {
if (!RefinedStorageUtils.compareStackNoQuantity(recipe.getRow(i), items.getStackInSlot(i)) && !RefinedStorageUtils.compareStackOreDict(recipe.getRow(i), items.getStackInSlot(i))) {
if (!CompareUtils.compareStackNoQuantity(recipe.getRow(i), items.getStackInSlot(i)) && !CompareUtils.compareStackOreDict(recipe.getRow(i), items.getStackInSlot(i))) {
found = false;
}

View File

@@ -1,53 +0,0 @@
package refinedstorage.apiimpl.storage;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import refinedstorage.RefinedStorageUtils;
import refinedstorage.api.network.INetworkMaster;
public class ClientStack {
private int id;
private ItemStack stack;
private boolean craftable;
public ClientStack(int id, ItemStack stack, boolean craftable) {
this.id = id;
this.stack = stack;
this.craftable = craftable;
}
public ClientStack(ByteBuf buf) {
stack = new ItemStack(Item.getItemById(buf.readInt()), buf.readInt(), buf.readInt());
stack.setTagCompound(ByteBufUtils.readTag(buf));
id = buf.readInt();
craftable = buf.readBoolean();
}
public int getId() {
return id;
}
public ItemStack getStack() {
return stack;
}
public boolean isCraftable() {
return craftable;
}
@Override
public boolean equals(Object obj) {
return obj instanceof ClientStack && ((ClientStack) obj).getId() == id;
}
public static void write(ByteBuf buf, INetworkMaster network, ItemStack stack) {
buf.writeInt(Item.getIdFromItem(stack.getItem()));
buf.writeInt(stack.stackSize);
buf.writeInt(stack.getItemDamage());
ByteBufUtils.writeTag(buf, stack.getTagCompound());
buf.writeInt(RefinedStorageUtils.getItemStackHashCode(stack));
buf.writeBoolean(RefinedStorageUtils.hasPattern(network, stack));
}
}

View File

@@ -0,0 +1,126 @@
package refinedstorage.apiimpl.storage.fluid;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
/**
* This fluid renderer is copied over from JEI because Forge lacks a utility method for rendering fluids.
*
* @link https://github.com/mezz/JustEnoughItems/blob/1.10/src/main/java/mezz/jei/gui/ingredients/FluidStackRenderer.java
*/
public class FluidRenderer {
private static final int TEX_WIDTH = 16;
private static final int TEX_HEIGHT = 16;
private static final int MIN_FLUID_HEIGHT = 1;
private final int capacityMb;
private final int width;
private final int height;
public FluidRenderer(int capacityMb, int width, int height) {
this.capacityMb = capacityMb;
this.width = width;
this.height = height;
}
public void draw(Minecraft minecraft, final int xPosition, final int yPosition, FluidStack fluidStack) {
GlStateManager.enableBlend();
GlStateManager.enableAlpha();
drawFluid(minecraft, xPosition, yPosition, fluidStack);
GlStateManager.color(1, 1, 1, 1);
GlStateManager.disableAlpha();
GlStateManager.disableBlend();
}
private void drawFluid(Minecraft minecraft, final int xPosition, final int yPosition, FluidStack fluidStack) {
if (fluidStack == null) {
return;
}
Fluid fluid = fluidStack.getFluid();
if (fluid == null) {
return;
}
TextureMap textureMapBlocks = minecraft.getTextureMapBlocks();
ResourceLocation fluidStill = fluid.getStill();
TextureAtlasSprite fluidStillSprite = null;
if (fluidStill != null) {
fluidStillSprite = textureMapBlocks.getTextureExtry(fluidStill.toString());
}
if (fluidStillSprite == null) {
fluidStillSprite = textureMapBlocks.getMissingSprite();
}
int fluidColor = fluid.getColor(fluidStack);
int scaledAmount = (fluidStack.amount * height) / capacityMb;
if (fluidStack.amount > 0 && scaledAmount < MIN_FLUID_HEIGHT) {
scaledAmount = MIN_FLUID_HEIGHT;
}
if (scaledAmount > height) {
scaledAmount = height;
}
minecraft.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
setGLColorFromInt(fluidColor);
final int xTileCount = width / TEX_WIDTH;
final int xRemainder = width - (xTileCount * TEX_WIDTH);
final int yTileCount = scaledAmount / TEX_HEIGHT;
final int yRemainder = scaledAmount - (yTileCount * TEX_HEIGHT);
final int yStart = yPosition + height;
for (int xTile = 0; xTile <= xTileCount; xTile++) {
for (int yTile = 0; yTile <= yTileCount; yTile++) {
int width = (xTile == xTileCount) ? xRemainder : TEX_WIDTH;
int height = (yTile == yTileCount) ? yRemainder : TEX_HEIGHT;
int x = xPosition + (xTile * TEX_WIDTH);
int y = yStart - ((yTile + 1) * TEX_HEIGHT);
if (width > 0 && height > 0) {
int maskTop = TEX_HEIGHT - height;
int maskRight = TEX_WIDTH - width;
drawFluidTexture(x, y, fluidStillSprite, maskTop, maskRight, 100);
}
}
}
}
private static void setGLColorFromInt(int color) {
float red = (color >> 16 & 0xFF) / 255.0F;
float green = (color >> 8 & 0xFF) / 255.0F;
float blue = (color & 0xFF) / 255.0F;
GlStateManager.color(red, green, blue, 1.0F);
}
private static void drawFluidTexture(double xCoord, double yCoord, TextureAtlasSprite textureSprite, int maskTop, int maskRight, double zLevel) {
double uMin = (double) textureSprite.getMinU();
double uMax = (double) textureSprite.getMaxU();
double vMin = (double) textureSprite.getMinV();
double vMax = (double) textureSprite.getMaxV();
uMax = uMax - (maskRight / 16.0 * (uMax - uMin));
vMax = vMax - (maskTop / 16.0 * (vMax - vMin));
Tessellator tessellator = Tessellator.getInstance();
VertexBuffer vertexBuffer = tessellator.getBuffer();
vertexBuffer.begin(7, DefaultVertexFormats.POSITION_TEX);
vertexBuffer.pos(xCoord, yCoord + 16, zLevel).tex(uMin, vMax).endVertex();
vertexBuffer.pos(xCoord + 16 - maskRight, yCoord + 16, zLevel).tex(uMax, vMax).endVertex();
vertexBuffer.pos(xCoord + 16 - maskRight, yCoord + maskTop, zLevel).tex(uMax, vMin).endVertex();
vertexBuffer.pos(xCoord, yCoord + maskTop, zLevel).tex(uMin, vMin).endVertex();
tessellator.draw();
}
}

View File

@@ -0,0 +1,217 @@
package refinedstorage.apiimpl.storage.fluid;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.FluidStack;
import refinedstorage.api.storage.CompareUtils;
import refinedstorage.api.storage.fluid.IFluidStorage;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
/**
* A implementation of {@link IFluidStorage} that stores storage fluids in NBT.
*/
public abstract class FluidStorageNBT implements IFluidStorage {
/**
* The current save protocol that is used. It's set to every {@link FluidStorageNBT} to allow for
* safe backwards compatibility breaks.
*/
private static final int PROTOCOL = 1;
private static final String NBT_PROTOCOL = "Protocol";
private static final String NBT_FLUIDS = "Fluids";
private static final String NBT_STORED = "Stored";
private NBTTagCompound tag;
private int capacity;
private TileEntity tile;
private List<FluidStack> stacks = new ArrayList<>();
/**
* @param tag The NBT tag we are reading from and writing the amount stored to, has to be initialized with {@link FluidStorageNBT#createNBT()} if it doesn't exist yet
* @param capacity The capacity of this storage, -1 for infinite capacity
* @param tile A {@link TileEntity} that the NBT storage is in, will be marked dirty when the storage changes
*/
public FluidStorageNBT(NBTTagCompound tag, int capacity, @Nullable TileEntity tile) {
this.tag = tag;
this.capacity = capacity;
this.tile = tile;
readFromNBT();
}
public void readFromNBT() {
NBTTagList list = (NBTTagList) tag.getTag(NBT_FLUIDS);
for (int i = 0; i < list.tagCount(); ++i) {
FluidStack stack = FluidStack.loadFluidStackFromNBT(list.getCompoundTagAt(i));
if (stack != null) {
stacks.add(stack);
}
}
}
/**
* Writes the items to the NBT tag.
*/
public void writeToNBT() {
NBTTagList list = new NBTTagList();
for (FluidStack stack : stacks) {
list.appendTag(stack.writeToNBT(new NBTTagCompound()));
}
tag.setTag(NBT_FLUIDS, list);
tag.setInteger(NBT_PROTOCOL, PROTOCOL);
}
@Override
public List<FluidStack> getStacks() {
return stacks;
}
@Override
public FluidStack insertFluid(FluidStack stack, int size, boolean simulate) {
for (FluidStack otherStack : stacks) {
if (otherStack.isFluidEqual(stack)) {
if (getCapacity() != -1 && getStored() + size > getCapacity()) {
int remainingSpace = getCapacity() - getStored();
if (remainingSpace <= 0) {
return FluidUtils.copyStackWithSize(stack, size);
}
if (!simulate) {
tag.setInteger(NBT_STORED, getStored() + remainingSpace);
otherStack.amount += remainingSpace;
onStorageChanged();
}
return FluidUtils.copyStackWithSize(otherStack, size - remainingSpace);
} else {
if (!simulate) {
tag.setInteger(NBT_STORED, getStored() + size);
otherStack.amount += size;
onStorageChanged();
}
return null;
}
}
}
if (getCapacity() != -1 && getStored() + size > getCapacity()) {
int remainingSpace = getCapacity() - getStored();
if (remainingSpace <= 0) {
return FluidUtils.copyStackWithSize(stack, size);
}
if (!simulate) {
tag.setInteger(NBT_STORED, getStored() + remainingSpace);
stacks.add(FluidUtils.copyStackWithSize(stack, remainingSpace));
onStorageChanged();
}
return FluidUtils.copyStackWithSize(stack, size - remainingSpace);
} else {
if (!simulate) {
tag.setInteger(NBT_STORED, getStored() + size);
stacks.add(FluidUtils.copyStackWithSize(stack, size));
onStorageChanged();
}
return null;
}
}
@Override
public FluidStack extractFluid(FluidStack stack, int size, int flags) {
for (FluidStack otherStack : stacks) {
if (CompareUtils.compareStack(otherStack, stack, flags)) {
if (size > otherStack.amount) {
size = otherStack.amount;
}
if (otherStack.amount - size == 0) {
stacks.remove(otherStack);
} else {
otherStack.amount -= size;
}
tag.setInteger(NBT_STORED, getStored() - size);
onStorageChanged();
return FluidUtils.copyStackWithSize(otherStack, size);
}
}
return null;
}
public void onStorageChanged() {
if (tile != null) {
tile.markDirty();
}
}
@Override
public int getStored() {
return getStoredFromNBT(tag);
}
public int getCapacity() {
return capacity;
}
public NBTTagCompound getTag() {
return tag;
}
public static int getStoredFromNBT(NBTTagCompound tag) {
return tag.getInteger(NBT_STORED);
}
/*
* @return A NBT tag initialized with the fields that {@link NBTStorage} uses
*/
public static NBTTagCompound createNBT() {
NBTTagCompound tag = new NBTTagCompound();
tag.setTag(NBT_FLUIDS, new NBTTagList());
tag.setInteger(NBT_STORED, 0);
tag.setInteger(NBT_PROTOCOL, PROTOCOL);
return tag;
}
public static boolean isValid(ItemStack stack) {
return stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_FLUIDS) && stack.getTagCompound().hasKey(NBT_STORED);
}
/**
* @param stack The {@link ItemStack} to populate with the NBT tags from {@link FluidStorageNBT#createNBT()}
* @return The provided {@link ItemStack} with NBT tags from {@link FluidStorageNBT#createNBT()}
*/
public static ItemStack createStackWithNBT(ItemStack stack) {
stack.setTagCompound(createNBT());
return stack;
}
}

View File

@@ -0,0 +1,68 @@
package refinedstorage.apiimpl.storage.fluid;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidContainerItem;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import refinedstorage.api.autocrafting.ICraftingPattern;
import refinedstorage.api.network.INetworkMaster;
import refinedstorage.api.network.NetworkUtils;
public final class FluidUtils {
public static final ItemStack EMPTY_BUCKET = new ItemStack(Items.BUCKET);
public static FluidStack copyStackWithSize(FluidStack stack, int size) {
FluidStack copy = stack.copy();
copy.amount = size;
return copy;
}
public static FluidStack copy(FluidStack stack) {
return stack == null ? null : stack.copy();
}
public static FluidStack getFluidFromStack(ItemStack stack, boolean simulate) {
if (stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null)) {
return stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null).drain(Fluid.BUCKET_VOLUME, !simulate);
} else if (stack.getItem() instanceof IFluidContainerItem) {
return ((IFluidContainerItem) stack.getItem()).drain(stack, Fluid.BUCKET_VOLUME, !simulate);
}
return null;
}
public static boolean hasFluidBucket(FluidStack stack) {
return stack.getFluid() == FluidRegistry.WATER || stack.getFluid() == FluidRegistry.LAVA || FluidRegistry.getBucketFluids().contains(stack.getFluid());
}
public static ItemStack extractItemOrIfBucketLookInFluids(INetworkMaster network, ItemStack stack, int size) {
ItemStack result = NetworkUtils.extractItem(network, stack, size);
if (result == null && stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null)) {
FluidStack fluidStack = getFluidFromStack(stack, true);
if (fluidStack != null && hasFluidBucket(fluidStack)) {
result = extractBucket(network);
if (result != null) {
result.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null).fill(NetworkUtils.extractFluid(network, fluidStack, Fluid.BUCKET_VOLUME), true);
} else {
ICraftingPattern pattern = NetworkUtils.getPattern(network, EMPTY_BUCKET);
if (pattern != null) {
network.addCraftingTask(network.createCraftingTask(pattern));
}
}
}
}
return result;
}
public static ItemStack extractBucket(INetworkMaster network) {
return NetworkUtils.extractItem(network, EMPTY_BUCKET, 1);
}
}

View File

@@ -0,0 +1,119 @@
package refinedstorage.apiimpl.storage.fluid;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import refinedstorage.api.network.INetworkMaster;
import refinedstorage.api.network.NetworkUtils;
import refinedstorage.api.storage.CompareUtils;
import refinedstorage.api.storage.fluid.IFluidStorage;
import refinedstorage.api.storage.fluid.IFluidStorageProvider;
import refinedstorage.api.storage.fluid.IGroupedFluidStorage;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class GroupedFluidStorage implements IGroupedFluidStorage {
private INetworkMaster network;
private List<IFluidStorage> storages = new ArrayList<>();
private Multimap<Fluid, FluidStack> stacks = ArrayListMultimap.create();
public GroupedFluidStorage(INetworkMaster network) {
this.network = network;
}
@Override
public void rebuild() {
storages.clear();
network.getNodeGraph().all().stream()
.filter(node -> node.canUpdate() && node instanceof IFluidStorageProvider)
.forEach(node -> ((IFluidStorageProvider) node).addFluidStorages(storages));
stacks.clear();
for (IFluidStorage storage : storages) {
for (FluidStack stack : storage.getStacks()) {
add(stack, true);
}
}
network.sendFluidStorageToClient();
}
@Override
public void add(@Nonnull FluidStack stack, boolean rebuilding) {
for (FluidStack otherStack : stacks.get(stack.getFluid())) {
if (otherStack.isFluidEqual(stack)) {
otherStack.amount += stack.amount;
if (!rebuilding) {
network.sendFluidStorageDeltaToClient(stack, stack.amount);
}
return;
}
}
stacks.put(stack.getFluid(), stack.copy());
if (!rebuilding) {
network.sendFluidStorageDeltaToClient(stack, stack.amount);
}
}
@Override
public void remove(@Nonnull FluidStack stack) {
for (FluidStack otherStack : stacks.get(stack.getFluid())) {
if (otherStack.isFluidEqual(stack)) {
otherStack.amount -= stack.amount;
if (otherStack.amount == 0) {
stacks.remove(otherStack.getFluid(), otherStack);
}
network.sendFluidStorageDeltaToClient(stack, -stack.amount);
return;
}
}
}
@Override
@Nullable
public FluidStack get(@Nonnull FluidStack stack, int flags) {
for (FluidStack otherStack : stacks.get(stack.getFluid())) {
if (CompareUtils.compareStack(otherStack, stack, flags)) {
return otherStack;
}
}
return null;
}
@Override
@Nullable
public FluidStack get(int hash) {
for (FluidStack stack : this.stacks.values()) {
if (NetworkUtils.getFluidStackHashCode(stack) == hash) {
return stack;
}
}
return null;
}
@Override
public Collection<FluidStack> getStacks() {
return stacks.values();
}
@Override
public List<IFluidStorage> getStorages() {
return storages;
}
}

View File

@@ -1,27 +1,29 @@
package refinedstorage.apiimpl.storage;
package refinedstorage.apiimpl.storage.item;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import refinedstorage.RefinedStorageUtils;
import refinedstorage.api.autocrafting.ICraftingPattern;
import refinedstorage.api.network.INetworkMaster;
import refinedstorage.api.network.INetworkNode;
import refinedstorage.api.storage.IGroupedStorage;
import refinedstorage.api.storage.IStorage;
import refinedstorage.api.storage.IStorageProvider;
import refinedstorage.api.network.NetworkUtils;
import refinedstorage.api.storage.CompareUtils;
import refinedstorage.api.storage.item.IGroupedItemStorage;
import refinedstorage.api.storage.item.IItemStorage;
import refinedstorage.api.storage.item.IItemStorageProvider;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class GroupedStorage implements IGroupedStorage {
public class GroupedItemStorage implements IGroupedItemStorage {
private INetworkMaster network;
private List<IStorage> storages = new ArrayList<IStorage>();
private List<IItemStorage> storages = new ArrayList<>();
private Multimap<Item, ItemStack> stacks = ArrayListMultimap.create();
public GroupedStorage(INetworkMaster network) {
public GroupedItemStorage(INetworkMaster network) {
this.network = network;
}
@@ -29,15 +31,13 @@ public class GroupedStorage implements IGroupedStorage {
public void rebuild() {
storages.clear();
for (INetworkNode node : network.getNodes()) {
if (node.canUpdate() && node instanceof IStorageProvider) {
((IStorageProvider) node).addStorages(storages);
}
}
network.getNodeGraph().all().stream()
.filter(node -> node.canUpdate() && node instanceof IItemStorageProvider)
.forEach(node -> ((IItemStorageProvider) node).addItemStorages(storages));
stacks.clear();
for (IStorage storage : storages) {
for (IItemStorage storage : storages) {
for (ItemStack stack : storage.getItems()) {
add(stack, true);
}
@@ -51,17 +51,17 @@ public class GroupedStorage implements IGroupedStorage {
}
}
network.sendStorageToClient();
network.sendItemStorageToClient();
}
@Override
public void add(ItemStack stack, boolean rebuilding) {
public void add(@Nonnull ItemStack stack, boolean rebuilding) {
for (ItemStack otherStack : stacks.get(stack.getItem())) {
if (RefinedStorageUtils.compareStackNoQuantity(otherStack, stack)) {
if (CompareUtils.compareStackNoQuantity(otherStack, stack)) {
otherStack.stackSize += stack.stackSize;
if (!rebuilding) {
network.sendStorageDeltaToClient(stack, stack.stackSize);
network.sendItemStorageDeltaToClient(stack, stack.stackSize);
}
return;
@@ -71,23 +71,23 @@ public class GroupedStorage implements IGroupedStorage {
stacks.put(stack.getItem(), stack.copy());
if (!rebuilding) {
network.sendStorageDeltaToClient(stack, stack.stackSize);
network.sendItemStorageDeltaToClient(stack, stack.stackSize);
}
}
@Override
public void remove(ItemStack stack) {
public void remove(@Nonnull ItemStack stack) {
for (ItemStack otherStack : stacks.get(stack.getItem())) {
if (RefinedStorageUtils.compareStackNoQuantity(otherStack, stack)) {
if (CompareUtils.compareStackNoQuantity(otherStack, stack)) {
otherStack.stackSize -= stack.stackSize;
if (otherStack.stackSize == 0) {
if (!RefinedStorageUtils.hasPattern(network, stack)) {
if (!NetworkUtils.hasPattern(network, stack)) {
stacks.remove(otherStack.getItem(), otherStack);
}
}
network.sendStorageDeltaToClient(stack, -stack.stackSize);
network.sendItemStorageDeltaToClient(stack, -stack.stackSize);
return;
}
@@ -95,9 +95,10 @@ public class GroupedStorage implements IGroupedStorage {
}
@Override
public ItemStack get(ItemStack stack, int flags) {
@Nullable
public ItemStack get(@Nonnull ItemStack stack, int flags) {
for (ItemStack otherStack : stacks.get(stack.getItem())) {
if (RefinedStorageUtils.compareStack(otherStack, stack, flags)) {
if (CompareUtils.compareStack(otherStack, stack, flags)) {
return otherStack;
}
}
@@ -106,9 +107,10 @@ public class GroupedStorage implements IGroupedStorage {
}
@Override
public ItemStack get(int id) {
@Nullable
public ItemStack get(int hash) {
for (ItemStack stack : this.stacks.values()) {
if (RefinedStorageUtils.getItemStackHashCode(stack) == id) {
if (NetworkUtils.getItemStackHashCode(stack) == hash) {
return stack;
}
}
@@ -122,7 +124,7 @@ public class GroupedStorage implements IGroupedStorage {
}
@Override
public List<IStorage> getStorages() {
public List<IItemStorage> getStorages() {
return storages;
}
}

View File

@@ -1,4 +1,4 @@
package refinedstorage.apiimpl.storage;
package refinedstorage.apiimpl.storage.item;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -6,19 +6,19 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.items.ItemHandlerHelper;
import refinedstorage.RefinedStorageUtils;
import refinedstorage.api.storage.IStorage;
import refinedstorage.api.storage.CompareUtils;
import refinedstorage.api.storage.item.IItemStorage;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
/**
* A implementation of {@link IStorage} that stores storage items in NBT.
* A implementation of {@link IItemStorage} that stores storage items in NBT.
*/
public abstract class NBTStorage implements IStorage {
public abstract class ItemStorageNBT implements IItemStorage {
/**
* The current save protocol that is used. It's set to every {@link NBTStorage} to allow for
* The current save protocol that is used. It's set to every {@link ItemStorageNBT} to allow for
* safe backwards compatibility breaks.
*/
private static final int PROTOCOL = 1;
@@ -38,14 +38,14 @@ public abstract class NBTStorage implements IStorage {
private int capacity;
private TileEntity tile;
private List<ItemStack> stacks = new ArrayList<ItemStack>();
private List<ItemStack> stacks = new ArrayList<>();
/**
* @param tag The NBT tag we are reading from and writing the amount stored to, has to be initialized with {@link NBTStorage#createNBT()} if it doesn't exist yet
* @param tag The NBT tag we are reading from and writing the amount stored to, has to be initialized with {@link ItemStorageNBT#createNBT()} if it doesn't exist yet
* @param capacity The capacity of this storage, -1 for infinite capacity
* @param tile A {@link TileEntity} that the NBT storage is in, will be marked dirty when the storage changes
*/
public NBTStorage(NBTTagCompound tag, int capacity, @Nullable TileEntity tile) {
public ItemStorageNBT(NBTTagCompound tag, int capacity, @Nullable TileEntity tile) {
this.tag = tag;
this.capacity = capacity;
this.tile = tile;
@@ -117,7 +117,7 @@ public abstract class NBTStorage implements IStorage {
@Override
public ItemStack insertItem(ItemStack stack, int size, boolean simulate) {
for (ItemStack otherStack : stacks) {
if (RefinedStorageUtils.compareStackNoQuantity(otherStack, stack)) {
if (CompareUtils.compareStackNoQuantity(otherStack, stack)) {
if (getCapacity() != -1 && getStored() + size > getCapacity()) {
int remainingSpace = getCapacity() - getStored();
@@ -180,7 +180,7 @@ public abstract class NBTStorage implements IStorage {
@Override
public ItemStack extractItem(ItemStack stack, int size, int flags) {
for (ItemStack otherStack : stacks) {
if (RefinedStorageUtils.compareStack(otherStack, stack, flags)) {
if (CompareUtils.compareStack(otherStack, stack, flags)) {
if (size > otherStack.stackSize) {
size = otherStack.stackSize;
}
@@ -243,8 +243,8 @@ public abstract class NBTStorage implements IStorage {
}
/**
* @param stack The {@link ItemStack} to populate with the NBT tags from {@link NBTStorage#createNBT()}
* @return The provided {@link ItemStack} with NBT tags from {@link NBTStorage#createNBT()}
* @param stack The {@link ItemStack} to populate with the NBT tags from {@link ItemStorageNBT#createNBT()}
* @return The provided {@link ItemStack} with NBT tags from {@link ItemStorageNBT#createNBT()}
*/
public static ItemStack createStackWithNBT(ItemStack stack) {
stack.setTagCompound(createNBT());

View File

@@ -17,12 +17,11 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import refinedstorage.RefinedStorage;
import refinedstorage.RefinedStorageUtils;
import refinedstorage.item.ItemBlockBase;
import refinedstorage.tile.TileBase;
public abstract class BlockBase extends Block {
public static final PropertyDirection DIRECTION = PropertyDirection.create("direction");
private static final PropertyDirection DIRECTION = PropertyDirection.create("direction");
private String name;
@@ -91,7 +90,7 @@ public abstract class BlockBase extends Block {
tile.setDirection(getPlacementType().getNext(tile.getDirection()));
RefinedStorageUtils.updateBlock(world, pos);
tile.updateBlock();
return true;
}
@@ -99,12 +98,23 @@ public abstract class BlockBase extends Block {
return false;
}
@Override
public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase entity) {
IBlockState state = super.onBlockPlaced(world, pos, facing, hitX, hitY, hitZ, meta, entity);
if (getPlacementType() != null) {
return state.withProperty(DIRECTION, getPlacementType().getFrom(facing, pos, entity));
}
return state;
}
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack) {
super.onBlockPlacedBy(world, pos, state, player, stack);
if (getPlacementType() != null) {
((TileBase) world.getTileEntity(pos)).setDirection(getPlacementType().getFrom(pos, player));
((TileBase) world.getTileEntity(pos)).setDirection(state.getValue(DIRECTION));
}
}
@@ -112,8 +122,8 @@ public abstract class BlockBase extends Block {
public void breakBlock(World world, BlockPos pos, IBlockState state) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileBase && ((TileBase) tile).getDroppedItems() != null) {
IItemHandler handler = ((TileBase) tile).getDroppedItems();
if (tile instanceof TileBase && ((TileBase) tile).getDrops() != null) {
IItemHandler handler = ((TileBase) tile).getDrops();
for (int i = 0; i < handler.getSlots(); ++i) {
if (handler.getStackInSlot(i) != null) {
@@ -137,7 +147,7 @@ public abstract class BlockBase extends Block {
world.setBlockToAir(pos);
}
public EnumPlacementType getPlacementType() {
protected EnumPlacementType getPlacementType() {
return EnumPlacementType.HORIZONTAL;
}
}

View File

@@ -1,83 +1,226 @@
package refinedstorage.block;
import mcmultipart.block.BlockCoverable;
import mcmultipart.block.BlockMultipartContainer;
import mcmultipart.raytrace.RayTraceUtils;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import refinedstorage.RefinedStorage;
import refinedstorage.api.network.INetworkMaster;
import refinedstorage.api.network.INetworkNode;
import refinedstorage.api.network.NetworkUtils;
import refinedstorage.tile.TileBase;
import refinedstorage.tile.TileCable;
import refinedstorage.tile.TileMultipartNode;
import refinedstorage.tile.TileNode;
public class BlockCable extends BlockNode {
private static final AxisAlignedBB CABLE_AABB = new AxisAlignedBB(4 * (1F / 16F), 4 * (1F / 16F), 4 * (1F / 16F), 1 - 4 * (1F / 16F), 1 - 4 * (1F / 16F), 1 - 4 * (1F / 16F));
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public static final PropertyBool NORTH = PropertyBool.create("north");
public static final PropertyBool EAST = PropertyBool.create("east");
public static final PropertyBool SOUTH = PropertyBool.create("south");
public static final PropertyBool WEST = PropertyBool.create("west");
public static final PropertyBool UP = PropertyBool.create("up");
public static final PropertyBool DOWN = PropertyBool.create("down");
public class BlockCable extends BlockCoverable {
protected static final PropertyDirection DIRECTION = PropertyDirection.create("direction");
protected static AxisAlignedBB createAABB(int fromX, int fromY, int fromZ, int toX, int toY, int toZ) {
return new AxisAlignedBB((float) fromX / 16F, (float) fromY / 16F, (float) fromZ / 16F, (float) toX / 16F, (float) toY / 16F, (float) toZ / 16F);
}
protected static AxisAlignedBB CORE_AABB = createAABB(6, 6, 6, 10, 10, 10);
protected static AxisAlignedBB NORTH_AABB = createAABB(6, 6, 0, 10, 10, 6);
protected static AxisAlignedBB EAST_AABB = createAABB(10, 6, 6, 16, 10, 10);
protected static AxisAlignedBB SOUTH_AABB = createAABB(6, 6, 10, 10, 10, 16);
protected static AxisAlignedBB WEST_AABB = createAABB(0, 6, 6, 6, 10, 10);
protected static AxisAlignedBB UP_AABB = createAABB(6, 10, 6, 10, 16, 10);
protected static AxisAlignedBB DOWN_AABB = createAABB(6, 0, 6, 10, 6, 10);
protected static final PropertyBool NORTH = PropertyBool.create("north");
protected static final PropertyBool EAST = PropertyBool.create("east");
protected static final PropertyBool SOUTH = PropertyBool.create("south");
protected static final PropertyBool WEST = PropertyBool.create("west");
protected static final PropertyBool UP = PropertyBool.create("up");
protected static final PropertyBool DOWN = PropertyBool.create("down");
private String name;
public BlockCable(String name) {
super(name);
super(Material.ROCK);
this.name = name;
setHardness(0.6F);
setRegistryName(RefinedStorage.ID, name);
setCreativeTab(RefinedStorage.INSTANCE.tab);
}
public BlockCable() {
this("cable");
}
@Override
public String getUnlocalizedName() {
return "block." + RefinedStorage.ID + ":" + name;
}
public String getName() {
return name;
}
@Override
public boolean canProvidePower(IBlockState state) {
return false;
}
@Override
public boolean hasTileEntity(IBlockState state) {
return true;
}
@Override
public TileEntity createTileEntity(World world, IBlockState state) {
return new TileCable();
}
@Override
protected BlockStateContainer.Builder createBlockStateBuilder() {
return super.createBlockStateBuilder()
.add(NORTH)
protected BlockStateContainer createBlockState() {
BlockStateContainer.Builder builder = new BlockStateContainer.Builder(this);
builder.add(NORTH)
.add(EAST)
.add(SOUTH)
.add(WEST)
.add(UP)
.add(DOWN);
.add(DOWN)
.add(BlockMultipartContainer.PROPERTY_MULTIPART_CONTAINER);
if (getPlacementType() != null) {
builder.add(DIRECTION);
}
return builder.build();
}
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
return super.getActualState(state, world, pos)
.withProperty(NORTH, hasConnectionWith(world, pos, pos.north()))
.withProperty(EAST, hasConnectionWith(world, pos, pos.east()))
.withProperty(SOUTH, hasConnectionWith(world, pos, pos.south()))
.withProperty(WEST, hasConnectionWith(world, pos, pos.west()))
.withProperty(UP, hasConnectionWith(world, pos, pos.up()))
.withProperty(DOWN, hasConnectionWith(world, pos, pos.down()));
state = super.getActualState(state, world, pos)
.withProperty(NORTH, hasConnectionWith(world, pos, EnumFacing.NORTH))
.withProperty(EAST, hasConnectionWith(world, pos, EnumFacing.EAST))
.withProperty(SOUTH, hasConnectionWith(world, pos, EnumFacing.SOUTH))
.withProperty(WEST, hasConnectionWith(world, pos, EnumFacing.WEST))
.withProperty(UP, hasConnectionWith(world, pos, EnumFacing.UP))
.withProperty(DOWN, hasConnectionWith(world, pos, EnumFacing.DOWN));
if (getPlacementType() != null) {
state = state.withProperty(DIRECTION, ((TileNode) world.getTileEntity(pos)).getDirection());
}
return state;
}
private boolean hasConnectionWith(IBlockAccess world, BlockPos basePos, BlockPos pos) {
TileEntity tile = world.getTileEntity(pos);
private boolean hasConnectionWith(IBlockAccess world, BlockPos pos, EnumFacing direction) {
TileEntity facing = world.getTileEntity(pos.offset(direction));
if (tile instanceof INetworkMaster || tile instanceof INetworkNode) {
// Do not render a cable extension to on this position when we have a direction (like an exporter, importer or external storage)
if (getPlacementType() != null) {
return ((TileBase) world.getTileEntity(basePos)).getFacingTile() != tile;
if (facing instanceof INetworkMaster || facing instanceof INetworkNode) {
// Do not render a cable extension where our cable "head" is (e.g. importer, exporter, external storage heads).
if (getPlacementType() != null && ((TileMultipartNode) world.getTileEntity(pos)).getFacingTile() == facing) {
return false;
}
return true;
return !TileMultipartNode.hasBlockingMicroblock(world, pos, direction) && !TileMultipartNode.hasBlockingMicroblock(world, pos.offset(direction), direction.getOpposite());
}
return false;
}
private boolean isInAABB(AxisAlignedBB aabb, float hitX, float hitY, float hitZ) {
return hitX >= aabb.minX && hitX <= aabb.maxX && hitY >= aabb.minY && hitY <= aabb.maxY && hitZ >= aabb.minZ && hitZ <= aabb.maxZ;
}
protected boolean hitCablePart(IBlockState state, World world, BlockPos pos, float hitX, float hitY, float hitZ) {
state = getActualState(state, world, pos);
return isInAABB(CORE_AABB, hitX, hitY, hitZ) ||
(state.getValue(NORTH) && isInAABB(NORTH_AABB, hitX, hitY, hitZ)) ||
(state.getValue(EAST) && isInAABB(EAST_AABB, hitX, hitY, hitZ)) ||
(state.getValue(SOUTH) && isInAABB(SOUTH_AABB, hitX, hitY, hitZ)) ||
(state.getValue(WEST) && isInAABB(WEST_AABB, hitX, hitY, hitZ)) ||
(state.getValue(UP) && isInAABB(UP_AABB, hitX, hitY, hitZ)) ||
(state.getValue(DOWN) && isInAABB(DOWN_AABB, hitX, hitY, hitZ));
}
public List<AxisAlignedBB> getUnionizedCollisionBoxes(IBlockState state) {
List<AxisAlignedBB> boxes = new ArrayList<>();
boxes.add(CORE_AABB);
if (state.getValue(NORTH)) {
boxes.add(NORTH_AABB);
}
if (state.getValue(EAST)) {
boxes.add(EAST_AABB);
}
if (state.getValue(SOUTH)) {
boxes.add(SOUTH_AABB);
}
if (state.getValue(WEST)) {
boxes.add(WEST_AABB);
}
if (state.getValue(UP)) {
boxes.add(UP_AABB);
}
if (state.getValue(DOWN)) {
boxes.add(DOWN_AABB);
}
return boxes;
}
public List<AxisAlignedBB> getNonUnionizedCollisionBoxes(IBlockState state) {
return Collections.emptyList();
}
public List<AxisAlignedBB> getCollisionBoxes(IBlockState state) {
List<AxisAlignedBB> boxes = new ArrayList<>();
boxes.addAll(getUnionizedCollisionBoxes(state));
boxes.addAll(getNonUnionizedCollisionBoxes(state));
return boxes;
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess world, BlockPos pos) {
return CABLE_AABB;
public void addCollisionBoxToListDefault(IBlockState state, World world, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn) {
for (AxisAlignedBB aabb : getCollisionBoxes(this.getActualState(state, world, pos))) {
addCollisionBoxToList(pos, entityBox, collidingBoxes, aabb);
}
}
@Override
public RayTraceResult collisionRayTraceDefault(IBlockState state, World world, BlockPos pos, Vec3d start, Vec3d end) {
RayTraceUtils.AdvancedRayTraceResult result = RayTraceUtils.collisionRayTrace(world, pos, start, end, getCollisionBoxes(this.getActualState(state, world, pos)));
return result != null ? result.hit : null;
}
@Override
@@ -90,8 +233,113 @@ public class BlockCable extends BlockNode {
return false;
}
@Override
public EnumPlacementType getPlacementType() {
protected EnumPlacementType getPlacementType() {
return null;
}
@Override
public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase entity) {
IBlockState state = super.onBlockPlaced(world, pos, facing, hitX, hitY, hitZ, meta, entity);
if (getPlacementType() != null) {
return state.withProperty(DIRECTION, getPlacementType().getFrom(facing, pos, entity));
}
return state;
}
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack) {
super.onBlockPlacedBy(world, pos, state, player, stack);
if (getPlacementType() != null) {
((TileBase) world.getTileEntity(pos)).setDirection(state.getValue(DIRECTION));
}
attemptConnect(world, pos);
}
public void attemptConnect(World world, BlockPos pos) {
if (!world.isRemote) {
for (EnumFacing facing : EnumFacing.VALUES) {
TileEntity tile = world.getTileEntity(pos.offset(facing));
if (tile instanceof TileNode && ((TileNode) tile).isConnected()) {
NetworkUtils.rebuildGraph(((TileNode) tile).getNetwork());
break;
}
}
}
}
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
INetworkMaster network = null;
if (!world.isRemote) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileNode) {
network = ((TileNode) tile).getNetwork();
}
if (tile instanceof TileBase && ((TileBase) tile).getDrops() != null) {
IItemHandler handler = ((TileBase) tile).getDrops();
for (int i = 0; i < handler.getSlots(); ++i) {
if (handler.getStackInSlot(i) != null) {
InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), handler.getStackInSlot(i));
}
}
}
}
super.breakBlock(world, pos, state);
if (network != null) {
NetworkUtils.rebuildGraph(network);
}
}
@Override
public List<ItemStack> getDropsDefault(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
List<ItemStack> drops = new ArrayList<>();
drops.add(new ItemStack(this, 1, getMetaFromState(state)));
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileBase && ((TileBase) tile).getDrops() != null) {
IItemHandler handler = ((TileBase) tile).getDrops();
for (int i = 0; i < handler.getSlots(); ++i) {
if (handler.getStackInSlot(i) != null) {
drops.add(handler.getStackInSlot(i));
}
}
}
return drops;
}
@Override
public boolean rotateBlock(World world, BlockPos pos, EnumFacing axis) {
if (!world.isRemote && getPlacementType() != null) {
TileBase tile = (TileBase) world.getTileEntity(pos);
tile.setDirection(getPlacementType().getNext(tile.getDirection()));
tile.updateBlock();
return true;
}
return false;
}
@Override
public BlockRenderLayer getBlockLayer() {
return RefinedStorage.INSTANCE.translucentCables ? BlockRenderLayer.TRANSLUCENT : super.getBlockLayer();
}
}

View File

@@ -6,15 +6,71 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import refinedstorage.RefinedStorage;
import refinedstorage.RefinedStorageGui;
import refinedstorage.tile.TileConstructor;
import java.util.ArrayList;
import java.util.List;
public class BlockConstructor extends BlockCable {
public static final AxisAlignedBB HOLDER_NORTH_AABB = createAABB(7, 7, 2, 9, 9, 6);
public static final AxisAlignedBB HOLDER_EAST_AABB = createAABB(10, 7, 7, 14, 9, 9);
public static final AxisAlignedBB HOLDER_SOUTH_AABB = createAABB(7, 7, 10, 9, 9, 14);
public static final AxisAlignedBB HOLDER_WEST_AABB = createAABB(2, 7, 7, 6, 9, 9);
public static final AxisAlignedBB HOLDER_UP_AABB = createAABB(7, 10, 7, 9, 14, 9);
public static final AxisAlignedBB HOLDER_DOWN_AABB = createAABB(7, 2, 7, 9, 6, 9);
public static final AxisAlignedBB HEAD_NORTH_AABB = createAABB(0, 0, 0, 16, 16, 2);
public static final AxisAlignedBB HEAD_EAST_AABB = createAABB(14, 0, 0, 16, 16, 16);
public static final AxisAlignedBB HEAD_SOUTH_AABB = createAABB(0, 0, 14, 16, 16, 16);
public static final AxisAlignedBB HEAD_WEST_AABB = createAABB(0, 0, 0, 2, 16, 16);
public static final AxisAlignedBB HEAD_DOWN_AABB = createAABB(0, 0, 0, 16, 2, 16);
public static final AxisAlignedBB HEAD_UP_AABB = createAABB(0, 14, 0, 16, 16, 16);
public BlockConstructor(String name) {
super(name);
}
public BlockConstructor() {
super("constructor");
this("constructor");
}
@Override
public List<AxisAlignedBB> getNonUnionizedCollisionBoxes(IBlockState state) {
List<AxisAlignedBB> boxes = new ArrayList<>();
switch (state.getValue(DIRECTION)) {
case NORTH:
boxes.add(HOLDER_NORTH_AABB);
boxes.add(HEAD_NORTH_AABB);
break;
case EAST:
boxes.add(HOLDER_EAST_AABB);
boxes.add(HEAD_EAST_AABB);
break;
case SOUTH:
boxes.add(HOLDER_SOUTH_AABB);
boxes.add(HEAD_SOUTH_AABB);
break;
case WEST:
boxes.add(HOLDER_WEST_AABB);
boxes.add(HEAD_WEST_AABB);
break;
case UP:
boxes.add(HOLDER_UP_AABB);
boxes.add(HEAD_UP_AABB);
break;
case DOWN:
boxes.add(HOLDER_DOWN_AABB);
boxes.add(HEAD_DOWN_AABB);
break;
}
return boxes;
}
@Override
@@ -23,7 +79,11 @@ public class BlockConstructor extends BlockCable {
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
public boolean onBlockActivatedDefault(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
if (hitCablePart(state, world, pos, hitX, hitY, hitZ)) {
return false;
}
if (!world.isRemote) {
player.openGui(RefinedStorage.INSTANCE, RefinedStorageGui.CONSTRUCTOR, world, pos.getX(), pos.getY(), pos.getZ());
}

View File

@@ -20,22 +20,24 @@ import net.minecraft.world.World;
import refinedstorage.RefinedStorage;
import refinedstorage.RefinedStorageBlocks;
import refinedstorage.RefinedStorageGui;
import refinedstorage.api.network.NetworkUtils;
import refinedstorage.item.ItemBlockController;
import refinedstorage.tile.controller.TileController;
import refinedstorage.tile.TileController;
import java.util.ArrayList;
import java.util.List;
public class BlockController extends BlockBase {
public static final PropertyEnum TYPE = PropertyEnum.create("type", EnumControllerType.class);
public static final PropertyInteger ENERGY = PropertyInteger.create("energy", 0, 7);
private static final PropertyInteger ENERGY = PropertyInteger.create("energy", 0, 7);
public BlockController() {
super("controller");
}
@Override
public void getSubBlocks(Item item, CreativeTabs tab, List subItems) {
public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> subItems) {
for (int i = 0; i <= 1; i++) {
subItems.add(ItemBlockController.createStackWithNBT(new ItemStack(item, 1, i)));
}
@@ -104,7 +106,7 @@ public class BlockController extends BlockBase {
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
if (!world.isRemote) {
((TileController) world.getTileEntity(pos)).disconnectAll();
((TileController) world.getTileEntity(pos)).getNodeGraph().disconnectAll();
}
super.breakBlock(world, pos, state);
@@ -115,13 +117,13 @@ public class BlockController extends BlockBase {
super.neighborChanged(state, world, pos, block);
if (!world.isRemote) {
((TileController) world.getTileEntity(pos)).rebuildNodes();
NetworkUtils.rebuildGraph((TileController) world.getTileEntity(pos));
}
}
@Override
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
List<ItemStack> drops = new ArrayList<ItemStack>();
List<ItemStack> drops = new ArrayList<>();
ItemStack stack = new ItemStack(RefinedStorageBlocks.CONTROLLER, 1, RefinedStorageBlocks.CONTROLLER.getMetaFromState(state));

View File

@@ -33,7 +33,7 @@ public class BlockCrafter extends BlockNode {
@Override
public EnumPlacementType getPlacementType() {
return EnumPlacementType.ANY;
return EnumPlacementType.ANY_FACE_PLAYER;
}
public boolean hasConnectivityState() {

View File

@@ -6,15 +6,23 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import refinedstorage.RefinedStorage;
import refinedstorage.RefinedStorageBlocks;
import refinedstorage.RefinedStorageGui;
import refinedstorage.tile.TileDestructor;
import java.util.List;
public class BlockDestructor extends BlockCable {
public BlockDestructor(String name) {
super(name);
}
public BlockDestructor() {
super("destructor");
this("destructor");
}
@Override
@@ -23,7 +31,16 @@ public class BlockDestructor extends BlockCable {
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
public List<AxisAlignedBB> getNonUnionizedCollisionBoxes(IBlockState state) {
return RefinedStorageBlocks.CONSTRUCTOR.getNonUnionizedCollisionBoxes(state);
}
@Override
public boolean onBlockActivatedDefault(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
if (hitCablePart(state, world, pos, hitX, hitY, hitZ)) {
return false;
}
if (!world.isRemote) {
player.openGui(RefinedStorage.INSTANCE, RefinedStorageGui.DESTRUCTOR, world, pos.getX(), pos.getY(), pos.getZ());
}

View File

@@ -18,9 +18,9 @@ import refinedstorage.RefinedStorageGui;
import refinedstorage.tile.TileDetector;
public class BlockDetector extends BlockNode {
public static final AxisAlignedBB AABB_DETECTOR = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 4D / 16D, 1.0D);
private static final AxisAlignedBB AABB_DETECTOR = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 4D / 16D, 1.0D);
public static final PropertyBool POWERED = PropertyBool.create("powered");
private static final PropertyBool POWERED = PropertyBool.create("powered");
public BlockDetector() {
super("detector");

View File

@@ -16,7 +16,7 @@ import refinedstorage.RefinedStorageGui;
import refinedstorage.tile.TileDiskDrive;
public class BlockDiskDrive extends BlockNode {
public static final PropertyInteger STORED = PropertyInteger.create("stored", 0, 7);
private static final PropertyInteger STORED = PropertyInteger.create("stored", 0, 7);
public BlockDiskDrive() {
super("disk_drive");
@@ -37,7 +37,7 @@ public class BlockDiskDrive extends BlockNode {
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
return super.getActualState(state, world, pos)
.withProperty(STORED, ((TileDiskDrive) world.getTileEntity(pos)).getStoredForScaledDisplay());
.withProperty(STORED, Math.max(0, ((TileDiskDrive) world.getTileEntity(pos)).getStoredForDisplay()));
}
@Override

View File

@@ -6,24 +6,91 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import refinedstorage.RefinedStorage;
import refinedstorage.RefinedStorageGui;
import refinedstorage.tile.TileExporter;
import java.util.ArrayList;
import java.util.List;
public class BlockExporter extends BlockCable {
public static final AxisAlignedBB LINE_NORTH_1_AABB = createAABB(6, 6, 0, 10, 10, 2);
public static final AxisAlignedBB LINE_NORTH_2_AABB = createAABB(5, 5, 2, 11, 11, 4);
public static final AxisAlignedBB LINE_NORTH_3_AABB = createAABB(3, 3, 4, 13, 13, 6);
public static final AxisAlignedBB LINE_EAST_1_AABB = createAABB(14, 6, 6, 16, 10, 10);
public static final AxisAlignedBB LINE_EAST_2_AABB = createAABB(12, 5, 5, 14, 11, 11);
public static final AxisAlignedBB LINE_EAST_3_AABB = createAABB(10, 3, 3, 12, 13, 13);
public static final AxisAlignedBB LINE_SOUTH_1_AABB = createAABB(6, 6, 14, 10, 10, 16);
public static final AxisAlignedBB LINE_SOUTH_2_AABB = createAABB(5, 5, 12, 11, 11, 14);
public static final AxisAlignedBB LINE_SOUTH_3_AABB = createAABB(3, 3, 10, 13, 13, 12);
public static final AxisAlignedBB LINE_WEST_1_AABB = createAABB(0, 6, 6, 2, 10, 10);
public static final AxisAlignedBB LINE_WEST_2_AABB = createAABB(2, 5, 5, 4, 11, 11);
public static final AxisAlignedBB LINE_WEST_3_AABB = createAABB(4, 3, 3, 6, 13, 13);
public static final AxisAlignedBB LINE_UP_1_AABB = createAABB(6, 14, 6, 10, 16, 10);
public static final AxisAlignedBB LINE_UP_2_AABB = createAABB(5, 12, 5, 11, 14, 11);
public static final AxisAlignedBB LINE_UP_3_AABB = createAABB(3, 10, 3, 13, 12, 13);
public static final AxisAlignedBB LINE_DOWN_1_AABB = createAABB(6, 0, 6, 10, 2, 10);
public static final AxisAlignedBB LINE_DOWN_2_AABB = createAABB(5, 2, 5, 11, 4, 11);
public static final AxisAlignedBB LINE_DOWN_3_AABB = createAABB(3, 4, 3, 13, 6, 13);
public BlockExporter() {
super("exporter");
}
@Override
public List<AxisAlignedBB> getNonUnionizedCollisionBoxes(IBlockState state) {
List<AxisAlignedBB> boxes = new ArrayList<>();
switch (state.getValue(DIRECTION)) {
case NORTH:
boxes.add(LINE_NORTH_1_AABB);
boxes.add(LINE_NORTH_2_AABB);
boxes.add(LINE_NORTH_3_AABB);
break;
case EAST:
boxes.add(LINE_EAST_1_AABB);
boxes.add(LINE_EAST_2_AABB);
boxes.add(LINE_EAST_3_AABB);
break;
case SOUTH:
boxes.add(LINE_SOUTH_1_AABB);
boxes.add(LINE_SOUTH_2_AABB);
boxes.add(LINE_SOUTH_3_AABB);
break;
case WEST:
boxes.add(LINE_WEST_1_AABB);
boxes.add(LINE_WEST_2_AABB);
boxes.add(LINE_WEST_3_AABB);
break;
case UP:
boxes.add(LINE_UP_1_AABB);
boxes.add(LINE_UP_2_AABB);
boxes.add(LINE_UP_3_AABB);
break;
case DOWN:
boxes.add(LINE_DOWN_1_AABB);
boxes.add(LINE_DOWN_2_AABB);
boxes.add(LINE_DOWN_3_AABB);
break;
}
return boxes;
}
@Override
public TileEntity createTileEntity(World world, IBlockState state) {
return new TileExporter();
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
public boolean onBlockActivatedDefault(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
if (hitCablePart(state, world, pos, hitX, hitY, hitZ)) {
return false;
}
if (!world.isRemote) {
player.openGui(RefinedStorage.INSTANCE, RefinedStorageGui.EXPORTER, world, pos.getX(), pos.getY(), pos.getZ());
}

View File

@@ -7,34 +7,83 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import refinedstorage.RefinedStorage;
import refinedstorage.RefinedStorageGui;
import refinedstorage.tile.externalstorage.TileExternalStorage;
import java.util.ArrayList;
import java.util.List;
public class BlockExternalStorage extends BlockCable {
public static final AxisAlignedBB HEAD_NORTH_AABB = createAABB(3, 3, 0, 13, 13, 2);
public static final AxisAlignedBB HEAD_EAST_AABB = createAABB(14, 3, 3, 16, 13, 13);
public static final AxisAlignedBB HEAD_SOUTH_AABB = createAABB(3, 3, 14, 13, 13, 16);
public static final AxisAlignedBB HEAD_WEST_AABB = createAABB(0, 3, 3, 2, 13, 13);
public static final AxisAlignedBB HEAD_UP_AABB = createAABB(3, 14, 3, 13, 16, 13);
public static final AxisAlignedBB HEAD_DOWN_AABB = createAABB(3, 0, 3, 13, 2, 13);
public BlockExternalStorage() {
super("external_storage");
}
@Override
public List<AxisAlignedBB> getNonUnionizedCollisionBoxes(IBlockState state) {
List<AxisAlignedBB> boxes = new ArrayList<>();
switch (state.getValue(DIRECTION)) {
case NORTH:
boxes.add(BlockConstructor.HOLDER_NORTH_AABB);
boxes.add(HEAD_NORTH_AABB);
break;
case EAST:
boxes.add(BlockConstructor.HOLDER_EAST_AABB);
boxes.add(HEAD_EAST_AABB);
break;
case SOUTH:
boxes.add(BlockConstructor.HOLDER_SOUTH_AABB);
boxes.add(HEAD_SOUTH_AABB);
break;
case WEST:
boxes.add(BlockConstructor.HOLDER_WEST_AABB);
boxes.add(HEAD_WEST_AABB);
break;
case UP:
boxes.add(BlockConstructor.HOLDER_UP_AABB);
boxes.add(HEAD_UP_AABB);
break;
case DOWN:
boxes.add(BlockConstructor.HOLDER_DOWN_AABB);
boxes.add(HEAD_DOWN_AABB);
break;
}
return boxes;
}
@Override
public TileEntity createTileEntity(World world, IBlockState state) {
return new TileExternalStorage();
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
public boolean onBlockActivatedDefault(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
if (hitCablePart(state, world, pos, hitX, hitY, hitZ)) {
return false;
}
if (!world.isRemote) {
player.openGui(RefinedStorage.INSTANCE, RefinedStorageGui.STORAGE, world, pos.getX(), pos.getY(), pos.getZ());
player.openGui(RefinedStorage.INSTANCE, RefinedStorageGui.EXTERNAL_STORAGE, world, pos.getX(), pos.getY(), pos.getZ());
}
return true;
}
@Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block block) {
super.neighborChanged(state, world, pos, block);
public void onNeighborBlockChangeDefault(World world, BlockPos pos, IBlockState state, Block neighborBlock) {
super.onNeighborBlockChangeDefault(world, pos, state, neighborBlock);
if (!world.isRemote) {
TileExternalStorage externalStorage = (TileExternalStorage) world.getTileEntity(pos);

View File

@@ -0,0 +1,43 @@
package refinedstorage.block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import refinedstorage.RefinedStorage;
import refinedstorage.RefinedStorageGui;
import refinedstorage.tile.TileFluidInterface;
public class BlockFluidInterface extends BlockNode {
public BlockFluidInterface() {
super("fluid_interface");
}
@Override
public TileEntity createTileEntity(World world, IBlockState state) {
return new TileFluidInterface();
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!world.isRemote) {
player.openGui(RefinedStorage.INSTANCE, RefinedStorageGui.FLUID_INTERFACE, world, pos.getX(), pos.getY(), pos.getZ());
}
return true;
}
@Override
public boolean hasConnectivityState() {
return true;
}
@Override
public EnumPlacementType getPlacementType() {
return null;
}
}

View File

@@ -0,0 +1,114 @@
package refinedstorage.block;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import refinedstorage.RefinedStorage;
import refinedstorage.RefinedStorageBlocks;
import refinedstorage.RefinedStorageGui;
import refinedstorage.item.ItemBlockFluidStorage;
import refinedstorage.tile.TileFluidStorage;
import java.util.ArrayList;
import java.util.List;
public class BlockFluidStorage extends BlockNode {
public static final PropertyEnum TYPE = PropertyEnum.create("type", EnumFluidStorageType.class);
public BlockFluidStorage() {
super("fluid_storage");
setHardness(5.8F);
}
@Override
public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> subItems) {
for (int i = 0; i <= 4; ++i) {
subItems.add(ItemBlockFluidStorage.initNBT(new ItemStack(item, 1, i)));
}
}
@Override
protected BlockStateContainer createBlockState() {
return createBlockStateBuilder()
.add(TYPE)
.build();
}
@Override
public IBlockState getStateFromMeta(int meta) {
return getDefaultState().withProperty(TYPE, EnumFluidStorageType.getById(meta));
}
@Override
public int getMetaFromState(IBlockState state) {
return ((EnumFluidStorageType) state.getValue(TYPE)).getId();
}
@Override
public TileEntity createTileEntity(World world, IBlockState state) {
return new TileFluidStorage();
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!world.isRemote) {
player.openGui(RefinedStorage.INSTANCE, RefinedStorageGui.FLUID_STORAGE, world, pos.getX(), pos.getY(), pos.getZ());
}
return true;
}
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack) {
super.onBlockPlacedBy(world, pos, state, player, stack);
if (!world.isRemote && stack.hasTagCompound() && stack.getTagCompound().hasKey(TileFluidStorage.NBT_STORAGE)) {
((TileFluidStorage) world.getTileEntity(pos)).setStorageTag(stack.getTagCompound().getCompoundTag(TileFluidStorage.NBT_STORAGE));
}
}
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
((TileFluidStorage) world.getTileEntity(pos)).onBreak();
super.breakBlock(world, pos, state);
}
@Override
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
TileFluidStorage storage = (TileFluidStorage) world.getTileEntity(pos);
List<ItemStack> drops = new ArrayList<>();
ItemStack stack = new ItemStack(RefinedStorageBlocks.FLUID_STORAGE, 1, getMetaFromState(state));
stack.setTagCompound(new NBTTagCompound());
stack.getTagCompound().setTag(TileFluidStorage.NBT_STORAGE, storage.getStorageTag());
drops.add(stack);
return drops;
}
@Override
public Item createItem() {
return new ItemBlockFluidStorage();
}
@Override
public EnumPlacementType getPlacementType() {
return null;
}
}

View File

@@ -32,8 +32,8 @@ public class BlockGrid extends BlockNode {
}
@Override
public void getSubBlocks(Item item, CreativeTabs tab, List subItems) {
for (int i = 0; i <= 2; i++) {
public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> subItems) {
for (int i = 0; i <= 3; i++) {
subItems.add(new ItemStack(item, 1, i));
}
}
@@ -47,12 +47,12 @@ public class BlockGrid extends BlockNode {
@Override
public IBlockState getStateFromMeta(int meta) {
return getDefaultState().withProperty(TYPE, meta == 0 ? EnumGridType.NORMAL : (meta == 1 ? EnumGridType.CRAFTING : EnumGridType.PATTERN));
return getDefaultState().withProperty(TYPE, meta == 0 ? EnumGridType.NORMAL : (meta == 1 ? EnumGridType.CRAFTING : (meta == 2 ? EnumGridType.PATTERN : EnumGridType.FLUID)));
}
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(TYPE) == EnumGridType.NORMAL ? 0 : (state.getValue(TYPE) == EnumGridType.CRAFTING ? 1 : 2);
return state.getValue(TYPE) == EnumGridType.NORMAL ? 0 : (state.getValue(TYPE) == EnumGridType.CRAFTING ? 1 : (state.getValue(TYPE) == EnumGridType.PATTERN ? 2 : 3));
}
@Override

View File

@@ -6,15 +6,82 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import refinedstorage.RefinedStorage;
import refinedstorage.RefinedStorageGui;
import refinedstorage.tile.TileImporter;
import java.util.ArrayList;
import java.util.List;
public class BlockImporter extends BlockCable {
public static final AxisAlignedBB LINE_NORTH_1_AABB = createAABB(6, 6, 4, 10, 10, 6);
public static final AxisAlignedBB LINE_NORTH_2_AABB = createAABB(5, 5, 2, 11, 11, 4);
public static final AxisAlignedBB LINE_NORTH_3_AABB = createAABB(3, 3, 0, 13, 13, 2);
public static final AxisAlignedBB LINE_EAST_1_AABB = createAABB(10, 6, 6, 12, 10, 10);
public static final AxisAlignedBB LINE_EAST_2_AABB = createAABB(12, 5, 5, 14, 11, 11);
public static final AxisAlignedBB LINE_EAST_3_AABB = createAABB(14, 3, 3, 16, 13, 13);
public static final AxisAlignedBB LINE_SOUTH_1_AABB = createAABB(6, 6, 10, 10, 10, 12);
public static final AxisAlignedBB LINE_SOUTH_2_AABB = createAABB(5, 5, 12, 11, 11, 14);
public static final AxisAlignedBB LINE_SOUTH_3_AABB = createAABB(3, 3, 14, 13, 13, 16);
public static final AxisAlignedBB LINE_WEST_1_AABB = createAABB(4, 6, 6, 6, 10, 10);
public static final AxisAlignedBB LINE_WEST_2_AABB = createAABB(2, 5, 5, 4, 11, 11);
public static final AxisAlignedBB LINE_WEST_3_AABB = createAABB(0, 3, 3, 2, 13, 13);
public static final AxisAlignedBB LINE_UP_1_AABB = createAABB(6, 10, 6, 10, 12, 10);
public static final AxisAlignedBB LINE_UP_2_AABB = createAABB(5, 12, 5, 11, 14, 11);
public static final AxisAlignedBB LINE_UP_3_AABB = createAABB(3, 14, 3, 13, 16, 13);
public static final AxisAlignedBB LINE_DOWN_1_AABB = createAABB(6, 4, 6, 10, 6, 10);
public static final AxisAlignedBB LINE_DOWN_2_AABB = createAABB(5, 2, 5, 11, 4, 11);
public static final AxisAlignedBB LINE_DOWN_3_AABB = createAABB(3, 0, 3, 13, 2, 13);
public BlockImporter(String name) {
super(name);
}
public BlockImporter() {
super("importer");
this("importer");
}
@Override
public List<AxisAlignedBB> getNonUnionizedCollisionBoxes(IBlockState state) {
List<AxisAlignedBB> boxes = new ArrayList<>();
switch (state.getValue(DIRECTION)) {
case NORTH:
boxes.add(LINE_NORTH_1_AABB);
boxes.add(LINE_NORTH_2_AABB);
boxes.add(LINE_NORTH_3_AABB);
break;
case EAST:
boxes.add(LINE_EAST_1_AABB);
boxes.add(LINE_EAST_2_AABB);
boxes.add(LINE_EAST_3_AABB);
break;
case SOUTH:
boxes.add(LINE_SOUTH_1_AABB);
boxes.add(LINE_SOUTH_2_AABB);
boxes.add(LINE_SOUTH_3_AABB);
break;
case WEST:
boxes.add(LINE_WEST_1_AABB);
boxes.add(LINE_WEST_2_AABB);
boxes.add(LINE_WEST_3_AABB);
break;
case UP:
boxes.add(LINE_UP_1_AABB);
boxes.add(LINE_UP_2_AABB);
boxes.add(LINE_UP_3_AABB);
break;
case DOWN:
boxes.add(LINE_DOWN_1_AABB);
boxes.add(LINE_DOWN_2_AABB);
boxes.add(LINE_DOWN_3_AABB);
break;
}
return boxes;
}
@Override
@@ -23,7 +90,11 @@ public class BlockImporter extends BlockCable {
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
public boolean onBlockActivatedDefault(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
if (hitCablePart(state, world, pos, hitX, hitY, hitZ)) {
return false;
}
if (!world.isRemote) {
player.openGui(RefinedStorage.INSTANCE, RefinedStorageGui.IMPORTER, world, pos.getX(), pos.getY(), pos.getZ());
}

View File

@@ -0,0 +1,27 @@
package refinedstorage.block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import refinedstorage.tile.TileNetworkReceiver;
public class BlockNetworkReceiver extends BlockNode {
public BlockNetworkReceiver() {
super("network_receiver");
}
@Override
public TileEntity createTileEntity(World world, IBlockState state) {
return new TileNetworkReceiver();
}
@Override
public EnumPlacementType getPlacementType() {
return null;
}
@Override
public boolean hasConnectivityState() {
return true;
}
}

View File

@@ -0,0 +1,43 @@
package refinedstorage.block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import refinedstorage.RefinedStorage;
import refinedstorage.RefinedStorageGui;
import refinedstorage.tile.TileNetworkTransmitter;
public class BlockNetworkTransmitter extends BlockNode {
public BlockNetworkTransmitter() {
super("network_transmitter");
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!world.isRemote) {
player.openGui(RefinedStorage.INSTANCE, RefinedStorageGui.NETWORK_TRANSMITTER, world, pos.getX(), pos.getY(), pos.getZ());
}
return true;
}
@Override
public TileEntity createTileEntity(World world, IBlockState state) {
return new TileNetworkTransmitter();
}
@Override
public EnumPlacementType getPlacementType() {
return null;
}
@Override
public boolean hasConnectivityState() {
return true;
}
}

View File

@@ -11,10 +11,11 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import refinedstorage.api.network.INetworkMaster;
import refinedstorage.api.network.NetworkUtils;
import refinedstorage.tile.TileNode;
public abstract class BlockNode extends BlockBase {
public static final PropertyBool CONNECTED = PropertyBool.create("connected");
private static final PropertyBool CONNECTED = PropertyBool.create("connected");
public BlockNode(String name) {
super(name);
@@ -63,7 +64,7 @@ public abstract class BlockNode extends BlockBase {
TileEntity tile = world.getTileEntity(pos.offset(facing));
if (tile instanceof TileNode && ((TileNode) tile).isConnected()) {
((TileNode) tile).getNetwork().rebuildNodes();
NetworkUtils.rebuildGraph(((TileNode) tile).getNetwork());
break;
}
@@ -86,7 +87,7 @@ public abstract class BlockNode extends BlockBase {
super.breakBlock(world, pos, state);
if (network != null) {
network.rebuildNodes();
NetworkUtils.rebuildGraph(network);
}
}
}

View File

@@ -17,9 +17,9 @@ import refinedstorage.RefinedStorageGui;
import refinedstorage.tile.TileSolderer;
public class BlockSolderer extends BlockNode {
public static final AxisAlignedBB AABB_SOLDERER = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 14D / 16D, 1.0D);
private static final AxisAlignedBB AABB_SOLDERER = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 14D / 16D, 1.0D);
public static final PropertyBool WORKING = PropertyBool.create("working");
private static final PropertyBool WORKING = PropertyBool.create("working");
public BlockSolderer() {
super("solderer");

View File

@@ -25,7 +25,7 @@ import java.util.ArrayList;
import java.util.List;
public class BlockStorage extends BlockNode {
public static final PropertyEnum TYPE = PropertyEnum.create("type", EnumStorageType.class);
public static final PropertyEnum TYPE = PropertyEnum.create("type", EnumItemStorageType.class);
public BlockStorage() {
super("storage");
@@ -34,7 +34,7 @@ public class BlockStorage extends BlockNode {
}
@Override
public void getSubBlocks(Item item, CreativeTabs tab, List subItems) {
public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> subItems) {
for (int i = 0; i <= 4; ++i) {
subItems.add(ItemBlockStorage.initNBT(new ItemStack(item, 1, i)));
}
@@ -49,12 +49,12 @@ public class BlockStorage extends BlockNode {
@Override
public IBlockState getStateFromMeta(int meta) {
return getDefaultState().withProperty(TYPE, EnumStorageType.getById(meta));
return getDefaultState().withProperty(TYPE, EnumItemStorageType.getById(meta));
}
@Override
public int getMetaFromState(IBlockState state) {
return ((EnumStorageType) state.getValue(TYPE)).getId();
return ((EnumItemStorageType) state.getValue(TYPE)).getId();
}
@Override
@@ -91,9 +91,9 @@ public class BlockStorage extends BlockNode {
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
TileStorage storage = (TileStorage) world.getTileEntity(pos);
List<ItemStack> drops = new ArrayList<ItemStack>();
List<ItemStack> drops = new ArrayList<>();
ItemStack stack = new ItemStack(RefinedStorageBlocks.STORAGE, 1, RefinedStorageBlocks.STORAGE.getMetaFromState(state));
ItemStack stack = new ItemStack(RefinedStorageBlocks.STORAGE, 1, getMetaFromState(state));
stack.setTagCompound(new NBTTagCompound());
stack.getTagCompound().setTag(TileStorage.NBT_STORAGE, storage.getStorageTag());

View File

@@ -0,0 +1,52 @@
package refinedstorage.block;
import net.minecraft.util.IStringSerializable;
public enum EnumFluidStorageType implements IStringSerializable {
TYPE_64K(0, 64000, "64k"),
TYPE_128K(1, 128000, "128k"),
TYPE_256K(2, 256000, "256k"),
TYPE_512K(3, 512000, "512k"),
TYPE_CREATIVE(4, -1, "creative");
private int id;
private int capacity;
private String name;
EnumFluidStorageType(int id, int capacity, String name) {
this.id = id;
this.capacity = capacity;
this.name = name;
}
@Override
public String getName() {
return name;
}
public int getId() {
return id;
}
public int getCapacity() {
return capacity;
}
@Override
public String toString() {
return name;
}
public static EnumFluidStorageType getById(int id) {
if (id == 5) {
return TYPE_CREATIVE;
}
for (EnumFluidStorageType type : EnumFluidStorageType.values()) {
if (type.getId() == id) {
return type;
}
}
return TYPE_CREATIVE;
}
}

View File

@@ -5,7 +5,8 @@ import net.minecraft.util.IStringSerializable;
public enum EnumGridType implements IStringSerializable {
NORMAL(0, "normal"),
CRAFTING(1, "crafting"),
PATTERN(2, "pattern");
PATTERN(2, "pattern"),
FLUID(3, "fluid");
private int id;
private String name;

View File

@@ -2,7 +2,7 @@ package refinedstorage.block;
import net.minecraft.util.IStringSerializable;
public enum EnumStorageType implements IStringSerializable {
public enum EnumItemStorageType implements IStringSerializable {
TYPE_1K(0, 1000, "1k"),
TYPE_4K(1, 4000, "4k"),
TYPE_16K(2, 16000, "16k"),
@@ -13,7 +13,7 @@ public enum EnumStorageType implements IStringSerializable {
private int capacity;
private String name;
EnumStorageType(int id, int capacity, String name) {
EnumItemStorageType(int id, int capacity, String name) {
this.id = id;
this.capacity = capacity;
this.name = name;
@@ -37,12 +37,12 @@ public enum EnumStorageType implements IStringSerializable {
return name;
}
public static EnumStorageType getById(int id) {
public static EnumItemStorageType getById(int id) {
if (id == 5) {
return TYPE_CREATIVE;
}
for (EnumStorageType type : EnumStorageType.values()) {
for (EnumItemStorageType type : EnumItemStorageType.values()) {
if (type.getId() == id) {
return type;
}

View File

@@ -9,6 +9,9 @@ public enum EnumPlacementType {
ANY(
EnumFacing.VALUES
),
ANY_FACE_PLAYER(
EnumFacing.VALUES
),
HORIZONTAL(
EnumFacing.NORTH,
EnumFacing.EAST,
@@ -16,18 +19,18 @@ public enum EnumPlacementType {
EnumFacing.WEST
);
public final EnumFacing[] allowed;
final EnumFacing[] allowed;
EnumPlacementType(EnumFacing... allowed) {
this.allowed = allowed;
}
EnumFacing getFrom(BlockPos pos, EntityLivingBase entity) {
EnumFacing getFrom(EnumFacing facing, BlockPos pos, EntityLivingBase entity) {
switch (this) {
case ANY:
EnumFacing facing = BlockPistonBase.getFacingFromEntity(pos, entity);
return entity.isSneaking() ? facing.getOpposite() : facing;
return facing.getOpposite();
case ANY_FACE_PLAYER:
return BlockPistonBase.getFacingFromEntity(pos, entity);
case HORIZONTAL:
return entity.getHorizontalFacing().getOpposite();
default:
@@ -38,6 +41,7 @@ public enum EnumPlacementType {
EnumFacing getNext(EnumFacing previous) {
switch (this) {
case ANY:
case ANY_FACE_PLAYER:
return previous.ordinal() + 1 >= EnumFacing.VALUES.length ? EnumFacing.VALUES[0] : EnumFacing.VALUES[previous.ordinal() + 1];
case HORIZONTAL:
return previous.rotateYCCW();

View File

@@ -1,19 +1,22 @@
package refinedstorage.container;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ClickType;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import refinedstorage.container.slot.SlotDisabled;
import refinedstorage.container.slot.SlotSpecimen;
import refinedstorage.container.slot.SlotSpecimenLegacy;
import net.minecraftforge.items.ItemHandlerHelper;
import refinedstorage.api.storage.CompareUtils;
import refinedstorage.container.slot.*;
import refinedstorage.tile.TileBase;
import refinedstorage.tile.grid.WirelessGrid;
public abstract class ContainerBase extends Container {
private TileBase tile;
private EntityPlayer player;
public ContainerBase(EntityPlayer player) {
public ContainerBase(TileBase tile, EntityPlayer player) {
this.tile = tile;
this.player = player;
}
@@ -21,11 +24,22 @@ public abstract class ContainerBase extends Container {
return player;
}
public TileBase getTile() {
return tile;
}
protected void addPlayerInventory(int xInventory, int yInventory) {
int id = 0;
for (int i = 0; i < 9; i++) {
addSlotToContainer(new Slot(player.inventory, id, xInventory + i * 18, yInventory + 4 + (3 * 18)));
int x = xInventory + i * 18;
int y = yInventory + 4 + (3 * 18);
if (i == player.inventory.currentItem && (ContainerBase.this instanceof ContainerGridFilter || (ContainerBase.this instanceof ContainerGrid && ((ContainerGrid) ContainerBase.this).getGrid() instanceof WirelessGrid))) {
addSlotToContainer(new SlotDisabled(player.inventory, id, x, y));
} else {
addSlotToContainer(new Slot(player.inventory, id, x, y));
}
id++;
}
@@ -46,23 +60,15 @@ public abstract class ContainerBase extends Container {
if (slot instanceof SlotSpecimen) {
if (((SlotSpecimen) slot).isWithSize()) {
if (slot.getStack() != null) {
if (GuiScreen.isShiftKeyDown()) {
if (clickType == ClickType.QUICK_MOVE) {
slot.putStack(null);
} else {
int amount = slot.getStack().stackSize;
if (clickedButton == 0) {
amount--;
if (amount < 1) {
amount = 1;
}
amount = Math.max(1, amount - 1);
} else if (clickedButton == 1) {
amount++;
if (amount > 64) {
amount = 64;
}
amount = Math.min(64, amount + 1);
}
slot.getStack().stackSize = amount;
@@ -70,14 +76,7 @@ public abstract class ContainerBase extends Container {
} else if (player.inventory.getItemStack() != null) {
int amount = player.inventory.getItemStack().stackSize;
if (clickedButton == 1) {
amount = 1;
}
ItemStack toPut = player.inventory.getItemStack().copy();
toPut.stackSize = amount;
slot.putStack(toPut);
slot.putStack(ItemHandlerHelper.copyStackWithSize(player.inventory.getItemStack(), clickedButton == 1 ? 1 : amount));
}
} else if (player.inventory.getItemStack() == null) {
slot.putStack(null);
@@ -106,6 +105,41 @@ public abstract class ContainerBase extends Container {
return null;
}
protected ItemStack mergeItemStackToSpecimen(ItemStack stack, int begin, int end) {
for (int i = begin; i < end; ++i) {
if (CompareUtils.compareStackNoQuantity(getStackFromSlot(getSlot(i)), stack)) {
return null;
}
}
for (int i = begin; i < end; ++i) {
Slot slot = getSlot(i);
if (getStackFromSlot(slot) == null && slot.isItemValid(stack)) {
slot.putStack(ItemHandlerHelper.copyStackWithSize(stack, 1));
slot.onSlotChanged();
return null;
}
}
return null;
}
private ItemStack getStackFromSlot(Slot slot) {
ItemStack stackInSlot = slot.getStack();
if (stackInSlot == null) {
if (slot instanceof SlotSpecimenFluid) {
stackInSlot = ((SlotSpecimenFluid) slot).getRealStack();
} else if (slot instanceof SlotSpecimenType) {
stackInSlot = ((SlotSpecimenType) slot).getRealStack();
}
}
return stackInSlot;
}
@Override
public boolean canInteractWith(EntityPlayer player) {
return true;

View File

@@ -5,17 +5,18 @@ import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.SlotItemHandler;
import refinedstorage.container.slot.SlotSpecimen;
import refinedstorage.container.slot.SlotSpecimenType;
import refinedstorage.tile.TileConstructor;
public class ContainerConstructor extends ContainerBase {
public ContainerConstructor(EntityPlayer player, TileConstructor constructor) {
super(player);
public ContainerConstructor(TileConstructor constructor, EntityPlayer player) {
super(constructor, player);
for (int i = 0; i < 4; ++i) {
addSlotToContainer(new SlotItemHandler(constructor.getUpgrades(), i, 187, 6 + (i * 18)));
}
addSlotToContainer(new SlotSpecimen(constructor.getFilter(), 0, 80, 20, SlotSpecimen.SPECIMEN_BLOCK));
addSlotToContainer(new SlotSpecimenType(constructor, 0, 80, 20, SlotSpecimen.SPECIMEN_BLOCK));
addPlayerInventory(8, 55);
}
@@ -34,7 +35,7 @@ public class ContainerConstructor extends ContainerBase {
return null;
}
} else if (!mergeItemStack(stack, 0, 4, false)) {
return null;
return mergeItemStackToSpecimen(stack, 4, 4 + 1);
}
if (stack.stackSize == 0) {

View File

@@ -1,10 +1,11 @@
package refinedstorage.container;
import net.minecraft.entity.player.EntityPlayer;
import refinedstorage.tile.TileController;
public class ContainerController extends ContainerBase {
public ContainerController(EntityPlayer player) {
super(player);
public ContainerController(TileController controller, EntityPlayer player) {
super(controller, player);
addPlayerInventory(8, 99);
}

View File

@@ -6,9 +6,9 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.items.SlotItemHandler;
import refinedstorage.tile.TileCrafter;
public class ContainerCrafter extends ContainerStorage {
public ContainerCrafter(EntityPlayer player, TileCrafter crafter) {
super(player);
public class ContainerCrafter extends ContainerBase {
public ContainerCrafter(TileCrafter crafter, EntityPlayer player) {
super(crafter, player);
for (int i = 0; i < 9; ++i) {
addSlotToContainer(new SlotItemHandler(crafter.getPatterns(), i, 8 + (18 * i), 20));

View File

@@ -1,10 +1,11 @@
package refinedstorage.container;
import net.minecraft.entity.player.EntityPlayer;
import refinedstorage.tile.TileCraftingMonitor;
public class ContainerCraftingMonitor extends ContainerBase {
public ContainerCraftingMonitor(EntityPlayer player) {
super(player);
public ContainerCraftingMonitor(TileCraftingMonitor craftingMonitor, EntityPlayer player) {
super(craftingMonitor, player);
addPlayerInventory(8, 148);
}

View File

@@ -11,7 +11,7 @@ import javax.annotation.Nullable;
public class ContainerCraftingSettings extends ContainerBase {
public ContainerCraftingSettings(EntityPlayer player, final ItemStack stack) {
super(player);
super(null, player);
final ItemStack slot = ItemHandlerHelper.copyStackWithSize(stack, 1);

View File

@@ -5,18 +5,19 @@ import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.SlotItemHandler;
import refinedstorage.container.slot.SlotSpecimen;
import refinedstorage.container.slot.SlotSpecimenType;
import refinedstorage.tile.TileDestructor;
public class ContainerDestructor extends ContainerBase {
public ContainerDestructor(EntityPlayer player, TileDestructor destructor) {
super(player);
public ContainerDestructor(TileDestructor destructor, EntityPlayer player) {
super(destructor, player);
for (int i = 0; i < 4; ++i) {
addSlotToContainer(new SlotItemHandler(destructor.getUpgrades(), i, 187, 6 + (i * 18)));
}
for (int i = 0; i < 9; ++i) {
addSlotToContainer(new SlotSpecimen(destructor.getInventory(), i, 8 + (18 * i), 20, SlotSpecimen.SPECIMEN_BLOCK));
addSlotToContainer(new SlotSpecimenType(destructor, i, 8 + (18 * i), 20, SlotSpecimen.SPECIMEN_BLOCK));
}
addPlayerInventory(8, 55);
@@ -36,7 +37,7 @@ public class ContainerDestructor extends ContainerBase {
return null;
}
} else if (!mergeItemStack(stack, 0, 4, false)) {
return null;
return mergeItemStackToSpecimen(stack, 4, 4 + 9);
}
if (stack.stackSize == 0) {

View File

@@ -1,15 +1,28 @@
package refinedstorage.container;
import net.minecraft.entity.player.EntityPlayer;
import refinedstorage.container.slot.SlotSpecimen;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import refinedstorage.container.slot.SlotSpecimenType;
import refinedstorage.tile.TileDetector;
public class ContainerDetector extends ContainerBase {
public ContainerDetector(EntityPlayer player, TileDetector detector) {
super(player);
public ContainerDetector(TileDetector detector, EntityPlayer player) {
super(detector, player);
addSlotToContainer(new SlotSpecimen(detector.getInventory(), 0, 107, 20));
addSlotToContainer(new SlotSpecimenType(detector, 0, 107, 20));
addPlayerInventory(8, 55);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int index) {
Slot slot = getSlot(index);
if (slot != null && slot.getHasStack() && index > 0) {
return mergeItemStackToSpecimen(slot.getStack(), 0, 1);
}
return null;
}
}

View File

@@ -4,11 +4,12 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.SlotItemHandler;
import refinedstorage.container.slot.SlotSpecimenType;
import refinedstorage.tile.TileDiskDrive;
public class ContainerDiskDrive extends ContainerStorage {
public ContainerDiskDrive(EntityPlayer player, TileDiskDrive drive) {
super(player);
public class ContainerDiskDrive extends ContainerBase {
public ContainerDiskDrive(TileDiskDrive drive, EntityPlayer player) {
super(drive, player);
for (int i = 0; i < 4; ++i) {
addSlotToContainer(new SlotItemHandler(drive.getDisks(), i, 98 + (i * 18), 78));
@@ -18,7 +19,11 @@ public class ContainerDiskDrive extends ContainerStorage {
addSlotToContainer(new SlotItemHandler(drive.getDisks(), 4 + i, 98 + (i * 18), 96));
}
addSpecimenAndPlayerInventorySlots(drive.getFilters());
for (int i = 0; i < 9; ++i) {
addSlotToContainer(new SlotSpecimenType(drive, i, 8 + (18 * i), 20));
}
addPlayerInventory(8, 129);
}
@Override
@@ -35,7 +40,7 @@ public class ContainerDiskDrive extends ContainerStorage {
return null;
}
} else if (!mergeItemStack(stack, 0, 8, false)) {
return null;
return mergeItemStackToSpecimen(stack, 8, 8 + 9);
}
if (stack.stackSize == 0) {

View File

@@ -1,11 +0,0 @@
package refinedstorage.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
public class ContainerDummy extends Container {
@Override
public boolean canInteractWith(EntityPlayer player) {
return false;
}
}

View File

@@ -4,19 +4,19 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.SlotItemHandler;
import refinedstorage.container.slot.SlotSpecimen;
import refinedstorage.container.slot.SlotSpecimenType;
import refinedstorage.tile.TileExporter;
public class ContainerExporter extends ContainerBase {
public ContainerExporter(EntityPlayer player, TileExporter exporter) {
super(player);
public ContainerExporter(TileExporter exporter, EntityPlayer player) {
super(exporter, player);
for (int i = 0; i < 4; ++i) {
addSlotToContainer(new SlotItemHandler(exporter.getUpgrades(), i, 187, 6 + (i * 18)));
}
for (int i = 0; i < 9; ++i) {
addSlotToContainer(new SlotSpecimen(exporter.getFilters(), i, 8 + (18 * i), 20));
addSlotToContainer(new SlotSpecimenType(exporter, i, 8 + (18 * i), 20));
}
addPlayerInventory(8, 55);
@@ -36,7 +36,7 @@ public class ContainerExporter extends ContainerBase {
return null;
}
} else if (!mergeItemStack(stack, 0, 4, false)) {
return null;
return mergeItemStackToSpecimen(stack, 4, 4 + 9);
}
if (stack.stackSize == 0) {

View File

@@ -0,0 +1,30 @@
package refinedstorage.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import refinedstorage.container.slot.SlotSpecimenType;
import refinedstorage.tile.externalstorage.TileExternalStorage;
public class ContainerExternalStorage extends ContainerBase {
public ContainerExternalStorage(TileExternalStorage tile, EntityPlayer player) {
super(tile, player);
for (int i = 0; i < 9; ++i) {
addSlotToContainer(new SlotSpecimenType(tile, i, 8 + (18 * i), 20));
}
addPlayerInventory(8, 129);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int index) {
Slot slot = getSlot(index);
if (slot != null && slot.getHasStack() && index >= 8) {
return mergeItemStackToSpecimen(slot.getStack(), 0, 9);
}
return null;
}
}

View File

@@ -0,0 +1,50 @@
package refinedstorage.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.SlotItemHandler;
import refinedstorage.container.slot.SlotSpecimenFluid;
import refinedstorage.tile.TileFluidInterface;
public class ContainerFluidInterface extends ContainerBase {
public ContainerFluidInterface(TileFluidInterface fluidInterface, EntityPlayer player) {
super(fluidInterface, player);
for (int i = 0; i < 4; ++i) {
addSlotToContainer(new SlotItemHandler(fluidInterface.getUpgrades(), i, 187, 6 + (i * 18)));
}
addSlotToContainer(new SlotItemHandler(fluidInterface.getIn(), 0, 44, 32));
addSlotToContainer(new SlotSpecimenFluid(!fluidInterface.getWorld().isRemote, fluidInterface.getOut(), 0, 116, 32));
addPlayerInventory(8, 122);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int index) {
ItemStack stack = null;
Slot slot = getSlot(index);
if (slot != null && slot.getHasStack()) {
stack = slot.getStack();
if (index < 4 + 2) {
if (!mergeItemStack(stack, 4 + 2, inventorySlots.size(), false)) {
return null;
}
} else if (!mergeItemStack(stack, 0, 4 + 2, false)) {
return null;
}
if (stack.stackSize == 0) {
slot.putStack(null);
} else {
slot.onSlotChanged();
}
}
return stack;
}
}

View File

@@ -0,0 +1,30 @@
package refinedstorage.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import refinedstorage.container.slot.SlotSpecimenFluid;
import refinedstorage.tile.TileFluidStorage;
public class ContainerFluidStorage extends ContainerBase {
public ContainerFluidStorage(TileFluidStorage tile, EntityPlayer player) {
super(tile, player);
for (int i = 0; i < 9; ++i) {
addSlotToContainer(new SlotSpecimenFluid(!tile.getWorld().isRemote, tile.getFilters(), i, 8 + (18 * i), 20));
}
addPlayerInventory(8, 129);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int index) {
Slot slot = getSlot(index);
if (slot != null && slot.getHasStack() && index >= 8) {
return mergeItemStackToSpecimen(slot.getStack(), 0, 9);
}
return null;
}
}

View File

@@ -1,11 +1,13 @@
package refinedstorage.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.SlotItemHandler;
import refinedstorage.block.EnumGridType;
import refinedstorage.container.slot.*;
import refinedstorage.tile.TileBase;
import refinedstorage.tile.grid.IGrid;
import refinedstorage.tile.grid.TileGrid;
import refinedstorage.tile.grid.WirelessGrid;
@@ -16,8 +18,8 @@ public class ContainerGrid extends ContainerBase {
private SlotGridCraftingResult craftingResultSlot;
private SlotDisabled patternResultSlot;
public ContainerGrid(EntityPlayer player, IGrid grid) {
super(player);
public ContainerGrid(IGrid grid, EntityPlayer player) {
super(grid instanceof TileBase ? (TileBase) grid : null, player);
this.grid = grid;
@@ -59,6 +61,12 @@ public class ContainerGrid extends ContainerBase {
addSlotToContainer(new SlotItemHandler(((TileGrid) grid).getPatterns(), 0, 152, 96));
addSlotToContainer(new SlotOutput(((TileGrid) grid).getPatterns(), 1, 152, 132));
}
if (grid.getType() != EnumGridType.FLUID) {
for (int i = 0; i < 4; ++i) {
addSlotToContainer(new SlotItemHandler(grid.getFilter(), i, 204, 6 + (18 * i)));
}
}
}
public IGrid getGrid() {
@@ -96,12 +104,18 @@ public class ContainerGrid extends ContainerBase {
if (!player.worldObj.isRemote) {
Slot slot = inventorySlots.get(slotIndex);
if (slot == craftingResultSlot) {
((TileGrid) grid).onCraftedShift(this, player);
} else if (grid.getGridHandler() != null && slot != patternResultSlot && !(slot instanceof SlotSpecimenLegacy) && slot.getHasStack()) {
slot.putStack(grid.getGridHandler().onInsert(slot.getStack()));
if (slot.getHasStack()) {
if (slot == craftingResultSlot) {
((TileGrid) grid).onCraftedShift(this, player);
} else if (slot != patternResultSlot && !(slot instanceof SlotSpecimenLegacy)) {
if (grid.getType() != EnumGridType.FLUID && grid.getItemHandler() != null) {
slot.putStack(grid.getItemHandler().onInsert((EntityPlayerMP) player, slot.getStack()));
} else if (grid.getType() == EnumGridType.FLUID && grid.getFluidHandler() != null) {
slot.putStack(grid.getFluidHandler().onInsert(slot.getStack()));
}
detectAndSendChanges();
detectAndSendChanges();
}
}
}

View File

@@ -0,0 +1,48 @@
package refinedstorage.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import refinedstorage.container.slot.SlotSpecimen;
import refinedstorage.inventory.ItemHandlerGridFilter;
public class ContainerGridFilter extends ContainerBase {
private ItemHandlerGridFilter filter;
private ItemStack stack;
public ContainerGridFilter(EntityPlayer player, ItemStack stack) {
super(null, player);
this.stack = stack;
this.filter = new ItemHandlerGridFilter(stack);
for (int i = 0; i < 9; ++i) {
addSlotToContainer(new SlotSpecimen(filter, i, 8 + (i * 18), 20));
}
addPlayerInventory(8, 70);
}
public ItemStack getStack() {
return stack;
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int index) {
ItemStack stack = null;
Slot slot = getSlot(index);
if (slot != null && slot.getHasStack()) {
stack = slot.getStack();
if (index > 9 - 1) {
return mergeItemStackToSpecimen(stack, 0, 9);
}
return null;
}
return stack;
}
}

View File

@@ -4,19 +4,19 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.SlotItemHandler;
import refinedstorage.container.slot.SlotSpecimen;
import refinedstorage.container.slot.SlotSpecimenType;
import refinedstorage.tile.TileImporter;
public class ContainerImporter extends ContainerBase {
public ContainerImporter(EntityPlayer player, TileImporter importer) {
super(player);
public ContainerImporter(TileImporter importer, EntityPlayer player) {
super(importer, player);
for (int i = 0; i < 4; ++i) {
addSlotToContainer(new SlotItemHandler(importer.getUpgrades(), i, 187, 6 + (i * 18)));
}
for (int i = 0; i < 9; ++i) {
addSlotToContainer(new SlotSpecimen(importer.getFilters(), i, 8 + (18 * i), 20));
addSlotToContainer(new SlotSpecimenType(importer, i, 8 + (18 * i), 20));
}
addPlayerInventory(8, 55);
@@ -36,7 +36,7 @@ public class ContainerImporter extends ContainerBase {
return null;
}
} else if (!mergeItemStack(stack, 0, 4, false)) {
return null;
return mergeItemStackToSpecimen(stack, 4, 4 + 9);
}
if (stack.stackSize == 0) {

View File

@@ -9,8 +9,8 @@ import refinedstorage.container.slot.SlotSpecimen;
import refinedstorage.tile.TileInterface;
public class ContainerInterface extends ContainerBase {
public ContainerInterface(EntityPlayer player, TileInterface tile) {
super(player);
public ContainerInterface(TileInterface tile, EntityPlayer player) {
super(tile, player);
for (int i = 0; i < 9; ++i) {
addSlotToContainer(new SlotItemHandler(tile.getImportItems(), i, 8 + (18 * i), 20));

View File

@@ -0,0 +1,46 @@
package refinedstorage.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.SlotItemHandler;
import refinedstorage.tile.TileNetworkTransmitter;
public class ContainerNetworkTransmitter extends ContainerBase {
public ContainerNetworkTransmitter(TileNetworkTransmitter networkTransmitter, EntityPlayer player) {
super(networkTransmitter, player);
addSlotToContainer(new SlotItemHandler(networkTransmitter.getNetworkCard(), 0, 8, 20));
addSlotToContainer(new SlotItemHandler(networkTransmitter.getUpgrades(), 0, 187, 6));
addPlayerInventory(8, 55);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int index) {
ItemStack stack = null;
Slot slot = getSlot(index);
if (slot != null && slot.getHasStack()) {
stack = slot.getStack();
if (index <= 1) {
if (!mergeItemStack(stack, 2, inventorySlots.size(), false)) {
return null;
}
} else if (!mergeItemStack(stack, 0, 2, false)) {
return null;
}
if (stack.stackSize == 0) {
slot.putStack(null);
} else {
slot.onSlotChanged();
}
}
return stack;
}
}

View File

@@ -9,8 +9,8 @@ import refinedstorage.container.slot.SlotSpecimen;
import refinedstorage.tile.TileProcessingPatternEncoder;
public class ContainerProcessingPatternEncoder extends ContainerBase {
public ContainerProcessingPatternEncoder(EntityPlayer player, TileProcessingPatternEncoder processingPatternEncoder) {
super(player);
public ContainerProcessingPatternEncoder(TileProcessingPatternEncoder processingPatternEncoder, EntityPlayer player) {
super(processingPatternEncoder, player);
addSlotToContainer(new SlotItemHandler(processingPatternEncoder.getPatterns(), 0, 152, 18));
addSlotToContainer(new SlotOutput(processingPatternEncoder.getPatterns(), 1, 152, 58));
@@ -20,7 +20,7 @@ public class ContainerProcessingPatternEncoder extends ContainerBase {
int y = 20;
for (int i = 0; i < 9 * 2; ++i) {
addSlotToContainer(new SlotSpecimen(processingPatternEncoder.getConfiguration(), i, x, y));
addSlotToContainer(new SlotSpecimen(processingPatternEncoder.getConfiguration(), i, x, y, SlotSpecimen.SPECIMEN_SIZE));
x += 18;

View File

@@ -1,10 +1,11 @@
package refinedstorage.container;
import net.minecraft.entity.player.EntityPlayer;
import refinedstorage.tile.TileRelay;
public class ContainerRelay extends ContainerBase {
public ContainerRelay(EntityPlayer player) {
super(player);
public ContainerRelay(TileRelay relay, EntityPlayer player) {
super(relay, player);
addPlayerInventory(8, 50);
}

View File

@@ -9,8 +9,8 @@ import refinedstorage.container.slot.SlotOutput;
import refinedstorage.tile.TileSolderer;
public class ContainerSolderer extends ContainerBase {
public ContainerSolderer(EntityPlayer player, TileSolderer solderer) {
super(player);
public ContainerSolderer(TileSolderer solderer, EntityPlayer player) {
super(solderer, player);
int x = 44;
int y = 20;

View File

@@ -1,25 +1,30 @@
package refinedstorage.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.items.IItemHandler;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import refinedstorage.container.slot.SlotSpecimen;
import refinedstorage.tile.TileStorage;
public class ContainerStorage extends ContainerBase {
public ContainerStorage(EntityPlayer player) {
super(player);
}
public ContainerStorage(TileStorage tile, EntityPlayer player) {
super(tile, player);
public ContainerStorage(EntityPlayer player, IItemHandler filters) {
this(player);
addSpecimenAndPlayerInventorySlots(filters);
}
protected void addSpecimenAndPlayerInventorySlots(IItemHandler filters) {
for (int i = 0; i < 9; ++i) {
addSlotToContainer(new SlotSpecimen(filters, i, 8 + (18 * i), 20));
addSlotToContainer(new SlotSpecimen(tile.getFilters(), i, 8 + (18 * i), 20));
}
addPlayerInventory(8, 129);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int index) {
Slot slot = getSlot(index);
if (slot != null && slot.getHasStack() && index >= 8) {
return mergeItemStackToSpecimen(slot.getStack(), 0, 9);
}
return null;
}
}

View File

@@ -7,8 +7,8 @@ import net.minecraftforge.items.SlotItemHandler;
import refinedstorage.tile.TileWirelessTransmitter;
public class ContainerWirelessTransmitter extends ContainerBase {
public ContainerWirelessTransmitter(EntityPlayer player, TileWirelessTransmitter wirelessTransmitter) {
super(player);
public ContainerWirelessTransmitter(TileWirelessTransmitter wirelessTransmitter, EntityPlayer player) {
super(wirelessTransmitter, player);
for (int i = 0; i < 4; ++i) {
addSlotToContainer(new SlotItemHandler(wirelessTransmitter.getUpgrades(), i, 187, 6 + (i * 18)));

View File

@@ -38,7 +38,7 @@ public class SlotSpecimen extends SlotItemHandler {
@Override
public boolean isItemValid(ItemStack stack) {
return isBlockOnly() ? (stack.getItem() instanceof ItemBlock || stack.getItem() instanceof ItemBlockSpecial || stack.getItem() instanceof IPlantable) : true;
return super.isItemValid(stack) && (isBlockOnly() ? (stack.getItem() instanceof ItemBlock || stack.getItem() instanceof ItemBlockSpecial || stack.getItem() instanceof IPlantable) : true);
}
@Override
@@ -67,9 +67,7 @@ public class SlotSpecimen extends SlotItemHandler {
Field f = ((ItemBlockSpecial) item).getClass().getDeclaredField("block");
f.setAccessible(true);
return ((Block) f.get(item)).getDefaultState();
} catch (IllegalAccessException e) {
// NO OP
} catch (NoSuchFieldException e) {
} catch (IllegalAccessException | NoSuchFieldException e) {
// NO OP
}
} else if (item instanceof ItemBlock) {

View File

@@ -0,0 +1,23 @@
package refinedstorage.container.slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
public class SlotSpecimenFluid extends SlotSpecimen {
private boolean server;
public SlotSpecimenFluid(boolean server, IItemHandler handler, int id, int x, int y) {
super(handler, id, x, y);
this.server = server;
}
@Override
public ItemStack getStack() {
return server ? super.getStack() : null;
}
public ItemStack getRealStack() {
return super.getStack();
}
}

View File

@@ -0,0 +1,44 @@
package refinedstorage.container.slot;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.items.IItemHandler;
import refinedstorage.tile.config.IType;
public class SlotSpecimenType extends SlotSpecimen {
private IType type;
public SlotSpecimenType(IType type, int id, int x, int y, int flags) {
super(null, id, x, y, flags);
this.type = type;
}
public SlotSpecimenType(IType type, int id, int x, int y) {
this(type, id, x, y, 0);
}
@Override
public IItemHandler getItemHandler() {
return type.getFilterInventory();
}
@Override
public boolean isWithSize() {
return super.isWithSize() && type.getType() != IType.FLUIDS;
}
@Override
public boolean isBlockOnly() {
return super.isBlockOnly() && type.getType() == IType.ITEMS;
}
@Override
public ItemStack getStack() {
return (type.getType() == IType.ITEMS || !((TileEntity) type).getWorld().isRemote) ? super.getStack() : null;
}
public ItemStack getRealStack() {
return super.getStack();
}
}

Some files were not shown because too many files have changed in this diff Show More