Skip to content

Commit

Permalink
Make getSubItems non-client only. Use it for Ingredient iteration.
Browse files Browse the repository at this point in the history
  • Loading branch information
LexManos committed Jun 24, 2017
1 parent 478a84e commit efd8b38
Show file tree
Hide file tree
Showing 18 changed files with 190 additions and 16 deletions.
14 changes: 11 additions & 3 deletions patches/minecraft/net/minecraft/block/Block.java.patch
Expand Up @@ -205,15 +205,23 @@
public ItemStack func_185473_a(World p_185473_1_, BlockPos p_185473_2_, IBlockState p_185473_3_)
{
return new ItemStack(Item.func_150898_a(this), 1, this.func_180651_a(p_185473_3_));
@@ -921,6 +937,7 @@
@@ -831,7 +847,6 @@
{
}

- @SideOnly(Side.CLIENT)
public CreativeTabs func_149708_J()
{
return this.field_149772_a;
@@ -921,6 +936,7 @@
}
}

+ @Deprecated // Forge - World/state/pos/entity sensitive version below
public SoundType func_185467_w()
{
return this.field_149762_H;
@@ -936,6 +953,1218 @@
@@ -936,6 +952,1218 @@
{
}

Expand Down Expand Up @@ -1432,7 +1440,7 @@
public static void func_149671_p()
{
func_176215_a(0, field_176230_a, (new BlockAir()).func_149663_c("air"));
@@ -1247,14 +2476,7 @@
@@ -1247,14 +2475,7 @@
}
else
{
Expand Down
29 changes: 23 additions & 6 deletions patches/minecraft/net/minecraft/item/Item.java.patch
Expand Up @@ -60,8 +60,19 @@
return p_77621_1_.func_147447_a(vec3d, vec3d1, p_77621_3_, !p_77621_3_, false);
}

@@ -411,6 +418,9 @@
@SideOnly(Side.CLIENT)
@@ -399,7 +406,6 @@
return 0;
}

- @SideOnly(Side.CLIENT)
public void func_150895_a(CreativeTabs p_150895_1_, NonNullList<ItemStack> p_150895_2_)
{
if (this.func_194125_a(p_150895_1_))
@@ -408,15 +414,16 @@
}
}

- @SideOnly(Side.CLIENT)
protected boolean func_194125_a(CreativeTabs p_194125_1_)
{
+ for (CreativeTabs tab : this.getCreativeTabs())
Expand All @@ -70,7 +81,13 @@
CreativeTabs creativetabs = this.func_77640_w();
return creativetabs != null && (p_194125_1_ == CreativeTabs.field_78027_g || p_194125_1_ == creativetabs);
}
@@ -438,11 +448,632 @@

@Nullable
- @SideOnly(Side.CLIENT)
public CreativeTabs func_77640_w()
{
return this.field_77701_a;
@@ -438,11 +445,632 @@
return false;
}

Expand Down Expand Up @@ -703,7 +720,7 @@
public static void func_150900_l()
{
func_179214_a(Blocks.field_150350_a, new ItemAir(Blocks.field_150350_a));
@@ -1002,6 +1633,8 @@
@@ -1002,6 +1630,8 @@
private final float field_78010_h;
private final float field_78011_i;
private final int field_78008_j;
Expand All @@ -712,15 +729,15 @@

private ToolMaterial(int p_i1874_3_, int p_i1874_4_, float p_i1874_5_, float p_i1874_6_, int p_i1874_7_)
{
@@ -1037,6 +1670,7 @@
@@ -1037,6 +1667,7 @@
return this.field_78008_j;
}

+ @Deprecated // Use getRepairItemStack below
public Item func_150995_f()
{
if (this == WOOD)
@@ -1060,5 +1694,21 @@
@@ -1060,5 +1691,21 @@
return this == DIAMOND ? Items.field_151045_i : null;
}
}
Expand Down
10 changes: 10 additions & 0 deletions patches/minecraft/net/minecraft/item/ItemAppleGold.java.patch
@@ -0,0 +1,10 @@
--- ../src-base/minecraft/net/minecraft/item/ItemAppleGold.java
+++ ../src-work/minecraft/net/minecraft/item/ItemAppleGold.java
@@ -47,7 +47,6 @@
}
}

