forked from MinecraftForge/MinecraftForge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalise EnumRarity to an interface (MinecraftForge#5182)
- Loading branch information
1 parent
e6fbf39
commit cc95c40
Showing
8 changed files
with
209 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
patches/minecraft/net/minecraft/item/EnumRarity.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
+ } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/test/java/net/minecraftforge/debug/item/CustomRarityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |