mirror of
https://github.com/GTNewHorizons/StorageDrawers.git
synced 2026-11-21 12:42:24 +00:00
Tile entity load hardening; fix storage upgrades on comp drawers.
This commit is contained in:
1 parent
c4be02f9c0
commit
01ca82d3c2
2 files changed
+76
-28
No files matched your search
@@ -7,6 +7,7 @@ import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup;
|
||||
import com.jaquadro.minecraft.storagedrawers.inventory.ISideManager;
|
||||
import com.jaquadro.minecraft.storagedrawers.inventory.StorageInventory;
|
||||
import com.jaquadro.minecraft.storagedrawers.network.CountUpdateMessage;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -21,7 +22,9 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class TileEntityDrawers extends TileEntity implements IDrawerGroup, ISidedInventory
|
||||
@@ -39,6 +42,8 @@ public abstract class TileEntityDrawers extends TileEntity implements IDrawerGro
|
||||
private long lastClickTime;
|
||||
private UUID lastClickUUID;
|
||||
|
||||
private NBTTagCompound failureSnapshot;
|
||||
|
||||
protected TileEntityDrawers (int drawerCount) {
|
||||
initWithDrawerCount(drawerCount);
|
||||
}
|
||||
@@ -127,8 +132,6 @@ public abstract class TileEntityDrawers extends TileEntity implements IDrawerGro
|
||||
if (slot < 0 || slot >= getDrawerCount())
|
||||
return 0;
|
||||
|
||||
// TODO: Override comp to pick the right slot
|
||||
|
||||
IDrawer drawer = drawers[slot];
|
||||
if (drawer.isEmpty())
|
||||
drawer.setStoredItem(stack, 0);
|
||||
@@ -173,36 +176,66 @@ public abstract class TileEntityDrawers extends TileEntity implements IDrawerGro
|
||||
return count;
|
||||
}
|
||||
|
||||
protected void trapLoadFailure (Throwable t, NBTTagCompound tag) {
|
||||
failureSnapshot = (NBTTagCompound)tag.copy();
|
||||
FMLLog.log(StorageDrawers.MOD_ID, Level.ERROR, t, "Tile Load Failure.");
|
||||
}
|
||||
|
||||
protected void restoreLoadFailure (NBTTagCompound tag) {
|
||||
Iterator<String> iter = failureSnapshot.func_150296_c().iterator();
|
||||
while (iter.hasNext()) {
|
||||
String key = iter.next();
|
||||
if (!tag.hasKey(key))
|
||||
tag.setTag(key, failureSnapshot.getTag(key));
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean loadDidFail () {
|
||||
return failureSnapshot != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT (NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
|
||||
setDirection(tag.getByte("Dir"));
|
||||
failureSnapshot = null;
|
||||
|
||||
drawerCapacity = tag.getByte("Cap");
|
||||
storageLevel = tag.getByte("Lev");
|
||||
try {
|
||||
setDirection(tag.getByte("Dir"));
|
||||
|
||||
statusLevel = 0;
|
||||
if (tag.hasKey("Stat"))
|
||||
statusLevel = tag.getByte("Stat");
|
||||
drawerCapacity = tag.getByte("Cap");
|
||||
storageLevel = tag.getByte("Lev");
|
||||
|
||||
NBTTagList slots = tag.getTagList("Slots", Constants.NBT.TAG_COMPOUND);
|
||||
int drawerCount = slots.tagCount();
|
||||
drawers = new IDrawer[slots.tagCount()];
|
||||
statusLevel = 0;
|
||||
if (tag.hasKey("Stat"))
|
||||
statusLevel = tag.getByte("Stat");
|
||||
|
||||
for (int i = 0, n = drawers.length; i < n; i++) {
|
||||
NBTTagCompound slot = slots.getCompoundTagAt(i);
|
||||
drawers[i] = createDrawer(i);
|
||||
drawers[i].readFromNBT(slot);
|
||||
NBTTagList slots = tag.getTagList("Slots", Constants.NBT.TAG_COMPOUND);
|
||||
int drawerCount = slots.tagCount();
|
||||
drawers = new IDrawer[slots.tagCount()];
|
||||
|
||||
for (int i = 0, n = drawers.length; i < n; i++) {
|
||||
NBTTagCompound slot = slots.getCompoundTagAt(i);
|
||||
drawers[i] = createDrawer(i);
|
||||
drawers[i].readFromNBT(slot);
|
||||
}
|
||||
|
||||
inventory = new StorageInventory(this, getSideManager());
|
||||
}
|
||||
catch (Throwable t) {
|
||||
trapLoadFailure(t, tag);
|
||||
}
|
||||
|
||||
inventory = new StorageInventory(this, getSideManager());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT (NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
|
||||
if (failureSnapshot != null) {
|
||||
restoreLoadFailure(tag);
|
||||
return;
|
||||
}
|
||||
|
||||
tag.setByte("Dir", (byte)direction);
|
||||
tag.setByte("Cap", (byte)drawerCapacity);
|
||||
tag.setByte("Lev", (byte) storageLevel);
|
||||
|
||||
@@ -3,9 +3,11 @@ package com.jaquadro.minecraft.storagedrawers.block.tile;
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
||||
import com.jaquadro.minecraft.storagedrawers.config.CompTierRegistry;
|
||||
import com.jaquadro.minecraft.storagedrawers.config.ConfigManager;
|
||||
import com.jaquadro.minecraft.storagedrawers.network.CountUpdateMessage;
|
||||
import com.jaquadro.minecraft.storagedrawers.storage.*;
|
||||
import com.jaquadro.minecraft.storagedrawers.storage.IStorageProvider;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
@@ -17,6 +19,7 @@ import net.minecraft.item.crafting.ShapelessRecipes;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -92,6 +95,8 @@ public class TileEntityDrawersComp extends TileEntityDrawers
|
||||
|
||||
@Override
|
||||
public void readFromNBT (NBTTagCompound tag) {
|
||||
pooledCount = 0;
|
||||
|
||||
for (int i = 0; i < getDrawerCount(); i++) {
|
||||
protoStack[i] = null;
|
||||
convRate[i] = 0;
|
||||
@@ -99,23 +104,28 @@ public class TileEntityDrawersComp extends TileEntityDrawers
|
||||
|
||||
super.readFromNBT(tag);
|
||||
|
||||
pooledCount = tag.getInteger("Count");
|
||||
try {
|
||||
pooledCount = tag.getInteger("Count");
|
||||
|
||||
for (int i = 0, n = convRate.length; i < n; i++)
|
||||
convRate[i] = 0;
|
||||
|
||||
if (tag.hasKey("Conv0"))
|
||||
convRate[0] = tag.getByte("Conv0");
|
||||
if (tag.hasKey("Conv1"))
|
||||
convRate[1] = tag.getByte("Conv1");
|
||||
if (tag.hasKey("Conv2"))
|
||||
convRate[2] = tag.getByte("Conv2");
|
||||
if (tag.hasKey("Conv0"))
|
||||
convRate[0] = tag.getByte("Conv0");
|
||||
if (tag.hasKey("Conv1"))
|
||||
convRate[1] = tag.getByte("Conv1");
|
||||
if (tag.hasKey("Conv2"))
|
||||
convRate[2] = tag.getByte("Conv2");
|
||||
}
|
||||
catch (Throwable t) {
|
||||
trapLoadFailure(t, tag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT (NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
|
||||
if (loadDidFail())
|
||||
return;
|
||||
|
||||
tag.setInteger("Count", pooledCount);
|
||||
|
||||
if (convRate[0] > 0)
|
||||
@@ -406,6 +416,8 @@ public class TileEntityDrawersComp extends TileEntityDrawers
|
||||
return protoStack[slot].getItem().getItemStackLimit(protoStack[slot]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void clear () {
|
||||
for (int i = 0; i < getDrawerCount(); i++) {
|
||||
protoStack[i] = null;
|
||||
@@ -428,7 +440,10 @@ public class TileEntityDrawersComp extends TileEntityDrawers
|
||||
if (convRate == null || convRate[slot] == 0)
|
||||
return 0;
|
||||
|
||||
int stackLimit = convRate[0] * TileEntityDrawersComp.this.getDrawerCapacity();
|
||||
ConfigManager config = StorageDrawers.config;
|
||||
int slotStacks = config.getStorageUpgradeMultiplier(getStorageLevel()) * TileEntityDrawersComp.this.getDrawerCapacity();
|
||||
|
||||
int stackLimit = convRate[0] * slotStacks;
|
||||
return stackLimit / convRate[slot];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user