Skip to content

Commit

Permalink
Fixed crash / Console spam issue with items that don't exist being ba…
Browse files Browse the repository at this point in the history
…nned in the world.
  • Loading branch information
dries007 committed Mar 21, 2016
1 parent 12001cd commit 2828fb1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
Expand Up @@ -44,6 +44,7 @@ public boolean handleRenderType(ItemStack item, ItemRenderType type)
{
if (!ItemBlacklisted.canUnpack(item)) return false;
ItemStack unpacked = ItemBlacklisted.unpack(item);
if (unpacked == item) return false;
IItemRenderer renderer = MinecraftForgeClient.getItemRenderer(unpacked, type);
if (renderer != null) return renderer.handleRenderType(unpacked, type);
return unpacked.getItem().getSpriteNumber() != ItemBlacklisted.I.getSpriteNumber();
Expand All @@ -53,6 +54,7 @@ public boolean handleRenderType(ItemStack item, ItemRenderType type)
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper)
{
ItemStack unpacked = ItemBlacklisted.unpack(item);
if (unpacked == item) return helper != ItemRendererHelper.INVENTORY_BLOCK;
IItemRenderer renderer = MinecraftForgeClient.getItemRenderer(unpacked, type);
if (renderer != null) return renderer.shouldUseRenderHelper(type, unpacked, helper);
return helper != ItemRendererHelper.INVENTORY_BLOCK;
Expand All @@ -62,6 +64,7 @@ public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRe
public void renderItem(ItemRenderType type, ItemStack item, Object... data)
{
ItemStack unpacked = ItemBlacklisted.unpack(item);
if (unpacked == item) return;
if (type == EQUIPPED || type == EQUIPPED_FIRST_PERSON || type == INVENTORY) unpacked.stackSize = 1;
IItemRenderer renderer = MinecraftForgeClient.getItemRenderer(unpacked, type);
if (renderer != null)
Expand Down
Expand Up @@ -145,15 +145,15 @@ public static ItemStack process(int dim, ItemStack itemStack, boolean unpackOnly
return itemStack;
}

public void add(String dimensions, BanListEntry banListEntry)
public BanList checkDuplicate(String dimensions)
{
BanList match = null;
if (dimensions.equals(GLOBAL_NAME))
{
match = global;
return global;
}
else
{
BanList match = null;
for (BanList banList : new HashSet<>(GlobalBanList.instance.dimesionMap.values()))
{
if (banList.dimension.equals(dimensions))
Expand All @@ -163,6 +163,12 @@ public void add(String dimensions, BanListEntry banListEntry)
}
}
}
return null;
}

public void add(String dimensions, BanListEntry banListEntry)
{
BanList match = checkDuplicate(dimensions);
if (match == null)
{
match = new BanList(dimensions);
Expand All @@ -178,22 +184,7 @@ public void add(String dimensions, BanListEntry banListEntry)

public boolean remove(String dimensions, BanListEntry banListEntry)
{
BanList match = null;
if (dimensions.equals(GLOBAL_NAME))
{
match = global;
}
else
{
for (BanList banList : new HashSet<>(GlobalBanList.instance.dimesionMap.values()))
{
if (banList.dimension.equals(dimensions))
{
if (match != null) throw new IllegalStateException("Duplicate banlist key. This is a serious issue. You should manually try to fix the json file!");
match = banList;
}
}
}
BanList match = checkDuplicate(dimensions);
if (match == null) return false;
if (!match.banListEntryMap.containsEntry(banListEntry.getItem(), banListEntry)) return false;
match.banListEntryMap.remove(banListEntry.getItem(), banListEntry);
Expand Down
Expand Up @@ -57,8 +57,7 @@ public String getUnlocalizedName(ItemStack in)
{
if (!canUnpack(in)) return "_ERROR_";
ItemStack unpack = unpack(in);
if (unpack == in || unpack == null) return super.getUnlocalizedName();

if (unpack == in || unpack == null) return "_ERROR_";
return unpack.getUnlocalizedName();
}

Expand Down

0 comments on commit 2828fb1

Please sign in to comment.