- @SideOnly(Side.CLIENT)
public void func_150895_a(CreativeTabs p_150895_1_, NonNullList<ItemStack> p_150895_2_)
{
if (this.func_194125_a(p_150895_1_))
18 changes: 18 additions & 0 deletions patches/minecraft/net/minecraft/item/ItemBanner.java.patch
@@ -0,0 +1,18 @@
--- ../src-base/minecraft/net/minecraft/item/ItemBanner.java
+++ ../src-work/minecraft/net/minecraft/item/ItemBanner.java
@@ -133,7 +133,6 @@
func_185054_a(p_77624_1_, p_77624_3_);
}

- @SideOnly(Side.CLIENT)
public void func_150895_a(CreativeTabs p_150895_1_, NonNullList<ItemStack> p_150895_2_)
{
if (this.func_194125_a(p_150895_1_))
@@ -157,7 +156,6 @@
return itemstack;
}

- @SideOnly(Side.CLIENT)
public CreativeTabs func_77640_w()
{
return CreativeTabs.field_78031_c;
8 changes: 8 additions & 0 deletions patches/minecraft/net/minecraft/item/ItemBed.java.patch
Expand Up @@ -9,3 +9,11 @@
p_180614_2_.func_184133_a((EntityPlayer)null, p_180614_3_, soundtype.func_185841_e(), SoundCategory.BLOCKS, (soundtype.func_185843_a() + 1.0F) / 2.0F, soundtype.func_185847_b() * 0.8F);
TileEntity tileentity = p_180614_2_.func_175625_s(blockpos);

@@ -113,7 +113,6 @@
return super.func_77658_a() + "." + EnumDyeColor.func_176764_b(p_77667_1_.func_77960_j()).func_176762_d();
}

- @SideOnly(Side.CLIENT)
public void func_150895_a(CreativeTabs p_150895_1_, NonNullList<ItemStack> p_150895_2_)
{
if (this.func_194125_a(p_150895_1_))
16 changes: 15 additions & 1 deletion patches/minecraft/net/minecraft/item/ItemBlock.java.patch
Expand Up @@ -37,7 +37,21 @@
{
p_179222_3_ = EnumFacing.UP;
}
@@ -173,6 +161,36 @@
@@ -149,13 +137,11 @@
return this.field_150939_a.func_149739_a();
}

- @SideOnly(Side.CLIENT)
public CreativeTabs func_77640_w()
{
return this.field_150939_a.func_149708_J();
}

- @SideOnly(Side.CLIENT)
public void func_150895_a(CreativeTabs p_150895_1_, NonNullList<ItemStack> p_150895_2_)
{
if (this.func_194125_a(p_150895_1_))
@@ -173,6 +159,36 @@

public Block func_179223_d()
{
Expand Down
10 changes: 10 additions & 0 deletions patches/minecraft/net/minecraft/item/ItemCoal.java.patch
@@ -0,0 +1,10 @@
--- ../src-base/minecraft/net/minecraft/item/ItemCoal.java
+++ ../src-work/minecraft/net/minecraft/item/ItemCoal.java
@@ -19,7 +19,6 @@
return p_77667_1_.func_77960_j() == 1 ? "item.charcoal" : "item.coal";
}

- @SideOnly(Side.CLIENT)
public void func_150895_a(CreativeTabs p_150895_1_, NonNullList<ItemStack> p_150895_2_)
{
if (this.func_194125_a(p_150895_1_))
10 changes: 10 additions & 0 deletions patches/minecraft/net/minecraft/item/ItemEnchantedBook.java.patch
@@ -0,0 +1,10 @@
--- ../src-base/minecraft/net/minecraft/item/ItemEnchantedBook.java
+++ ../src-work/minecraft/net/minecraft/item/ItemEnchantedBook.java
@@ -101,7 +101,6 @@
return itemstack;
}

- @SideOnly(Side.CLIENT)
public void func_150895_a(CreativeTabs p_150895_1_, NonNullList<ItemStack> p_150895_2_)
{
if (p_150895_1_ == CreativeTabs.field_78027_g)
10 changes: 10 additions & 0 deletions patches/minecraft/net/minecraft/item/ItemFishFood.java.patch
@@ -0,0 +1,10 @@
--- ../src-base/minecraft/net/minecraft/item/ItemFishFood.java
+++ ../src-work/minecraft/net/minecraft/item/ItemFishFood.java
@@ -47,7 +47,6 @@
super.func_77849_c(p_77849_1_, p_77849_2_, p_77849_3_);
}

- @SideOnly(Side.CLIENT)
public void func_150895_a(CreativeTabs p_150895_1_, NonNullList<ItemStack> p_150895_2_)
{
if (this.func_194125_a(p_150895_1_))
18 changes: 18 additions & 0 deletions patches/minecraft/net/minecraft/item/ItemMonsterPlacer.java.patch
@@ -0,0 +1,18 @@
--- ../src-base/minecraft/net/minecraft/item/ItemMonsterPlacer.java
+++ ../src-work/minecraft/net/minecraft/item/ItemMonsterPlacer.java
@@ -250,7 +250,6 @@
}
}

- @SideOnly(Side.CLIENT)
public void func_150895_a(CreativeTabs p_150895_1_, NonNullList<ItemStack> p_150895_2_)
{
if (this.func_194125_a(p_150895_1_))
@@ -264,7 +263,6 @@
}
}

- @SideOnly(Side.CLIENT)
public static void func_185078_a(ItemStack p_185078_0_, ResourceLocation p_185078_1_)
{
NBTTagCompound nbttagcompound = p_185078_0_.func_77942_o() ? p_185078_0_.func_77978_p() : new NBTTagCompound();
10 changes: 10 additions & 0 deletions patches/minecraft/net/minecraft/item/ItemPotion.java.patch
@@ -0,0 +1,10 @@
--- ../src-base/minecraft/net/minecraft/item/ItemPotion.java
+++ ../src-work/minecraft/net/minecraft/item/ItemPotion.java
@@ -120,7 +120,6 @@
return super.func_77636_d(p_77636_1_) || !PotionUtils.func_185189_a(p_77636_1_).isEmpty();
}

- @SideOnly(Side.CLIENT)
public void func_150895_a(CreativeTabs p_150895_1_, NonNullList<ItemStack> p_150895_2_)
{
if (this.func_194125_a(p_150895_1_))
8 changes: 8 additions & 0 deletions patches/minecraft/net/minecraft/item/ItemSkull.java.patch
Expand Up @@ -20,3 +20,11 @@
{
return EnumActionResult.FAIL;
}
@@ -128,7 +133,6 @@
}
}

- @SideOnly(Side.CLIENT)
public void func_150895_a(CreativeTabs p_150895_1_, NonNullList<ItemStack> p_150895_2_)
{
if (this.func_194125_a(p_150895_1_))
10 changes: 10 additions & 0 deletions patches/minecraft/net/minecraft/item/ItemTippedArrow.java.patch
@@ -0,0 +1,10 @@
--- ../src-base/minecraft/net/minecraft/item/ItemTippedArrow.java
+++ ../src-work/minecraft/net/minecraft/item/ItemTippedArrow.java
@@ -31,7 +31,6 @@
return entitytippedarrow;
}

- @SideOnly(Side.CLIENT)
public void func_150895_a(CreativeTabs p_150895_1_, NonNullList<ItemStack> p_150895_2_)
{
if (this.func_194125_a(p_150895_1_))
Expand Up @@ -21,7 +21,7 @@
+ this(new ItemStack[size]);
+ }
+
private Ingredient(ItemStack... p_i47503_1_)
protected Ingredient(ItemStack... p_i47503_1_)
{
this.field_193371_b = p_i47503_1_;
+ Ingredient.INSTANCES.add(this);
Expand Down
Expand Up @@ -527,7 +527,7 @@ private static void init()

registerI("minecraft:item", (context, json) -> Ingredient.fromStacks(CraftingHelper.getItemStackBasic(json, context)));
registerI("minecraft:empty", (context, json) -> Ingredient.EMPTY);
registerI("minecraft:item_nbt", (context, json) -> Ingredient.fromStacks(CraftingHelper.getItemStack(json, context)));
registerI("minecraft:item_nbt", (context, json) -> new IngredientNBT(CraftingHelper.getItemStack(json, context)));
registerI("forge:ore_dict", (context, json) -> new OreIngredient(JsonUtils.getString(json, "ore")));
}

