Skip to content

Commit

Permalink
Fix empty locked drawer being cleared on chunk reload; fix rendering …
Browse files Browse the repository at this point in the history
…0 items in UI
  • Loading branch information
jaquadro committed Mar 29, 2020
1 parent 95311ad commit 52a0e0a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ public abstract class TileEntityDrawers extends ChamTileEntity implements IDrawe

private long lastClickTime;
private UUID lastClickUUID;
private boolean loading;

private class DrawerAttributes extends BasicDrawerAttributes
{
@Override
protected void onAttributeChanged () {
if (!TileEntityDrawers.this.drawerAttributes.isItemLocked(LockAttribute.LOCK_POPULATED)) {
if (!loading && !TileEntityDrawers.this.drawerAttributes.isItemLocked(LockAttribute.LOCK_POPULATED)) {
for (int slot = 0; slot < TileEntityDrawers.this.getGroup().getDrawerCount(); slot++) {
if (TileEntityDrawers.this.emptySlotCanBeCleared(slot)) {
IDrawer drawer = TileEntityDrawers.this.getGroup().getDrawer(slot);
Expand Down Expand Up @@ -459,6 +460,7 @@ public int interactPutItemsIntoSlot (int slot, PlayerEntity player) {

@Override
public void readPortable (CompoundNBT tag) {
loading = true;
super.readPortable(tag);

//material = null;
Expand Down Expand Up @@ -494,6 +496,7 @@ public void readPortable (CompoundNBT tag) {
securityKey = null;
if (tag.hasKey("Sec"))
securityKey = tag.getString("Sec");*/
loading = false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,9 @@ public ItemStack getStoredItemPrototype () {
@Nonnull
@Override
public IDrawer setStoredItem (@Nonnull ItemStack itemPrototype) {
if (ItemStackHelper.isStackEncoded(itemPrototype))
itemPrototype = ItemStackHelper.decodeItemStackPrototype(itemPrototype);

return storage.setStoredItem(slot, itemPrototype);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,11 @@ public IDrawer setStoredItem (@Nonnull ItemStack itemPrototype) {
}

protected IDrawer setStoredItem (@Nonnull ItemStack itemPrototype, boolean notify) {
if (matcher.matches(itemPrototype)) {
if (ItemStackHelper.isStackEncoded(itemPrototype))
itemPrototype = ItemStackHelper.decodeItemStackPrototype(itemPrototype);

if (matcher.matches(itemPrototype))
return this;
}

itemPrototype = ItemStackHelper.getItemPrototype(itemPrototype);
if (itemPrototype.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ public void renderItemOverlayIntoGUI (FontRenderer font, @Nonnull ItemStack item
return;
}

item = ItemStackHelper.decodeItemStack(item);

if (!item.isEmpty())
{
item = ItemStackHelper.decodeItemStack(item);

float scale = .5f;
float xoff = 0;
//if (font.getUnicodeFlag()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,39 @@ public static ItemStack encodeItemStack (@Nonnull ItemStack proto, int count) {
}

public static ItemStack decodeItemStack (@Nonnull ItemStack stack) {
int count = ItemStackHelper.decodedCount(stack);
ItemStack decode = ItemStackHelper.stripDecoding(stack);
decode.setCount(count);
return decode;
}

public static ItemStack decodeItemStackPrototype (@Nonnull ItemStack stack) {
ItemStack decode = ItemStackHelper.stripDecoding(stack);
decode.setCount(1);
return decode;
}

public static int decodedCount (@Nonnull ItemStack stack) {
CompoundNBT tag = stack.getTag();
if (tag == null)
return stack;
if (tag != null && tag.contains("__storagedrawers_count"))
return tag.getInt("__storagedrawers_count");

if (tag.contains("__storagedrawers_count")) {
ItemStack decode = stack.copy();
decode.setCount(tag.getInt("__storagedrawers_count"));
return stack.getCount();
}

tag = decode.getTag();
if (tag != null) {
decode.getTag().remove("__storagedrawers_count");
if (tag.size() == 0)
decode.setTag(null);
}
public static ItemStack stripDecoding (@Nonnull ItemStack stack) {
ItemStack decode = stack.copy();
CompoundNBT tag = decode.getTag();

return decode;
if (tag != null && tag.contains("__storagedrawers_count")) {
tag.remove("__storagedrawers_count");
if (tag.size() == 0)
decode.setTag(null);
else
decode.setTag(tag);
}

return stack;
return decode;
}

public static boolean isStackEncoded (@Nonnull ItemStack stack) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public ItemStack getStack () {

@Override
public void putStack (@Nonnull ItemStack stack) {
stack = ItemStackHelper.decodeItemStack(stack);
IDrawer target = drawer.setStoredItem(stack);
stack = ItemStackHelper.decodeItemStack(stack);
target.setStoredItemCount(stack.getCount());
}

Expand Down

0 comments on commit 52a0e0a

Please sign in to comment.