From bdf84a2a3367790c4531eb0112511e4c21c2df50 Mon Sep 17 00:00:00 2001 From: Wilhelm Schuster Date: Mon, 14 Dec 2015 20:28:48 +0100 Subject: [PATCH 01/24] Add German translation --- .../assets/storagedrawers/lang/de_DE.lang | 183 ++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 resources/assets/storagedrawers/lang/de_DE.lang diff --git a/resources/assets/storagedrawers/lang/de_DE.lang b/resources/assets/storagedrawers/lang/de_DE.lang new file mode 100644 index 0000000..5a57431 --- /dev/null +++ b/resources/assets/storagedrawers/lang/de_DE.lang @@ -0,0 +1,183 @@ +itemGroup.storageDrawers=Storage Drawers +itemGroup.storageDrawersSorting=Storage Drawers - Sortieren + +storageDrawers.container.drawers=Schubfächer +storageDrawers.container.compDrawers=Verdichtende Schubfächer +storageDrawers.container.upgrades=Upgrades +storageDrawers.container.controller=Schubfach-Controller +storageDrawers.container.unboundSlave=Uneingebundener Slave + +storagedrawers.msg.maxUpgrades=Dieses Schubfach kann keine Upgrades mehr annehmen. + +# Items +item.storagedrawers.upgradeTemplate.name=Upgradeschablone +item.storagedrawers.upgrade.iron.name=Speicherupgrade (II) +item.storagedrawers.upgrade.gold.name=Speicherupgrade (III) +item.storagedrawers.upgrade.obsidian.name=Speicherupgrade (IV) +item.storagedrawers.upgrade.diamond.name=Speicherupgrade (V) +item.storagedrawers.upgrade.emerald.name=Speicherupgrade (VI) +item.storagedrawers.upgradeStatus.level1.name=Statusupgrade (I) +item.storagedrawers.upgradeStatus.level1.description=Zeige volle Speicher +item.storagedrawers.upgradeStatus.level2.name=Statusupgrade (II) +item.storagedrawers.upgradeStatus.level2.description=Zeige Füllstand +item.storagedrawers.upgradeLock.name=Schubfachschlüssel +item.storagedrawers.upgradeLock.description=Schließt und öffnet Schubfach +item.storagedrawers.upgradeVoid.name=Void Upgrade +item.storagedrawers.upgradeVoid.description=Zerstört überschüssige Items +item.storagedrawers.upgradeCreative.store.name=Kreativspeicherupgrade +item.storagedrawers.upgradeCreative.store.description=Fast unendlicher Speicher +item.storagedrawers.upgradeCreative.vend.name=Kreativautomatenupgrade +item.storagedrawers.upgradeCreative.vend.description=Uneingeschränkte Itementnahme +item.storagedrawers.upgradeSorting.name=Sortierungsupgrade +item.storagedrawers.upgradeSorting.description=Für Refined Relocation +item.storagedrawers.shroudKey.name=Verbergungsschlüssel +item.storagedrawers.shroudKey.description=Zeige oder verstecke Itemlabels +item.storagedrawers.tape.name=Packband +item.storagedrawers.tape.description=Dichte Schubfächer ab für den Umzug + +# Blocks +tile.fullDrawers1.oak.name=Eichenschubfach +tile.fullDrawers1.spruce.name=Fichtenschubfach +tile.fullDrawers1.birch.name=Birkenschubfach +tile.fullDrawers1.jungle.name=Tropenschubfach +tile.fullDrawers1.acacia.name=Akazienschubfach +tile.fullDrawers1.big_oak.name=Dunkles Eichenschubfach + +tile.fullDrawers2.oak.name=Eichenschubfach 1x2 +tile.fullDrawers2.spruce.name=Fichtenschubfach 1x2 +tile.fullDrawers2.birch.name=Birkenschubfach 1x2 +tile.fullDrawers2.jungle.name=Tropenschubfach 1x2 +tile.fullDrawers2.acacia.name=Akazienschubfach 1x2 +tile.fullDrawers2.big_oak.name=Dunkles Eichenschubfach 1x2 + +tile.fullDrawers4.oak.name=Eichenschubfach 2x2 +tile.fullDrawers4.spruce.name=Fichtenschubfach 2x2 +tile.fullDrawers4.birch.name=Birkenschubfach 2x2 +tile.fullDrawers4.jungle.name=Tropenschubfach 2x2 +tile.fullDrawers4.acacia.name=Akazienschubfach 2x2 +tile.fullDrawers4.big_oak.name=Dunkles Eichenschubfach 2x2 + +tile.halfDrawers2.oak.name=Kompaktes Eichenschubfach 1x2 +tile.halfDrawers2.spruce.name=Kompaktes Fichtenschubfach 1x2 +tile.halfDrawers2.birch.name=Kompaktes Birkenschubfach 1x2 +tile.halfDrawers2.jungle.name=Kompaktes Tropenschubfach 1x2 +tile.halfDrawers2.acacia.name=Kompaktes Akazienschubfach 1x2 +tile.halfDrawers2.big_oak.name=Kompaktes Dunkles Eichenschubfach 1x2 + +tile.halfDrawers4.oak.name=Kompaktes Eichenschubfach 2x2 +tile.halfDrawers4.spruce.name=Kompaktes Fichtenschubfach 2x2 +tile.halfDrawers4.birch.name=Kompaktes Birkenschubfach 2x2 +tile.halfDrawers4.jungle.name=Kompaktes Tropenschubfach 2x2 +tile.halfDrawers4.acacia.name=Kompaktes Akazienschubfach 2x2 +tile.halfDrawers4.big_oak.name=Kompaktes Dunkles Eichenschubfach 2x2 + +tile.compDrawers.name=Verdichtendes Schubfach +tile.drawerController.name=Schubfach-Controller +tile.controllerSlave.name=Controller Slave + +tile.trim.oak.name=Eichenverkleidung +tile.trim.spruce.name=Fichtenverkleidung +tile.trim.birch.name=Birkenverkleidung +tile.trim.jungle.name=Tropenverkleidung +tile.trim.acacia.name=Akazienverkleidung +tile.trim.big_oak.name=Dunkle Eichenverkleidung + +storageDrawers.drawers.description=Hält %d Stapel pro Schubfach +storageDrawers.drawers.sealed=Inhalt abgedichtet +storageDrawers.upgrade.description=Erhöht den Speicher zu %d mal dem Grundwert +storageDrawers.controller.description=Interagiere mit einer Bank an verbundenen Schubfächern +storageDrawers.controllerSlave.description=Zusätzlich Anhangspunkte für Controller + +# Integration +storageDrawers.waila.empty= +storageDrawers.waila.level=Upgrade Level: %s +storageDrawers.waila.drawer=#%s: %s +storageDrawers.waila.locked=Gelockt +storageDrawers.waila.void=Void +storageDrawers.waila.sorting=Sortieren + +# Configuration +storageDrawers.config.title=Storage Drawers Konfiguration + +storageDrawers.config.general=Allgemeine Einstellungen +storageDrawers.config.general.tooltip=Dies und Jenes. + +storageDrawers.config.blocks=Blockeinstellungen +storageDrawers.config.blocks.tooltip=Konfiguriere individuelle Speicherblocks. + +storageDrawers.config.blocks.fullDrawers1=Schubfächer 1x1 +storageDrawers.config.blocks.fullDrawers2=Schubfächer 1x2 +storageDrawers.config.blocks.fullDrawers4=Schubfächer 2x2 +storageDrawers.config.blocks.halfDrawers2=Kompakte Schubfächer 1x2 +storageDrawers.config.blocks.halfDrawers4=Kompakte Schubfächer 2x2 +storageDrawers.config.blocks.compDrawers=Verdichtende Schubfächer +storageDrawers.config.blocks.controller=Schubfachcontroller +storageDrawers.config.blocks.trim=Verkleidung +storageDrawers.config.blocks.controllerSlave=Controller Slave + +storageDrawers.config.upgrades=Upgradeeinstellungen +storageDrawers.config.upgrades.tooltip=Konfiguriere einzelne Speicherupgrades. + +storageDrawers.config.upgrades.level2Mult=Speichermultiplikator (II) +storageDrawers.config.upgrades.level3Mult=Speichermultiplikator (III) +storageDrawers.config.upgrades.level4Mult=Speichermultiplikator (IV) +storageDrawers.config.upgrades.level5Mult=Speichermultiplikator (V) +storageDrawers.config.upgrades.level6Mult=Speichermultiplikator (VI) + +storageDrawers.config.prop.itemRenderType=Itemrendertyp +storageDrawers.config.prop.itemRenderType.tooltip=Rendere Items in 3D oder flach (2D). +storageDrawers.config.prop.enableIndicatorUpgrades=Erlaube Indikatorupgrades +storageDrawers.config.prop.enableStorageUpgrades=Erlaube Storageupgrades +storageDrawers.config.prop.enableLockUpgrades=Erlaube Schubfachverschließung +storageDrawers.config.prop.enableShroudUpgrades=Erlaube Verbergen +storageDrawers.config.prop.enableVoidUpgrades=Erlaube Voidupgrade +storageDrawers.config.prop.enableCreativeUpgrades=Erlaube Kreativupgrade +storageDrawers.config.prop.enableSortingUpgrades=Erlaube Sortierungsupgrade +storageDrawers.config.prop.enableSortingUpgrades.tooltip=Refined Relocation muss geladen seien. +storageDrawers.config.prop.renderStorageUpgrades=Zeige Speicherupgrades +storageDrawers.config.prop.creativeTabVanillaWoods=Kreativ-Tab Vanillaholz +storageDrawers.config.prop.creativeTabVanillaWoods.tooltip=Erlaube alle Vanillaholzarten in Kreativemenütab. +storageDrawers.config.prop.enabled=Erlaubt +storageDrawers.config.prop.enabled.tooltip=Erlaube Block im Spiel. +storageDrawers.config.prop.baseStorage=Basisspeicher +storageDrawers.config.prop.baseStorage.tooltip=Anzahl an Stapeln gehalten in einem Schubfach +storageDrawers.config.prop.recipeOutput=Rezeptausgabe +storageDrawers.config.prop.recipeOutput.tooltip=Anzahl an Items von Einzelcrafting +storageDrawers.config.prop.enableDrawerUI=Erlaube Schubfach UI +storageDrawers.config.prop.enableDrawerUI.tooltip=Zeigt Itemzahlen und erlaubt Upgrades +storageDrawers.config.prop.enableSidedInput=Erlaube seitliche Itemeingabe +storageDrawers.config.prop.enableSidedInput.tooltip=Andere Blöcke können Items in Schubfächer einfügen +storageDrawers.config.prop.enableSidedOutput=Erlaube seitliche Itemausgabe +storageDrawers.config.prop.enableSidedOutput.tooltip=Andere Blöcke können Items auf Schubfächern entnehmen +storageDrawers.config.prop.enableItemConversion=Erlaube Itemumwandlung +storageDrawers.config.prop.enableItemConversion.tooltip=Schubfächer konvertieren automatich OreDict-kompatible Items +storageDrawers.config.prop.enableFallbackRecipes=Erlaube Fallback-Rezepte +storageDrawers.config.prop.enableFallbackRecipes.tooltip=Jedes valide Brettholz kann zu Eichenschubfächern gefertigt werden +storageDrawers.config.prop.invertShift=Invertiere Shift +storageDrawers.config.prop.invertShift.tooltip=Invertiert Klick- und Shift-Klick-Verhalten +storageDrawers.config.prop.enableDebugLogging=Enable Debug Logging +storageDrawers.config.prop.enableDebugLogging.tooltip=Gibt zusätzliche Informationen in das Log +storageDrawers.config.prop.enableTape=Erlaube Packband +storageDrawers.config.prop.enableTape.tooltip=Zum Verschieben der Schubfächer mit Iteminhalten +storageDrawers.config.prop.wailaStackRemainder=WAILA Anzahl-Darstellung +storageDrawers.config.prop.wailaStackRemainder.tooltip=Bestimme wie Anzahlen in WAILA dargestellt werden +storageDrawers.config.prop.controllerRange=Controllerreichweite +storageDrawers.config.prop.controllerRange.tooltip=Reichweite zur Erkennung von Netzwerkblöcken + +storageDrawers.config.addons=Addons +storageDrawers.config.addons.tooltip=Konfiguriere globale Addons-Einstellungen + +storageDrawers.config.addons.showNEI=Zeige Blöcke in NEI +storageDrawers.config.addons.showCreative=Zeige Blöcke in Kreativtabs +storageDrawers.config.addons.separateTabs=Separate Kreativtabs +storageDrawers.config.addons.tooltip=Jedes Pack benutzt seinen eigenen Kreativtab. + +storageDrawers.config.integration=Integration +storageDrawers.config.integration.tooltip=Konfiguriere Integration mit anderen Mods + +storageDrawers.config.integration.enableAE2=Erlaube Applied Energistics 2 Integration +storageDrawers.config.integration.enableWaila=Erlaube WAILA Integration +storageDrawers.config.integration.enableThaumcraft=Erlaube Thaumcraft Integration +storageDrawers.config.integration.enableMineTweaker=Erlaube MineTweaker Integration +storageDrawers.config.integration.enableRefinedRelocation=Erlaube Refined Relocation Integration +storageDrawers.config.integration.enableThermalExpansion=Elaube Thermal Expansion Integration From 752c65698c318e18a9469dbd9676657bb2fea0f6 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 18 Dec 2015 11:15:05 +0000 Subject: [PATCH 02/24] Do not drop drawer contents if the drawer has the creative vending upgrade --- .../storagedrawers/block/BlockDrawers.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java index 23f36e2..cb6f163 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java @@ -465,17 +465,19 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH dropBlockAsItem(world, x, y, z, stack); } - for (int i = 0; i < tile.getDrawerCount(); i++) { - if (!tile.isDrawerEnabled(i)) - continue; + if (!tile.isVending()) { + for (int i = 0; i < tile.getDrawerCount(); i++) { + if (!tile.isDrawerEnabled(i)) + continue; - IDrawer drawer = tile.getDrawer(i); - while (drawer.getStoredItemCount() > 0) { - ItemStack stack = tile.takeItemsFromSlot(i, drawer.getStoredItemStackSize()); - if (stack == null || stack.stackSize == 0) - break; + IDrawer drawer = tile.getDrawer(i); + while (drawer.getStoredItemCount() > 0) { + ItemStack stack = tile.takeItemsFromSlot(i, drawer.getStoredItemStackSize()); + if (stack == null || stack.stackSize == 0) + break; - dropStackInBatches(world, x, y, z, stack); + dropStackInBatches(world, x, y, z, stack); + } } } From e146f976eec811bb635bf8341110a0fb8f0b1a67 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Sun, 10 Jan 2016 01:23:36 -0500 Subject: [PATCH 03/24] Update AE2 dep --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index daa63f8..bc6da67 100644 --- a/build.gradle +++ b/build.gradle @@ -80,7 +80,7 @@ dependencies { compile "codechicken:CodeChickenCore:1.7.10-1.0.6.44:dev" compile "codechicken:NotEnoughItems:1.7.10-1.0.4.107:dev" - compile "appeng:appliedenergistics2:rv2-stable-3:api" + compile "appeng:appliedenergistics2:rv3-beta-1:api" compile name: 'MineTweaker3', version: "Dev-1.7.10-3.0.9B", ext: 'jar' } From abdc006b5c680202d080be1296818f1eb9ea453a Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Thu, 14 Jan 2016 01:44:52 -0500 Subject: [PATCH 04/24] Add in-place retrimming --- build.gradle | 2 +- .../storagedrawers/StorageDrawers.java | 6 + .../api/pack/IPackBlockFactory.java | 5 + .../block/BlockCompDrawers.java | 6 + .../storagedrawers/block/BlockDrawers.java | 58 +++++++- .../storagedrawers/block/DataResolver.java | 67 +++++++++ .../storagedrawers/core/ModBlocks.java | 6 + .../core/api/BlockRegistry.java | 81 +++++++++++ .../storagedrawers/core/api/PackFactory.java | 37 +++++ .../BlockSortingDrawers.java | 6 + .../storagedrawers/item/ItemTrim.java | 7 + .../util/UniqueMetaIdentifier.java | 133 ++++++++++++++++++ .../util/UniqueMetaRegistry.java | 55 ++++++++ 13 files changed, 467 insertions(+), 2 deletions(-) create mode 100644 src/com/jaquadro/minecraft/storagedrawers/block/DataResolver.java create mode 100644 src/com/jaquadro/minecraft/storagedrawers/core/api/BlockRegistry.java create mode 100644 src/com/jaquadro/minecraft/storagedrawers/util/UniqueMetaIdentifier.java create mode 100644 src/com/jaquadro/minecraft/storagedrawers/util/UniqueMetaRegistry.java diff --git a/build.gradle b/build.gradle index bc6da67..2558e1b 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ buildscript { apply plugin: 'forge' -version = "1.7.10-1.7.5" +version = "1.7.10-1.7.6" group= "com.jaquadro.minecraft.storagedrawers" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "StorageDrawers" diff --git a/src/com/jaquadro/minecraft/storagedrawers/StorageDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/StorageDrawers.java index 64e1d8c..dbdf1bc 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/StorageDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/StorageDrawers.java @@ -1,7 +1,9 @@ package com.jaquadro.minecraft.storagedrawers; +import com.jaquadro.minecraft.storagedrawers.api.StorageDrawersApi; import com.jaquadro.minecraft.storagedrawers.config.*; import com.jaquadro.minecraft.storagedrawers.core.*; +import com.jaquadro.minecraft.storagedrawers.core.api.BlockRegistry; import com.jaquadro.minecraft.storagedrawers.core.handlers.GuiHandler; import com.jaquadro.minecraft.storagedrawers.integration.IntegrationRegistry; import com.jaquadro.minecraft.storagedrawers.network.BlockClickMessage; @@ -43,6 +45,7 @@ public class StorageDrawers public static RecipeHandlerRegistry recipeHandlerRegistry; public static RenderRegistry renderRegistry; public static WailaRegistry wailaRegistry; + public static BlockRegistry blockRegistry; @Mod.Instance(MOD_ID) public static StorageDrawers instance; @@ -69,6 +72,7 @@ public class StorageDrawers recipeHandlerRegistry = new RecipeHandlerRegistry(); renderRegistry = new RenderRegistry(); wailaRegistry = new WailaRegistry(); + blockRegistry = new BlockRegistry(); blocks.init(); items.init(); @@ -90,6 +94,8 @@ public class StorageDrawers recipes.init(); IntegrationRegistry.instance().postInit(); + + StorageDrawersApi.instance().packFactory().registerResolver(ModBlocks.resolver); } @SubscribeEvent diff --git a/src/com/jaquadro/minecraft/storagedrawers/api/pack/IPackBlockFactory.java b/src/com/jaquadro/minecraft/storagedrawers/api/pack/IPackBlockFactory.java index 41a9793..0f399b0 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/api/pack/IPackBlockFactory.java +++ b/src/com/jaquadro/minecraft/storagedrawers/api/pack/IPackBlockFactory.java @@ -21,4 +21,9 @@ public interface IPackBlockFactory * Hides block from NEI if NEI is active. */ void hideBlock (String blockID); + + /** + * Registers block metadata from an initialized DataResolver with Storage Drawers. + */ + void registerResolver (IExtendedDataResolver resolver); } diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/BlockCompDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/block/BlockCompDrawers.java index 01a3886..32b70c8 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/BlockCompDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/BlockCompDrawers.java @@ -1,6 +1,7 @@ package com.jaquadro.minecraft.storagedrawers.block; import com.jaquadro.minecraft.storagedrawers.StorageDrawers; +import com.jaquadro.minecraft.storagedrawers.api.pack.BlockType; import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer; import com.jaquadro.minecraft.storagedrawers.api.storage.INetworked; import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers; @@ -52,6 +53,11 @@ public class BlockCompDrawers extends BlockDrawers implements INetworked return 2; } + @Override + protected BlockType retrimType () { + return null; + } + @Override public TileEntityDrawers createNewTileEntity (World world, int meta) { return new TileEntityDrawersComp(); diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java index cb6f163..01711ff 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java @@ -3,6 +3,8 @@ package com.jaquadro.minecraft.storagedrawers.block; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.jaquadro.minecraft.storagedrawers.StorageDrawers; +import com.jaquadro.minecraft.storagedrawers.api.pack.BlockConfiguration; +import com.jaquadro.minecraft.storagedrawers.api.pack.BlockType; import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer; import com.jaquadro.minecraft.storagedrawers.api.storage.INetworked; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.LockAttribute; @@ -11,6 +13,7 @@ import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersStandar import com.jaquadro.minecraft.storagedrawers.core.ModCreativeTabs; import com.jaquadro.minecraft.storagedrawers.core.ModItems; import com.jaquadro.minecraft.storagedrawers.core.handlers.GuiHandler; +import com.jaquadro.minecraft.storagedrawers.item.ItemTrim; import com.jaquadro.minecraft.storagedrawers.network.BlockClickMessage; import cpw.mods.fml.common.FMLLog; @@ -122,6 +125,48 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH setLightOpacity(255); } + public boolean retrimBlock (World world, int x, int y, int z, ItemStack prototype) { + if (retrimType() == null) + return false; + + Block protoBlock = Block.getBlockFromItem(prototype.getItem()); + int protoMeta = prototype.getItemDamage(); + + BlockConfiguration config = BlockConfiguration.by(retrimType(), drawerCount, halfDepth); + + Block plankBlock = StorageDrawers.blockRegistry.getPlankBlock(BlockConfiguration.Trim, protoBlock, protoMeta); + int plankMeta = StorageDrawers.blockRegistry.getPlankMeta(BlockConfiguration.Trim, protoBlock, protoMeta); + + Block newBlock = StorageDrawers.blockRegistry.getBlock(config, plankBlock, plankMeta); + int newMeta = StorageDrawers.blockRegistry.getMeta(config, plankBlock, plankMeta); + + if (newBlock == null) + return false; + + if (newBlock == this) + world.setBlockMetadataWithNotify(x, y, z, newMeta, 3); + else { + TileEntity tile = world.getTileEntity(x, y, z); + TileEntity newDrawer = createNewTileEntity(world, newMeta); + + NBTTagCompound tag = new NBTTagCompound(); + tile.writeToNBT(tag); + newDrawer.readFromNBT(tag); + + world.removeTileEntity(x, y, z); + world.setBlockToAir(x, y, z); + + world.setBlock(x, y, z, newBlock, newMeta, 3); + world.setTileEntity(x, y, z, newDrawer); + } + + return true; + } + + protected BlockType retrimType () { + return BlockType.Drawers; + } + public float getTrimWidth () { return trimWidth; } @@ -252,7 +297,18 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH } if (item != null && item.getItem() != null) { - if (item.getItem() == ModItems.upgrade || item.getItem() == ModItems.upgradeStatus || item.getItem() == ModItems.upgradeVoid || item.getItem() == ModItems.upgradeCreative) { + if (item.getItem() instanceof ItemTrim && player.isSneaking()) { + if (!retrimBlock(world, x, y, z, item)) + return false; + + if (player != null && !player.capabilities.isCreativeMode) { + if (--item.stackSize <= 0) + player.inventory.setInventorySlotContents(player.inventory.currentItem, null); + } + + return true; + } + else if (item.getItem() == ModItems.upgrade || item.getItem() == ModItems.upgradeStatus || item.getItem() == ModItems.upgradeVoid || item.getItem() == ModItems.upgradeCreative) { if (!tileDrawers.addUpgrade(item)) { player.addChatMessage(new ChatComponentTranslation("storagedrawers.msg.maxUpgrades")); return false; diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/DataResolver.java b/src/com/jaquadro/minecraft/storagedrawers/block/DataResolver.java new file mode 100644 index 0000000..7bd1f5e --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/block/DataResolver.java @@ -0,0 +1,67 @@ +package com.jaquadro.minecraft.storagedrawers.block; + +import com.jaquadro.minecraft.storagedrawers.api.pack.BlockConfiguration; +import com.jaquadro.minecraft.storagedrawers.api.pack.BlockType; +import com.jaquadro.minecraft.storagedrawers.api.pack.ExtendedDataResolver; +import com.jaquadro.minecraft.storagedrawers.core.ModBlocks; +import com.jaquadro.minecraft.storagedrawers.core.ModCreativeTabs; +import com.jaquadro.minecraft.storagedrawers.integration.RefinedRelocation; +import net.minecraft.block.Block; +import net.minecraft.block.BlockWood; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.init.Blocks; + +public class DataResolver extends ExtendedDataResolver +{ + private static String[] textureNames = BlockWood.field_150096_a; + + public DataResolver (String modID) { + super(modID, textureNames); + } + + @Override + public CreativeTabs getCreativeTabs (BlockType type) { + return ModCreativeTabs.tabStorageDrawers; + } + + @Override + public Block getBlock (BlockConfiguration blockConfig) { + switch (blockConfig.getBlockType()) { + case Drawers: + if (blockConfig.getDrawerCount() == 1) + return ModBlocks.fullDrawers1; + if (blockConfig.getDrawerCount() == 2 && !blockConfig.isHalfDepth()) + return ModBlocks.fullDrawers2; + if (blockConfig.getDrawerCount() == 4 && !blockConfig.isHalfDepth()) + return ModBlocks.fullDrawers4; + if (blockConfig.getDrawerCount() == 2 && blockConfig.isHalfDepth()) + return ModBlocks.halfDrawers2; + if (blockConfig.getDrawerCount() == 4 && blockConfig.isHalfDepth()) + return ModBlocks.halfDrawers4; + break; + case DrawersSorting: + if (blockConfig.getDrawerCount() == 1) + return RefinedRelocation.fullDrawers1; + if (blockConfig.getDrawerCount() == 2 && !blockConfig.isHalfDepth()) + return RefinedRelocation.fullDrawers2; + if (blockConfig.getDrawerCount() == 4 && !blockConfig.isHalfDepth()) + return RefinedRelocation.fullDrawers4; + if (blockConfig.getDrawerCount() == 2 && blockConfig.isHalfDepth()) + return RefinedRelocation.halfDrawers2; + if (blockConfig.getDrawerCount() == 4 && blockConfig.isHalfDepth()) + return RefinedRelocation.halfDrawers4; + break; + case Trim: + return ModBlocks.trim; + case TrimSorting: + return RefinedRelocation.trim; + } + return null; + } + + @Override + public void init () { + for (int i = 0, p = 0, m = 0; i < 6; i++, p++, m++) + setPlankSlab(i, Blocks.planks, p, Blocks.wooden_slab, m); + } +} diff --git a/src/com/jaquadro/minecraft/storagedrawers/core/ModBlocks.java b/src/com/jaquadro/minecraft/storagedrawers/core/ModBlocks.java index 6c3e65c..ddffb6b 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/core/ModBlocks.java +++ b/src/com/jaquadro/minecraft/storagedrawers/core/ModBlocks.java @@ -19,6 +19,8 @@ import net.minecraftforge.oredict.OreDictionary; public class ModBlocks { + public static DataResolver resolver; + public static BlockDrawers fullDrawers1; public static BlockDrawers fullDrawers2; public static BlockDrawers fullDrawers4; @@ -30,6 +32,8 @@ public class ModBlocks public static BlockSlave controllerSlave; public void init () { + resolver = new DataResolver(StorageDrawers.MOD_ID); + fullDrawers1 = new BlockDrawers("fullDrawers1", 1, false); fullDrawers2 = new BlockDrawers("fullDrawers2", 2, false); fullDrawers4 = new BlockDrawers("fullDrawers4", 4, false); @@ -91,6 +95,8 @@ public class ModBlocks OreDictionary.registerOre(key, new ItemStack(halfDrawers2, 1, OreDictionary.WILDCARD_VALUE)); for (String key : new String[] { "drawerBasic" }) OreDictionary.registerOre(key, new ItemStack(halfDrawers4, 1, OreDictionary.WILDCARD_VALUE)); + + resolver.init(); } public static String getQualifiedName (String name) { diff --git a/src/com/jaquadro/minecraft/storagedrawers/core/api/BlockRegistry.java b/src/com/jaquadro/minecraft/storagedrawers/core/api/BlockRegistry.java new file mode 100644 index 0000000..bf83f55 --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/core/api/BlockRegistry.java @@ -0,0 +1,81 @@ +package com.jaquadro.minecraft.storagedrawers.core.api; + +import com.jaquadro.minecraft.storagedrawers.api.pack.BlockConfiguration; +import com.jaquadro.minecraft.storagedrawers.api.pack.IExtendedDataResolver; +import com.jaquadro.minecraft.storagedrawers.util.UniqueMetaIdentifier; +import com.jaquadro.minecraft.storagedrawers.util.UniqueMetaRegistry; +import net.minecraft.block.Block; + +import java.util.HashMap; +import java.util.Map; + +public class BlockRegistry +{ + private Map> registry = new HashMap>(); + private Map> invertRegistry = new HashMap>(); + + public void register (BlockConfiguration config, IExtendedDataResolver resolver) { + for (int i = 0; i < 16; i++) { + if (resolver.isValidMetaValue(i)) + register(config, resolver.getBlock(config), i, resolver.getPlankBlock(i), resolver.getPlankMeta(i)); + } + } + + public void register (BlockConfiguration config, Block block, int meta, Block plankBlock, int plankMeta) { + UniqueMetaRegistry uniq = registry.get(config); + if (uniq == null) { + uniq = new UniqueMetaRegistry(); + registry.put(config, uniq); + } + + uniq.register(UniqueMetaIdentifier.createFor(plankBlock, plankMeta), UniqueMetaIdentifier.createFor(block, meta)); + + UniqueMetaRegistry blockReg = invertRegistry.get(config); + if (blockReg == null) { + blockReg = new UniqueMetaRegistry(); + invertRegistry.put(config, blockReg); + } + + blockReg.register(UniqueMetaIdentifier.createFor(block, meta), UniqueMetaIdentifier.createFor(plankBlock, plankMeta)); + } + + public Block getBlock (BlockConfiguration config, Block plankBlock, int plankMeta) { + return blockLookup(registry, config, plankBlock, plankMeta); + } + + public int getMeta (BlockConfiguration config, Block plankBlock, int plankMeta) { + return metaLookup(registry, config, plankBlock, plankMeta); + } + + public Block getPlankBlock (BlockConfiguration config, Block block, int meta) { + return blockLookup(invertRegistry, config, block, meta); + } + + public int getPlankMeta (BlockConfiguration config, Block block, int meta) { + return metaLookup(invertRegistry, config, block, meta); + } + + private Block blockLookup (Map> reg, BlockConfiguration config, Block block, int meta) { + UniqueMetaRegistry uniq = reg.get(config); + if (uniq == null) + return null; + + UniqueMetaIdentifier id = uniq.getEntry(UniqueMetaIdentifier.createFor(block, meta)); + if (id == null) + return null; + + return id.getBlock(); + } + + private int metaLookup (Map> reg, BlockConfiguration config, Block block, int meta) { + UniqueMetaRegistry uniq = reg.get(config); + if (uniq == null) + return 0; + + UniqueMetaIdentifier id = uniq.getEntry(UniqueMetaIdentifier.createFor(block, meta)); + if (id == null) + return 0; + + return id.meta; + } +} diff --git a/src/com/jaquadro/minecraft/storagedrawers/core/api/PackFactory.java b/src/com/jaquadro/minecraft/storagedrawers/core/api/PackFactory.java index 6f845e2..c1855b0 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/core/api/PackFactory.java +++ b/src/com/jaquadro/minecraft/storagedrawers/core/api/PackFactory.java @@ -2,9 +2,11 @@ package com.jaquadro.minecraft.storagedrawers.core.api; import com.jaquadro.minecraft.storagedrawers.StorageDrawers; import com.jaquadro.minecraft.storagedrawers.api.pack.BlockConfiguration; +import com.jaquadro.minecraft.storagedrawers.api.pack.IExtendedDataResolver; import com.jaquadro.minecraft.storagedrawers.api.pack.IPackBlockFactory; import com.jaquadro.minecraft.storagedrawers.api.pack.IPackDataResolver; import com.jaquadro.minecraft.storagedrawers.block.pack.BlockSortingTrimPack; +import com.jaquadro.minecraft.storagedrawers.config.ConfigManager; import com.jaquadro.minecraft.storagedrawers.integration.IntegrationRegistry; import com.jaquadro.minecraft.storagedrawers.block.pack.BlockDrawersPack; import com.jaquadro.minecraft.storagedrawers.block.pack.BlockSortingDrawersPack; @@ -83,4 +85,39 @@ public class PackFactory implements IPackBlockFactory public void hideBlock (String blockID) { NEIStorageDrawersConfig.hideBlock(blockID); } + + @Override + public void registerResolver (IExtendedDataResolver resolver) { + ConfigManager config = StorageDrawers.config; + if (config.isBlockEnabled("fulldrawers1")) { + StorageDrawers.blockRegistry.register(BlockConfiguration.BasicFull1, resolver); + if (config.cache.enableRefinedRelocationIntegration) + StorageDrawers.blockRegistry.register(BlockConfiguration.SortingFull1, resolver); + } + if (config.isBlockEnabled("fulldrawers2")) { + StorageDrawers.blockRegistry.register(BlockConfiguration.BasicFull2, resolver); + if (config.cache.enableRefinedRelocationIntegration) + StorageDrawers.blockRegistry.register(BlockConfiguration.SortingFull2, resolver); + } + if (config.isBlockEnabled("fulldrawers4")) { + StorageDrawers.blockRegistry.register(BlockConfiguration.BasicFull4, resolver); + if (config.cache.enableRefinedRelocationIntegration) + StorageDrawers.blockRegistry.register(BlockConfiguration.SortingFull4, resolver); + } + if (config.isBlockEnabled("halfdrawers2")) { + StorageDrawers.blockRegistry.register(BlockConfiguration.BasicHalf2, resolver); + if (config.cache.enableRefinedRelocationIntegration) + StorageDrawers.blockRegistry.register(BlockConfiguration.SortingHalf2, resolver); + } + if (config.isBlockEnabled("halfdrawers4")) { + StorageDrawers.blockRegistry.register(BlockConfiguration.BasicHalf4, resolver); + if (config.cache.enableRefinedRelocationIntegration) + StorageDrawers.blockRegistry.register(BlockConfiguration.SortingHalf4, resolver); + } + if (config.isBlockEnabled("trim")) { + StorageDrawers.blockRegistry.register(BlockConfiguration.Trim, resolver); + if (config.cache.enableRefinedRelocationIntegration) + StorageDrawers.blockRegistry.register(BlockConfiguration.TrimSorting, resolver); + } + } } diff --git a/src/com/jaquadro/minecraft/storagedrawers/integration/refinedrelocation/BlockSortingDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/integration/refinedrelocation/BlockSortingDrawers.java index abcd94d..1a35f85 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/integration/refinedrelocation/BlockSortingDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/integration/refinedrelocation/BlockSortingDrawers.java @@ -1,6 +1,7 @@ package com.jaquadro.minecraft.storagedrawers.integration.refinedrelocation; import com.jaquadro.minecraft.storagedrawers.StorageDrawers; +import com.jaquadro.minecraft.storagedrawers.api.pack.BlockType; import com.jaquadro.minecraft.storagedrawers.block.BlockDrawers; import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersStandard; import com.jaquadro.minecraft.storagedrawers.integration.RefinedRelocation; @@ -54,6 +55,11 @@ public class BlockSortingDrawers extends BlockDrawers return true; } + @Override + protected BlockType retrimType () { + return BlockType.DrawersSorting; + } + @Override public TileSortingDrawersStandard createNewTileEntity (World world, int meta) { return new TileSortingDrawersStandard(); diff --git a/src/com/jaquadro/minecraft/storagedrawers/item/ItemTrim.java b/src/com/jaquadro/minecraft/storagedrawers/item/ItemTrim.java index d307233..db34475 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/item/ItemTrim.java +++ b/src/com/jaquadro/minecraft/storagedrawers/item/ItemTrim.java @@ -2,7 +2,9 @@ package com.jaquadro.minecraft.storagedrawers.item; import net.minecraft.block.Block; import net.minecraft.block.BlockWood; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemMultiTexture; +import net.minecraft.world.World; public class ItemTrim extends ItemMultiTexture { @@ -13,4 +15,9 @@ public class ItemTrim extends ItemMultiTexture protected ItemTrim (Block block, String[] names) { super(block, block, names); } + + @Override + public boolean doesSneakBypassUse (World world, int x, int y, int z, EntityPlayer player) { + return true; + } } diff --git a/src/com/jaquadro/minecraft/storagedrawers/util/UniqueMetaIdentifier.java b/src/com/jaquadro/minecraft/storagedrawers/util/UniqueMetaIdentifier.java new file mode 100644 index 0000000..2cbf2e8 --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/util/UniqueMetaIdentifier.java @@ -0,0 +1,133 @@ +package com.jaquadro.minecraft.storagedrawers.util; + +import com.google.common.base.Objects; +import cpw.mods.fml.common.registry.GameData; +import cpw.mods.fml.common.registry.GameRegistry; +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; + +public final class UniqueMetaIdentifier +{ + public final String modId; + public final String name; + public final int meta; + + private GameRegistry.UniqueIdentifier cachedUID; + + public UniqueMetaIdentifier (String modId, String name) { + this.modId = modId; + this.name = name; + this.meta = OreDictionary.WILDCARD_VALUE; + } + + public UniqueMetaIdentifier (String modId, String name, int meta) { + this.modId = modId; + this.name = name; + this.meta = meta; + } + + public UniqueMetaIdentifier (String qualifiedName, int meta) { + String[] parts = qualifiedName.split(":"); + this.modId = parts[0]; + this.name = parts[1]; + this.meta = meta; + } + + public UniqueMetaIdentifier (String compoundName) { + String[] parts1 = compoundName.split(";"); + String[] parts2 = parts1[0].split(":"); + this.modId = parts2[0]; + + if (parts2.length >= 2) + this.name = parts2[1]; + else + this.name = ""; + + if (parts1.length >= 2) + this.meta = Integer.parseInt(parts1[1]); + else if (parts2.length > 2) + this.meta = Integer.parseInt(parts2[parts2.length - 1]); + else + this.meta = OreDictionary.WILDCARD_VALUE; + } + + public UniqueMetaIdentifier (String compoundName, char separator) { + String[] parts1 = compoundName.split("[ ]*" + separator + "[ ]*"); + String[] parts2 = parts1[0].split(":"); + this.modId = parts2[0]; + + if (parts2.length >= 2) + this.name = parts2[1]; + else + this.name = ""; + + if (parts1.length >= 2) + this.meta = Integer.parseInt(parts1[1]); + else + this.meta = OreDictionary.WILDCARD_VALUE; + } + + public GameRegistry.UniqueIdentifier getUniqueIdentifier () { + if (cachedUID == null) + cachedUID = new GameRegistry.UniqueIdentifier(modId + ":" + name); + return cachedUID; + } + + public Block getBlock () { + return GameRegistry.findBlock(modId, name); + } + + public Item getItem () { + return GameRegistry.findItem(modId, name); + } + + @Override + public boolean equals (Object obj) { + if (obj == null) + return false; + if (obj.getClass() != getClass()) + return false; + + final UniqueMetaIdentifier other = (UniqueMetaIdentifier) obj; + + return Objects.equal(modId, other.modId) + && Objects.equal(name, other.name) + && meta == other.meta; + } + + @Override + public int hashCode () { + return Objects.hashCode(modId, name) ^ (meta * 37); + } + + @Override + public String toString () { + return String.format("%s:%s;%d", modId, name, meta); + } + + public static UniqueMetaIdentifier createFor (ItemStack itemStack) { + if (itemStack.getItem() == null) + return null; + + String name = GameData.getItemRegistry().getNameForObject(itemStack.getItem()); + return new UniqueMetaIdentifier(name, itemStack.getItemDamage()); + } + + public static UniqueMetaIdentifier createFor (Block block, int meta) { + if (block == null) + return null; + + String name = GameData.getBlockRegistry().getNameForObject(block); + return new UniqueMetaIdentifier(name, meta); + } + + public static UniqueMetaIdentifier createFor (Block block) { + if (block == null) + return null; + + String name = GameData.getBlockRegistry().getNameForObject(block); + return new UniqueMetaIdentifier(name); + } +} diff --git a/src/com/jaquadro/minecraft/storagedrawers/util/UniqueMetaRegistry.java b/src/com/jaquadro/minecraft/storagedrawers/util/UniqueMetaRegistry.java new file mode 100644 index 0000000..6bc3c24 --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/util/UniqueMetaRegistry.java @@ -0,0 +1,55 @@ +package com.jaquadro.minecraft.storagedrawers.util; + +import net.minecraftforge.oredict.OreDictionary; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +public class UniqueMetaRegistry +{ + private Map registry; + + public UniqueMetaRegistry () { + registry = new HashMap(); + } + + public void register (UniqueMetaIdentifier id, E entry) { + registry.put(id, entry); + } + + public E getEntry (UniqueMetaIdentifier id) { + if (id == null) + return null; + + if (registry.containsKey(id)) + return registry.get(id); + + if (id.meta != OreDictionary.WILDCARD_VALUE) { + id = new UniqueMetaIdentifier(id.modId, id.name); + if (registry.containsKey(id)) + return registry.get(id); + + if (!id.name.isEmpty()) { + id = new UniqueMetaIdentifier(id.modId); + if (registry.containsKey(id)) + return registry.get(id); + } + } + + return null; + } + + public void remove (UniqueMetaIdentifier id) { + if (id != null) + registry.remove(id); + } + + public Set> entrySet () { + return registry.entrySet(); + } + + public void clear () { + registry.clear(); + } +} From cf1f5f383cd15d1c4873c56070d690376354c80b Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Thu, 14 Jan 2016 01:47:10 -0500 Subject: [PATCH 05/24] Update addon packs to support retrimming --- packs/BiomesOPlenty/build.gradle | 2 +- .../storagedrawers/packs/bop/StorageDrawersPack.java | 4 +++- packs/Erebus/build.gradle | 2 +- .../storagedrawers/packs/erebus/StorageDrawersPack.java | 4 +++- packs/Forestry/build.gradle | 2 +- .../storagedrawers/packs/forestry/StorageDrawersPack.java | 4 +++- packs/Misc/build.gradle | 2 +- .../storagedrawers/packs/misc/StorageDrawersPack.java | 4 +++- packs/Natura/build.gradle | 2 +- .../storagedrawers/packs/natura/StorageDrawersPack.java | 4 +++- 10 files changed, 20 insertions(+), 10 deletions(-) diff --git a/packs/BiomesOPlenty/build.gradle b/packs/BiomesOPlenty/build.gradle index 2e86ac8..b6ef9eb 100644 --- a/packs/BiomesOPlenty/build.gradle +++ b/packs/BiomesOPlenty/build.gradle @@ -17,7 +17,7 @@ buildscript { apply plugin: 'forge' -version = "1.7.10-1.1.0" +version = "1.7.10-1.1.1" group= "com.jaquadro.minecraft.storagedrawers" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "StorageDrawers-BiomesOPlenty" diff --git a/packs/BiomesOPlenty/src/com/jaquadro/minecraft/storagedrawers/packs/bop/StorageDrawersPack.java b/packs/BiomesOPlenty/src/com/jaquadro/minecraft/storagedrawers/packs/bop/StorageDrawersPack.java index 81f04aa..c41cab9 100644 --- a/packs/BiomesOPlenty/src/com/jaquadro/minecraft/storagedrawers/packs/bop/StorageDrawersPack.java +++ b/packs/BiomesOPlenty/src/com/jaquadro/minecraft/storagedrawers/packs/bop/StorageDrawersPack.java @@ -41,7 +41,9 @@ public class StorageDrawersPack @Mod.EventHandler public void postInit (FMLPostInitializationEvent event) { IStorageDrawersApi api = StorageDrawersApi.instance(); - if (api != null) + if (api != null) { api.registerStandardPackRecipes(resolver); + api.packFactory().registerResolver(resolver); + } } } diff --git a/packs/Erebus/build.gradle b/packs/Erebus/build.gradle index ad02755..db27a5c 100644 --- a/packs/Erebus/build.gradle +++ b/packs/Erebus/build.gradle @@ -17,7 +17,7 @@ buildscript { apply plugin: 'forge' -version = "1.7.10-1.1.0" +version = "1.7.10-1.1.1" group= "com.jaquadro.minecraft.storagedrawers" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "StorageDrawers-Erebus" diff --git a/packs/Erebus/src/com/jaquadro/minecraft/storagedrawers/packs/erebus/StorageDrawersPack.java b/packs/Erebus/src/com/jaquadro/minecraft/storagedrawers/packs/erebus/StorageDrawersPack.java index 53a5c38..95a751f 100644 --- a/packs/Erebus/src/com/jaquadro/minecraft/storagedrawers/packs/erebus/StorageDrawersPack.java +++ b/packs/Erebus/src/com/jaquadro/minecraft/storagedrawers/packs/erebus/StorageDrawersPack.java @@ -41,7 +41,9 @@ public class StorageDrawersPack @Mod.EventHandler public void postInit (FMLPostInitializationEvent event) { IStorageDrawersApi api = StorageDrawersApi.instance(); - if (api != null) + if (api != null) { api.registerStandardPackRecipes(resolver); + api.packFactory().registerResolver(resolver); + } } } diff --git a/packs/Forestry/build.gradle b/packs/Forestry/build.gradle index 1abcc20..3f46e3f 100644 --- a/packs/Forestry/build.gradle +++ b/packs/Forestry/build.gradle @@ -17,7 +17,7 @@ buildscript { apply plugin: 'forge' -version = "1.7.10-1.1.0" +version = "1.7.10-1.1.1" group= "com.jaquadro.minecraft.storagedrawers" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "StorageDrawers-Forestry" diff --git a/packs/Forestry/src/com/jaquadro/minecraft/storagedrawers/packs/forestry/StorageDrawersPack.java b/packs/Forestry/src/com/jaquadro/minecraft/storagedrawers/packs/forestry/StorageDrawersPack.java index 81fbc87..24470ab 100644 --- a/packs/Forestry/src/com/jaquadro/minecraft/storagedrawers/packs/forestry/StorageDrawersPack.java +++ b/packs/Forestry/src/com/jaquadro/minecraft/storagedrawers/packs/forestry/StorageDrawersPack.java @@ -49,8 +49,10 @@ public class StorageDrawersPack public void postInit (FMLPostInitializationEvent event) { IStorageDrawersApi api = StorageDrawersApi.instance(); if (api != null) { - for (IExtendedDataResolver resolver : resolvers) + for (IExtendedDataResolver resolver : resolvers) { api.registerStandardPackRecipes(resolver); + api.packFactory().registerResolver(resolver); + } } } } diff --git a/packs/Misc/build.gradle b/packs/Misc/build.gradle index afd81e9..38a4b1d 100644 --- a/packs/Misc/build.gradle +++ b/packs/Misc/build.gradle @@ -17,7 +17,7 @@ buildscript { apply plugin: 'forge' -version = "1.7.10-1.1.0" +version = "1.7.10-1.1.1" group= "com.jaquadro.minecraft.storagedrawers" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "StorageDrawers-Misc" diff --git a/packs/Misc/src/com/jaquadro/minecraft/storagedrawers/packs/misc/StorageDrawersPack.java b/packs/Misc/src/com/jaquadro/minecraft/storagedrawers/packs/misc/StorageDrawersPack.java index 7248a37..cd42acc 100644 --- a/packs/Misc/src/com/jaquadro/minecraft/storagedrawers/packs/misc/StorageDrawersPack.java +++ b/packs/Misc/src/com/jaquadro/minecraft/storagedrawers/packs/misc/StorageDrawersPack.java @@ -47,8 +47,10 @@ public class StorageDrawersPack public void postInit (FMLPostInitializationEvent event) { IStorageDrawersApi api = StorageDrawersApi.instance(); if (api != null) { - for (IExtendedDataResolver resolver : resolvers) + for (IExtendedDataResolver resolver : resolvers) { api.registerStandardPackRecipes(resolver); + api.packFactory().registerResolver(resolver); + } } } } diff --git a/packs/Natura/build.gradle b/packs/Natura/build.gradle index 805dda8..fc38568 100644 --- a/packs/Natura/build.gradle +++ b/packs/Natura/build.gradle @@ -17,7 +17,7 @@ buildscript { apply plugin: 'forge' -version = "1.7.10-1.1.0" +version = "1.7.10-1.1.1" group= "com.jaquadro.minecraft.storagedrawers" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "StorageDrawers-Natura" diff --git a/packs/Natura/src/com/jaquadro/minecraft/storagedrawers/packs/natura/StorageDrawersPack.java b/packs/Natura/src/com/jaquadro/minecraft/storagedrawers/packs/natura/StorageDrawersPack.java index 81787fd..c256000 100644 --- a/packs/Natura/src/com/jaquadro/minecraft/storagedrawers/packs/natura/StorageDrawersPack.java +++ b/packs/Natura/src/com/jaquadro/minecraft/storagedrawers/packs/natura/StorageDrawersPack.java @@ -41,7 +41,9 @@ public class StorageDrawersPack @Mod.EventHandler public void postInit (FMLPostInitializationEvent event) { IStorageDrawersApi api = StorageDrawersApi.instance(); - if (api != null) + if (api != null) { api.registerStandardPackRecipes(resolver); + api.packFactory().registerResolver(resolver); + } } } From 519a2087416c1cff8913954f94e7d5cc6ebc9ad8 Mon Sep 17 00:00:00 2001 From: David Vierra Date: Thu, 14 Jan 2016 00:22:50 -1000 Subject: [PATCH 06/24] Fix NPE in PackFactory.registerResolver when RR is not installed. --- .../storagedrawers/core/api/PackFactory.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/com/jaquadro/minecraft/storagedrawers/core/api/PackFactory.java b/src/com/jaquadro/minecraft/storagedrawers/core/api/PackFactory.java index c1855b0..b6ba386 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/core/api/PackFactory.java +++ b/src/com/jaquadro/minecraft/storagedrawers/core/api/PackFactory.java @@ -17,6 +17,7 @@ import com.jaquadro.minecraft.storagedrawers.item.pack.ItemDrawersPack; import com.jaquadro.minecraft.storagedrawers.item.pack.ItemSortingDrawersPack; import com.jaquadro.minecraft.storagedrawers.item.pack.ItemSortingTrimPack; import com.jaquadro.minecraft.storagedrawers.item.pack.ItemTrimPack; +import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.registry.GameRegistry; import net.minecraft.block.Block; import net.minecraft.item.ItemStack; @@ -91,32 +92,32 @@ public class PackFactory implements IPackBlockFactory ConfigManager config = StorageDrawers.config; if (config.isBlockEnabled("fulldrawers1")) { StorageDrawers.blockRegistry.register(BlockConfiguration.BasicFull1, resolver); - if (config.cache.enableRefinedRelocationIntegration) + if (Loader.isModLoaded("RefinedRelocation") && config.cache.enableRefinedRelocationIntegration) StorageDrawers.blockRegistry.register(BlockConfiguration.SortingFull1, resolver); } if (config.isBlockEnabled("fulldrawers2")) { StorageDrawers.blockRegistry.register(BlockConfiguration.BasicFull2, resolver); - if (config.cache.enableRefinedRelocationIntegration) + if (Loader.isModLoaded("RefinedRelocation") && config.cache.enableRefinedRelocationIntegration) StorageDrawers.blockRegistry.register(BlockConfiguration.SortingFull2, resolver); } if (config.isBlockEnabled("fulldrawers4")) { StorageDrawers.blockRegistry.register(BlockConfiguration.BasicFull4, resolver); - if (config.cache.enableRefinedRelocationIntegration) + if (Loader.isModLoaded("RefinedRelocation") && config.cache.enableRefinedRelocationIntegration) StorageDrawers.blockRegistry.register(BlockConfiguration.SortingFull4, resolver); } if (config.isBlockEnabled("halfdrawers2")) { StorageDrawers.blockRegistry.register(BlockConfiguration.BasicHalf2, resolver); - if (config.cache.enableRefinedRelocationIntegration) + if (Loader.isModLoaded("RefinedRelocation") && config.cache.enableRefinedRelocationIntegration) StorageDrawers.blockRegistry.register(BlockConfiguration.SortingHalf2, resolver); } if (config.isBlockEnabled("halfdrawers4")) { StorageDrawers.blockRegistry.register(BlockConfiguration.BasicHalf4, resolver); - if (config.cache.enableRefinedRelocationIntegration) + if (Loader.isModLoaded("RefinedRelocation") && config.cache.enableRefinedRelocationIntegration) StorageDrawers.blockRegistry.register(BlockConfiguration.SortingHalf4, resolver); } if (config.isBlockEnabled("trim")) { StorageDrawers.blockRegistry.register(BlockConfiguration.Trim, resolver); - if (config.cache.enableRefinedRelocationIntegration) + if (Loader.isModLoaded("RefinedRelocation") && config.cache.enableRefinedRelocationIntegration) StorageDrawers.blockRegistry.register(BlockConfiguration.TrimSorting, resolver); } } From f217dd6c99bdaa8c3a95d0c461f946be9668d754 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Fri, 15 Jan 2016 02:09:09 -0500 Subject: [PATCH 07/24] Apply same-style trim to hide upgrade border; added capacity line to WAILA; changed default WAILA item counts to 'JABBA' style --- .../assets/storagedrawers/lang/en_US.lang | 1 + .../block/BlockCompDrawers.java | 2 +- .../storagedrawers/block/BlockDrawers.java | 10 +++++++-- .../block/tile/TileEntityDrawers.java | 21 +++++++++++++++++++ .../client/renderer/DrawersRenderer.java | 2 +- .../storagedrawers/config/ConfigManager.java | 2 +- .../storagedrawers/integration/Waila.java | 3 +++ .../BlockSortingDrawers.java | 2 +- .../storagedrawers/item/ItemTrim.java | 7 ++++++- 9 files changed, 43 insertions(+), 7 deletions(-) diff --git a/resources/assets/storagedrawers/lang/en_US.lang b/resources/assets/storagedrawers/lang/en_US.lang index 3b06ec7..8c4985d 100644 --- a/resources/assets/storagedrawers/lang/en_US.lang +++ b/resources/assets/storagedrawers/lang/en_US.lang @@ -92,6 +92,7 @@ storageDrawers.controllerSlave.description=Extra attach points for controllers storageDrawers.waila.empty= storageDrawers.waila.level=Upgrade Level: %s storageDrawers.waila.drawer=#%s: %s +storageDrawers.waila.limit=Stack Limit: %s (x%s) storageDrawers.waila.locked=Locked storageDrawers.waila.void=Void storageDrawers.waila.sorting=Sorting diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/BlockCompDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/block/BlockCompDrawers.java index 32b70c8..28fc504 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/BlockCompDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/BlockCompDrawers.java @@ -54,7 +54,7 @@ public class BlockCompDrawers extends BlockDrawers implements INetworked } @Override - protected BlockType retrimType () { + public BlockType retrimType () { return null; } diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java index 01711ff..b51188f 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java @@ -143,10 +143,16 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH if (newBlock == null) return false; + TileEntityDrawers tile = getTileEntity(world, x, y, z); + if (newBlock == this && newMeta == world.getBlockMetadata(x, y, z) && !tile.shouldHideUpgrades()) { + tile.setShouldHideUpgrades(true); + return true; + } + if (newBlock == this) world.setBlockMetadataWithNotify(x, y, z, newMeta, 3); else { - TileEntity tile = world.getTileEntity(x, y, z); + TileEntity newDrawer = createNewTileEntity(world, newMeta); NBTTagCompound tag = new NBTTagCompound(); @@ -163,7 +169,7 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH return true; } - protected BlockType retrimType () { + public BlockType retrimType () { return BlockType.Drawers; } diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java index eab6d54..0010a8f 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java @@ -46,6 +46,7 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe private int drawerCapacity = 1; private boolean shrouded = false; private boolean taped = false; + private boolean hideUpgrade = false; private EnumSet lockAttributes = null; @@ -240,6 +241,19 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe } } + public boolean shouldHideUpgrades () { + return hideUpgrade; + } + + public void setShouldHideUpgrades (boolean hide) { + hideUpgrade = hide; + + if (worldObj != null && !worldObj.isRemote) { + markDirty(); + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + } + public boolean isSealed () { if (!StorageDrawers.config.cache.enableTape) return false; @@ -462,6 +476,10 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe if (tag.hasKey("Shr")) shrouded = tag.getBoolean("Shr"); + hideUpgrade = false; + if (tag.hasKey("HideUp")) + hideUpgrade = tag.getBoolean("HideUp"); + NBTTagList slots = tag.getTagList("Slots", Constants.NBT.TAG_COMPOUND); drawers = new IDrawer[slots.tagCount()]; @@ -499,6 +517,9 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe if (shrouded) tag.setBoolean("Shr", shrouded); + if (hideUpgrade) + tag.setBoolean("HideUp", hideUpgrade); + NBTTagList slots = new NBTTagList(); for (IDrawer drawer : drawers) { NBTTagCompound slot = new NBTTagCompound(); diff --git a/src/com/jaquadro/minecraft/storagedrawers/client/renderer/DrawersRenderer.java b/src/com/jaquadro/minecraft/storagedrawers/client/renderer/DrawersRenderer.java index 5768687..d451ee5 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/client/renderer/DrawersRenderer.java +++ b/src/com/jaquadro/minecraft/storagedrawers/client/renderer/DrawersRenderer.java @@ -115,7 +115,7 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler renderer.uvRotateTop = 0; int maxStorageLevel = tile.getMaxStorageLevel(); - if (maxStorageLevel > 1 && StorageDrawers.config.cache.renderStorageUpgrades) { + if (maxStorageLevel > 1 && StorageDrawers.config.cache.renderStorageUpgrades && !tile.shouldHideUpgrades()) { for (int i = 0; i < 6; i++) boxRenderer.setExteriorIcon(block.getOverlayIcon(world, x, y, z, i, maxStorageLevel), i); diff --git a/src/com/jaquadro/minecraft/storagedrawers/config/ConfigManager.java b/src/com/jaquadro/minecraft/storagedrawers/config/ConfigManager.java index e4caaf7..9e671a6 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/config/ConfigManager.java +++ b/src/com/jaquadro/minecraft/storagedrawers/config/ConfigManager.java @@ -239,7 +239,7 @@ public class ConfigManager cache.enableSidedOutput = config.get(Configuration.CATEGORY_GENERAL, "enableSidedOutput", true).setLanguageKey(LANG_PREFIX + "prop.enableSidedOutput").getBoolean(); cache.enableItemConversion = config.get(Configuration.CATEGORY_GENERAL, "enableItemConversion", true).setLanguageKey(LANG_PREFIX + "prop.enableItemConversion").getBoolean(); cache.enableFallbackRecipes = config.get(Configuration.CATEGORY_GENERAL, "enableFallbackRecipes", true).setLanguageKey(LANG_PREFIX + "prop.enableFallbackRecipes").setRequiresMcRestart(true).getBoolean(); - cache.stackRemainderWaila = !config.get(Configuration.CATEGORY_GENERAL, "wailaStackRemainder", "exact", null, new String[]{"exact", "stack + remainder"}).setLanguageKey(LANG_PREFIX + "prop.wailaStackRemainder").getString().equals("exact"); + cache.stackRemainderWaila = !config.get(Configuration.CATEGORY_GENERAL, "wailaStackRemainder", "stack + remainder", null, new String[]{"exact", "stack + remainder"}).setLanguageKey(LANG_PREFIX + "prop.wailaStackRemainder").getString().equals("exact"); cache.invertShift = config.get(Configuration.CATEGORY_GENERAL, "invertShift", false, "Inverts how shift works with drawers. If this is true, shifting will only give one item, where regular clicks will give a full stack. Leave false for default behavior.") .setLanguageKey(LANG_PREFIX + "prop.invertShift").getBoolean(); diff --git a/src/com/jaquadro/minecraft/storagedrawers/integration/Waila.java b/src/com/jaquadro/minecraft/storagedrawers/integration/Waila.java index 54e322e..474f148 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/integration/Waila.java +++ b/src/com/jaquadro/minecraft/storagedrawers/integration/Waila.java @@ -96,6 +96,9 @@ public class Waila extends IntegrationModule currenttip.add(StatCollector.translateToLocalFormatted("storageDrawers.waila.drawer", i + 1, name)); } + int limit = tile.getDrawerCapacity() * tile.getEffectiveStorageMultiplier(); + currenttip.add(StatCollector.translateToLocalFormatted("storageDrawers.waila.limit", limit, tile.getEffectiveStorageMultiplier())); + String attrib = ""; if (tile.isLocked(LockAttribute.LOCK_POPULATED)) attrib += (attrib.isEmpty() ? "" : ", ") + StatCollector.translateToLocal("storageDrawers.waila.locked"); diff --git a/src/com/jaquadro/minecraft/storagedrawers/integration/refinedrelocation/BlockSortingDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/integration/refinedrelocation/BlockSortingDrawers.java index 1a35f85..cdf0c18 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/integration/refinedrelocation/BlockSortingDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/integration/refinedrelocation/BlockSortingDrawers.java @@ -56,7 +56,7 @@ public class BlockSortingDrawers extends BlockDrawers } @Override - protected BlockType retrimType () { + public BlockType retrimType () { return BlockType.DrawersSorting; } diff --git a/src/com/jaquadro/minecraft/storagedrawers/item/ItemTrim.java b/src/com/jaquadro/minecraft/storagedrawers/item/ItemTrim.java index db34475..5e86c71 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/item/ItemTrim.java +++ b/src/com/jaquadro/minecraft/storagedrawers/item/ItemTrim.java @@ -1,5 +1,6 @@ package com.jaquadro.minecraft.storagedrawers.item; +import com.jaquadro.minecraft.storagedrawers.block.BlockDrawers; import net.minecraft.block.Block; import net.minecraft.block.BlockWood; import net.minecraft.entity.player.EntityPlayer; @@ -18,6 +19,10 @@ public class ItemTrim extends ItemMultiTexture @Override public boolean doesSneakBypassUse (World world, int x, int y, int z, EntityPlayer player) { - return true; + Block block = world.getBlock(x, y, z); + if (block instanceof BlockDrawers && ((BlockDrawers) block).retrimType() != null) + return true; + + return false; } } From 5d61d8f5784295662a15fd048db246d554d173c7 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Sun, 17 Jan 2016 01:37:20 -0500 Subject: [PATCH 08/24] Fix thermal expansion integration returning the wrong planks/objects --- .../integration/ThermalExpansion.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/com/jaquadro/minecraft/storagedrawers/integration/ThermalExpansion.java b/src/com/jaquadro/minecraft/storagedrawers/integration/ThermalExpansion.java index 1c58862..9b76fa8 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/integration/ThermalExpansion.java +++ b/src/com/jaquadro/minecraft/storagedrawers/integration/ThermalExpansion.java @@ -121,37 +121,41 @@ public class ThermalExpansion extends IntegrationModule continue; Block plank = resolver.getPlankBlock(i); + int plankMeta = resolver.getPlankMeta(i); + if (plank != null) { if (basicFull1 != null) - mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(basicFull1, 1, i), new ItemStack(plank, 6, i), new ItemStack(Blocks.planks, 8, 0), 100); + mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(basicFull1, 1, i), new ItemStack(plank, 6, plankMeta), new ItemStack(Blocks.planks, 8, 0), 100); if (basicFull2 != null) - mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(basicFull2, 1, i), new ItemStack(plank, 7, i), new ItemStack(Blocks.planks, 8, 0), 100); + mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(basicFull2, 1, i), new ItemStack(plank, 7, plankMeta), new ItemStack(Blocks.planks, 8, 0), 100); if (basicFull4 != null) - mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(basicFull4, 1, i), new ItemStack(plank, 5, i), new ItemStack(Blocks.planks, 8, 0), 100); + mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(basicFull4, 1, i), new ItemStack(plank, 5, plankMeta), new ItemStack(Blocks.planks, 8, 0), 100); if (basicTrim != null) - mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(basicTrim, 1, i), new ItemStack(plank, 5, i), itemSawdust, 100); + mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(basicTrim, 1, i), new ItemStack(plank, 5, plankMeta), itemSawdust, 100); if (sortingFull1 != null) - mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(sortingFull1, 1, i), new ItemStack(plank, 6, i), new ItemStack(Blocks.planks, 8, 0), 100); + mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(sortingFull1, 1, i), new ItemStack(plank, 6, plankMeta), new ItemStack(Blocks.planks, 8, 0), 100); if (sortingFull2 != null) - mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(sortingFull2, 1, i), new ItemStack(plank, 7, i), new ItemStack(Blocks.planks, 8, 0), 100); + mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(sortingFull2, 1, i), new ItemStack(plank, 7, plankMeta), new ItemStack(Blocks.planks, 8, 0), 100); if (sortingFull4 != null) - mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(sortingFull4, 1, i), new ItemStack(plank, 5, i), new ItemStack(Blocks.planks, 8, 0), 100); + mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(sortingFull4, 1, i), new ItemStack(plank, 5, plankMeta), new ItemStack(Blocks.planks, 8, 0), 100); if (sortingTrim != null) - mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(sortingTrim, 1, i), new ItemStack(plank, 5, i), itemSawdust, 100); + mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(sortingTrim, 1, i), new ItemStack(plank, 5, plankMeta), itemSawdust, 100); } Block slab = resolver.getSlabBlock(i); + int slabMeta = resolver.getSlabMeta(i); + if (slab != null) { if (basicHalf2 != null) - mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(basicHalf2, 1, i), new ItemStack(slab, 7, i), new ItemStack(Blocks.planks, 8, 0), 100); + mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(basicHalf2, 1, i), new ItemStack(slab, 7, slabMeta), new ItemStack(Blocks.planks, 8, 0), 100); if (basicHalf4 != null) - mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(basicHalf4, 1, i), new ItemStack(slab, 5, i), new ItemStack(Blocks.planks, 8, 0), 100); + mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(basicHalf4, 1, i), new ItemStack(slab, 5, slabMeta), new ItemStack(Blocks.planks, 8, 0), 100); if (sortingHalf2 != null) - mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(sortingHalf2, 1, i), new ItemStack(slab, 7, i), new ItemStack(Blocks.planks, 8, 0), 100); + mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(sortingHalf2, 1, i), new ItemStack(slab, 7, slabMeta), new ItemStack(Blocks.planks, 8, 0), 100); if (sortingHalf4 != null) - mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(sortingHalf4, 1, i), new ItemStack(slab, 5, i), new ItemStack(Blocks.planks, 8, 0), 100); + mtSawmillAddRecipe.invoke(null, 2400, new ItemStack(sortingHalf4, 1, i), new ItemStack(slab, 5, slabMeta), new ItemStack(Blocks.planks, 8, 0), 100); } } } From ad65bc675ac3560249b008aabcdf3667ac263a03 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Sun, 17 Jan 2016 01:47:33 -0500 Subject: [PATCH 09/24] update pack dependency --- packs/BiomesOPlenty/build.gradle | 2 +- packs/Erebus/build.gradle | 2 +- packs/Forestry/build.gradle | 2 +- packs/Misc/build.gradle | 2 +- packs/Natura/build.gradle | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packs/BiomesOPlenty/build.gradle b/packs/BiomesOPlenty/build.gradle index b6ef9eb..ed061a1 100644 --- a/packs/BiomesOPlenty/build.gradle +++ b/packs/BiomesOPlenty/build.gradle @@ -26,7 +26,7 @@ minecraft { assetDir = "../../runtime/assets" replace '@VERSION@', project.version - replace 'required-after:StorageDrawers', "required-after:StorageDrawers@[1.7.5,)" + replace 'required-after:StorageDrawers', "required-after:StorageDrawers@[1.7.6,)" } sourceSets.main { diff --git a/packs/Erebus/build.gradle b/packs/Erebus/build.gradle index db27a5c..e94ca51 100644 --- a/packs/Erebus/build.gradle +++ b/packs/Erebus/build.gradle @@ -26,7 +26,7 @@ minecraft { assetDir = "../../runtime/assets" replace '@VERSION@', project.version - replace 'required-after:StorageDrawers', "required-after:StorageDrawers@[1.7.5,)" + replace 'required-after:StorageDrawers', "required-after:StorageDrawers@[1.7.6,)" } sourceSets.main { diff --git a/packs/Forestry/build.gradle b/packs/Forestry/build.gradle index 3f46e3f..d3d404e 100644 --- a/packs/Forestry/build.gradle +++ b/packs/Forestry/build.gradle @@ -26,7 +26,7 @@ minecraft { assetDir = "../../runtime/assets" replace '@VERSION@', project.version - replace 'required-after:StorageDrawers', "required-after:StorageDrawers@[1.7.5,)" + replace 'required-after:StorageDrawers', "required-after:StorageDrawers@[1.7.6,)" } sourceSets.main { diff --git a/packs/Misc/build.gradle b/packs/Misc/build.gradle index 38a4b1d..2ed6d39 100644 --- a/packs/Misc/build.gradle +++ b/packs/Misc/build.gradle @@ -26,7 +26,7 @@ minecraft { assetDir = "../../runtime/assets" replace '@VERSION@', project.version - replace 'required-after:StorageDrawers', "required-after:StorageDrawers@[1.7.5,)" + replace 'required-after:StorageDrawers', "required-after:StorageDrawers@[1.7.6,)" } sourceSets.main { diff --git a/packs/Natura/build.gradle b/packs/Natura/build.gradle index fc38568..c3076e6 100644 --- a/packs/Natura/build.gradle +++ b/packs/Natura/build.gradle @@ -26,7 +26,7 @@ minecraft { assetDir = "../../runtime/assets" replace '@VERSION@', project.version - replace 'required-after:StorageDrawers', "required-after:StorageDrawers@[1.7.5,)" + replace 'required-after:StorageDrawers', "required-after:StorageDrawers@[1.7.6,)" } sourceSets.main { From 7c0daec960c4d6c4ab1488c059d641b1786aac1f Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Sun, 17 Jan 2016 02:00:22 -0500 Subject: [PATCH 10/24] Back out AE version change - breaks the biuld --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 2558e1b..2659723 100644 --- a/build.gradle +++ b/build.gradle @@ -80,7 +80,7 @@ dependencies { compile "codechicken:CodeChickenCore:1.7.10-1.0.6.44:dev" compile "codechicken:NotEnoughItems:1.7.10-1.0.4.107:dev" - compile "appeng:appliedenergistics2:rv3-beta-1:api" + compile "appeng:appliedenergistics2:rv2-stable-3:api" compile name: 'MineTweaker3', version: "Dev-1.7.10-3.0.9B", ext: 'jar' } From 468438db9fc7ff1889c23d70624634d3de274a40 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Wed, 20 Jan 2016 21:24:44 -0500 Subject: [PATCH 11/24] Fix crash if Thermal Expansion integration fails to load --- .../storagedrawers/integration/IntegrationModule.java | 4 +--- .../storagedrawers/integration/ThermalExpansion.java | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/com/jaquadro/minecraft/storagedrawers/integration/IntegrationModule.java b/src/com/jaquadro/minecraft/storagedrawers/integration/IntegrationModule.java index 00859d0..523c09d 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/integration/IntegrationModule.java +++ b/src/com/jaquadro/minecraft/storagedrawers/integration/IntegrationModule.java @@ -11,9 +11,7 @@ import java.util.List; public abstract class IntegrationModule { - public String getModID () { - return null; - } + public abstract String getModID (); public boolean versionCheck () { String pattern = versionPattern(); diff --git a/src/com/jaquadro/minecraft/storagedrawers/integration/ThermalExpansion.java b/src/com/jaquadro/minecraft/storagedrawers/integration/ThermalExpansion.java index 9b76fa8..3bc8c78 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/integration/ThermalExpansion.java +++ b/src/com/jaquadro/minecraft/storagedrawers/integration/ThermalExpansion.java @@ -29,6 +29,11 @@ public class ThermalExpansion extends IntegrationModule static boolean initialized; + @Override + public String getModID () { + return MOD_ID; + } + @Override public void init () throws Throwable { clSawmillManager = Class.forName("cofh.thermalexpansion.util.crafting.SawmillManager"); From 15440384e616fdb2a1857986c60553583720604d Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Wed, 20 Jan 2016 23:35:20 -0500 Subject: [PATCH 12/24] Version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 2659723..818a58a 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ buildscript { apply plugin: 'forge' -version = "1.7.10-1.7.6" +version = "1.7.10-1.7.7" group= "com.jaquadro.minecraft.storagedrawers" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "StorageDrawers" From a79fe59264b24145f668d1e029662e4b3b3b5912 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Sun, 31 Jan 2016 16:20:06 -0500 Subject: [PATCH 13/24] Set WAILA stack limit to infinity with creative upgrades in place --- resources/assets/storagedrawers/lang/en_US.lang | 1 + .../minecraft/storagedrawers/integration/Waila.java | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/resources/assets/storagedrawers/lang/en_US.lang b/resources/assets/storagedrawers/lang/en_US.lang index 8c4985d..87762c6 100644 --- a/resources/assets/storagedrawers/lang/en_US.lang +++ b/resources/assets/storagedrawers/lang/en_US.lang @@ -93,6 +93,7 @@ storageDrawers.waila.empty= storageDrawers.waila.level=Upgrade Level: %s storageDrawers.waila.drawer=#%s: %s storageDrawers.waila.limit=Stack Limit: %s (x%s) +storageDrawers.waila.nolimit=Stack Limit: ∞ storageDrawers.waila.locked=Locked storageDrawers.waila.void=Void storageDrawers.waila.sorting=Sorting diff --git a/src/com/jaquadro/minecraft/storagedrawers/integration/Waila.java b/src/com/jaquadro/minecraft/storagedrawers/integration/Waila.java index 474f148..1568d5f 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/integration/Waila.java +++ b/src/com/jaquadro/minecraft/storagedrawers/integration/Waila.java @@ -96,8 +96,12 @@ public class Waila extends IntegrationModule currenttip.add(StatCollector.translateToLocalFormatted("storageDrawers.waila.drawer", i + 1, name)); } - int limit = tile.getDrawerCapacity() * tile.getEffectiveStorageMultiplier(); - currenttip.add(StatCollector.translateToLocalFormatted("storageDrawers.waila.limit", limit, tile.getEffectiveStorageMultiplier())); + if (tile.isUnlimited() || tile.isVending()) + currenttip.add(StatCollector.translateToLocalFormatted("storageDrawers.waila.nolimit")); + else { + int limit = tile.getDrawerCapacity() * tile.getEffectiveStorageMultiplier(); + currenttip.add(StatCollector.translateToLocalFormatted("storageDrawers.waila.limit", limit, tile.getEffectiveStorageMultiplier())); + } String attrib = ""; if (tile.isLocked(LockAttribute.LOCK_POPULATED)) From 88d13afaa1e229b435d4b9b2f1cc58d54dc71849 Mon Sep 17 00:00:00 2001 From: NatsuArashi Date: Mon, 1 Feb 2016 21:52:46 +0800 Subject: [PATCH 14/24] Update zh_TW.lang --- resources/assets/storagedrawers/lang/zh_TW.lang | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/resources/assets/storagedrawers/lang/zh_TW.lang b/resources/assets/storagedrawers/lang/zh_TW.lang index 48288a4..45a95c2 100644 --- a/resources/assets/storagedrawers/lang/zh_TW.lang +++ b/resources/assets/storagedrawers/lang/zh_TW.lang @@ -35,7 +35,7 @@ item.storagedrawers.shroudKey.description=隱藏或顯示抽屜上的物品圖 item.storagedrawers.tape.name=打包帶 item.storagedrawers.tape.description=捆紮封裝抽屜以便攜帶。 -# Block +# Blocks tile.fullDrawers1.oak.name=橡木抽屜 tile.fullDrawers1.spruce.name=雲杉木抽屜 tile.fullDrawers1.birch.name=白樺木抽屜 @@ -88,15 +88,17 @@ storageDrawers.upgrade.description=將抽屜容量升級為其基礎容量的%d storageDrawers.controller.description=將放入的物品分配存入鄰接的抽屜中。 storageDrawers.controllerSlave.description=為抽屜管理器擴展存儲連接面。 -# Integration/WAILA +# Integration storageDrawers.waila.empty=<空> storageDrawers.waila.level=級別:%s storageDrawers.waila.drawer=#%s:%s +storageDrawers.waila.limit=堆疊上限: %s (x%s) +storageDrawers.waila.nolimit=堆疊上限: ∞ storageDrawers.waila.locked=鎖定 storageDrawers.waila.void=清空 storageDrawers.waila.sorting=分揀 -# Configruation +# Configuration storageDrawers.config.title=儲物抽屜-模組選項 storageDrawers.config.general=一般設定 @@ -180,3 +182,4 @@ storageDrawers.config.integration.enableWaila=允許關聯WAILA顯示 storageDrawers.config.integration.enableThaumcraft=允許關聯秘術時代 storageDrawers.config.integration.enableMineTweaker=允許關聯MineTweaker storageDrawers.config.integration.enableRefinedRelocation=允許關聯精準重定位 +storageDrawers.config.integration.enableThermalExpansion=允許關聯精煉機械 From 3efdc56d32fb480864c314e4064ab75f343600bf Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Sun, 7 Feb 2016 00:40:51 -0500 Subject: [PATCH 15/24] Support multiple oredict-compatible items coexisting in drawer system via IInventory and AE2 access. --- .../api/storage/ISmartGroup.java | 18 ++ .../block/tile/TileEntityController.java | 180 +++++++++++++++++- .../integration/ae2/DrawerMEInventory.java | 142 +++++++++----- .../util/ItemMetaListRegistry.java | 63 ++++++ .../storagedrawers/util/ItemMetaRegistry.java | 83 ++++++++ 5 files changed, 431 insertions(+), 55 deletions(-) create mode 100644 src/com/jaquadro/minecraft/storagedrawers/api/storage/ISmartGroup.java create mode 100644 src/com/jaquadro/minecraft/storagedrawers/util/ItemMetaListRegistry.java create mode 100644 src/com/jaquadro/minecraft/storagedrawers/util/ItemMetaRegistry.java diff --git a/src/com/jaquadro/minecraft/storagedrawers/api/storage/ISmartGroup.java b/src/com/jaquadro/minecraft/storagedrawers/api/storage/ISmartGroup.java new file mode 100644 index 0000000..c441a76 --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/api/storage/ISmartGroup.java @@ -0,0 +1,18 @@ +package com.jaquadro.minecraft.storagedrawers.api.storage; + +import net.minecraft.item.ItemStack; + +public interface ISmartGroup +{ + /** + * Gets a lazy enumeration of all slots that will accept at least one item of the given stack, ordered by + * insertion preference. + */ + Iterable enumerateDrawersForInsertion (ItemStack stack, boolean strict); + + /** + * Gets a lazy enumeration of all slots that will provide at least one item of the given stack, ordered by + * extraction preference. + */ + Iterable enumerateDrawersForExtraction (ItemStack stack, boolean strict); +} diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java index 4d8d89b..85469e2 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java @@ -8,9 +8,13 @@ import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IShroudable; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IVoidable; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.LockAttribute; import com.jaquadro.minecraft.storagedrawers.block.BlockSlave; +import com.jaquadro.minecraft.storagedrawers.util.ItemMetaListRegistry; +import com.jaquadro.minecraft.storagedrawers.util.ItemMetaRegistry; +import com.jaquadro.minecraft.storagedrawers.util.UniqueMetaIdentifier; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; @@ -22,13 +26,14 @@ import net.minecraftforge.common.util.ForgeDirection; import java.util.*; -public class TileEntityController extends TileEntity implements IDrawerGroup, IPriorityGroup, ISidedInventory +public class TileEntityController extends TileEntity implements IDrawerGroup, IPriorityGroup, ISmartGroup, ISidedInventory { private static final int PRI_VOID = 0; private static final int PRI_LOCKED = 1; private static final int PRI_NORMAL = 2; private static final int PRI_EMPTY = 3; - private static final int PRI_DISABLED = 4; + private static final int PRI_LOCKED_EMPTY = 4; + private static final int PRI_DISABLED = 5; private static final int DEPTH_LIMIT = 12; private static final int[] emptySlots = new int[0]; @@ -85,7 +90,12 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP IDrawer drawer = group.getDrawer(drawerSlot); if (drawer.isEmpty()) { - return PRI_EMPTY; + if ((drawer instanceof ILockable && ((ILockable) drawer).isLocked(LockAttribute.LOCK_EMPTY)) || + (group instanceof ILockable && ((ILockable) group).isLocked(LockAttribute.LOCK_EMPTY))) { + return PRI_LOCKED_EMPTY; + } + else + return PRI_EMPTY; } if ((drawer instanceof IVoidable && ((IVoidable) drawer).isVoid()) || @@ -108,6 +118,9 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP private List invSlotList = new ArrayList(); private List drawerSlotList = new ArrayList(); + private ItemMetaListRegistry invPrimaryLookup = new ItemMetaListRegistry(); + private ItemMetaListRegistry drawerPrimaryLookup = new ItemMetaListRegistry(); + private int[] inventorySlots = new int[0]; private int[] drawerSlots = new int[0]; private int[] autoSides = new int[] { 0, 1, 2, 3, 4, 5 }; @@ -261,9 +274,12 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP populateNodes(xCoord, yCoord, zCoord); flattenLists(); - inventorySlots = sortSlotRecords(invSlotList, true); //sortInventorySlots(); + inventorySlots = sortSlotRecords(invSlotList, true); drawerSlots = sortSlotRecords(drawerSlotList, false); + rebuildPrimaryLookup(invPrimaryLookup, invSlotList, true); + rebuildPrimaryLookup(drawerPrimaryLookup, drawerSlotList, false); + if (preCount != inventorySlots.length && (preCount == 0 || inventorySlots.length == 0)) { if (!worldObj.isRemote) markDirty(); @@ -293,6 +309,27 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP return slotMap; } + private void rebuildPrimaryLookup (ItemMetaListRegistry lookup, List records, boolean invBased) { + lookup.clear(); + + for (SlotRecord record : records) { + IDrawerGroup group = getGroupForCoord(record.coord); + if (group == null) + continue; + + int drawerSlot = (invBased) ? group.getDrawerInventory().getDrawerSlot(record.slot) : record.slot; + if (!group.isDrawerEnabled(drawerSlot)) + continue; + + IDrawer drawer = group.getDrawer(drawerSlot); + if (drawer.isEmpty()) + continue; + + ItemStack item = drawer.getStoredItemPrototype(); + lookup.register(item.getItem(), item.getItemDamage(), record); + } + } + private boolean containsNullEntries (List list) { int nullCount = 0; for (int i = 0, n = list.size(); i < n; i++) { @@ -638,6 +675,20 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP if (inventory == null) return false; + if (slot >= invSlotList.size()) + return false; + + SlotRecord record = invSlotList.get(slot); + List primaryRecords = invPrimaryLookup.getEntries(stack.getItem(), stack.getItemDamage()); + if (primaryRecords != null && !primaryRecords.contains(record)) { + for (SlotRecord candidate : primaryRecords) { + IDrawerGroup candidateGroup = getGroupForCoord(candidate.coord); + IDrawerInventory candidateInventory = candidateGroup.getDrawerInventory(); + if (candidateInventory.canInsertItem(candidate.slot, stack)) + return false; + } + } + return inventory.canInsertItem(getLocalInvSlot(slot), stack); } @@ -728,6 +779,127 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP if (inventory == null) return false; + if (slot >= invSlotList.size()) + return false; + + SlotRecord record = invSlotList.get(slot); + List primaryRecords = invPrimaryLookup.getEntries(stack.getItem(), stack.getItemDamage()); + if (primaryRecords != null && !primaryRecords.contains(record)) { + for (SlotRecord candidate : primaryRecords) { + IDrawerGroup candidateGroup = getGroupForCoord(candidate.coord); + IDrawerInventory candidateInventory = candidateGroup.getDrawerInventory(); + if (candidateInventory.isItemValidForSlot(candidate.slot, stack)) + return false; + } + } + return inventory.isItemValidForSlot(getLocalInvSlot(slot), stack); } + + private class DrawerStackIterator implements Iterable + { + private ItemStack stack; + private boolean strict; + private boolean insert; + + public DrawerStackIterator (ItemStack stack, boolean strict, boolean insert) { + this.stack = stack; + this.strict = strict; + this.insert = insert; + } + + @Override + public Iterator iterator () { + return new Iterator () + { + List primaryRecords = drawerPrimaryLookup.getEntries(stack.getItem(), stack.getItemDamage()); + Iterator iter1; + int index2; + Integer nextSlot = null; + + @Override + public boolean hasNext () { + if (nextSlot == null) + advance(); + return nextSlot != null; + } + + @Override + public Integer next () { + if (nextSlot == null) + advance(); + + Integer slot = nextSlot; + nextSlot = null; + return slot; + } + + private void advance () { + if (iter1 == null && primaryRecords != null && primaryRecords.size() > 0) + iter1 = primaryRecords.iterator(); + + if (iter1 != null) { + while (iter1.hasNext()) { + SlotRecord candidate = iter1.next(); + IDrawerGroup candidateGroup = getGroupForCoord(candidate.coord); + IDrawer drawer = candidateGroup.getDrawer(candidate.slot); + + if (insert) { + if (!(drawer.canItemBeStored(stack) && (drawer.isEmpty() || drawer.getRemainingCapacity() > 0))) + continue; + } + else { + if (!(drawer.canItemBeExtracted(stack) && drawer.getStoredItemCount() > 0)) + continue; + } + + int slot = drawerSlotList.indexOf(candidate); + if (slot > -1) { + nextSlot = slot; + return; + } + } + } + + for (; index2 < drawerSlots.length; index2++) { + int slot = drawerSlots[index2]; + if (!isDrawerEnabled(slot)) + continue; + + IDrawer drawer = getDrawer(slot); + if (strict) { + ItemStack proto = drawer.getStoredItemPrototype(); + if (proto != null && !proto.isItemEqual(stack)) + continue; + } + + if (insert) { + if (!(drawer.canItemBeStored(stack) && (drawer.isEmpty() || drawer.getRemainingCapacity() > 0))) + continue; + } + else { + if (!(drawer.canItemBeExtracted(stack) && drawer.getStoredItemCount() > 0)) + continue; + } + + SlotRecord record = drawerSlotList.get(slot); + if (primaryRecords != null && primaryRecords.contains(record)) + continue; + + nextSlot = slot; + index2++; + return; + } + } + }; + } + }; + + public Iterable enumerateDrawersForInsertion (ItemStack stack, boolean strict) { + return new DrawerStackIterator(stack, strict, true); + } + + public Iterable enumerateDrawersForExtraction (ItemStack stack, boolean strict) { + return new DrawerStackIterator(stack, strict, false); + } } diff --git a/src/com/jaquadro/minecraft/storagedrawers/integration/ae2/DrawerMEInventory.java b/src/com/jaquadro/minecraft/storagedrawers/integration/ae2/DrawerMEInventory.java index 451b24d..1671857 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/integration/ae2/DrawerMEInventory.java +++ b/src/com/jaquadro/minecraft/storagedrawers/integration/ae2/DrawerMEInventory.java @@ -7,15 +7,14 @@ import appeng.api.storage.IMEInventory; import appeng.api.storage.StorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; -import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer; -import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup; -import com.jaquadro.minecraft.storagedrawers.api.storage.IFractionalDrawer; -import com.jaquadro.minecraft.storagedrawers.api.storage.IPriorityGroup; +import com.jaquadro.minecraft.storagedrawers.api.storage.*; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.ILockable; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IVoidable; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.LockAttribute; import net.minecraft.item.ItemStack; +import java.util.Iterator; + public class DrawerMEInventory implements IMEInventory { final IDrawerGroup group; @@ -26,52 +25,71 @@ public class DrawerMEInventory implements IMEInventory @Override public IAEItemStack injectItems (IAEItemStack input, Actionable type, BaseActionSource src) { - int[] order = null; - if (group instanceof IPriorityGroup) - order = ((IPriorityGroup) group).getAccessibleDrawerSlots(); - long itemsLeft = input.getStackSize(); - for (int i = 0, n = group.getDrawerCount(); i < n; i++) { - int slot = (order != null) ? order[i] : i; - if (!group.isDrawerEnabled(slot)) - continue; - IDrawer drawer = group.getDrawer(slot); - ItemStack itemProto = drawer.getStoredItemPrototype(); - if (itemProto != null) { - if (drawer.canItemBeStored(input.getItemStack())) { - itemsLeft = injectItemsIntoDrawer(drawer, itemsLeft, type); - if (drawer instanceof IVoidable && ((IVoidable) drawer).isVoid()) - itemsLeft = 0; - if (itemsLeft == 0) - return null; - } + if (group instanceof ISmartGroup) { + for (int slot : ((ISmartGroup) group).enumerateDrawersForInsertion(input.getItemStack(), false)) { + IDrawer drawer = group.getDrawer(slot); + ItemStack itemProto = drawer.getStoredItemPrototype(); + if (itemProto == null) + drawer.setStoredItem(input.getItemStack(), 0); + + itemsLeft = injectItemsIntoDrawer(drawer, itemsLeft, type); + + if (drawer instanceof IVoidable && ((IVoidable) drawer).isVoid()) + itemsLeft = 0; + if (itemsLeft == 0) + return null; } } + else { + int[] order = null; + if (group instanceof IPriorityGroup) + order = ((IPriorityGroup) group).getAccessibleDrawerSlots(); - for (int i = 0, n = group.getDrawerCount(); i < n; i++) { - int slot = (order != null) ? order[i] : i; - if (!group.isDrawerEnabled(slot)) - continue; - if (group instanceof ILockable && ((ILockable) group).isLocked(LockAttribute.LOCK_EMPTY)) - continue; + for (int i = 0, n = group.getDrawerCount(); i < n; i++) { + int slot = (order != null) ? order[i] : i; + if (!group.isDrawerEnabled(slot)) + continue; - IDrawer drawer = group.getDrawer(slot); - ItemStack itemProto = drawer.getStoredItemPrototype(); + IDrawer drawer = group.getDrawer(slot); + ItemStack itemProto = drawer.getStoredItemPrototype(); + if (itemProto != null) { + if (drawer.canItemBeStored(input.getItemStack())) { + itemsLeft = injectItemsIntoDrawer(drawer, itemsLeft, type); + if (drawer instanceof IVoidable && ((IVoidable) drawer).isVoid()) + itemsLeft = 0; + if (itemsLeft == 0) + return null; + } + } + } - if (itemProto == null && drawer instanceof ILockable && ((ILockable) drawer).isLocked(LockAttribute.LOCK_EMPTY)) - continue; + for (int i = 0, n = group.getDrawerCount(); i < n; i++) { + int slot = (order != null) ? order[i] : i; + if (!group.isDrawerEnabled(slot)) + continue; - if (itemProto == null) { - itemProto = input.getItemStack(); - if (drawer.canItemBeStored(itemProto)) { - drawer.setStoredItem(itemProto, 0); - itemsLeft = injectItemsIntoDrawer(drawer, itemsLeft, type); - if (drawer instanceof IVoidable && ((IVoidable) drawer).isVoid()) - itemsLeft = 0; - if (itemsLeft == 0) - return null; + if (group instanceof ILockable && ((ILockable) group).isLocked(LockAttribute.LOCK_EMPTY)) + continue; + + IDrawer drawer = group.getDrawer(slot); + ItemStack itemProto = drawer.getStoredItemPrototype(); + + if (itemProto == null && drawer instanceof ILockable && ((ILockable) drawer).isLocked(LockAttribute.LOCK_EMPTY)) + continue; + + if (itemProto == null) { + itemProto = input.getItemStack(); + if (drawer.canItemBeStored(itemProto)) { + drawer.setStoredItem(itemProto, 0); + itemsLeft = injectItemsIntoDrawer(drawer, itemsLeft, type); + if (drawer instanceof IVoidable && ((IVoidable) drawer).isVoid()) + itemsLeft = 0; + if (itemsLeft == 0) + return null; + } } } } @@ -110,18 +128,13 @@ public class DrawerMEInventory implements IMEInventory @Override public IAEItemStack extractItems (IAEItemStack request, Actionable mode, BaseActionSource src) { - int[] order = null; - if (group instanceof IPriorityGroup) - order = ((IPriorityGroup) group).getAccessibleDrawerSlots(); - long itemsLeft = request.getStackSize(); - for (int i = 0, n = group.getDrawerCount(); i < n; i++) { - int slot = (order != null) ? order[i] : i; - if (!group.isDrawerEnabled(slot)) - continue; + if (group instanceof ISmartGroup) { + for (int slot : ((ISmartGroup) group).enumerateDrawersForExtraction(request.getItemStack(), true)) { + if (itemsLeft == 0) + break; - IDrawer drawer = group.getDrawer(slot); - if (drawer.canItemBeExtracted(request.getItemStack())) { + IDrawer drawer = group.getDrawer(slot); int itemCount = drawer.getStoredItemCount(); if (itemsLeft > itemCount) { if (mode == Actionable.MODULATE) @@ -136,6 +149,33 @@ public class DrawerMEInventory implements IMEInventory } } } + else { + int[] order = null; + if (group instanceof IPriorityGroup) + order = ((IPriorityGroup) group).getAccessibleDrawerSlots(); + + + for (int i = 0, n = group.getDrawerCount(); i < n; i++) { + int slot = (order != null) ? order[i] : i; + if (!group.isDrawerEnabled(slot)) + continue; + + IDrawer drawer = group.getDrawer(slot); + if (drawer.canItemBeExtracted(request.getItemStack())) { + int itemCount = drawer.getStoredItemCount(); + if (itemsLeft > itemCount) { + if (mode == Actionable.MODULATE) + drawer.setStoredItemCount(0); + itemsLeft -= itemCount; + } else { + if (mode == Actionable.MODULATE) + drawer.setStoredItemCount(itemCount - (int) itemsLeft); + itemsLeft = 0; + break; + } + } + } + } if (itemsLeft < request.getStackSize()) { ItemStack fulfillment = request.getItemStack().copy(); diff --git a/src/com/jaquadro/minecraft/storagedrawers/util/ItemMetaListRegistry.java b/src/com/jaquadro/minecraft/storagedrawers/util/ItemMetaListRegistry.java new file mode 100644 index 0000000..49e3240 --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/util/ItemMetaListRegistry.java @@ -0,0 +1,63 @@ +package com.jaquadro.minecraft.storagedrawers.util; + +import net.minecraft.item.Item; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class ItemMetaListRegistry +{ + private ItemMetaRegistry> registry; + private boolean compactTopLevel; + + public ItemMetaListRegistry () { + this(false); + } + + public ItemMetaListRegistry (boolean compactTopLevel) { + this.registry = new ItemMetaRegistry>(compactTopLevel); + this.compactTopLevel = compactTopLevel; + } + + public void register (Item item, int meta, E entry) { + List list = registry.getEntry(item, meta); + if (list == null) { + list = new ArrayList(); + registry.register(item, meta, list); + } + + list.add(entry); + } + + public List getEntries (Item item, int meta) { + return registry.getEntry(item, meta); + } + + public void remove (Item item, int meta) { + registry.remove(item, meta); + } + + public void clear (Item item, int meta) { + List list = registry.getEntry(item, meta); + if (list != null) + list.clear(); + } + + public void clear (Item item) { + for (Map.Entry> map : registry.entrySet(item)) + map.getValue().clear(); + } + + public void clear () { + for (Map.Entry>> map : registry.entrySet()) { + for (List list : map.getValue().values()) + list.clear(); + } + } + + public Set>>> entrySet () { + return registry.entrySet(); + } +} diff --git a/src/com/jaquadro/minecraft/storagedrawers/util/ItemMetaRegistry.java b/src/com/jaquadro/minecraft/storagedrawers/util/ItemMetaRegistry.java new file mode 100644 index 0000000..9a02e22 --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/util/ItemMetaRegistry.java @@ -0,0 +1,83 @@ +package com.jaquadro.minecraft.storagedrawers.util; + +import net.minecraft.item.Item; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +public class ItemMetaRegistry +{ + private Map> registry; + private boolean compactTopLevel; + + public ItemMetaRegistry () { + registry = new HashMap>(); + } + + public ItemMetaRegistry (boolean compactTopLevel) { + this(); + this.compactTopLevel = compactTopLevel; + } + + public void register (Item item, int meta, E entry) { + Map metamap = registry.get(item); + if (metamap == null) { + metamap = new HashMap(); + registry.put(item, metamap); + } + + metamap.put(meta, entry); + } + + public E getEntry (Item item, int meta) { + Map metamap = registry.get(item); + if (metamap == null) + return null; + + return metamap.get(meta); + } + + public void remove (Item item, int meta) { + Map metamap = registry.get(item); + if (metamap == null) + return; + + metamap.remove(meta); + if (compactTopLevel && metamap.isEmpty()) + registry.remove(item); + } + + public void clear (Item item) { + Map metamap = registry.get(item); + if (metamap == null) + return; + + metamap.clear(); + if (compactTopLevel) + registry.remove(item); + } + + public void clear () { + if (compactTopLevel) + registry.clear(); + else { + for (Item item : registry.keySet()) + clear(item); + } + } + + public Set>> entrySet () { + return registry.entrySet(); + } + + public Set> entrySet (Item item) { + Map metamap = registry.get(item); + if (metamap == null) { + metamap = new HashMap(); + registry.put(item, metamap); + } + + return metamap.entrySet(); + } +} From edec7874f1b553eb0ad082ea7c94b3e3382a4fff Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Sun, 7 Feb 2016 01:22:35 -0500 Subject: [PATCH 16/24] And now support for manual controller insertion --- build.gradle | 2 +- .../block/tile/TileEntityController.java | 80 ++++++++++++++----- 2 files changed, 62 insertions(+), 20 deletions(-) diff --git a/build.gradle b/build.gradle index 818a58a..98c7fb9 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ buildscript { apply plugin: 'forge' -version = "1.7.10-1.7.7" +version = "1.7.10-1.7.8" group= "com.jaquadro.minecraft.storagedrawers" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "StorageDrawers" diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java index 85469e2..c2dc52e 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java @@ -155,27 +155,25 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP boolean dumpInventory = worldObj.getTotalWorldTime() - lastClickTime < 10 && player.getPersistentID().equals(lastClickUUID); int count = 0; - for (int i = 0, n = drawerSlots.length; i < n; i++) { - int slotIndex = drawerSlots[i]; + if (!dumpInventory) { + ItemStack currentStack = player.inventory.getCurrentItem(); + count = insertItems(currentStack); - IDrawerGroup group = getGroupForDrawerSlot(slotIndex); - if (group == null || !(group instanceof IDrawerGroupInteractive)) - continue; + if (currentStack.stackSize == 0) + player.inventory.setInventorySlotContents(player.inventory.currentItem, null); + } + else { + for (int i = 0, n = player.inventory.getSizeInventory(); i < n; i++) { + ItemStack subStack = player.inventory.getStackInSlot(i); + if (subStack != null) { + count += insertItems(subStack); + if (subStack.stackSize == 0) + player.inventory.setInventorySlotContents(i, null); + } + } - IDrawerGroupInteractive intGroup = (IDrawerGroupInteractive)group; - - int slot = getLocalDrawerSlot(slotIndex); - if (!group.isDrawerEnabled(slot)) - continue; - - IDrawer drawer = group.getDrawer(slot); - if (drawer == null || drawer.isEmpty()) - continue; - - if (dumpInventory) - count += intGroup.interactPutCurrentInventoryIntoSlot(slot, player); - else - count += intGroup.interactPutCurrentItemIntoSlot(slot, player); + if (count > 0) + StorageDrawers.proxy.updatePlayerInventory(player); } lastClickTime = worldObj.getTotalWorldTime(); @@ -184,6 +182,50 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP return count; } + private int insertItems (ItemStack stack) { + int itemsLeft = stack.stackSize; + + for (int slot : enumerateDrawersForInsertion(stack, false)) { + IDrawer drawer = getDrawer(slot); + ItemStack itemProto = drawer.getStoredItemPrototype(); + if (itemProto == null) + break; + + itemsLeft = insertItemsIntoDrawer(drawer, itemsLeft); + + if (drawer instanceof IVoidable && ((IVoidable) drawer).isVoid()) + itemsLeft = 0; + if (itemsLeft == 0) + break; + } + + int count = stack.stackSize - itemsLeft; + stack.stackSize = itemsLeft; + + return count; + } + + private int insertItemsIntoDrawer (IDrawer drawer, int itemCount) { + int capacity = drawer.getMaxCapacity(); + int storedItems = drawer.getStoredItemCount(); + + int storableItems = capacity - storedItems; + if (drawer instanceof IFractionalDrawer) { + IFractionalDrawer fracDrawer = (IFractionalDrawer)drawer; + if (!fracDrawer.isSmallestUnit() && fracDrawer.getStoredItemRemainder() > 0) + storableItems--; + } + + if (storableItems == 0) + return itemCount; + + int remainder = Math.max(itemCount - storableItems, 0); + storedItems += Math.min(itemCount, storableItems); + drawer.setStoredItemCount(storedItems); + + return remainder; + } + public void toggleShroud () { IShroudable template = null; boolean state = false; From 6852be7300a23e32acb3d9aaba3e04075fd7c9cc Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Sun, 7 Feb 2016 01:34:45 -0500 Subject: [PATCH 17/24] Add renderutil safety in unusual case an icon is missing --- .../client/renderer/RenderUtil.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/com/jaquadro/minecraft/storagedrawers/client/renderer/RenderUtil.java b/src/com/jaquadro/minecraft/storagedrawers/client/renderer/RenderUtil.java index c1e4863..04aa1d0 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/client/renderer/RenderUtil.java +++ b/src/com/jaquadro/minecraft/storagedrawers/client/renderer/RenderUtil.java @@ -137,6 +137,9 @@ public final class RenderUtil } public static void renderFaceYNegColorMult (RenderBlocks renderer, Block block, int x, int y, int z, IIcon icon, float r, float g, float b) { + if (icon == null) + return; + Tessellator tessellator = Tessellator.instance; tessellator.setColorOpaque_F(.5f * r, .5f * g, .5f * b); if (renderer.blockAccess == null) { @@ -154,6 +157,9 @@ public final class RenderUtil } public static void renderFaceYPosColorMult (RenderBlocks renderer, Block block, int x, int y, int z, IIcon icon, float r, float g, float b) { + if (icon == null) + return; + Tessellator tessellator = Tessellator.instance; tessellator.setColorOpaque_F(1f * r, 1f * g, 1f * b); if (renderer.blockAccess == null) { @@ -171,6 +177,9 @@ public final class RenderUtil } public static void renderFaceZNegColorMult (RenderBlocks renderer, Block block, int x, int y, int z, IIcon icon, float r, float g, float b) { + if (icon == null) + return; + Tessellator tessellator = Tessellator.instance; tessellator.setColorOpaque_F(.8f * r, .8f * g, .8f * b); if (renderer.blockAccess == null) { @@ -188,6 +197,9 @@ public final class RenderUtil } public static void renderFaceZPosColorMult (RenderBlocks renderer, Block block, int x, int y, int z, IIcon icon, float r, float g, float b) { + if (icon == null) + return; + Tessellator tessellator = Tessellator.instance; tessellator.setColorOpaque_F(.8f * r, .8f * g, .8f * b); if (renderer.blockAccess == null) { @@ -205,6 +217,9 @@ public final class RenderUtil } public static void renderFaceXNegColorMult (RenderBlocks renderer, Block block, int x, int y, int z, IIcon icon, float r, float g, float b) { + if (icon == null) + return; + Tessellator tessellator = Tessellator.instance; tessellator.setColorOpaque_F(.6f * r, .6f * g, .6f * b); if (renderer.blockAccess == null) { @@ -222,6 +237,9 @@ public final class RenderUtil } public static void renderFaceXPosColorMult (RenderBlocks renderer, Block block, int x, int y, int z, IIcon icon, float r, float g, float b) { + if (icon == null) + return; + Tessellator tessellator = Tessellator.instance; tessellator.setColorOpaque_F(.6f * r, .6f * g, .6f * b); if (renderer.blockAccess == null) { From 552eea57d5f108a9125ff21e35998527e9582598 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Sun, 7 Feb 2016 01:45:12 -0500 Subject: [PATCH 18/24] Fix crash in Forestry and Misc packs when Thermal Expansion integration is enabled and Refined Relocation is missing. --- packs/Forestry/build.gradle | 2 +- .../packs/forestry/core/DataResolver.java | 28 +++++++++++-------- packs/Misc/build.gradle | 2 +- .../packs/misc/core/DataResolver.java | 28 +++++++++++-------- 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/packs/Forestry/build.gradle b/packs/Forestry/build.gradle index d3d404e..68742a2 100644 --- a/packs/Forestry/build.gradle +++ b/packs/Forestry/build.gradle @@ -17,7 +17,7 @@ buildscript { apply plugin: 'forge' -version = "1.7.10-1.1.1" +version = "1.7.10-1.1.2" group= "com.jaquadro.minecraft.storagedrawers" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "StorageDrawers-Forestry" diff --git a/packs/Forestry/src/com/jaquadro/minecraft/storagedrawers/packs/forestry/core/DataResolver.java b/packs/Forestry/src/com/jaquadro/minecraft/storagedrawers/packs/forestry/core/DataResolver.java index 1a0592f..a2af2c3 100644 --- a/packs/Forestry/src/com/jaquadro/minecraft/storagedrawers/packs/forestry/core/DataResolver.java +++ b/packs/Forestry/src/com/jaquadro/minecraft/storagedrawers/packs/forestry/core/DataResolver.java @@ -30,33 +30,37 @@ public class DataResolver extends ExtendedDataResolver public Block getBlock (BlockConfiguration blockConfig) { switch (blockConfig.getBlockType()) { case Drawers: - if (blockConfig.getDrawerCount() == 1) + if (blockConfig.getDrawerCount() == 1 && ModBlocks.fullDrawers1 != null) return ModBlocks.fullDrawers1[bank]; - if (blockConfig.getDrawerCount() == 2 && !blockConfig.isHalfDepth()) + if (blockConfig.getDrawerCount() == 2 && !blockConfig.isHalfDepth() && ModBlocks.fullDrawers2 != null) return ModBlocks.fullDrawers2[bank]; - if (blockConfig.getDrawerCount() == 4 && !blockConfig.isHalfDepth()) + if (blockConfig.getDrawerCount() == 4 && !blockConfig.isHalfDepth() && ModBlocks.fullDrawers4 != null) return ModBlocks.fullDrawers4[bank]; - if (blockConfig.getDrawerCount() == 2 && blockConfig.isHalfDepth()) + if (blockConfig.getDrawerCount() == 2 && blockConfig.isHalfDepth() && ModBlocks.halfDrawers2 != null) return ModBlocks.halfDrawers2[bank]; - if (blockConfig.getDrawerCount() == 4 && blockConfig.isHalfDepth()) + if (blockConfig.getDrawerCount() == 4 && blockConfig.isHalfDepth() && ModBlocks.halfDrawers4 != null) return ModBlocks.halfDrawers4[bank]; break; case DrawersSorting: - if (blockConfig.getDrawerCount() == 1) + if (blockConfig.getDrawerCount() == 1 && RefinedRelocation.fullDrawers1 != null) return RefinedRelocation.fullDrawers1[bank]; - if (blockConfig.getDrawerCount() == 2 && !blockConfig.isHalfDepth()) + if (blockConfig.getDrawerCount() == 2 && !blockConfig.isHalfDepth() && RefinedRelocation.fullDrawers2 != null) return RefinedRelocation.fullDrawers2[bank]; - if (blockConfig.getDrawerCount() == 4 && !blockConfig.isHalfDepth()) + if (blockConfig.getDrawerCount() == 4 && !blockConfig.isHalfDepth() && RefinedRelocation.fullDrawers4 != null) return RefinedRelocation.fullDrawers4[bank]; - if (blockConfig.getDrawerCount() == 2 && blockConfig.isHalfDepth()) + if (blockConfig.getDrawerCount() == 2 && blockConfig.isHalfDepth() && RefinedRelocation.halfDrawers2 != null) return RefinedRelocation.halfDrawers2[bank]; - if (blockConfig.getDrawerCount() == 4 && blockConfig.isHalfDepth()) + if (blockConfig.getDrawerCount() == 4 && blockConfig.isHalfDepth() && RefinedRelocation.halfDrawers4 != null) return RefinedRelocation.halfDrawers4[bank]; break; case Trim: - return ModBlocks.trim[bank]; + if (ModBlocks.trim != null) + return ModBlocks.trim[bank]; + break; case TrimSorting: - return RefinedRelocation.trim[bank]; + if (RefinedRelocation.trim != null) + return RefinedRelocation.trim[bank]; + break; } return null; } diff --git a/packs/Misc/build.gradle b/packs/Misc/build.gradle index 2ed6d39..cb1e762 100644 --- a/packs/Misc/build.gradle +++ b/packs/Misc/build.gradle @@ -17,7 +17,7 @@ buildscript { apply plugin: 'forge' -version = "1.7.10-1.1.1" +version = "1.7.10-1.1.2" group= "com.jaquadro.minecraft.storagedrawers" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "StorageDrawers-Misc" diff --git a/packs/Misc/src/com/jaquadro/minecraft/storagedrawers/packs/misc/core/DataResolver.java b/packs/Misc/src/com/jaquadro/minecraft/storagedrawers/packs/misc/core/DataResolver.java index 4a8c2ed..5c8e23e 100644 --- a/packs/Misc/src/com/jaquadro/minecraft/storagedrawers/packs/misc/core/DataResolver.java +++ b/packs/Misc/src/com/jaquadro/minecraft/storagedrawers/packs/misc/core/DataResolver.java @@ -32,33 +32,37 @@ public class DataResolver extends ExtendedDataResolver public Block getBlock (BlockConfiguration blockConfig) { switch (blockConfig.getBlockType()) { case Drawers: - if (blockConfig.getDrawerCount() == 1) + if (blockConfig.getDrawerCount() == 1 && ModBlocks.fullDrawers1 != null) return ModBlocks.fullDrawers1[bank]; - if (blockConfig.getDrawerCount() == 2 && !blockConfig.isHalfDepth()) + if (blockConfig.getDrawerCount() == 2 && !blockConfig.isHalfDepth() && ModBlocks.fullDrawers2 != null) return ModBlocks.fullDrawers2[bank]; - if (blockConfig.getDrawerCount() == 4 && !blockConfig.isHalfDepth()) + if (blockConfig.getDrawerCount() == 4 && !blockConfig.isHalfDepth() && ModBlocks.fullDrawers4 != null) return ModBlocks.fullDrawers4[bank]; - if (blockConfig.getDrawerCount() == 2 && blockConfig.isHalfDepth()) + if (blockConfig.getDrawerCount() == 2 && blockConfig.isHalfDepth() && ModBlocks.halfDrawers2 != null) return ModBlocks.halfDrawers2[bank]; - if (blockConfig.getDrawerCount() == 4 && blockConfig.isHalfDepth()) + if (blockConfig.getDrawerCount() == 4 && blockConfig.isHalfDepth() && ModBlocks.halfDrawers4 != null) return ModBlocks.halfDrawers4[bank]; break; case DrawersSorting: - if (blockConfig.getDrawerCount() == 1) + if (blockConfig.getDrawerCount() == 1 && RefinedRelocation.fullDrawers1 != null) return RefinedRelocation.fullDrawers1[bank]; - if (blockConfig.getDrawerCount() == 2 && !blockConfig.isHalfDepth()) + if (blockConfig.getDrawerCount() == 2 && !blockConfig.isHalfDepth() && RefinedRelocation.fullDrawers2 != null) return RefinedRelocation.fullDrawers2[bank]; - if (blockConfig.getDrawerCount() == 4 && !blockConfig.isHalfDepth()) + if (blockConfig.getDrawerCount() == 4 && !blockConfig.isHalfDepth() && RefinedRelocation.fullDrawers4 != null) return RefinedRelocation.fullDrawers4[bank]; - if (blockConfig.getDrawerCount() == 2 && blockConfig.isHalfDepth()) + if (blockConfig.getDrawerCount() == 2 && blockConfig.isHalfDepth() && RefinedRelocation.halfDrawers2 != null) return RefinedRelocation.halfDrawers2[bank]; - if (blockConfig.getDrawerCount() == 4 && blockConfig.isHalfDepth()) + if (blockConfig.getDrawerCount() == 4 && blockConfig.isHalfDepth() && RefinedRelocation.halfDrawers4 != null) return RefinedRelocation.halfDrawers4[bank]; break; case Trim: - return ModBlocks.trim[bank]; + if (ModBlocks.trim != null) + return ModBlocks.trim[bank]; + break; case TrimSorting: - return RefinedRelocation.trim[bank]; + if (RefinedRelocation.trim != null) + return RefinedRelocation.trim[bank]; + break; } return null; } From 280719a1ef1ae7c5341cdd9ec9d72680a5dfa788 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Mon, 8 Feb 2016 18:17:03 -0500 Subject: [PATCH 19/24] Fix crash when right-clicking controller with empty hand. --- build.gradle | 2 +- .../storagedrawers/block/tile/TileEntityController.java | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 98c7fb9..2d949eb 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ buildscript { apply plugin: 'forge' -version = "1.7.10-1.7.8" +version = "1.7.10-1.7.9" group= "com.jaquadro.minecraft.storagedrawers" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "StorageDrawers" diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java index c2dc52e..ac271ac 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java @@ -157,10 +157,11 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP if (!dumpInventory) { ItemStack currentStack = player.inventory.getCurrentItem(); - count = insertItems(currentStack); - - if (currentStack.stackSize == 0) - player.inventory.setInventorySlotContents(player.inventory.currentItem, null); + if (currentStack != null) { + count = insertItems(currentStack); + if (currentStack.stackSize == 0) + player.inventory.setInventorySlotContents(player.inventory.currentItem, null); + } } else { for (int i = 0, n = player.inventory.getSizeInventory(); i < n; i++) { From f94d25fc6842ee74d8a6dd7cc4c53c39ffe7cbff Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Mon, 8 Feb 2016 23:04:37 -0500 Subject: [PATCH 20/24] Access protection key --- .../assets/storagedrawers/lang/en_US.lang | 4 + .../textures/blocks/indicator/claim_icon.png | Bin 0 -> 235 bytes .../blocks/indicator/claim_lock_icon.png | Bin 0 -> 251 bytes .../textures/items/drawer_key_personal.png | Bin 0 -> 357 bytes .../api/storage/attribute/IProtectable.java | 8 ++ .../storagedrawers/block/BlockDrawers.java | 32 +++++++- .../block/tile/TileEntityDrawers.java | 26 +++++++ .../client/renderer/DrawersRenderer.java | 8 +- .../storagedrawers/config/ConfigManager.java | 2 + .../storagedrawers/core/ModItems.java | 4 + .../storagedrawers/core/ModRecipes.java | 4 + .../storagedrawers/integration/Waila.java | 72 +++++++++--------- .../storagedrawers/item/ItemPersonalKey.java | 45 +++++++++++ 13 files changed, 165 insertions(+), 40 deletions(-) create mode 100644 resources/assets/storagedrawers/textures/blocks/indicator/claim_icon.png create mode 100644 resources/assets/storagedrawers/textures/blocks/indicator/claim_lock_icon.png create mode 100644 resources/assets/storagedrawers/textures/items/drawer_key_personal.png create mode 100644 src/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IProtectable.java create mode 100644 src/com/jaquadro/minecraft/storagedrawers/item/ItemPersonalKey.java diff --git a/resources/assets/storagedrawers/lang/en_US.lang b/resources/assets/storagedrawers/lang/en_US.lang index 87762c6..478f451 100644 --- a/resources/assets/storagedrawers/lang/en_US.lang +++ b/resources/assets/storagedrawers/lang/en_US.lang @@ -32,6 +32,8 @@ item.storagedrawers.upgradeSorting.name=Sorting Upgrade item.storagedrawers.upgradeSorting.description=For Refined Relocation item.storagedrawers.shroudKey.name=Concealment Key item.storagedrawers.shroudKey.description=Show or hide item labels +item.storagedrawers.personalKey.name=Personal Key +item.storagedrawers.personalKey.description=Protect access from other players item.storagedrawers.tape.name=Packing Tape item.storagedrawers.tape.description=Seals drawers for moving @@ -97,6 +99,7 @@ storageDrawers.waila.nolimit=Stack Limit: ∞ storageDrawers.waila.locked=Locked storageDrawers.waila.void=Void storageDrawers.waila.sorting=Sorting +storageDrawers.waila.protected=Protected # Configuration storageDrawers.config.title=Storage Drawers Configuration @@ -132,6 +135,7 @@ storageDrawers.config.prop.enableIndicatorUpgrades=Enable Indicator Upgrades storageDrawers.config.prop.enableStorageUpgrades=Enable Storage Upgrades storageDrawers.config.prop.enableLockUpgrades=Enable Drawer Locking storageDrawers.config.prop.enableShroudUpgrades=Enable Item Concealing +storageDrawers.config.prop.enablePersonalUpgrades=Enable Access Protection storageDrawers.config.prop.enableVoidUpgrades=Enable Void Upgrade storageDrawers.config.prop.enableCreativeUpgrades=Enable Creative Upgrade storageDrawers.config.prop.enableSortingUpgrades=Enable Sorting Upgrade diff --git a/resources/assets/storagedrawers/textures/blocks/indicator/claim_icon.png b/resources/assets/storagedrawers/textures/blocks/indicator/claim_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a054a475335ba1eed5694507ce569940133c3f09 GIT binary patch literal 235 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Iwh_VCC){ui6xo&c?uz!xv2~x z8Knw_W(tl4MG8g+hNcRJmR6=_RtBaDx(22O2JgHhoPhe+OFVsD*&i@*GMSmpsH*h> z3UL;AL>4nJaD4z_MyE95jgR3=A9lx&I`x0{Kp!E{-7;w~|v1Fus#b{?UIX zd{a_Fih|gJ>|?5KThbQsDjpLnG4*lz&CM=R!R*1s-j&2O{aGV_b0D)sL3&`)W@839 WW`*MCbNNADVeoYIb6Mw<&;$VXJ3y8I literal 0 HcmV?d00001 diff --git a/resources/assets/storagedrawers/textures/blocks/indicator/claim_lock_icon.png b/resources/assets/storagedrawers/textures/blocks/indicator/claim_lock_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..47e4c5f52e4fd334af16911e7e64ce4e222456c7 GIT binary patch literal 251 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Iwh_VCC){ui6xo&c?uz!xv2~x z8Knw_W(tl4MG8g+hNcRJmR6=_RtBaDx(22O2JgHhoPhe+OFVsD*&i@*GK*QfZjrkI z6yhxKh%9Dc;Q9cbP0l+XkKAahCM literal 0 HcmV?d00001 diff --git a/resources/assets/storagedrawers/textures/items/drawer_key_personal.png b/resources/assets/storagedrawers/textures/items/drawer_key_personal.png new file mode 100644 index 0000000000000000000000000000000000000000..1b36446fe81d22a3b8a6db4adda15160eb3f84f2 GIT binary patch literal 357 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`+9j?LCC){ui6xo&c?uz!xv31k zK!$~aTWXSmk%6HZkgzf^vNAMO&^0hMFgU;DOEFLzdx@v7EBgZ`PDWwIQ$^c;1BEyX zJR*ToTpvJ~(P@pz44@!Ox}&cn1H;CC?mvmFK>l7&7srr_TgeFv)K7d){ms8PF-I)O zL_Fjl(JpAvHy|29I;s1}EdkUnUF*Th#n#K`0Yoh3*%V(N=imdKI;Vst0GT_8EdT%j literal 0 HcmV?d00001 diff --git a/src/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IProtectable.java b/src/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IProtectable.java new file mode 100644 index 0000000..e076dc8 --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IProtectable.java @@ -0,0 +1,8 @@ +package com.jaquadro.minecraft.storagedrawers.api.storage.attribute; + +/** + * Created by Justin on 2/8/2016. + */ +public interface IProtectable +{ +} diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java index b51188f..09cc1b8 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java @@ -99,6 +99,10 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH @SideOnly(Side.CLIENT) private IIcon iconLock; @SideOnly(Side.CLIENT) + private IIcon iconClaim; + @SideOnly(Side.CLIENT) + private IIcon iconClaimLock; + @SideOnly(Side.CLIENT) private IIcon iconVoid; @SideOnly(Side.CLIENT) @@ -297,6 +301,9 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH TileEntityDrawers tileDrawers = getTileEntitySafe(world, x, y, z); ItemStack item = player.inventory.getCurrentItem(); + if (tileDrawers.getOwner() != null && !player.getPersistentID().equals(tileDrawers.getOwner())) + return false; + if (StorageDrawers.config.cache.debugTrace) { FMLLog.log(StorageDrawers.MOD_ID, Level.INFO, "BlockDrawers.onBlockActivated"); FMLLog.log(StorageDrawers.MOD_ID, Level.INFO, (item == null) ? " null item" : " " + item.toString()); @@ -340,6 +347,15 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH tileDrawers.setIsShrouded(!tileDrawers.isShrouded()); return true; } + else if (item.getItem() == ModItems.personalKey) { + if (tileDrawers.getOwner() == null) + tileDrawers.setOwner(player.getPersistentID()); + else if (player.getPersistentID().equals(tileDrawers.getOwner())) + tileDrawers.setOwner(null); + else + return false; + return true; + } else if (item.getItem() == ModItems.tape) return false; } @@ -433,6 +449,9 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH if (tileDrawers.isSealed()) return; + if (tileDrawers.getOwner() != null && !tileDrawers.getOwner().equals(player.getPersistentID())) + return; + int slot = getDrawerSlot(side, hitX, hitY, hitZ); IDrawer drawer = tileDrawers.getDrawer(slot); @@ -791,8 +810,15 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH } @SideOnly(Side.CLIENT) - public IIcon getLockIcon () { - return iconLock; + public IIcon getLockIcon (boolean locked, boolean claimed) { + if (locked && claimed) + return iconClaimLock; + else if (locked) + return iconLock; + else if (claimed) + return iconClaim; + else + return null; } @SideOnly(Side.CLIENT) @@ -854,6 +880,8 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH iconIndicator4[1] = register.registerIcon(StorageDrawers.MOD_ID + ":indicator/indicator_4_on"); iconLock = register.registerIcon(StorageDrawers.MOD_ID + ":indicator/lock_icon"); + iconClaim = register.registerIcon(StorageDrawers.MOD_ID + ":indicator/claim_icon"); + iconClaimLock = register.registerIcon(StorageDrawers.MOD_ID + ":indicator/claim_lock_icon"); iconVoid = register.registerIcon(StorageDrawers.MOD_ID + ":indicator/void_icon"); loadBlockConfig(); diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java index 0010a8f..a171e7b 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java @@ -47,6 +47,7 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe private boolean shrouded = false; private boolean taped = false; private boolean hideUpgrade = false; + private UUID owner; private EnumSet lockAttributes = null; @@ -241,6 +242,24 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe } } + public UUID getOwner () { + if (!StorageDrawers.config.cache.enablePersonalUpgrades) + return null; + + return owner; + } + + public void setOwner (UUID owner) { + if ((this.owner != null && !this.owner.equals(owner)) || (owner != null && !owner.equals(this.owner))) { + this.owner = owner; + + if (worldObj != null && !worldObj.isRemote) { + markDirty(); + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + } + } + public boolean shouldHideUpgrades () { return hideUpgrade; } @@ -476,6 +495,10 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe if (tag.hasKey("Shr")) shrouded = tag.getBoolean("Shr"); + owner = null; + if (tag.hasKey("Own")) + owner = UUID.fromString(tag.getString("Own")); + hideUpgrade = false; if (tag.hasKey("HideUp")) hideUpgrade = tag.getBoolean("HideUp"); @@ -517,6 +540,9 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe if (shrouded) tag.setBoolean("Shr", shrouded); + if (owner != null) + tag.setString("Own", owner.toString()); + if (hideUpgrade) tag.setBoolean("HideUp", hideUpgrade); diff --git a/src/com/jaquadro/minecraft/storagedrawers/client/renderer/DrawersRenderer.java b/src/com/jaquadro/minecraft/storagedrawers/client/renderer/DrawersRenderer.java index d451ee5..8f3f350 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/client/renderer/DrawersRenderer.java +++ b/src/com/jaquadro/minecraft/storagedrawers/client/renderer/DrawersRenderer.java @@ -136,7 +136,7 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler if (StorageDrawers.config.cache.enableIndicatorUpgrades) renderIndicator(block, x, y, z, side, renderer, tile.getEffectiveStatusLevel()); if (StorageDrawers.config.cache.enableLockUpgrades) - renderLock(block, x, y, z, side, renderer, tile.isLocked(LockAttribute.LOCK_POPULATED)); + renderLock(block, x, y, z, side, renderer, tile.isLocked(LockAttribute.LOCK_POPULATED), tile.getOwner() != null); if (StorageDrawers.config.cache.enableVoidUpgrades) renderVoid(block, x, y, z, side, renderer, tile.isVoid()); if (StorageDrawers.config.cache.enableTape) @@ -147,12 +147,12 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler return true; } - private void renderLock (BlockDrawers block, int x, int y, int z, int side, RenderBlocks renderer, boolean locked) { - if (!locked) + private void renderLock (BlockDrawers block, int x, int y, int z, int side, RenderBlocks renderer, boolean locked, boolean owned) { + if (!locked && !owned) return; double depth = block.halfDepth ? .5 : 1; - IIcon iconLock = block.getLockIcon(); + IIcon iconLock = block.getLockIcon(locked, owned); RenderHelper.instance.setRenderBounds(0.46875, 0.9375, 0, 0.53125, 1, depth + .005); RenderHelper.instance.state.setRotateTransform(RenderHelper.ZPOS, side); diff --git a/src/com/jaquadro/minecraft/storagedrawers/config/ConfigManager.java b/src/com/jaquadro/minecraft/storagedrawers/config/ConfigManager.java index 9e671a6..e346d29 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/config/ConfigManager.java +++ b/src/com/jaquadro/minecraft/storagedrawers/config/ConfigManager.java @@ -60,6 +60,7 @@ public class ConfigManager public boolean enableVoidUpgrades; public boolean enableCreativeUpgrades; public boolean enableShroudUpgrades; + public boolean enablePersonalUpgrades; public boolean enableSortingUpgrades; public boolean renderStorageUpgrades; public boolean enableDrawerUI; @@ -229,6 +230,7 @@ public class ConfigManager cache.enableVoidUpgrades = config.get(Configuration.CATEGORY_GENERAL, "enableVoidUpgrades", true).setLanguageKey(LANG_PREFIX + "prop.enableVoidUpgrades").setRequiresMcRestart(true).getBoolean(); cache.enableCreativeUpgrades = config.get(Configuration.CATEGORY_GENERAL, "enableCreativeUpgrades", true).setLanguageKey(LANG_PREFIX + "prop.enableCreativeUpgrades").setRequiresMcRestart(true).getBoolean(); cache.enableShroudUpgrades = config.get(Configuration.CATEGORY_GENERAL, "enableShroudUpgrades", true).setLanguageKey(LANG_PREFIX + "prop.enableShroudUpgrades").setRequiresMcRestart(true).getBoolean(); + cache.enablePersonalUpgrades = config.get(Configuration.CATEGORY_GENERAL, "enablePersonalUpgrades", true).setLanguageKey(LANG_PREFIX + "prop.enablePersonalUpgrades").setRequiresMcRestart(true).getBoolean(); cache.enableSortingUpgrades = config.get(Configuration.CATEGORY_GENERAL, "enableSortingUpgrades", true).setLanguageKey(LANG_PREFIX + "prop.enableSortingUpgrades").setRequiresMcRestart(true).getBoolean(); cache.enableTape = config.get(Configuration.CATEGORY_GENERAL, "enableTape", true).setLanguageKey(LANG_PREFIX + "prop.enableTape").setRequiresMcRestart(true).getBoolean(); cache.itemRenderType = config.get(Configuration.CATEGORY_GENERAL, "itemRenderType", "fast", null, new String[]{"fancy", "fast"}).setLanguageKey(LANG_PREFIX + "prop.itemRenderType").getString(); diff --git a/src/com/jaquadro/minecraft/storagedrawers/core/ModItems.java b/src/com/jaquadro/minecraft/storagedrawers/core/ModItems.java index a16346f..d989b92 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/core/ModItems.java +++ b/src/com/jaquadro/minecraft/storagedrawers/core/ModItems.java @@ -14,6 +14,7 @@ public class ModItems public static ItemUpgradeVoid upgradeVoid; public static ItemUpgradeCreative upgradeCreative; public static ItemShroudKey shroudKey; + public static ItemPersonalKey personalKey; public static ItemTape tape; public void init () { @@ -24,6 +25,7 @@ public class ModItems upgradeVoid = new ItemUpgradeVoid(makeName("upgradeVoid")); upgradeCreative = new ItemUpgradeCreative(makeName("upgradeCreative")); shroudKey = new ItemShroudKey(makeName("shroudKey")); + personalKey = new ItemPersonalKey(makeName("personalKey")); tape = new ItemTape(makeName("tape")); GameRegistry.registerItem(upgradeTemplate, "upgradeTemplate"); @@ -40,6 +42,8 @@ public class ModItems GameRegistry.registerItem(upgradeLock, "upgradeLock"); if (StorageDrawers.config.cache.enableShroudUpgrades) GameRegistry.registerItem(shroudKey, "shroudKey"); + if (StorageDrawers.config.cache.enablePersonalUpgrades) + GameRegistry.registerItem(personalKey, "personalKey"); if (StorageDrawers.config.cache.enableTape) GameRegistry.registerItem(tape, "tape"); } diff --git a/src/com/jaquadro/minecraft/storagedrawers/core/ModRecipes.java b/src/com/jaquadro/minecraft/storagedrawers/core/ModRecipes.java index 764c1db..0a294d7 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/core/ModRecipes.java +++ b/src/com/jaquadro/minecraft/storagedrawers/core/ModRecipes.java @@ -116,6 +116,10 @@ public class ModRecipes GameRegistry.addShapelessRecipe(new ItemStack(ModItems.shroudKey), ModItems.upgradeLock, Items.ender_eye); } + if (config.cache.enablePersonalUpgrades) { + GameRegistry.addShapelessRecipe(new ItemStack(ModItems.personalKey), ModItems.upgradeLock, Items.name_tag); + } + if (config.cache.enableTape) { GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModItems.tape), " x ", "yyy", 'x', "slimeball", 'y', Items.paper)); diff --git a/src/com/jaquadro/minecraft/storagedrawers/integration/Waila.java b/src/com/jaquadro/minecraft/storagedrawers/integration/Waila.java index 1568d5f..42131f1 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/integration/Waila.java +++ b/src/com/jaquadro/minecraft/storagedrawers/integration/Waila.java @@ -13,6 +13,7 @@ import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; import mcp.mobius.waila.api.IWailaDataProvider; import mcp.mobius.waila.api.IWailaRegistrar; +import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -61,46 +62,47 @@ public class Waila extends IntegrationModule public List getWailaBody (ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) { TileEntityDrawers tile = (TileEntityDrawers) accessor.getTileEntity(); - IDrawerGroup group = tile; - for (int i = 0; i < group.getDrawerCount(); i++) { - if (!group.isDrawerEnabled(i)) - continue; + if (tile.getOwner() == null || tile.getOwner().equals(Minecraft.getMinecraft().thePlayer.getPersistentID())) { + IDrawerGroup group = tile; + for (int i = 0; i < group.getDrawerCount(); i++) { + if (!group.isDrawerEnabled(i)) + continue; - String name = StatCollector.translateToLocal("storageDrawers.waila.empty"); + String name = StatCollector.translateToLocal("storageDrawers.waila.empty"); - IDrawer drawer = group.getDrawer(i); - ItemStack stack = drawer.getStoredItemPrototype(); - if (stack != null && stack.getItem() != null) { - String stackName = stack.getDisplayName(); - List handlers = StorageDrawers.wailaRegistry.getTooltipHandlers(); - for (int j = 0, n = handlers.size(); j < n; j++) - stackName = handlers.get(j).transformItemName(drawer, stackName); + IDrawer drawer = group.getDrawer(i); + ItemStack stack = drawer.getStoredItemPrototype(); + if (stack != null && stack.getItem() != null) { + String stackName = stack.getDisplayName(); + List handlers = StorageDrawers.wailaRegistry.getTooltipHandlers(); + for (int j = 0, n = handlers.size(); j < n; j++) + stackName = handlers.get(j).transformItemName(drawer, stackName); - if (drawer.getStoredItemCount() == Integer.MAX_VALUE) - name = stackName + " [\u221E]"; - else if (drawer instanceof IFractionalDrawer && ((IFractionalDrawer) drawer).getConversionRate() > 1) - name = stackName + ((i == 0) ? " [" : " [+") + ((IFractionalDrawer) drawer).getStoredItemRemainder() + "]"; - else if (StorageDrawers.config.cache.stackRemainderWaila) { - int stacks = drawer.getStoredItemCount() / drawer.getStoredItemStackSize(); - int remainder = drawer.getStoredItemCount() - (stacks * drawer.getStoredItemStackSize()); - if (stacks > 0 && remainder > 0) - name = stackName + " [" + stacks + "x" + drawer.getStoredItemStackSize() + " + " + remainder + "]"; - else if (stacks > 0) - name = stackName + " [" + stacks + "x" + drawer.getStoredItemStackSize() + "]"; - else - name = stackName + " [" + remainder + "]"; + if (drawer.getStoredItemCount() == Integer.MAX_VALUE) + name = stackName + " [\u221E]"; + else if (drawer instanceof IFractionalDrawer && ((IFractionalDrawer) drawer).getConversionRate() > 1) + name = stackName + ((i == 0) ? " [" : " [+") + ((IFractionalDrawer) drawer).getStoredItemRemainder() + "]"; + else if (StorageDrawers.config.cache.stackRemainderWaila) { + int stacks = drawer.getStoredItemCount() / drawer.getStoredItemStackSize(); + int remainder = drawer.getStoredItemCount() - (stacks * drawer.getStoredItemStackSize()); + if (stacks > 0 && remainder > 0) + name = stackName + " [" + stacks + "x" + drawer.getStoredItemStackSize() + " + " + remainder + "]"; + else if (stacks > 0) + name = stackName + " [" + stacks + "x" + drawer.getStoredItemStackSize() + "]"; + else + name = stackName + " [" + remainder + "]"; + } else + name = stackName + " [" + drawer.getStoredItemCount() + "]"; } - else - name = stackName + " [" + drawer.getStoredItemCount() + "]"; + currenttip.add(StatCollector.translateToLocalFormatted("storageDrawers.waila.drawer", i + 1, name)); } - currenttip.add(StatCollector.translateToLocalFormatted("storageDrawers.waila.drawer", i + 1, name)); - } - if (tile.isUnlimited() || tile.isVending()) - currenttip.add(StatCollector.translateToLocalFormatted("storageDrawers.waila.nolimit")); - else { - int limit = tile.getDrawerCapacity() * tile.getEffectiveStorageMultiplier(); - currenttip.add(StatCollector.translateToLocalFormatted("storageDrawers.waila.limit", limit, tile.getEffectiveStorageMultiplier())); + if (tile.isUnlimited() || tile.isVending()) + currenttip.add(StatCollector.translateToLocalFormatted("storageDrawers.waila.nolimit")); + else { + int limit = tile.getDrawerCapacity() * tile.getEffectiveStorageMultiplier(); + currenttip.add(StatCollector.translateToLocalFormatted("storageDrawers.waila.limit", limit, tile.getEffectiveStorageMultiplier())); + } } String attrib = ""; @@ -110,6 +112,8 @@ public class Waila extends IntegrationModule attrib += (attrib.isEmpty() ? "" : ", ") + StatCollector.translateToLocal("storageDrawers.waila.void"); if (tile.isSorting()) attrib += (attrib.isEmpty() ? "" : ", ") + StatCollector.translateToLocal("storageDrawers.waila.sorting"); + if (tile.getOwner() != null) + attrib += (attrib.isEmpty() ? "" : ", ") + StatCollector.translateToLocal("storageDrawers.waila.protected"); if (!attrib.isEmpty()) currenttip.add(attrib); diff --git a/src/com/jaquadro/minecraft/storagedrawers/item/ItemPersonalKey.java b/src/com/jaquadro/minecraft/storagedrawers/item/ItemPersonalKey.java new file mode 100644 index 0000000..e6348a3 --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/item/ItemPersonalKey.java @@ -0,0 +1,45 @@ +package com.jaquadro.minecraft.storagedrawers.item; + +import com.google.common.collect.Multimap; +import com.jaquadro.minecraft.storagedrawers.StorageDrawers; +import com.jaquadro.minecraft.storagedrawers.core.ModCreativeTabs; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.attributes.AttributeModifier; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.StatCollector; + +import java.util.List; + +public class ItemPersonalKey extends Item +{ + public ItemPersonalKey (String name) { + setUnlocalizedName(name); + setCreativeTab(ModCreativeTabs.tabStorageDrawers); + setTextureName(StorageDrawers.MOD_ID + ":drawer_key_personal"); + setMaxDamage(0); + } + + @Override + @SideOnly(Side.CLIENT) + public void addInformation (ItemStack itemStack, EntityPlayer player, List list, boolean par4) { + String name = getUnlocalizedName(itemStack); + list.add(StatCollector.translateToLocalFormatted(name + ".description")); + } + + @SideOnly(Side.CLIENT) + public boolean isFull3D() + { + return true; + } + + @Override + public Multimap getAttributeModifiers (ItemStack item) { + Multimap multimap = super.getAttributeModifiers(item); + multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Weapon modifier", (double)2, 0)); + return multimap; + } +} From 6b34cefaf20fa630973077d095a36ec01c99b274 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Mon, 8 Feb 2016 23:37:16 -0500 Subject: [PATCH 21/24] Add protection support to tape and (manual) controller interaction. --- .../api/storage/attribute/IProtectable.java | 15 ++++- .../storagedrawers/block/BlockController.java | 9 ++- .../block/tile/TileEntityController.java | 61 ++++++++++++++++--- .../block/tile/TileEntityDrawers.java | 12 +++- .../storagedrawers/item/ItemTape.java | 8 +++ 5 files changed, 89 insertions(+), 16 deletions(-) diff --git a/src/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IProtectable.java b/src/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IProtectable.java index e076dc8..3a38009 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IProtectable.java +++ b/src/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IProtectable.java @@ -1,8 +1,17 @@ package com.jaquadro.minecraft.storagedrawers.api.storage.attribute; -/** - * Created by Justin on 2/8/2016. - */ +import java.util.UUID; + public interface IProtectable { + /** + * Gets the owner of the drawer, or null if there is no owner. + */ + UUID getOwner (); + + /** + * Sets the owner of the drawer. Set to null to set no owner. + * @return false if the operation is not supported, true otherwise. + */ + boolean setOwner (UUID owner); } diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/BlockController.java b/src/com/jaquadro/minecraft/storagedrawers/block/BlockController.java index 305e64f..4bc29e5 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/BlockController.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/BlockController.java @@ -121,12 +121,17 @@ public class BlockController extends BlockContainer implements INetworked if (item != null && item.getItem() != null) { if (item.getItem() == ModItems.shroudKey) { if (!world.isRemote) - te.toggleShroud(); + te.toggleShroud(player.getPersistentID()); return true; } else if (item.getItem() == ModItems.upgradeLock) { if (!world.isRemote) - te.toggleLock(EnumSet.allOf(LockAttribute.class), LockAttribute.LOCK_POPULATED); + te.toggleLock(EnumSet.allOf(LockAttribute.class), LockAttribute.LOCK_POPULATED, player.getPersistentID()); + return true; + } + else if (item.getItem() == ModItems.personalKey) { + if (!world.isRemote) + te.toggleProtection(player.getPersistentID()); return true; } } diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java index ac271ac..1d12fe8 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java @@ -3,10 +3,7 @@ package com.jaquadro.minecraft.storagedrawers.block.tile; import com.jaquadro.minecraft.storagedrawers.StorageDrawers; import com.jaquadro.minecraft.storagedrawers.api.inventory.IDrawerInventory; import com.jaquadro.minecraft.storagedrawers.api.storage.*; -import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.ILockable; -import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IShroudable; -import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IVoidable; -import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.LockAttribute; +import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.*; import com.jaquadro.minecraft.storagedrawers.block.BlockSlave; import com.jaquadro.minecraft.storagedrawers.util.ItemMetaListRegistry; import com.jaquadro.minecraft.storagedrawers.util.ItemMetaRegistry; @@ -158,7 +155,7 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP if (!dumpInventory) { ItemStack currentStack = player.inventory.getCurrentItem(); if (currentStack != null) { - count = insertItems(currentStack); + count = insertItems(currentStack, player.getPersistentID()); if (currentStack.stackSize == 0) player.inventory.setInventorySlotContents(player.inventory.currentItem, null); } @@ -167,7 +164,7 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP for (int i = 0, n = player.inventory.getSizeInventory(); i < n; i++) { ItemStack subStack = player.inventory.getStackInSlot(i); if (subStack != null) { - count += insertItems(subStack); + count += insertItems(subStack, player.getPersistentID()); if (subStack.stackSize == 0) player.inventory.setInventorySlotContents(i, null); } @@ -183,10 +180,17 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP return count; } - private int insertItems (ItemStack stack) { + private int insertItems (ItemStack stack, UUID owner) { int itemsLeft = stack.stackSize; for (int slot : enumerateDrawersForInsertion(stack, false)) { + IDrawerGroup group = getGroupForDrawerSlot(slot); + if (group instanceof IProtectable) { + IProtectable protectable = (IProtectable)group; + if (protectable.getOwner() != null && !protectable.getOwner().equals(owner)) + continue; + } + IDrawer drawer = getDrawer(slot); ItemStack itemProto = drawer.getStoredItemPrototype(); if (itemProto == null) @@ -227,7 +231,34 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP return remainder; } - public void toggleShroud () { + public void toggleProtection (UUID owner) { + IProtectable template = null; + UUID state = null; + + for (StorageRecord record : storage.values()) { + if (record.storage == null) + continue; + + if (record.storage instanceof IProtectable) { + IProtectable protectable = (IProtectable)record.storage; + if (protectable.getOwner() != null && !protectable.getOwner().equals(owner)) + continue; + + if (template == null) { + template = protectable; + + if (template.getOwner() == null) + state = owner; + else + state = null; + } + + protectable.setOwner(state); + } + } + } + + public void toggleShroud (UUID owner) { IShroudable template = null; boolean state = false; @@ -235,6 +266,12 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP if (record.storage == null) continue; + if (record.storage instanceof IProtectable) { + IProtectable protectable = (IProtectable)record.storage; + if (protectable.getOwner() != null && !protectable.getOwner().equals(owner)) + continue; + } + for (int i = 0, n = record.storage.getDrawerCount(); i < n; i++) { if (!record.storage.isDrawerEnabled(i)) continue; @@ -254,7 +291,7 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP } } - public void toggleLock (EnumSet attributes, LockAttribute key) { + public void toggleLock (EnumSet attributes, LockAttribute key, UUID owner) { ILockable template = null; boolean state = false; @@ -262,6 +299,12 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP if (record.storage == null) continue; + if (record.storage instanceof IProtectable) { + IProtectable protectable = (IProtectable)record.storage; + if (protectable.getOwner() != null && !protectable.getOwner().equals(owner)) + continue; + } + if (record.storage instanceof ILockable) { ILockable lockableStorage = (ILockable)record.storage; if (template == null) { diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java index a171e7b..f650489 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java @@ -5,6 +5,7 @@ import com.jaquadro.minecraft.storagedrawers.api.inventory.IDrawerInventory; import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer; import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroupInteractive; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.ILockable; +import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IProtectable; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.ISealable; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.LockAttribute; import com.jaquadro.minecraft.storagedrawers.config.ConfigManager; @@ -35,7 +36,7 @@ import java.util.EnumSet; import java.util.Iterator; import java.util.UUID; -public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawerGroupInteractive, ISidedInventory, IUpgradeProvider, ILockable, ISealable +public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawerGroupInteractive, ISidedInventory, IUpgradeProvider, ILockable, ISealable, IProtectable { private IDrawer[] drawers; private IDrawerInventory inventory; @@ -242,6 +243,7 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe } } + @Override public UUID getOwner () { if (!StorageDrawers.config.cache.enablePersonalUpgrades) return null; @@ -249,7 +251,11 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe return owner; } - public void setOwner (UUID owner) { + @Override + public boolean setOwner (UUID owner) { + if (!StorageDrawers.config.cache.enablePersonalUpgrades) + return false; + if ((this.owner != null && !this.owner.equals(owner)) || (owner != null && !owner.equals(this.owner))) { this.owner = owner; @@ -258,6 +264,8 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } } + + return true; } public boolean shouldHideUpgrades () { diff --git a/src/com/jaquadro/minecraft/storagedrawers/item/ItemTape.java b/src/com/jaquadro/minecraft/storagedrawers/item/ItemTape.java index 1acedd1..46b69f0 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/item/ItemTape.java +++ b/src/com/jaquadro/minecraft/storagedrawers/item/ItemTape.java @@ -1,6 +1,7 @@ package com.jaquadro.minecraft.storagedrawers.item; import com.jaquadro.minecraft.storagedrawers.StorageDrawers; +import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IProtectable; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.ISealable; import com.jaquadro.minecraft.storagedrawers.core.ModCreativeTabs; import cpw.mods.fml.relauncher.Side; @@ -37,6 +38,13 @@ public class ItemTape extends Item return false; TileEntity tile = world.getTileEntity(x, y, z); + if (tile instanceof IProtectable) { + IProtectable protectable = (IProtectable)tile; + if (protectable.getOwner() != null && !protectable.getOwner().equals(player.getPersistentID())) + return false; + + } + if (tile instanceof ISealable) { ISealable tileseal = (ISealable) tile; if (tileseal.isSealed()) From fed06411874f3bf14da6919db2dd5e9c001d5afd Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Wed, 10 Feb 2016 02:11:09 -0500 Subject: [PATCH 22/24] Add security provider system --- .../api/security/ISecurityProvider.java | 9 +++++++ .../api/storage/attribute/IProtectable.java | 8 ++++++ .../storagedrawers/block/BlockController.java | 6 ++--- .../storagedrawers/block/BlockDrawers.java | 5 ++-- .../block/tile/TileEntityController.java | 27 +++++++++---------- .../block/tile/TileEntityDrawers.java | 6 +++++ .../storagedrawers/integration/Waila.java | 10 +++---- .../storagedrawers/item/ItemTape.java | 5 ++-- .../security/DefaultSecurityProvider.java | 16 +++++++++++ .../security/SecurityManager.java | 21 +++++++++++++++ 10 files changed, 86 insertions(+), 27 deletions(-) create mode 100644 src/com/jaquadro/minecraft/storagedrawers/api/security/ISecurityProvider.java create mode 100644 src/com/jaquadro/minecraft/storagedrawers/security/DefaultSecurityProvider.java create mode 100644 src/com/jaquadro/minecraft/storagedrawers/security/SecurityManager.java diff --git a/src/com/jaquadro/minecraft/storagedrawers/api/security/ISecurityProvider.java b/src/com/jaquadro/minecraft/storagedrawers/api/security/ISecurityProvider.java new file mode 100644 index 0000000..119c8bb --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/api/security/ISecurityProvider.java @@ -0,0 +1,9 @@ +package com.jaquadro.minecraft.storagedrawers.api.security; + +import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IProtectable; +import com.mojang.authlib.GameProfile; + +public interface ISecurityProvider +{ + boolean hasAccess (GameProfile profile, IProtectable target); +} diff --git a/src/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IProtectable.java b/src/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IProtectable.java index 3a38009..845f4d0 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IProtectable.java +++ b/src/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IProtectable.java @@ -1,5 +1,7 @@ package com.jaquadro.minecraft.storagedrawers.api.storage.attribute; +import com.jaquadro.minecraft.storagedrawers.api.security.ISecurityProvider; + import java.util.UUID; public interface IProtectable @@ -14,4 +16,10 @@ public interface IProtectable * @return false if the operation is not supported, true otherwise. */ boolean setOwner (UUID owner); + + /** + * Gets the provider managing security for the target. + * @return null to use the default provider, which enforces strict owner access. + */ + ISecurityProvider getSecurityProvider (); } diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/BlockController.java b/src/com/jaquadro/minecraft/storagedrawers/block/BlockController.java index 4bc29e5..3dfc0dc 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/BlockController.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/BlockController.java @@ -121,17 +121,17 @@ public class BlockController extends BlockContainer implements INetworked if (item != null && item.getItem() != null) { if (item.getItem() == ModItems.shroudKey) { if (!world.isRemote) - te.toggleShroud(player.getPersistentID()); + te.toggleShroud(player.getGameProfile()); return true; } else if (item.getItem() == ModItems.upgradeLock) { if (!world.isRemote) - te.toggleLock(EnumSet.allOf(LockAttribute.class), LockAttribute.LOCK_POPULATED, player.getPersistentID()); + te.toggleLock(EnumSet.allOf(LockAttribute.class), LockAttribute.LOCK_POPULATED, player.getGameProfile()); return true; } else if (item.getItem() == ModItems.personalKey) { if (!world.isRemote) - te.toggleProtection(player.getPersistentID()); + te.toggleProtection(player.getGameProfile()); return true; } } diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java index 09cc1b8..2d02e45 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java @@ -16,6 +16,7 @@ import com.jaquadro.minecraft.storagedrawers.core.handlers.GuiHandler; import com.jaquadro.minecraft.storagedrawers.item.ItemTrim; import com.jaquadro.minecraft.storagedrawers.network.BlockClickMessage; +import com.jaquadro.minecraft.storagedrawers.security.SecurityManager; import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -301,7 +302,7 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH TileEntityDrawers tileDrawers = getTileEntitySafe(world, x, y, z); ItemStack item = player.inventory.getCurrentItem(); - if (tileDrawers.getOwner() != null && !player.getPersistentID().equals(tileDrawers.getOwner())) + if (!SecurityManager.hasAccess(player.getGameProfile(), tileDrawers)) return false; if (StorageDrawers.config.cache.debugTrace) { @@ -449,7 +450,7 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH if (tileDrawers.isSealed()) return; - if (tileDrawers.getOwner() != null && !tileDrawers.getOwner().equals(player.getPersistentID())) + if (!SecurityManager.hasAccess(player.getGameProfile(), tileDrawers)) return; int slot = getDrawerSlot(side, hitX, hitY, hitZ); diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java index 1d12fe8..99c4c10 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java @@ -5,9 +5,11 @@ import com.jaquadro.minecraft.storagedrawers.api.inventory.IDrawerInventory; import com.jaquadro.minecraft.storagedrawers.api.storage.*; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.*; import com.jaquadro.minecraft.storagedrawers.block.BlockSlave; +import com.jaquadro.minecraft.storagedrawers.security.SecurityManager; import com.jaquadro.minecraft.storagedrawers.util.ItemMetaListRegistry; import com.jaquadro.minecraft.storagedrawers.util.ItemMetaRegistry; import com.jaquadro.minecraft.storagedrawers.util.UniqueMetaIdentifier; +import com.mojang.authlib.GameProfile; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ISidedInventory; @@ -155,7 +157,7 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP if (!dumpInventory) { ItemStack currentStack = player.inventory.getCurrentItem(); if (currentStack != null) { - count = insertItems(currentStack, player.getPersistentID()); + count = insertItems(currentStack, player.getGameProfile()); if (currentStack.stackSize == 0) player.inventory.setInventorySlotContents(player.inventory.currentItem, null); } @@ -164,7 +166,7 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP for (int i = 0, n = player.inventory.getSizeInventory(); i < n; i++) { ItemStack subStack = player.inventory.getStackInSlot(i); if (subStack != null) { - count += insertItems(subStack, player.getPersistentID()); + count += insertItems(subStack, player.getGameProfile()); if (subStack.stackSize == 0) player.inventory.setInventorySlotContents(i, null); } @@ -180,14 +182,13 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP return count; } - private int insertItems (ItemStack stack, UUID owner) { + private int insertItems (ItemStack stack, GameProfile profile) { int itemsLeft = stack.stackSize; for (int slot : enumerateDrawersForInsertion(stack, false)) { IDrawerGroup group = getGroupForDrawerSlot(slot); if (group instanceof IProtectable) { - IProtectable protectable = (IProtectable)group; - if (protectable.getOwner() != null && !protectable.getOwner().equals(owner)) + if (!SecurityManager.hasAccess(profile, (IProtectable)group)) continue; } @@ -231,7 +232,7 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP return remainder; } - public void toggleProtection (UUID owner) { + public void toggleProtection (GameProfile profile) { IProtectable template = null; UUID state = null; @@ -241,14 +242,14 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP if (record.storage instanceof IProtectable) { IProtectable protectable = (IProtectable)record.storage; - if (protectable.getOwner() != null && !protectable.getOwner().equals(owner)) + if (!SecurityManager.hasAccess(profile, protectable)) continue; if (template == null) { template = protectable; if (template.getOwner() == null) - state = owner; + state = profile.getId(); else state = null; } @@ -258,7 +259,7 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP } } - public void toggleShroud (UUID owner) { + public void toggleShroud (GameProfile profile) { IShroudable template = null; boolean state = false; @@ -267,8 +268,7 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP continue; if (record.storage instanceof IProtectable) { - IProtectable protectable = (IProtectable)record.storage; - if (protectable.getOwner() != null && !protectable.getOwner().equals(owner)) + if (!SecurityManager.hasAccess(profile, (IProtectable)record.storage)) continue; } @@ -291,7 +291,7 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP } } - public void toggleLock (EnumSet attributes, LockAttribute key, UUID owner) { + public void toggleLock (EnumSet attributes, LockAttribute key, GameProfile profile) { ILockable template = null; boolean state = false; @@ -300,8 +300,7 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP continue; if (record.storage instanceof IProtectable) { - IProtectable protectable = (IProtectable)record.storage; - if (protectable.getOwner() != null && !protectable.getOwner().equals(owner)) + if (!SecurityManager.hasAccess(profile, (IProtectable)record.storage)) continue; } diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java index f650489..9d67794 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java @@ -2,6 +2,7 @@ package com.jaquadro.minecraft.storagedrawers.block.tile; import com.jaquadro.minecraft.storagedrawers.StorageDrawers; import com.jaquadro.minecraft.storagedrawers.api.inventory.IDrawerInventory; +import com.jaquadro.minecraft.storagedrawers.api.security.ISecurityProvider; import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer; import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroupInteractive; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.ILockable; @@ -268,6 +269,11 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe return true; } + @Override + public ISecurityProvider getSecurityProvider () { + return null; + } + public boolean shouldHideUpgrades () { return hideUpgrade; } diff --git a/src/com/jaquadro/minecraft/storagedrawers/integration/Waila.java b/src/com/jaquadro/minecraft/storagedrawers/integration/Waila.java index 42131f1..f1782ba 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/integration/Waila.java +++ b/src/com/jaquadro/minecraft/storagedrawers/integration/Waila.java @@ -8,6 +8,7 @@ import com.jaquadro.minecraft.storagedrawers.api.storage.IFractionalDrawer; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.LockAttribute; import com.jaquadro.minecraft.storagedrawers.block.BlockDrawers; import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers; +import com.jaquadro.minecraft.storagedrawers.security.SecurityManager; import cpw.mods.fml.common.event.FMLInterModComms; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; @@ -62,15 +63,14 @@ public class Waila extends IntegrationModule public List getWailaBody (ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) { TileEntityDrawers tile = (TileEntityDrawers) accessor.getTileEntity(); - if (tile.getOwner() == null || tile.getOwner().equals(Minecraft.getMinecraft().thePlayer.getPersistentID())) { - IDrawerGroup group = tile; - for (int i = 0; i < group.getDrawerCount(); i++) { - if (!group.isDrawerEnabled(i)) + if (SecurityManager.hasAccess(Minecraft.getMinecraft().thePlayer.getGameProfile(), tile)) { + for (int i = 0; i < tile.getDrawerCount(); i++) { + if (!tile.isDrawerEnabled(i)) continue; String name = StatCollector.translateToLocal("storageDrawers.waila.empty"); - IDrawer drawer = group.getDrawer(i); + IDrawer drawer = tile.getDrawer(i); ItemStack stack = drawer.getStoredItemPrototype(); if (stack != null && stack.getItem() != null) { String stackName = stack.getDisplayName(); diff --git a/src/com/jaquadro/minecraft/storagedrawers/item/ItemTape.java b/src/com/jaquadro/minecraft/storagedrawers/item/ItemTape.java index 46b69f0..1145666 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/item/ItemTape.java +++ b/src/com/jaquadro/minecraft/storagedrawers/item/ItemTape.java @@ -4,6 +4,7 @@ import com.jaquadro.minecraft.storagedrawers.StorageDrawers; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IProtectable; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.ISealable; import com.jaquadro.minecraft.storagedrawers.core.ModCreativeTabs; +import com.jaquadro.minecraft.storagedrawers.security.SecurityManager; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.entity.player.EntityPlayer; @@ -39,10 +40,8 @@ public class ItemTape extends Item TileEntity tile = world.getTileEntity(x, y, z); if (tile instanceof IProtectable) { - IProtectable protectable = (IProtectable)tile; - if (protectable.getOwner() != null && !protectable.getOwner().equals(player.getPersistentID())) + if (!SecurityManager.hasAccess(player.getGameProfile(), (IProtectable)tile)) return false; - } if (tile instanceof ISealable) { diff --git a/src/com/jaquadro/minecraft/storagedrawers/security/DefaultSecurityProvider.java b/src/com/jaquadro/minecraft/storagedrawers/security/DefaultSecurityProvider.java new file mode 100644 index 0000000..6bea448 --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/security/DefaultSecurityProvider.java @@ -0,0 +1,16 @@ +package com.jaquadro.minecraft.storagedrawers.security; + +import com.jaquadro.minecraft.storagedrawers.api.security.ISecurityProvider; +import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IProtectable; +import com.mojang.authlib.GameProfile; + +public class DefaultSecurityProvider implements ISecurityProvider +{ + @Override + public boolean hasAccess (GameProfile profile, IProtectable target) { + if (target == null || profile == null) + return false; + + return target.getOwner() == null || target.getOwner().equals(profile.getId()); + } +} diff --git a/src/com/jaquadro/minecraft/storagedrawers/security/SecurityManager.java b/src/com/jaquadro/minecraft/storagedrawers/security/SecurityManager.java new file mode 100644 index 0000000..78f29dd --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/security/SecurityManager.java @@ -0,0 +1,21 @@ +package com.jaquadro.minecraft.storagedrawers.security; + +import com.jaquadro.minecraft.storagedrawers.api.security.ISecurityProvider; +import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IProtectable; +import com.mojang.authlib.GameProfile; + +public class SecurityManager +{ + private static ISecurityProvider defaultProvider = new DefaultSecurityProvider(); + + public static boolean hasAccess (GameProfile profile, IProtectable target) { + if (target == null || profile == null) + return false; + + ISecurityProvider provider = target.getSecurityProvider(); + if (provider == null) + provider = defaultProvider; + + return provider.hasAccess(profile, target); + } +} From 2cc1fc2c328c0e0118b20c83c7fbb5c6068fe3cd Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Thu, 11 Feb 2016 02:02:14 -0500 Subject: [PATCH 23/24] Security provider framework; CoFH provider support via Thermal Foundation integration. Not currently loading... --- .../assets/storagedrawers/lang/en_US.lang | 7 ++- .../items/drawer_key_personal_cofh.png | Bin 0 -> 364 bytes ...al.png => drawer_key_personal_default.png} | Bin .../storagedrawers/StorageDrawers.java | 3 + .../api/security/ISecurityProvider.java | 4 ++ .../api/storage/attribute/IProtectable.java | 6 ++ .../storagedrawers/block/BlockController.java | 11 +++- .../storagedrawers/block/BlockDrawers.java | 15 ++++- .../block/tile/TileEntityController.java | 10 +++- .../block/tile/TileEntityDrawers.java | 28 ++++++++- .../storagedrawers/config/ConfigManager.java | 2 + .../integration/IntegrationRegistry.java | 2 + .../integration/ThermalFoundation.java | 40 +++++++++++++ .../CoFHSecurityProvider.java | 40 +++++++++++++ .../storagedrawers/item/ItemPersonalKey.java | 54 +++++++++++++++++- .../storagedrawers/item/ItemTape.java | 2 +- .../security/DefaultSecurityProvider.java | 12 +++- .../security/SecurityManager.java | 11 ++++ .../security/SecurityRegistry.java | 19 ++++++ 19 files changed, 252 insertions(+), 14 deletions(-) create mode 100644 resources/assets/storagedrawers/textures/items/drawer_key_personal_cofh.png rename resources/assets/storagedrawers/textures/items/{drawer_key_personal.png => drawer_key_personal_default.png} (100%) create mode 100644 src/com/jaquadro/minecraft/storagedrawers/integration/ThermalFoundation.java create mode 100644 src/com/jaquadro/minecraft/storagedrawers/integration/thermalfoundation/CoFHSecurityProvider.java create mode 100644 src/com/jaquadro/minecraft/storagedrawers/security/SecurityRegistry.java diff --git a/resources/assets/storagedrawers/lang/en_US.lang b/resources/assets/storagedrawers/lang/en_US.lang index 478f451..1c089f5 100644 --- a/resources/assets/storagedrawers/lang/en_US.lang +++ b/resources/assets/storagedrawers/lang/en_US.lang @@ -32,8 +32,10 @@ item.storagedrawers.upgradeSorting.name=Sorting Upgrade item.storagedrawers.upgradeSorting.description=For Refined Relocation item.storagedrawers.shroudKey.name=Concealment Key item.storagedrawers.shroudKey.description=Show or hide item labels -item.storagedrawers.personalKey.name=Personal Key -item.storagedrawers.personalKey.description=Protect access from other players +item.storagedrawers.personalKey.default.name=Personal Key +item.storagedrawers.personalKey.default.description=Protect access from other players +item.storagedrawers.personalKey.cofh.name=Personal Key (CoFH) +item.storagedrawers.personalKey.cofh.description=Protect access from other players item.storagedrawers.tape.name=Packing Tape item.storagedrawers.tape.description=Seals drawers for moving @@ -187,3 +189,4 @@ storageDrawers.config.integration.enableThaumcraft=Enable Thaumcraft Integration storageDrawers.config.integration.enableMineTweaker=Enable MineTweaker Integration storageDrawers.config.integration.enableRefinedRelocation=Enable Refined Relocation Integration storageDrawers.config.integration.enableThermalExpansion=Enable Thermal Expansion Integration +storageDrawers.config.integration.enableThermalFoundation=Enable Thermal Foundation Integration diff --git a/resources/assets/storagedrawers/textures/items/drawer_key_personal_cofh.png b/resources/assets/storagedrawers/textures/items/drawer_key_personal_cofh.png new file mode 100644 index 0000000000000000000000000000000000000000..03ae7ebdc8cd6db48f00759453c22cac06019ac2 GIT binary patch literal 364 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Iwh_VCC){ui6xo&c?uz!xv31{ zsVNGE1`2MeNeV^=hGq%|23AJqR)!`Dx(22O28`BmaX@|SC7!;n><^f@SXHEsuDKxy z6yhxKh%9Dc;Q9c lockAttributes = null; @@ -271,7 +272,25 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe @Override public ISecurityProvider getSecurityProvider () { - return null; + return StorageDrawers.securityRegistry.getProvider(securityKey); + } + + @Override + public boolean setSecurityProvider (ISecurityProvider provider) { + if (!StorageDrawers.config.cache.enablePersonalUpgrades) + return false; + + String newKey = (provider == null) ? null : provider.getProviderID(); + if ((newKey != null && !newKey.equals(securityKey)) || (securityKey != null && !securityKey.equals(newKey))) { + securityKey = newKey; + + if (worldObj != null && !worldObj.isRemote) { + markDirty(); + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + } + + return true; } public boolean shouldHideUpgrades () { @@ -513,6 +532,10 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe if (tag.hasKey("Own")) owner = UUID.fromString(tag.getString("Own")); + securityKey = null; + if (tag.hasKey("Sec")) + securityKey = tag.getString("Sec"); + hideUpgrade = false; if (tag.hasKey("HideUp")) hideUpgrade = tag.getBoolean("HideUp"); @@ -557,6 +580,9 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe if (owner != null) tag.setString("Own", owner.toString()); + if (securityKey != null) + tag.setString("Sec", securityKey); + if (hideUpgrade) tag.setBoolean("HideUp", hideUpgrade); diff --git a/src/com/jaquadro/minecraft/storagedrawers/config/ConfigManager.java b/src/com/jaquadro/minecraft/storagedrawers/config/ConfigManager.java index e346d29..c605877 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/config/ConfigManager.java +++ b/src/com/jaquadro/minecraft/storagedrawers/config/ConfigManager.java @@ -75,6 +75,7 @@ public class ConfigManager public boolean enableMineTweakerIntegration; public boolean enableRefinedRelocationIntegration; public boolean enableThermalExpansionIntegration; + public boolean enableThermalFoundationIntegration; public boolean enableTape; public boolean enableFallbackRecipes; public boolean invertShift; @@ -255,6 +256,7 @@ public class ConfigManager cache.enableMineTweakerIntegration = config.get(sectionIntegration.getQualifiedName(), "enableMineTweaker", true).setLanguageKey(LANG_PREFIX + "integration.enableMineTweaker").setRequiresMcRestart(true).getBoolean(); cache.enableRefinedRelocationIntegration = config.get(sectionIntegration.getQualifiedName(), "enableRefinedRelocation", true).setLanguageKey(LANG_PREFIX + "integration.enableRefinedRelocation").setRequiresMcRestart(true).getBoolean(); cache.enableThermalExpansionIntegration = config.get(sectionIntegration.getQualifiedName(), "enableThermalExpansion", true).setLanguageKey(LANG_PREFIX + "integration.enableThermalExpansion").setRequiresMcRestart(true).getBoolean(); + cache.enableThermalFoundationIntegration = config.get(sectionIntegration.getQualifiedName(), "enableThermalFoundation", true).setLanguageKey(LANG_PREFIX + "integration.enableThermalFoundation").setRequiresMcRestart(true).getBoolean(); config.get(sectionBlocksFullDrawers1x1.getQualifiedName(), "enabled", true).setLanguageKey(LANG_PREFIX + "prop.enabled").setRequiresMcRestart(true); config.get(sectionBlocksFullDrawers1x1.getQualifiedName(), "baseStorage", 32).setLanguageKey(LANG_PREFIX + "prop.baseStorage").setRequiresWorldRestart(true); diff --git a/src/com/jaquadro/minecraft/storagedrawers/integration/IntegrationRegistry.java b/src/com/jaquadro/minecraft/storagedrawers/integration/IntegrationRegistry.java index be49974..000609c 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/integration/IntegrationRegistry.java +++ b/src/com/jaquadro/minecraft/storagedrawers/integration/IntegrationRegistry.java @@ -30,6 +30,8 @@ public class IntegrationRegistry reg.add(new NotEnoughItems()); if (Loader.isModLoaded("ThermalExpansion") && StorageDrawers.config.cache.enableThermalExpansionIntegration) reg.add(new ThermalExpansion()); + if (Loader.isModLoaded("ThermalFoundation") && StorageDrawers.config.cache.enableThermalFoundationIntegration) + reg.add(new ThermalFoundation()); } private IntegrationRegistry () { diff --git a/src/com/jaquadro/minecraft/storagedrawers/integration/ThermalFoundation.java b/src/com/jaquadro/minecraft/storagedrawers/integration/ThermalFoundation.java new file mode 100644 index 0000000..6d716d9 --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/integration/ThermalFoundation.java @@ -0,0 +1,40 @@ +package com.jaquadro.minecraft.storagedrawers.integration; + +import com.jaquadro.minecraft.storagedrawers.StorageDrawers; +import com.jaquadro.minecraft.storagedrawers.integration.thermalfoundation.CoFHSecurityProvider; +import com.mojang.authlib.GameProfile; + +import java.lang.reflect.Method; + +public class ThermalFoundation extends IntegrationModule +{ + private Class classRegistrySocial; + + private Method methodPlayerHasAccess; + + @Override + public String getModID () { + return "ThermalFoundation"; + } + + @Override + public void init () throws Throwable { + classRegistrySocial = Class.forName("cofh.core.RegistrySocial"); + + methodPlayerHasAccess = classRegistrySocial.getDeclaredMethod("playerHasAccess", String.class, GameProfile.class); + } + + @Override + public void postInit () { + StorageDrawers.securityRegistry.registerProvider(new CoFHSecurityProvider(this)); + } + + public boolean playerHasAccess (String playerName, GameProfile owner) { + try { + return (Boolean) methodPlayerHasAccess.invoke(null, playerName, owner); + } + catch (Throwable t) { + return false; + } + } +} diff --git a/src/com/jaquadro/minecraft/storagedrawers/integration/thermalfoundation/CoFHSecurityProvider.java b/src/com/jaquadro/minecraft/storagedrawers/integration/thermalfoundation/CoFHSecurityProvider.java new file mode 100644 index 0000000..0ffe93e --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/integration/thermalfoundation/CoFHSecurityProvider.java @@ -0,0 +1,40 @@ +package com.jaquadro.minecraft.storagedrawers.integration.thermalfoundation; + +import com.jaquadro.minecraft.storagedrawers.api.security.ISecurityProvider; +import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IProtectable; +import com.jaquadro.minecraft.storagedrawers.integration.ThermalFoundation; +import com.jaquadro.minecraft.storagedrawers.security.DefaultSecurityProvider; +import com.mojang.authlib.GameProfile; +import net.minecraft.server.MinecraftServer; + +public class CoFHSecurityProvider implements ISecurityProvider +{ + ThermalFoundation foundation; + private DefaultSecurityProvider defaultProvider = new DefaultSecurityProvider(); + + public CoFHSecurityProvider (ThermalFoundation foundation) { + this.foundation = foundation; + } + + @Override + public String getProviderID () { + return "cofh"; + } + + @Override + public boolean hasOwnership (GameProfile profile, IProtectable target) { + return defaultProvider.hasOwnership(profile, target); + } + + @Override + public boolean hasAccess (GameProfile profile, IProtectable target) { + if (target.getOwner() == null) + return true; + + GameProfile ownerProfile = MinecraftServer.getServer().func_152358_ax().func_152652_a(target.getOwner()); + if (ownerProfile == null) + return false; + + return foundation.playerHasAccess(profile.getName(), ownerProfile); + } +} diff --git a/src/com/jaquadro/minecraft/storagedrawers/item/ItemPersonalKey.java b/src/com/jaquadro/minecraft/storagedrawers/item/ItemPersonalKey.java index e6348a3..d3f8d5f 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/item/ItemPersonalKey.java +++ b/src/com/jaquadro/minecraft/storagedrawers/item/ItemPersonalKey.java @@ -3,26 +3,51 @@ package com.jaquadro.minecraft.storagedrawers.item; import com.google.common.collect.Multimap; import com.jaquadro.minecraft.storagedrawers.StorageDrawers; import com.jaquadro.minecraft.storagedrawers.core.ModCreativeTabs; +import com.jaquadro.minecraft.storagedrawers.integration.IntegrationRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.util.MathHelper; import net.minecraft.util.StatCollector; import java.util.List; public class ItemPersonalKey extends Item { + public static final String[] iconNames = new String[] { "default", "cofh" }; + + @SideOnly(Side.CLIENT) + private IIcon[] icons; + public ItemPersonalKey (String name) { setUnlocalizedName(name); setCreativeTab(ModCreativeTabs.tabStorageDrawers); - setTextureName(StorageDrawers.MOD_ID + ":drawer_key_personal"); + setHasSubtypes(true); setMaxDamage(0); } + @Override + @SideOnly(Side.CLIENT) + public IIcon getIconFromDamage (int meta) { + return icons[MathHelper.clamp_int(meta, 0, iconNames.length - 1)]; + } + + @Override + public String getUnlocalizedName (ItemStack itemStack) { + int meta = MathHelper.clamp_int(itemStack.getItemDamage(), 0, iconNames.length - 1); + if (iconNames[meta] == null) + return super.getUnlocalizedName(); + + return super.getUnlocalizedName() + "." + iconNames[meta]; + } + @Override @SideOnly(Side.CLIENT) public void addInformation (ItemStack itemStack, EntityPlayer player, List list, boolean par4) { @@ -42,4 +67,31 @@ public class ItemPersonalKey extends Item multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Weapon modifier", (double)2, 0)); return multimap; } + + @Override + @SideOnly(Side.CLIENT) + public void getSubItems (Item item, CreativeTabs creativeTabs, List list) { + list.add(new ItemStack(item, 1, 0)); + if (StorageDrawers.config.cache.enableThermalFoundationIntegration && IntegrationRegistry.instance().isModLoaded("ThermalFoundation")) + list.add(new ItemStack(item, 1, 1)); + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons (IIconRegister register) { + icons = new IIcon[iconNames.length]; + + for (int i = 0, n = iconNames.length; i < n; i++) { + if (iconNames[i] != null) + icons[i] = register.registerIcon(StorageDrawers.MOD_ID + ":drawer_key_personal_" + iconNames[i]); + } + } + + public String getSecurityProviderKey (int meta) { + switch (meta) { + case 0: return null; + case 1: return "cofh"; + default: return null; + } + } } diff --git a/src/com/jaquadro/minecraft/storagedrawers/item/ItemTape.java b/src/com/jaquadro/minecraft/storagedrawers/item/ItemTape.java index 1145666..73bd98c 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/item/ItemTape.java +++ b/src/com/jaquadro/minecraft/storagedrawers/item/ItemTape.java @@ -40,7 +40,7 @@ public class ItemTape extends Item TileEntity tile = world.getTileEntity(x, y, z); if (tile instanceof IProtectable) { - if (!SecurityManager.hasAccess(player.getGameProfile(), (IProtectable)tile)) + if (!SecurityManager.hasOwnership(player.getGameProfile(), (IProtectable)tile)) return false; } diff --git a/src/com/jaquadro/minecraft/storagedrawers/security/DefaultSecurityProvider.java b/src/com/jaquadro/minecraft/storagedrawers/security/DefaultSecurityProvider.java index 6bea448..832275f 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/security/DefaultSecurityProvider.java +++ b/src/com/jaquadro/minecraft/storagedrawers/security/DefaultSecurityProvider.java @@ -7,10 +7,20 @@ import com.mojang.authlib.GameProfile; public class DefaultSecurityProvider implements ISecurityProvider { @Override - public boolean hasAccess (GameProfile profile, IProtectable target) { + public String getProviderID () { + return null; + } + + @Override + public boolean hasOwnership (GameProfile profile, IProtectable target) { if (target == null || profile == null) return false; return target.getOwner() == null || target.getOwner().equals(profile.getId()); } + + @Override + public boolean hasAccess (GameProfile profile, IProtectable target) { + return hasOwnership(profile, target); + } } diff --git a/src/com/jaquadro/minecraft/storagedrawers/security/SecurityManager.java b/src/com/jaquadro/minecraft/storagedrawers/security/SecurityManager.java index 78f29dd..f0e921a 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/security/SecurityManager.java +++ b/src/com/jaquadro/minecraft/storagedrawers/security/SecurityManager.java @@ -8,6 +8,17 @@ public class SecurityManager { private static ISecurityProvider defaultProvider = new DefaultSecurityProvider(); + public static boolean hasOwnership (GameProfile profile, IProtectable target) { + if (target == null || profile == null) + return false; + + ISecurityProvider provider = target.getSecurityProvider(); + if (provider == null) + provider = defaultProvider; + + return provider.hasOwnership(profile, target); + } + public static boolean hasAccess (GameProfile profile, IProtectable target) { if (target == null || profile == null) return false; diff --git a/src/com/jaquadro/minecraft/storagedrawers/security/SecurityRegistry.java b/src/com/jaquadro/minecraft/storagedrawers/security/SecurityRegistry.java new file mode 100644 index 0000000..8c5a3da --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/security/SecurityRegistry.java @@ -0,0 +1,19 @@ +package com.jaquadro.minecraft.storagedrawers.security; + +import com.jaquadro.minecraft.storagedrawers.api.security.ISecurityProvider; + +import java.util.HashMap; +import java.util.Map; + +public class SecurityRegistry +{ + private Map registry = new HashMap(); + + public void registerProvider (ISecurityProvider provider) { + registry.put(provider.getProviderID(), provider); + } + + public ISecurityProvider getProvider (String name) { + return registry.get(name); + } +} From 6d8d2f53629ab2f65ec185d12039f8f63b6526c4 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Thu, 11 Feb 2016 23:45:29 -0500 Subject: [PATCH 24/24] Fix thermal foundation integration (support older versions) --- build.gradle | 2 +- .../integration/ThermalFoundation.java | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 2d949eb..f89a6ba 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ buildscript { apply plugin: 'forge' -version = "1.7.10-1.7.9" +version = "1.7.10-1.8.0" group= "com.jaquadro.minecraft.storagedrawers" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "StorageDrawers" diff --git a/src/com/jaquadro/minecraft/storagedrawers/integration/ThermalFoundation.java b/src/com/jaquadro/minecraft/storagedrawers/integration/ThermalFoundation.java index 6d716d9..5ddc957 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/integration/ThermalFoundation.java +++ b/src/com/jaquadro/minecraft/storagedrawers/integration/ThermalFoundation.java @@ -1,8 +1,13 @@ package com.jaquadro.minecraft.storagedrawers.integration; import com.jaquadro.minecraft.storagedrawers.StorageDrawers; +import com.jaquadro.minecraft.storagedrawers.core.ModItems; import com.jaquadro.minecraft.storagedrawers.integration.thermalfoundation.CoFHSecurityProvider; import com.mojang.authlib.GameProfile; +import cpw.mods.fml.common.registry.GameRegistry; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.ShapedOreRecipe; import java.lang.reflect.Method; @@ -19,7 +24,12 @@ public class ThermalFoundation extends IntegrationModule @Override public void init () throws Throwable { - classRegistrySocial = Class.forName("cofh.core.RegistrySocial"); + try { + classRegistrySocial = Class.forName("cofh.core.RegistrySocial"); + } + catch (ClassNotFoundException e) { + classRegistrySocial = Class.forName("cofh.core.util.SocialRegistry"); + } methodPlayerHasAccess = classRegistrySocial.getDeclaredMethod("playerHasAccess", String.class, GameProfile.class); } @@ -27,6 +37,11 @@ public class ThermalFoundation extends IntegrationModule @Override public void postInit () { StorageDrawers.securityRegistry.registerProvider(new CoFHSecurityProvider(this)); + + if (StorageDrawers.config.cache.enablePersonalUpgrades) { + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModItems.personalKey, 1, 1), "xxx", "xyx", "xxx", + 'x', "nuggetSignalum", 'y', ModItems.personalKey)); + } } public boolean playerHasAccess (String playerName, GameProfile owner) {