Expand Down
Expand Up @@ -101,7 +101,6 @@ public ItemStack getContainerItem(@Nonnull ItemStack itemStack)
return super.getContainerItem(itemStack);
}

@SideOnly(Side.CLIENT)
@Override
public void getSubItems(@Nullable CreativeTabs tab, @Nonnull NonNullList<ItemStack> subItems)
{
Expand Down
Expand Up @@ -596,7 +596,7 @@ public static boolean itemMatches(@Nonnull ItemStack target, @Nonnull ItemStack
{
return false;
}
return (target.getItem() == input.getItem() && ((target.getItemDamage() == WILDCARD_VALUE && !strict) || target.getItemDamage() == input.getItemDamage()));
return (target.getItem() == input.getItem() && ((target.getMetadata() == WILDCARD_VALUE && !strict) || target.getMetadata() == input.getMetadata()));
}

//Convenience functions that make for cleaner code mod side. They all drill down to registerOre(String, int, ItemStack)
Expand Down
28 changes: 26 additions & 2 deletions src/main/java/net/minecraftforge/oredict/OreIngredient.java
Expand Up @@ -25,6 +25,7 @@
import it.unimi.dsi.fastutil.ints.IntComparators;
import it.unimi.dsi.fastutil.ints.IntList;
import net.minecraft.client.util.RecipeItemHelper;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.NonNullList;
Expand All @@ -35,6 +36,7 @@ public class OreIngredient extends Ingredient
{
private NonNullList<ItemStack> ores;
private IntList itemIds = null;
private ItemStack[] array = null;

public OreIngredient(String ore)
{
Expand All @@ -46,7 +48,19 @@ public OreIngredient(String ore)
@Nonnull
public ItemStack[] getMatchingStacks()
{
return ores.toArray(new ItemStack[ores.size()]);
if (array == null || this.array.length != ores.size())
{
NonNullList<ItemStack> lst = NonNullList.create();
for (ItemStack itemstack : this.ores)
{
if (itemstack.getMetadata() == OreDictionary.WILDCARD_VALUE)
itemstack.getItem().getSubItems(CreativeTabs.SEARCH, lst);
else
lst.add(itemstack);
}
this.array = lst.toArray(new ItemStack[lst.size()]);
}
return this.array;
}


Expand All @@ -61,7 +75,17 @@ public IntList getValidItemStacksPacked()

for (ItemStack itemstack : this.ores)
{
this.itemIds.add(RecipeItemHelper.pack(itemstack));
if (itemstack.getMetadata() == OreDictionary.WILDCARD_VALUE)
{
NonNullList<ItemStack> lst = NonNullList.create();
itemstack.getItem().getSubItems(CreativeTabs.SEARCH, lst);
for (ItemStack item : lst)
this.itemIds.add(RecipeItemHelper.pack(item));
}
else
{
this.itemIds.add(RecipeItemHelper.pack(itemstack));
}
}

this.itemIds.sort(IntComparators.NATURAL_COMPARATOR);
Expand Down

5 comments on commit efd8b38

@Texasjake95
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to cause a crash server side if getSubItems is called on an ItemBlock because Block#getSubBlocks is seems to be client side only still

@LexManos
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh I Specifically fucking checked that.. I swear eclipse doesn't like saving 1/2 my modifications...

@Texasjake95
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a modder were to call it it does crash but when crafting it doesn't seem to

@LexManos
Copy link
Member Author

@LexManos LexManos commented on efd8b38 Jun 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats because it's only called for OreDict wildcards, which vanilla crafting never does.
368d206
REALLY wish Mojang wouldnt strip this method.

@Texasjake95
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah didn't realize that sorry about that... I did notice you fixed it, but one last thing in EnumFlowerType getTypes is used in getSubBlocks and it is client side only as well

Please sign in to comment.