mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 11:59:25 +00:00
Generalise EnumRarity to an interface (#5182)
This commit is contained in:
1 parent
e6fbf39591
commit
cc95c40b5b
8 files changed
+209
-10
No files matched your search
@@ -20,6 +20,15 @@
|
||||
}
|
||||
|
||||
public List<String> func_191927_a(ItemStack p_191927_1_)
|
||||
@@ -142,7 +146,7 @@
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
- list.set(i, p_191927_1_.func_77953_t().field_77937_e + (String)list.get(i));
|
||||
+ list.set(i, p_191927_1_.func_77973_b().getForgeRarity(p_191927_1_).getColor() + (String)list.get(i));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -170,7 +174,13 @@
|
||||
|
||||
public void func_146283_a(List<String> p_146283_1_, int p_146283_2_, int p_146283_3_)
|
||||
|
||||
@@ -164,6 +164,15 @@
|
||||
GlStateManager.func_179131_c(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GlStateManager.func_179140_f();
|
||||
this.func_191948_b(p_73863_1_, p_73863_2_);
|
||||
@@ -654,7 +719,7 @@
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
- list.set(i, p_146285_1_.func_77953_t().field_77937_e + (String)list.get(i));
|
||||
+ list.set(i, p_146285_1_.func_77973_b().getForgeRarity(p_146285_1_).getColor() + (String)list.get(i));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -662,7 +727,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
--- ../src-base/minecraft/net/minecraft/item/EnumRarity.java
|
||||
+++ ../src-work/minecraft/net/minecraft/item/EnumRarity.java
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
||||
-public enum EnumRarity
|
||||
+public enum EnumRarity implements net.minecraftforge.common.IRarity
|
||||
{
|
||||
COMMON(TextFormatting.WHITE, "Common"),
|
||||
UNCOMMON(TextFormatting.YELLOW, "Uncommon"),
|
||||
@@ -17,4 +17,16 @@
|
||||
this.field_77937_e = p_i45349_3_;
|
||||
this.field_77934_f = p_i45349_4_;
|
||||
}
|
||||
+
|
||||
+ @Override
|
||||
+ public TextFormatting getColor()
|
||||
+ {
|
||||
+ return this.field_77937_e;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public String getName()
|
||||
+ {
|
||||
+ return this.field_77934_f;
|
||||
+ }
|
||||
}
|
||||
@@ -38,7 +38,15 @@
|
||||
public boolean func_77634_r()
|
||||
{
|
||||
return this.field_77700_c != null;
|
||||
@@ -372,7 +375,7 @@
|
||||
@@ -365,6 +368,7 @@
|
||||
return p_77636_1_.func_77948_v();
|
||||
}
|
||||
|
||||
+ @Deprecated // use Forge version
|
||||
public EnumRarity func_77613_e(ItemStack p_77613_1_)
|
||||
{
|
||||
return p_77613_1_.func_77948_v() ? EnumRarity.RARE : EnumRarity.COMMON;
|
||||
@@ -372,7 +376,7 @@
|
||||
|
||||
public boolean func_77616_k(ItemStack p_77616_1_)
|
||||
{
|
||||
@@ -47,7 +55,7 @@
|
||||
}
|
||||
|
||||
protected RayTraceResult func_77621_a(World p_77621_1_, EntityPlayer p_77621_2_, boolean p_77621_3_)
|
||||
@@ -389,8 +392,8 @@
|
||||
@@ -389,8 +393,8 @@
|
||||
float f5 = MathHelper.func_76126_a(-f * 0.017453292F);
|
||||
float f6 = f3 * f4;
|
||||
float f7 = f2 * f4;
|
||||
@@ -58,7 +66,7 @@
|
||||
return p_77621_1_.func_147447_a(vec3d, vec3d1, p_77621_3_, !p_77621_3_, false);
|
||||
}
|
||||
|
||||
@@ -409,6 +412,9 @@
|
||||
@@ -409,6 +413,9 @@
|
||||
|
||||
protected boolean func_194125_a(CreativeTabs p_194125_1_)
|
||||
{
|
||||
@@ -68,7 +76,7 @@
|
||||
CreativeTabs creativetabs = this.func_77640_w();
|
||||
return creativetabs != null && (p_194125_1_ == CreativeTabs.field_78027_g || p_194125_1_ == creativetabs);
|
||||
}
|
||||
@@ -435,11 +441,779 @@
|
||||
@@ -435,11 +442,784 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -841,14 +849,19 @@
|
||||
+ public void setTileEntityItemStackRenderer(@Nullable net.minecraft.client.renderer.tileentity.TileEntityItemStackRenderer teisr)
|
||||
+ {
|
||||
+ this.teisr = teisr;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public net.minecraftforge.common.IRarity getForgeRarity(ItemStack stack)
|
||||
+ {
|
||||
+ return this.func_77613_e(stack);
|
||||
+ }
|
||||
+
|
||||
+ /* ======================================== FORGE END =====================================*/
|
||||
+
|
||||
public static void func_150900_l()
|
||||
{
|
||||
func_179214_a(Blocks.field_150350_a, new ItemAir(Blocks.field_150350_a));
|
||||
@@ -999,6 +1773,8 @@
|
||||
@@ -999,6 +1779,8 @@
|
||||
private final float field_78010_h;
|
||||
private final float field_78011_i;
|
||||
private final int field_78008_j;
|
||||
@@ -857,7 +870,7 @@
|
||||
|
||||
private ToolMaterial(int p_i1874_3_, int p_i1874_4_, float p_i1874_5_, float p_i1874_6_, int p_i1874_7_)
|
||||
{
|
||||
@@ -1034,6 +1810,7 @@
|
||||
@@ -1034,6 +1816,7 @@
|
||||
return this.field_78008_j;
|
||||
}
|
||||
|
||||
@@ -865,7 +878,7 @@
|
||||
public Item func_150995_f()
|
||||
{
|
||||
if (this == WOOD)
|
||||
@@ -1057,5 +1834,21 @@
|
||||
@@ -1057,5 +1840,21 @@
|
||||
return this == DIAMOND ? Items.field_151045_i : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,7 +223,15 @@
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -987,7 +1012,7 @@
|
||||
@@ -871,6 +896,7 @@
|
||||
return this.func_77973_b().func_77636_d(this);
|
||||
}
|
||||
|
||||
+ @Deprecated // use Forge version on item
|
||||
public EnumRarity func_77953_t()
|
||||
{
|
||||
return this.func_77973_b().func_77613_e(this);
|
||||
@@ -987,7 +1013,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -232,7 +240,16 @@
|
||||
}
|
||||
|
||||
return multimap;
|
||||
@@ -1130,4 +1155,128 @@
|
||||
@@ -1032,7 +1058,7 @@
|
||||
{
|
||||
NBTTagCompound nbttagcompound = this.func_77955_b(new NBTTagCompound());
|
||||
itextcomponent.func_150256_b().func_150209_a(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new TextComponentString(nbttagcompound.toString())));
|
||||
- itextcomponent.func_150256_b().func_150238_a(this.func_77953_t().field_77937_e);
|
||||
+ itextcomponent.func_150256_b().func_150238_a(this.func_77973_b().getForgeRarity(this).getColor());
|
||||
}
|
||||
|
||||
return itextcomponent;
|
||||
@@ -1130,4 +1156,128 @@
|
||||
{
|
||||
this.func_190917_f(-p_190918_1_);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2018.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common;
|
||||
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
||||
/**
|
||||
* Interface generalisation of {@link net.minecraft.item.EnumRarity}.
|
||||
*/
|
||||
public interface IRarity
|
||||
{
|
||||
TextFormatting getColor();
|
||||
|
||||
String getName();
|
||||
}
|
||||
@@ -144,7 +144,10 @@ public class EnumHelper
|
||||
{
|
||||
return addEnum(ToolMaterial.class, name, harvestLevel, maxUses, efficiency, damage, enchantability);
|
||||
}
|
||||
|
||||
/** @deprecated use {@link net.minecraftforge.common.IRarity} instead */
|
||||
@Nullable
|
||||
@Deprecated
|
||||
public static EnumRarity addRarity(String name, TextFormatting color, String displayName)
|
||||
{
|
||||
return addEnum(EnumRarity.class, name, color, displayName);
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2018.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.debug.item;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.client.event.ModelRegistryEvent;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.common.IRarity;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
@Mod.EventBusSubscriber
|
||||
@Mod(modid = CustomRarityTest.MOD_ID, name = "Custom rarity test mod", version = "1.0", acceptableRemoteVersions = "*")
|
||||
public class CustomRarityTest
|
||||
{
|
||||
static final String MOD_ID = "custom_rarity_test";
|
||||
|
||||
@GameRegistry.ObjectHolder("test_item")
|
||||
public static final Item TEST_ITEM = null;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerItem(RegistryEvent.Register<Item> event)
|
||||
{
|
||||
event.getRegistry().register(new TestItem()
|
||||
.setRegistryName(MOD_ID, "test_item")
|
||||
.setUnlocalizedName(MOD_ID + ".test_item")
|
||||
.setCreativeTab(CreativeTabs.MISC)
|
||||
);
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(value = Side.CLIENT, modid = MOD_ID)
|
||||
public static class ClientEventHandler
|
||||
{
|
||||
@SubscribeEvent
|
||||
public static void registerModels(ModelRegistryEvent event)
|
||||
{
|
||||
ModelLoader.setCustomModelResourceLocation(TEST_ITEM, 0, new ModelResourceLocation("minecraft:book#inventory"));
|
||||
}
|
||||
}
|
||||
|
||||
static final class TestItem extends Item
|
||||
{
|
||||
private static final IRarity RARITY = new IRarity()
|
||||
{
|
||||
@Override
|
||||
public TextFormatting getColor()
|
||||
{
|
||||
return TextFormatting.RED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "Test";
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public IRarity getForgeRarity(ItemStack stack)
|
||||
{
|
||||
return RARITY;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user