mirror of
https://github.com/GTNewHorizons/StorageDrawers.git
synced 2026-11-20 20:22:22 +00:00
The locking update
This commit is contained in:
1 parent
6f9464e61e
commit
bd59f3475a
16 files changed
+185
-3
No files matched your search
@@ -13,6 +13,8 @@ item.upgradeStatus.level2.name=Status Upgrade (II)
|
||||
item.upgradeStatus.level2.description=Shows near-full storage
|
||||
item.upgradeStatus.level3.name=Status Upgrade (III)
|
||||
item.upgradeStatus.level3.description=Shows fill level
|
||||
item.upgradeLock.name=Lock Upgrade
|
||||
item.upgradeLock.description=Drawers keep associated item even when empty
|
||||
|
||||
# Blocks
|
||||
tile.fullDrawers2.oak.name=Oak Drawers 1x2
|
||||
@@ -52,6 +54,7 @@ storageDrawers.upgrade.description=Increases storage to %d times base value
|
||||
storageDrawers.waila.empty=Empty
|
||||
storageDrawers.waila.level=Upgrade Level: %s
|
||||
storageDrawers.waila.drawer=Drawer #%s: %s
|
||||
storageDrawers.waila.locked=Locked
|
||||
|
||||
# Configuration
|
||||
storageDrawers.config.title=Storage Drawers Configuration
|
||||
@@ -81,6 +84,7 @@ storageDrawers.config.prop.itemRenderType=Item Render Type
|
||||
storageDrawers.config.prop.itemRenderType.tooltip=Render items in 3D or flat.
|
||||
storageDrawers.config.prop.enableIndicatorUpgrades=Enable Indicator Upgrades
|
||||
storageDrawers.config.prop.enableStorageUpgrades=Enable Storage Upgrades
|
||||
storageDrawers.config.prop.enableLockUpgrades=Enable Lock Upgrade
|
||||
storageDrawers.config.prop.renderStorageUpgrades=Render Storage Upgrades
|
||||
storageDrawers.config.prop.creativeTabVanillaWoods=Creative Tab Vanilla Woods
|
||||
storageDrawers.config.prop.creativeTabVanillaWoods.tooltip=Enable all vanilla wood styles on creative tab.
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 456 B |
@@ -69,6 +69,9 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon iconIndicatorOff;
|
||||
|
||||
//@SideOnly(Side.CLIENT)
|
||||
//private IIcon iconLockFace;
|
||||
|
||||
public BlockDrawers (String blockName, int drawerCount, boolean halfDepth) {
|
||||
this(Material.wood, blockName, drawerCount, halfDepth);
|
||||
}
|
||||
@@ -195,6 +198,27 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (item.getItem() == ModItems.upgradeLock && !tileDrawers.isLocked()) {
|
||||
tileDrawers.setIsLocked(true);
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
|
||||
if (player != null && !player.capabilities.isCreativeMode) {
|
||||
if (--item.stackSize <= 0)
|
||||
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (item == null && player.isSneaking()) {
|
||||
if (tileDrawers.isLocked()) {
|
||||
tileDrawers.setIsLocked(false);
|
||||
if (player != null && !player.capabilities.isCreativeMode)
|
||||
dropBlockAsItem(world, x, y, z, new ItemStack(ModItems.upgradeLock));
|
||||
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (tileDrawers.getDirection() != side)
|
||||
@@ -300,6 +324,8 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
dropBlockAsItem(world, x, y, z, new ItemStack(ModItems.upgrade, 1, tile.getStorageLevel()));
|
||||
if (tile.getStatusLevel() > 0)
|
||||
dropBlockAsItem(world, x, y, z, new ItemStack(ModItems.upgradeStatus, 1, tile.getStatusLevel()));
|
||||
if (tile.isLocked())
|
||||
dropBlockAsItem(world, x, y, z, new ItemStack(ModItems.upgradeLock));
|
||||
|
||||
for (int i = 0; i < tile.getDrawerCount(); i++) {
|
||||
if (!tile.isDrawerEnabled(i))
|
||||
@@ -470,6 +496,11 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
}
|
||||
}
|
||||
|
||||
/*@SideOnly(Side.CLIENT)
|
||||
public IIcon getIconLockFace () {
|
||||
return iconLockFace;
|
||||
}*/
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon getIcon (IBlockAccess blockAccess, int x, int y, int z, int side, int level) {
|
||||
int meta = blockAccess.getBlockMetadata(x, y, z) % BlockWood.field_150096_a.length;
|
||||
@@ -543,5 +574,7 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
iconIndicatorOff = register.registerIcon(StorageDrawers.MOD_ID + ":indicator_off");
|
||||
iconIndicatorAmber = register.registerIcon(StorageDrawers.MOD_ID + ":indicator_amber");
|
||||
iconIndicatorOn = register.registerIcon(StorageDrawers.MOD_ID + ":indicator_on");
|
||||
|
||||
//iconLockFace = register.registerIcon(StorageDrawers.MOD_ID + ":lock_face");
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,7 @@ public abstract class TileEntityDrawers extends TileEntity implements IDrawerGro
|
||||
private int drawerCapacity = 1;
|
||||
private int storageLevel = 1;
|
||||
private int statusLevel = 0;
|
||||
private boolean locked = false;
|
||||
|
||||
private long lastClickTime;
|
||||
private UUID lastClickUUID;
|
||||
@@ -101,6 +102,25 @@ public abstract class TileEntityDrawers extends TileEntity implements IDrawerGro
|
||||
drawerCapacity = stackCount;
|
||||
}
|
||||
|
||||
public boolean isLocked () {
|
||||
return locked;
|
||||
}
|
||||
|
||||
public void setIsLocked (boolean locked) {
|
||||
this.locked = locked;
|
||||
|
||||
if (!locked) {
|
||||
for (int i = 0; i < getDrawerCount(); i++) {
|
||||
if (!isDrawerEnabled(i))
|
||||
continue;
|
||||
|
||||
IDrawer drawer = getDrawer(i);
|
||||
if (drawer != null && drawer.getStoredItemCount() == 0)
|
||||
drawer.setStoredItemCount(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack takeItemsFromSlot (int slot, int count) {
|
||||
if (slot < 0 || slot >= getDrawerCount())
|
||||
return null;
|
||||
@@ -210,6 +230,10 @@ public abstract class TileEntityDrawers extends TileEntity implements IDrawerGro
|
||||
if (tag.hasKey("Stat"))
|
||||
statusLevel = tag.getByte("Stat");
|
||||
|
||||
locked = false;
|
||||
if (tag.hasKey("Lock"))
|
||||
locked = tag.getBoolean("Lock");
|
||||
|
||||
NBTTagList slots = tag.getTagList("Slots", Constants.NBT.TAG_COMPOUND);
|
||||
int drawerCount = slots.tagCount();
|
||||
drawers = new IDrawer[slots.tagCount()];
|
||||
@@ -243,6 +267,9 @@ public abstract class TileEntityDrawers extends TileEntity implements IDrawerGro
|
||||
if (statusLevel > 0)
|
||||
tag.setByte("Stat", (byte)statusLevel);
|
||||
|
||||
if (locked)
|
||||
tag.setBoolean("Lock", locked);
|
||||
|
||||
NBTTagList slots = new NBTTagList();
|
||||
for (IDrawer drawer : drawers) {
|
||||
NBTTagCompound slot = new NBTTagCompound();
|
||||
|
||||
@@ -424,7 +424,7 @@ public class TileEntityDrawersComp extends TileEntityDrawers
|
||||
pooledCount = (pooledCount % convRate[slot]) + convRate[slot] * amount;
|
||||
|
||||
if (pooledCount != oldCount) {
|
||||
if (pooledCount != 0)
|
||||
if (pooledCount != 0 || isLocked())
|
||||
markAmountDirty();
|
||||
else {
|
||||
clear();
|
||||
|
||||
@@ -42,5 +42,10 @@ public class TileEntityDrawersStandard extends TileEntityDrawers
|
||||
ConfigManager config = StorageDrawers.config;
|
||||
return config.getStorageUpgradeMultiplier(getStorageLevel()) * getDrawerCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLocked (int slot) {
|
||||
return TileEntityDrawersStandard.this.isLocked();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -18,6 +19,8 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler
|
||||
|
||||
private ModularBoxRenderer boxRenderer = new ModularBoxRenderer();
|
||||
|
||||
private double[] boxCoord = new double[6];
|
||||
|
||||
@Override
|
||||
public void renderInventoryBlock (Block block, int metadata, int modelId, RenderBlocks renderer) {
|
||||
if (!(block instanceof BlockDrawers))
|
||||
@@ -94,6 +97,15 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler
|
||||
if (StorageDrawers.config.cache.enableIndicatorUpgrades)
|
||||
renderHandleIndicator(block, x, y, z, side, renderer, tile.getStatusLevel());
|
||||
|
||||
/*if (tile.isLocked()) {
|
||||
boxRenderer.setExteriorIcon(Blocks.iron_block.getIcon(0, 0));
|
||||
boxRenderer.setExteriorIcon(block.getIconLockFace(), side);
|
||||
|
||||
double depth = block.halfDepth ? 8 : 0;
|
||||
setCoord(boxCoord, 7 * unit, 7 * unit, (depth + .5) * unit, 9 * unit, 9 * unit, (depth + 1) * unit, side);
|
||||
boxRenderer.renderExterior(renderer, block, x, y, z, boxCoord[0], boxCoord[1], boxCoord[2], boxCoord[3], boxCoord[4], boxCoord[5], 0, 0);
|
||||
}*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -171,6 +183,53 @@ public class DrawersRenderer implements ISimpleBlockRenderingHandler
|
||||
}
|
||||
}
|
||||
|
||||
private void setCoord (double[] coords, double xMin, double yMin, double zMin, double xMax, double yMax, double zMax) {
|
||||
coords[0] = xMin;
|
||||
coords[1] = yMin;
|
||||
coords[2] = zMin;
|
||||
coords[3] = xMax;
|
||||
coords[4] = yMax;
|
||||
coords[5] = zMax;
|
||||
}
|
||||
|
||||
private void setCoord (double[] coords, double xMin, double yMin, double zMin, double xMax, double yMax, double zMax, int side) {
|
||||
setCoord(coords, xMin, yMin, zMin, xMax, yMax, zMax);
|
||||
transformCoord(coords, side);
|
||||
}
|
||||
|
||||
private void transformCoord (double[] coords, int side) {
|
||||
double tmpX, tmpZ;
|
||||
|
||||
switch (side) {
|
||||
case 2:
|
||||
return;
|
||||
case 3:
|
||||
tmpX = coords[0];
|
||||
tmpZ = coords[2];
|
||||
coords[0] = 1 - coords[3];
|
||||
coords[3] = 1 - tmpX;
|
||||
coords[2] = 1 - coords[5];
|
||||
coords[5] = 1 - tmpZ;
|
||||
return;
|
||||
case 4:
|
||||
tmpX = coords[0];
|
||||
coords[0] = coords[2];
|
||||
coords[2] = 1 - coords[3];
|
||||
coords[3] = coords[5];
|
||||
coords[5] = 1 - tmpX;
|
||||
return;
|
||||
case 5:
|
||||
tmpX = coords[0];
|
||||
tmpZ = coords[2];
|
||||
coords[0] = 1 - coords[5];
|
||||
coords[2] = tmpX;
|
||||
tmpX = coords[3];
|
||||
coords[3] = 1 - tmpZ;
|
||||
coords[5] = tmpX;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void renderExterior (BlockDrawers block, int x, int y, int z, int side, RenderBlocks renderer) {
|
||||
double depth = block.halfDepth ? .5 : 1;
|
||||
double xMin = 0, xMax = 0, zMin = 0, zMax = 0;
|
||||
|
||||
@@ -53,6 +53,7 @@ public class ConfigManager
|
||||
public class ConfigCache {
|
||||
public boolean enableIndicatorUpgrades;
|
||||
public boolean enableStorageUpgrades;
|
||||
public boolean enableLockUpgrades;
|
||||
public boolean renderStorageUpgrades;
|
||||
public String itemRenderType;
|
||||
public boolean creativeTabVanillaWoods;
|
||||
@@ -110,6 +111,7 @@ public class ConfigManager
|
||||
public void syncConfig () {
|
||||
cache.enableIndicatorUpgrades = config.get(Configuration.CATEGORY_GENERAL, "enableIndicatorUpgrades", true).setLanguageKey(LANG_PREFIX + "prop.enableIndicatorUpgrades").setRequiresMcRestart(true).getBoolean();
|
||||
cache.enableStorageUpgrades = config.get(Configuration.CATEGORY_GENERAL, "enableStorageUpgrades", true).setLanguageKey(LANG_PREFIX + "prop.enableStorageUpgrades").setRequiresMcRestart(true).getBoolean();
|
||||
cache.enableLockUpgrades = config.get(Configuration.CATEGORY_GENERAL, "enableLockUpgrades", true).setLanguageKey(LANG_PREFIX + "prop.enableLockUpgrades").setRequiresMcRestart(true).getBoolean();
|
||||
cache.itemRenderType = config.get(Configuration.CATEGORY_GENERAL, "itemRenderType", "fast", null, new String[] { "fancy", "fast" }).setLanguageKey(LANG_PREFIX + "prop.itemRenderType").getString();
|
||||
cache.renderStorageUpgrades = config.get(Configuration.CATEGORY_GENERAL, "renderStorageUpgrades", true).setLanguageKey(LANG_PREFIX + "prop.renderStorageUpgrades").getBoolean();
|
||||
cache.creativeTabVanillaWoods = config.get(Configuration.CATEGORY_GENERAL, "creativeTabVanillaWoods", true).setLanguageKey(LANG_PREFIX + "prop.creativeTabVanillaWoods").getBoolean();
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.jaquadro.minecraft.storagedrawers.core;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.item.ItemUpgrade;
|
||||
import com.jaquadro.minecraft.storagedrawers.item.ItemUpgradeLock;
|
||||
import com.jaquadro.minecraft.storagedrawers.item.ItemUpgradeStatus;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -11,11 +12,13 @@ public class ModItems
|
||||
public static Item upgradeTemplate;
|
||||
public static ItemUpgrade upgrade;
|
||||
public static ItemUpgradeStatus upgradeStatus;
|
||||
public static ItemUpgradeLock upgradeLock;
|
||||
|
||||
public void init () {
|
||||
upgradeTemplate = new Item().setUnlocalizedName("upgradeTemplate").setTextureName(StorageDrawers.MOD_ID + ":upgrade_template").setCreativeTab(ModCreativeTabs.tabStorageDrawers);
|
||||
upgrade = new ItemUpgrade("upgrade");
|
||||
upgradeStatus = new ItemUpgradeStatus("upgradeStatus");
|
||||
upgradeLock = new ItemUpgradeLock("upgradeLock");
|
||||
|
||||
GameRegistry.registerItem(upgradeTemplate, "upgradeTemplate");
|
||||
|
||||
@@ -23,5 +26,7 @@ public class ModItems
|
||||
GameRegistry.registerItem(upgrade, "upgrade");
|
||||
if (StorageDrawers.config.cache.enableIndicatorUpgrades)
|
||||
GameRegistry.registerItem(upgradeStatus, "upgradeStatus");
|
||||
if (StorageDrawers.config.cache.enableLockUpgrades)
|
||||
GameRegistry.registerItem(upgradeLock, "upgradeLock");
|
||||
}
|
||||
}
|
||||
@@ -68,5 +68,10 @@ public class ModRecipes
|
||||
GameRegistry.addRecipe(new ItemStack(ModItems.upgradeStatus, 1, 3), "wyw", "yzy", "xyx",
|
||||
'w', Items.comparator, 'x', Items.redstone, 'y', Items.stick, 'z', ModItems.upgradeTemplate);
|
||||
}
|
||||
|
||||
if (config.cache.enableLockUpgrades) {
|
||||
GameRegistry.addRecipe(new ItemStack(ModItems.upgradeLock), " y ", "xzx", "yxy",
|
||||
'x', Items.stick, 'y', Items.gold_nugget, 'z', ModItems.upgradeTemplate);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,6 +68,9 @@ public class Waila extends IntegrationModule
|
||||
currenttip.add(StatCollector.translateToLocalFormatted("storageDrawers.waila.drawer", i + 1, name));
|
||||
}
|
||||
|
||||
if (tile.isLocked())
|
||||
currenttip.add(StatCollector.translateToLocal("storageDrawers.waila.locked"));
|
||||
|
||||
return currenttip;
|
||||
}
|
||||
|
||||
|
||||
@@ -130,7 +130,8 @@ public class StorageInventory implements IDrawerInventory
|
||||
|
||||
ItemStack stack = drawer.getStoredItemCopy();
|
||||
if (stack.stackSize <= count) {
|
||||
drawer.setStoredItem(null, 0);
|
||||
drawer.setStoredItemCount(0);
|
||||
// drawer.setStoredItem(null, 0);
|
||||
}
|
||||
else {
|
||||
stack.stackSize = count;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.item;
|
||||
|
||||
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.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ItemUpgradeLock extends Item
|
||||
{
|
||||
public ItemUpgradeLock (String name) {
|
||||
setUnlocalizedName(name);
|
||||
setCreativeTab(ModCreativeTabs.tabStorageDrawers);
|
||||
setTextureName(StorageDrawers.MOD_ID + ":upgrade_lock");
|
||||
setMaxDamage(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation (ItemStack itemStack, EntityPlayer player, List list, boolean par4) {
|
||||
int mult = StorageDrawers.config.getStorageUpgradeMultiplier(itemStack.getItemDamage());
|
||||
list.add(StatCollector.translateToLocalFormatted("storageDrawers.upgradeLock.description", mult));
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,11 @@ public class DefaultStorageProvider implements IStorageProvider
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLocked (int slot) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markAmountDirty (int slot) {
|
||||
if (tile.getWorldObj().isRemote)
|
||||
|
||||
@@ -79,7 +79,8 @@ public class DrawerData extends BaseDrawerData
|
||||
count = amount;
|
||||
if (amount == 0) {
|
||||
if (clearOnEmpty) {
|
||||
reset();
|
||||
if (!storageProvider.isLocked(slot))
|
||||
reset();
|
||||
if (mark)
|
||||
storageProvider.markDirty(slot);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ public interface IStorageProvider
|
||||
|
||||
public int getSlotStackCapacity (int slot);
|
||||
|
||||
public boolean isLocked (int slot);
|
||||
|
||||
public void markAmountDirty (int slot);
|
||||
|
||||
public void markDirty (int slot);
|
||||
|
||||
Reference in new issue
Block a user