Skip to content

Commit

Permalink
Merge pull request #5 from johnch18/downgrade
Browse files Browse the repository at this point in the history
Backported Storage Downgrade
  • Loading branch information
Dream-Master authored Apr 9, 2021
2 parents 9df127f + 208959a commit 74c980b
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 25 deletions.
2 changes: 2 additions & 0 deletions resources/assets/storagedrawers/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ item.storagedrawers.upgradeRedstone.max.name=Redstone Max Upgrade
item.storagedrawers.upgradeRedstone.max.description=Emits signal for most full slot.
item.storagedrawers.upgradeRedstone.min.name=Redstone Min Upgrade
item.storagedrawers.upgradeRedstone.min.description=Emits signal for least full slot.
item.storagedrawers.upgradeDowngrade.name=Storage Downgrade
item.storagedrawers.upgradeDowngrade.description=Sets the base storage capacity to 1 stack.
item.storagedrawers.upgradeSorting.name=Sorting Upgrade
item.storagedrawers.upgradeSorting.description=For Refined Relocation
item.storagedrawers.shroudKey.name=Concealment Key
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.jaquadro.minecraft.storagedrawers.api.storage.attribute;

public interface IDowngradable {

boolean canDowngrade();

boolean isDowngraded();

boolean checkDowngraded();

void setDowngraded(boolean state);

}
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,13 @@ public boolean onBlockActivated (World world, int x, int y, int z, EntityPlayer

return true;
}
/**
* Gee, it'd be nice if we could make all of these Items descend from one thing, almost like children
* and it would great if we could just find if it was an instance of said thing.
* Crazy concept!
* */
else if (item.getItem() == ModItems.upgrade || item.getItem() == ModItems.upgradeStatus || item.getItem() == ModItems.upgradeVoid ||
item.getItem() == ModItems.upgradeCreative || item.getItem() == ModItems.upgradeRedstone) {
item.getItem() == ModItems.upgradeCreative || item.getItem() == ModItems.upgradeRedstone || item.getItem() == ModItems.upgradeDowngrade) {
if (!tileDrawers.addUpgrade(item)) {
player.addChatMessage(new ChatComponentTranslation("storagedrawers.msg.maxUpgrades"));
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
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;
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.api.storage.attribute.*;
import com.jaquadro.minecraft.storagedrawers.block.BlockDrawersCustom;
import com.jaquadro.minecraft.storagedrawers.config.ConfigManager;
import com.jaquadro.minecraft.storagedrawers.core.ModItems;
Expand Down Expand Up @@ -38,7 +35,7 @@
import java.util.Iterator;
import java.util.UUID;

public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawerGroupInteractive, ISidedInventory, IUpgradeProvider, ILockable, ISealable, IProtectable
public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawerGroupInteractive, ISidedInventory, IUpgradeProvider, ILockable, ISealable, IProtectable, IDowngradable
{
private IDrawer[] drawers;
private IDrawerInventory inventory;
Expand All @@ -50,6 +47,8 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe
private boolean shrouded = false;
private boolean taped = false;
private boolean hideUpgrade = false;
private boolean downgraded = false;

private UUID owner;
private String securityKey;

Expand Down Expand Up @@ -93,6 +92,7 @@ public void setDirection (int direction) {
}

public int getMaxStorageLevel () {
// Could use iterables and lambdas instead
int maxLevel = 1;
for (ItemStack upgrade : upgrades) {
if (upgrade != null && upgrade.getItem() == ModItems.upgrade)
Expand All @@ -114,7 +114,6 @@ public int getEffectiveStorageLevel () {

public int getEffectiveStorageMultiplier () {
ConfigManager config = StorageDrawers.config;

int multiplier = 0;
for (ItemStack stack : upgrades) {
if (stack != null && stack.getItem() == ModItems.upgrade)
Expand Down Expand Up @@ -152,6 +151,7 @@ public boolean addUpgrade (ItemStack upgrade) {
return false;

setUpgrade(slot, upgrade);
checkDowngraded();
return true;
}

Expand Down Expand Up @@ -336,6 +336,28 @@ public boolean setIsSealed (boolean state) {
return true;
}

public boolean isDowngraded() {
return downgraded;
}

public boolean canDowngrade() {
// TODO: Config check
return true;
}

public boolean checkDowngraded() {
for (ItemStack stack : upgrades) {
if (stack != null && stack.getItem() == ModItems.upgradeDowngrade) {
return (downgraded = true);
}
}
return (downgraded = false);
}

public void setDowngraded(boolean state) {
downgraded = state;
}

public boolean isVoid () {
if (!StorageDrawers.config.cache.enableVoidUpgrades)
return false;
Expand Down Expand Up @@ -617,6 +639,8 @@ private void readLegacyUpgradeNBT (NBTTagCompound tag) {
addUpgrade(new ItemStack(ModItems.upgradeStatus, 1, tag.getByte("Stat")));
if (tag.hasKey("Void"))
addUpgrade(new ItemStack(ModItems.upgradeVoid));
if (tag.hasKey("Down"))
addUpgrade(new ItemStack(ModItems.upgradeDowngrade));
}

@Override
Expand All @@ -632,6 +656,8 @@ protected void readFromFixedNBT (NBTTagCompound tag) {
customName = null;
if (tag.hasKey("CustomName", Constants.NBT.TAG_STRING))
customName = tag.getString("CustomName");

downgraded = tag.hasKey("Down") && tag.getBoolean("Down");
}

@Override
Expand All @@ -645,6 +671,11 @@ protected void writeToFixedNBT (NBTTagCompound tag) {

if (hasCustomInventoryName())
tag.setString("CustomName", customName);

if (checkDowngraded())
tag.setBoolean("Down", downgraded);


}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,74 +10,80 @@
import com.jaquadro.minecraft.storagedrawers.storage.IStorageProvider;
import net.minecraft.tileentity.TileEntity;

public class TileEntityDrawersStandard extends TileEntityDrawers
{
public class TileEntityDrawersStandard extends TileEntityDrawers {

private IStorageProvider storageProvider = new StandardStorageProvider();

public TileEntityDrawersStandard () {
public TileEntityDrawersStandard() {
super(1);
}

public void setDrawerCount (int count) {
public void setDrawerCount(int count) {
initWithDrawerCount(count);
}

protected IStorageProvider getStorageProvider () {
protected IStorageProvider getStorageProvider() {
if (storageProvider == null)
storageProvider = new StandardStorageProvider();
return storageProvider;
}

@Override
protected IDrawer createDrawer (int slot) {
protected IDrawer createDrawer(int slot) {
return new DrawerData(getStorageProvider(), slot);
}

private class StandardStorageProvider extends DefaultStorageProvider
{
public StandardStorageProvider () {

private class StandardStorageProvider extends DefaultStorageProvider {
public StandardStorageProvider() {
super(TileEntityDrawersStandard.this, TileEntityDrawersStandard.this);
}

@Override
public int getSlotStackCapacity (int slot) {
public int getSlotStackCapacity(int slot) {
ConfigManager config = StorageDrawers.config;
return getEffectiveStorageMultiplier() * getDrawerCapacity();
return getEffectiveStorageMultiplier() * (isDowngraded(slot) ? 1 : getDrawerCapacity());
}

@Override
public boolean isLocked (int slot, LockAttribute attr) {
public boolean isLocked(int slot, LockAttribute attr) {
return TileEntityDrawersStandard.this.isLocked(attr);
}

@Override
public boolean isVoid (int slot) {
public boolean isVoid(int slot) {
return TileEntityDrawersStandard.this.isVoid();
}

@Override
public boolean isShrouded (int slot) {
public boolean isShrouded(int slot) {
return TileEntityDrawersStandard.this.isShrouded();
}


@Override
public boolean isDowngraded(int slot) {
return TileEntityDrawersStandard.this.isDowngraded();
}

@Override
public boolean setIsShrouded (int slot, boolean state) {
public boolean setIsShrouded(int slot, boolean state) {
TileEntityDrawersStandard.this.setIsShrouded(state);
return true;
}

@Override
public boolean isStorageUnlimited (int slot) {
public boolean isStorageUnlimited(int slot) {
return TileEntityDrawersStandard.this.isUnlimited();
}

@Override
public boolean isVendingUnlimited (int slot) {
public boolean isVendingUnlimited(int slot) {
return TileEntityDrawersStandard.this.isVending();
}

@Override
public boolean isRedstone (int slot) {
public boolean isRedstone(int slot) {
return TileEntityDrawersStandard.this.isRedstone();
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/com/jaquadro/minecraft/storagedrawers/core/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class ModItems
public static ItemShroudKey shroudKey;
public static ItemPersonalKey personalKey;
public static ItemTape tape;
public static ItemUpgradeDowngrade upgradeDowngrade;

public void init () {
upgradeTemplate = new Item().setUnlocalizedName(makeName("upgradeTemplate")).setTextureName(StorageDrawers.MOD_ID + ":upgrade_template").setCreativeTab(ModCreativeTabs.tabStorageDrawers);
Expand All @@ -26,6 +27,8 @@ public void init () {
upgradeVoid = new ItemUpgradeVoid(makeName("upgradeVoid"));
upgradeCreative = new ItemUpgradeCreative(makeName("upgradeCreative"));
upgradeRedstone = new ItemUpgradeRedstone(makeName("upgradeRedstone"));
upgradeDowngrade = new ItemUpgradeDowngrade(makeName("upgradeDowngrade"));

shroudKey = new ItemShroudKey(makeName("shroudKey"));
personalKey = new ItemPersonalKey(makeName("personalKey"));
tape = new ItemTape(makeName("tape"));
Expand All @@ -50,6 +53,7 @@ public void init () {
GameRegistry.registerItem(personalKey, "personalKey");
if (StorageDrawers.config.cache.enableTape)
GameRegistry.registerItem(tape, "tape");
GameRegistry.registerItem(upgradeDowngrade, "upgradeDowngrade");
}

public static String makeName (String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public void init() {
'x', "gemDiamond", 'y', "stickWood", 'z', ModItems.upgradeTemplate));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModItems.upgrade, 1, 6), "xyx", "yzy", "xyx",
'x', "gemEmerald", 'y', "stickWood", 'z', ModItems.upgradeTemplate));


GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModItems.upgradeDowngrade, 1, 0), "xyx", "yzy", "xyx",
'x', Items.flint, 'y', "stickWood", 'z', ModItems.upgradeTemplate));
}

if (config.cache.enableIndicatorUpgrades) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.StatCollector;

import java.util.List;

public class ItemUpgradeDowngrade extends Item {

public ItemUpgradeDowngrade(String name) {
setUnlocalizedName(name);
setCreativeTab(ModCreativeTabs.tabStorageDrawers);
setTextureName(StorageDrawers.MOD_ID + ":upgrade_downgrade");
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"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public boolean isShrouded (int slot) {
return false;
}

@Override
public boolean isDowngraded(int slot) {
return false;
}

@Override
public boolean setIsShrouded (int slot, boolean state) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public interface IStorageProvider

public boolean isShrouded (int slot);

public boolean isDowngraded (int slot);

public boolean setIsShrouded (int slot, boolean state);

public boolean isStorageUnlimited (int slot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ public interface IUpgradeProvider
boolean isSorting ();

boolean isShrouded ();

boolean isDowngraded ();

}

0 comments on commit 74c980b

Please sign in to comment.