Update to new forge rarity system

This commit is contained in:
Shadows_of_Fire 2019-05-02 03:08:15 -04:00
parent 1ce4d21159
commit 95a25dbfc4
21 changed files with 466 additions and 225 deletions

View file

@ -24,6 +24,7 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.common.IRarity;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@ -83,7 +84,7 @@ public class BlockCrystal extends BlockBase{
}
@Override
public EnumRarity getRarity(ItemStack stack){
public IRarity getRarity(ItemStack stack) {
return stack.getItemDamage() >= ALL_CRYSTALS.length ? EnumRarity.COMMON : ALL_CRYSTALS[stack.getItemDamage()].rarity;
}

View file

@ -17,6 +17,7 @@ import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.IRarity;
public class BlockBase extends Block implements ItemBlockBase.ICustomRarity, IHasModel{
@ -51,7 +52,7 @@ public class BlockBase extends Block implements ItemBlockBase.ICustomRarity, IHa
}
@Override
public EnumRarity getRarity(ItemStack stack){
public IRarity getRarity(ItemStack stack){
return EnumRarity.COMMON;
}
}

View file

@ -12,9 +12,9 @@ package de.ellpeck.actuallyadditions.mod.blocks.base;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.block.Block;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.IRarity;
public class ItemBlockBase extends ItemBlock {
@ -24,7 +24,6 @@ public class ItemBlockBase extends ItemBlock{
this.setMaxDamage(0);
}
@Override
public String getTranslationKey(ItemStack stack) {
return this.getTranslationKey();
@ -35,20 +34,18 @@ public class ItemBlockBase extends ItemBlock{
return damage;
}
@Override
public EnumRarity getRarity(ItemStack stack){
public IRarity getForgeRarity(ItemStack stack) {
if (this.block instanceof ICustomRarity) {
return ((ICustomRarity) this.block).getRarity(stack);
}
else{
} else {
return Util.FALLBACK_RARITY;
}
}
public interface ICustomRarity {
EnumRarity getRarity(ItemStack stack);
IRarity getRarity(ItemStack stack);
}
}

View file

@ -63,7 +63,7 @@ public class ItemDisplay{
for(int k = 0; k < list.size(); ++k){
if(k == 0){
list.set(k, this.stack.getRarity().color+list.get(k));
list.set(k, this.stack.getItem().getForgeRarity(this.stack).getColor()+list.get(k));
}
else{
list.set(k, TextFormatting.GRAY+list.get(k));

View file

@ -10,9 +10,13 @@
package de.ellpeck.actuallyadditions.mod.booklet.page;
import java.util.Arrays;
import java.util.List;
import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiBooklet;
import de.ellpeck.actuallyadditions.mod.util.RefHelp;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
@ -23,15 +27,11 @@ import net.minecraft.item.crafting.Ingredient;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraftforge.fml.client.config.GuiUtils;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import java.util.Arrays;
import java.util.List;
public class PageCrafting extends BookletPage{
private final List<IRecipe> recipes;
@ -152,8 +152,8 @@ public class PageCrafting extends BookletPage{
else if(recipe instanceof ShapedOreRecipe){
ShapedOreRecipe shaped = (ShapedOreRecipe)recipe;
try{
width = ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, shaped, 4);
height = ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, shaped, 5);
width = RefHelp.getPrivateValue(ShapedOreRecipe.class, shaped, 4);
height = RefHelp.getPrivateValue(ShapedOreRecipe.class, shaped, 5);
}
catch(Exception e){
ActuallyAdditions.LOGGER.error("Something went wrong trying to get the Crafting Recipe in the booklet to display!", e);

View file

@ -10,6 +10,11 @@
package de.ellpeck.actuallyadditions.mod.items;
import java.util.HashSet;
import java.util.Set;
import com.google.common.collect.Sets;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues;
import de.ellpeck.actuallyadditions.mod.items.base.ItemToolAA;
@ -22,7 +27,6 @@ import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
@ -30,19 +34,15 @@ import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.IRarity;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.HashSet;
import java.util.Set;
import com.google.common.collect.Sets;
public class ItemAllToolAA extends ItemToolAA implements IColorProvidingItem {
public final int color;
public ItemAllToolAA(ToolMaterial toolMat, String repairItem, String unlocalizedName, EnumRarity rarity, int color){
public ItemAllToolAA(ToolMaterial toolMat, String repairItem, String unlocalizedName, IRarity rarity, int color) {
super(4.0F, -2F, toolMat, repairItem, unlocalizedName, rarity, new HashSet<>());
this.color = color;
@ -50,7 +50,7 @@ public class ItemAllToolAA extends ItemToolAA implements IColorProvidingItem{
this.setHarvestLevels(toolMat.getHarvestLevel());
}
public ItemAllToolAA(ToolMaterial toolMat, ItemStack repairItem, String unlocalizedName, EnumRarity rarity, int color){
public ItemAllToolAA(ToolMaterial toolMat, ItemStack repairItem, String unlocalizedName, IRarity rarity, int color) {
super(4.0F, -2F, toolMat, repairItem, unlocalizedName, rarity, new HashSet<>());
this.color = color;
@ -69,7 +69,6 @@ public class ItemAllToolAA extends ItemToolAA implements IColorProvidingItem{
ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this), new ResourceLocation(ActuallyAdditions.MODID, "item_paxel"), "inventory");
}
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!playerIn.isSneaking()) return Items.IRON_HOE.onItemUse(playerIn, worldIn, pos, hand, side, hitX, hitY, hitZ);
@ -84,14 +83,11 @@ public class ItemAllToolAA extends ItemToolAA implements IColorProvidingItem{
private boolean hasExtraWhitelist(Block block) {
String name = block.getRegistryName().toString();
for (String list : ConfigStringListValues.PAXEL_EXTRA_MINING_WHITELIST.getValue()) {
if(list.equals(name)){
return true;
}
if (list.equals(name)) { return true; }
}
return false;
}
@Override
public Set<String> getToolClasses(ItemStack stack) {
return Sets.newHashSet("pickaxe", "axe", "shovel");
@ -101,8 +97,7 @@ public class ItemAllToolAA extends ItemToolAA implements IColorProvidingItem{
public float getDestroySpeed(ItemStack stack, IBlockState state) {
if (state.getBlock() == Blocks.WEB) {
return 15.0F;
}
else{
} else {
return this.hasExtraWhitelist(state.getBlock()) || state.getBlock().getHarvestTool(state) == null || state.getBlock().getHarvestTool(state).isEmpty() || this.getToolClasses(stack).contains(state.getBlock().getHarvestTool(state)) ? this.efficiency : 1.0F;
}
}

View file

@ -10,29 +10,30 @@
package de.ellpeck.actuallyadditions.mod.items;
import java.util.Collections;
import java.util.Set;
import com.google.common.collect.Sets;
import de.ellpeck.actuallyadditions.mod.items.base.ItemToolAA;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import java.util.Collections;
import java.util.Set;
import net.minecraftforge.common.IRarity;
public class ItemAxeAA extends ItemToolAA{
private static final Set<Block> EFFECTIVE_ON = Sets.newHashSet(Blocks.PLANKS, Blocks.BOOKSHELF, Blocks.LOG, Blocks.LOG2, Blocks.CHEST, Blocks.PUMPKIN, Blocks.LIT_PUMPKIN, Blocks.MELON_BLOCK, Blocks.LADDER, Blocks.WOODEN_BUTTON, Blocks.WOODEN_PRESSURE_PLATE);
public ItemAxeAA(Item.ToolMaterial material, String repairItem, String unlocalizedName, EnumRarity rarity){
public ItemAxeAA(Item.ToolMaterial material, String repairItem, String unlocalizedName, IRarity rarity){
super(6.0F, -3.0F, material, repairItem, unlocalizedName, rarity, EFFECTIVE_ON);
this.setHarvestLevel("axe", material.getHarvestLevel());
}
public ItemAxeAA(Item.ToolMaterial material, ItemStack repairItem, String unlocalizedName, EnumRarity rarity){
public ItemAxeAA(Item.ToolMaterial material, ItemStack repairItem, String unlocalizedName, IRarity rarity){
super(6.0F, -3.0F, material, repairItem, unlocalizedName, rarity, EFFECTIVE_ON);
this.setHarvestLevel("axe", material.getHarvestLevel());
}

View file

@ -19,6 +19,7 @@ import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.IRarity;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@ -48,9 +49,8 @@ public class ItemCrystal extends ItemBase{
return stack.getItemDamage() >= BlockCrystal.ALL_CRYSTALS.length ? StringUtil.BUGGED_ITEM_NAME : this.getTranslationKey() + "_" + BlockCrystal.ALL_CRYSTALS[stack.getItemDamage()].name;
}
@Override
public EnumRarity getRarity(ItemStack stack){
public IRarity getForgeRarity(ItemStack stack) {
return stack.getItemDamage() >= BlockCrystal.ALL_CRYSTALS.length ? EnumRarity.COMMON : BlockCrystal.ALL_CRYSTALS[stack.getItemDamage()].rarity;
}

View file

@ -20,6 +20,7 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.common.IRarity;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@ -43,7 +44,7 @@ public class ItemCrystalShard extends ItemBase implements IColorProvidingItem{
@Override
public EnumRarity getRarity(ItemStack stack){
public IRarity getForgeRarity(ItemStack stack) {
return stack.getItemDamage() >= BlockCrystal.ALL_CRYSTALS.length ? EnumRarity.COMMON : BlockCrystal.ALL_CRYSTALS[stack.getItemDamage()].rarity;
}

View file

@ -24,6 +24,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.IRarity;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.fml.relauncher.Side;
@ -50,7 +51,7 @@ public class ItemMisc extends ItemBase{
@Override
public EnumRarity getRarity(ItemStack stack){
public IRarity getForgeRarity(ItemStack stack){
return stack.getItemDamage() >= ALL_MISC_ITEMS.length ? EnumRarity.COMMON : ALL_MISC_ITEMS[stack.getItemDamage()].rarity;
}

View file

@ -10,29 +10,30 @@
package de.ellpeck.actuallyadditions.mod.items;
import java.util.Collections;
import java.util.Set;
import com.google.common.collect.Sets;
import de.ellpeck.actuallyadditions.mod.items.base.ItemToolAA;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import java.util.Collections;
import java.util.Set;
import net.minecraftforge.common.IRarity;
public class ItemPickaxeAA extends ItemToolAA {
private static final Set<Block> EFFECTIVE_ON = Sets.newHashSet(Blocks.ACTIVATOR_RAIL, Blocks.COAL_ORE, Blocks.COBBLESTONE, Blocks.DETECTOR_RAIL, Blocks.DIAMOND_BLOCK, Blocks.DIAMOND_ORE, Blocks.DOUBLE_STONE_SLAB, Blocks.GOLDEN_RAIL, Blocks.GOLD_BLOCK, Blocks.GOLD_ORE, Blocks.ICE, Blocks.IRON_BLOCK, Blocks.IRON_ORE, Blocks.LAPIS_BLOCK, Blocks.LAPIS_ORE, Blocks.LIT_REDSTONE_ORE, Blocks.MOSSY_COBBLESTONE, Blocks.NETHERRACK, Blocks.PACKED_ICE, Blocks.RAIL, Blocks.REDSTONE_ORE, Blocks.SANDSTONE, Blocks.RED_SANDSTONE, Blocks.STONE, Blocks.STONE_SLAB, Blocks.STONE_BUTTON, Blocks.STONE_PRESSURE_PLATE);
public ItemPickaxeAA(Item.ToolMaterial material, String repairItem, String unlocalizedName, EnumRarity rarity){
public ItemPickaxeAA(Item.ToolMaterial material, String repairItem, String unlocalizedName, IRarity rarity) {
super(1.0F, -2.8F, material, repairItem, unlocalizedName, rarity, EFFECTIVE_ON);
this.setHarvestLevel("pickaxe", material.getHarvestLevel());
}
public ItemPickaxeAA(Item.ToolMaterial material, ItemStack repairItem, String unlocalizedName, EnumRarity rarity){
public ItemPickaxeAA(Item.ToolMaterial material, ItemStack repairItem, String unlocalizedName, IRarity rarity) {
super(1.0F, -2.8F, material, repairItem, unlocalizedName, rarity, EFFECTIVE_ON);
this.setHarvestLevel("pickaxe", material.getHarvestLevel());
}
@ -43,8 +44,7 @@ public class ItemPickaxeAA extends ItemToolAA{
if (block == Blocks.OBSIDIAN) {
return this.toolMaterial.getHarvestLevel() == 3;
}
else if(block != Blocks.DIAMOND_BLOCK && block != Blocks.DIAMOND_ORE){
} else if (block != Blocks.DIAMOND_BLOCK && block != Blocks.DIAMOND_ORE) {
if (block != Blocks.EMERALD_ORE && block != Blocks.EMERALD_BLOCK) {
if (block != Blocks.GOLD_BLOCK && block != Blocks.GOLD_ORE) {
if (block != Blocks.IRON_BLOCK && block != Blocks.IRON_ORE) {
@ -52,28 +52,22 @@ public class ItemPickaxeAA extends ItemToolAA{
if (block != Blocks.REDSTONE_ORE && block != Blocks.LIT_REDSTONE_ORE) {
Material material = blockIn.getMaterial();
return material == Material.ROCK || material == Material.IRON || material == Material.ANVIL;
}
else{
} else {
return this.toolMaterial.getHarvestLevel() >= 2;
}
}
else{
} else {
return this.toolMaterial.getHarvestLevel() >= 1;
}
}
else{
} else {
return this.toolMaterial.getHarvestLevel() >= 1;
}
}
else{
} else {
return this.toolMaterial.getHarvestLevel() >= 2;
}
}
else{
} else {
return this.toolMaterial.getHarvestLevel() >= 2;
}
}
else{
} else {
return this.toolMaterial.getHarvestLevel() >= 2;
}
}

View file

@ -10,14 +10,17 @@
package de.ellpeck.actuallyadditions.mod.items;
import java.util.Collections;
import java.util.Set;
import com.google.common.collect.Sets;
import de.ellpeck.actuallyadditions.mod.items.base.ItemToolAA;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
@ -25,20 +28,18 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.Collections;
import java.util.Set;
import net.minecraftforge.common.IRarity;
public class ItemShovelAA extends ItemToolAA {
private static final Set<Block> EFFECTIVE_ON = Sets.newHashSet(Blocks.CLAY, Blocks.DIRT, Blocks.FARMLAND, Blocks.GRASS, Blocks.GRAVEL, Blocks.MYCELIUM, Blocks.SAND, Blocks.SNOW, Blocks.SNOW_LAYER, Blocks.SOUL_SAND, Blocks.GRASS_PATH);
public ItemShovelAA(Item.ToolMaterial material, String repairItem, String unlocalizedName, EnumRarity rarity){
public ItemShovelAA(Item.ToolMaterial material, String repairItem, String unlocalizedName, IRarity rarity) {
super(1.5F, -3.0F, material, repairItem, unlocalizedName, rarity, EFFECTIVE_ON);
this.setHarvestLevel("shovel", material.getHarvestLevel());
}
public ItemShovelAA(Item.ToolMaterial material, ItemStack repairItem, String unlocalizedName, EnumRarity rarity){
public ItemShovelAA(Item.ToolMaterial material, ItemStack repairItem, String unlocalizedName, IRarity rarity) {
super(1.5F, -3.0F, material, repairItem, unlocalizedName, rarity, EFFECTIVE_ON);
this.setHarvestLevel("shovel", material.getHarvestLevel());
}
@ -49,7 +50,6 @@ public class ItemShovelAA extends ItemToolAA{
return block == Blocks.SNOW_LAYER || block == Blocks.SNOW;
}
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
return Items.IRON_SHOVEL.onItemUse(playerIn, worldIn, pos, hand, facing, hitX, hitY, hitZ);

View file

@ -20,19 +20,20 @@ import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.IRarity;
public class ItemArmorAA extends ItemArmor implements IDisableableItem {
private final ItemStack repairItem;
private final String name;
private final EnumRarity rarity;
private final IRarity rarity;
private final boolean disabled;
public ItemArmorAA(String name, ArmorMaterial material, int type, ItemStack repairItem) {
this(name, material, type, repairItem, EnumRarity.RARE);
}
public ItemArmorAA(String name, ArmorMaterial material, int type, ItemStack repairItem, EnumRarity rarity){
public ItemArmorAA(String name, ArmorMaterial material, int type, ItemStack repairItem, IRarity rarity) {
super(material, 0, ContainerEnergizer.VALID_EQUIPMENT_SLOTS[type]);
this.repairItem = repairItem;
this.name = name;
@ -60,7 +61,7 @@ public class ItemArmorAA extends ItemArmor implements IDisableableItem{
}
@Override
public EnumRarity getRarity(ItemStack stack){
public IRarity getForgeRarity(ItemStack stack) {
return this.rarity;
}

View file

@ -15,19 +15,19 @@ import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.config.ConfigurationHandler;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.IRarity;
public class ItemHoeAA extends ItemHoe implements IDisableableItem {
private final String name;
private final EnumRarity rarity;
private final IRarity rarity;
private final ItemStack repairItem;
private final boolean disabled;
public ItemHoeAA(Item.ToolMaterial toolMat, ItemStack repairItem, String unlocalizedName, EnumRarity rarity){
public ItemHoeAA(Item.ToolMaterial toolMat, ItemStack repairItem, String unlocalizedName, IRarity rarity) {
super(toolMat);
this.repairItem = repairItem;
@ -56,9 +56,8 @@ public class ItemHoeAA extends ItemHoe implements IDisableableItem {
ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this), this.getRegistryName(), "inventory");
}
@Override
public EnumRarity getRarity(ItemStack stack){
public IRarity getForgeRarity(ItemStack stack) {
return this.rarity;
}

View file

@ -16,18 +16,18 @@ import de.ellpeck.actuallyadditions.mod.blocks.base.ItemBlockBase;
import de.ellpeck.actuallyadditions.mod.config.ConfigurationHandler;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraftforge.common.IRarity;
public class ItemSwordAA extends ItemSword implements IDisableableItem {
private final String name;
private final EnumRarity rarity;
private final IRarity rarity;
private final ItemStack repairItem;
private final boolean disabled;
public ItemSwordAA(ToolMaterial toolMat, ItemStack repairItem, String unlocalizedName, EnumRarity rarity){
public ItemSwordAA(ToolMaterial toolMat, ItemStack repairItem, String unlocalizedName, IRarity rarity) {
super(toolMat);
this.repairItem = repairItem;
@ -65,9 +65,8 @@ public class ItemSwordAA extends ItemSword implements IDisableableItem {
return ItemUtil.areItemsEqual(this.repairItem, stack, false);
}
@Override
public EnumRarity getRarity(ItemStack stack){
public IRarity getForgeRarity(ItemStack stack) {
return this.rarity;
}

View file

@ -10,6 +10,8 @@
package de.ellpeck.actuallyadditions.mod.items.base;
import java.util.Set;
import de.ellpeck.actuallyadditions.api.misc.IDisableableItem;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.config.ConfigurationHandler;
@ -17,27 +19,25 @@ import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.block.Block;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraftforge.common.IRarity;
import net.minecraftforge.oredict.OreDictionary;
import java.util.Set;
public class ItemToolAA extends ItemTool implements IDisableableItem {
private final String name;
private final EnumRarity rarity;
private final IRarity rarity;
private final ItemStack repairItem;
private String repairOredict;
private final boolean disabled;
public ItemToolAA(float attack, float speed, ToolMaterial toolMat, String repairItem, String unlocalizedName, EnumRarity rarity, Set<Block> effectiveStuff){
public ItemToolAA(float attack, float speed, ToolMaterial toolMat, String repairItem, String unlocalizedName, IRarity rarity, Set<Block> effectiveStuff) {
this(attack, speed, toolMat, ItemStack.EMPTY, unlocalizedName, rarity, effectiveStuff);
this.repairOredict = repairItem;
}
public ItemToolAA(float attack, float speed, ToolMaterial toolMat, ItemStack repairItem, String unlocalizedName, EnumRarity rarity, Set<Block> effectiveStuff){
public ItemToolAA(float attack, float speed, ToolMaterial toolMat, ItemStack repairItem, String unlocalizedName, IRarity rarity, Set<Block> effectiveStuff) {
super(attack, speed, toolMat, effectiveStuff);
this.repairItem = repairItem;
@ -65,9 +65,8 @@ public class ItemToolAA extends ItemTool implements IDisableableItem{
ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this), this.getRegistryName(), "inventory");
}
@Override
public EnumRarity getRarity(ItemStack stack){
public IRarity getForgeRarity(ItemStack stack) {
return this.rarity;
}
@ -75,13 +74,10 @@ public class ItemToolAA extends ItemTool implements IDisableableItem{
public boolean getIsRepairable(ItemStack itemToRepair, ItemStack stack) {
if (StackUtil.isValid(this.repairItem)) {
return ItemUtil.areItemsEqual(this.repairItem, stack, false);
}
else if(this.repairOredict != null){
} else if (this.repairOredict != null) {
int[] idsStack = OreDictionary.getOreIDs(stack);
for (int id : idsStack) {
if(OreDictionary.getOreName(id).equals(this.repairOredict)){
return true;
}
if (OreDictionary.getOreName(id).equals(this.repairOredict)) { return true; }
}
}
return false;

View file

@ -11,8 +11,8 @@
package de.ellpeck.actuallyadditions.mod.items.metalists;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.item.EnumRarity;
import net.minecraft.util.IStringSerializable;
import net.minecraftforge.common.IRarity;
public enum TheCrystals implements IStringSerializable {
@ -24,11 +24,11 @@ public enum TheCrystals implements IStringSerializable{
IRON("white", Util.CRYSTAL_WHITE_RARITY, 0xCEDDD4, 0.8F, 0.8F, 0.8F);
public final String name;
public final EnumRarity rarity;
public final IRarity rarity;
public final float[] conversionColorParticles;
public final int clusterColor;
TheCrystals(String name, EnumRarity rarity, int clusterColor, float... conversionColorParticles){
TheCrystals(String name, IRarity rarity, int clusterColor, float... conversionColorParticles) {
this.name = name;
this.rarity = rarity;
this.conversionColorParticles = conversionColorParticles;

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.items.metalists;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.item.EnumRarity;
import net.minecraftforge.common.IRarity;
public enum TheMiscItems {
@ -43,9 +44,9 @@ public enum TheMiscItems{
YOUTUBE_ICON("youtube_icon", Util.FALLBACK_RARITY);
public final String name;
public final EnumRarity rarity;
public final IRarity rarity;
TheMiscItems(String name, EnumRarity rarity){
TheMiscItems(String name, IRarity rarity) {
this.name = name;
this.rarity = rarity;
}

View file

@ -0,0 +1,26 @@
package de.ellpeck.actuallyadditions.mod.util;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.common.IRarity;
public class Rarity implements IRarity {
TextFormatting color;
String name;
public Rarity(TextFormatting color, String name) {
this.color = color;
this.name = name;
}
@Override
public TextFormatting getColor() {
return color;
}
@Override
public String getName() {
return name;
}
}

View file

@ -0,0 +1,231 @@
package de.ellpeck.actuallyadditions.mod.util;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.StringJoiner;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.commons.lang3.StringUtils;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import net.minecraftforge.fml.relauncher.FMLLaunchHandler;
public class RefHelp {
public static class UnableToFindMethodException extends RuntimeException {
private static final long serialVersionUID = 1L;
public UnableToFindMethodException(String[] methodNames, Exception failed) {
super(failed);
}
public UnableToFindMethodException(Throwable failed) {
super(failed);
}
}
public static class UnableToFindClassException extends RuntimeException {
private static final long serialVersionUID = 1L;
public UnableToFindClassException(String[] classNames, @Nullable Exception err) {
super(err);
}
}
public static class UnableToAccessFieldException extends RuntimeException {
private static final long serialVersionUID = 1L;
public UnableToAccessFieldException(String[] fieldNames, Exception e) {
super(e);
}
public UnableToAccessFieldException(Exception e) {
super(e);
}
}
public static class UnableToFindFieldException extends RuntimeException {
private static final long serialVersionUID = 1L;
public UnableToFindFieldException(String[] fieldNameList, Exception e) {
super(e);
}
public UnableToFindFieldException(Exception e) {
super(e);
}
}
public static class UnknownConstructorException extends RuntimeException {
public UnknownConstructorException(final String message) {
super(message);
}
}
public static Field findField(Class<?> clazz, String... fieldNames) {
Exception failed = null;
for (String fieldName : fieldNames) {
try {
Field f = clazz.getDeclaredField(fieldName);
f.setAccessible(true);
return f;
} catch (Exception e) {
failed = e;
}
}
throw new UnableToFindFieldException(fieldNames, failed);
}
@Nonnull
public static Field findField(@Nonnull Class<?> clazz, @Nonnull String fieldName, @Nullable String fieldObfName) {
Preconditions.checkNotNull(clazz);
Preconditions.checkArgument(StringUtils.isNotEmpty(fieldName), "Field name cannot be empty");
String nameToFind = FMLLaunchHandler.isDeobfuscatedEnvironment() ? fieldName : MoreObjects.firstNonNull(fieldObfName, fieldName);
try {
Field f = clazz.getDeclaredField(nameToFind);
f.setAccessible(true);
return f;
} catch (Exception e) {
throw new UnableToFindFieldException(e);
}
}
@SuppressWarnings("unchecked")
public static <T, E> T getPrivateValue(Class<? super E> classToAccess, @Nullable E instance, int fieldIndex) {
try {
Field f = classToAccess.getDeclaredFields()[fieldIndex];
f.setAccessible(true);
return (T) f.get(instance);
} catch (Exception e) {
throw new UnableToAccessFieldException(e);
}
}
@SuppressWarnings("unchecked")
public static <T, E> T getPrivateValue(Class<? super E> classToAccess, E instance, String... fieldNames) {
try {
return (T) findField(classToAccess, fieldNames).get(instance);
} catch (Exception e) {
throw new UnableToAccessFieldException(fieldNames, e);
}
}
@SuppressWarnings("unchecked")
public static <T, E> T getPrivateValue(Class<? super E> classToAccess, @Nullable E instance, String fieldName, @Nullable String fieldObfName) {
try {
return (T) findField(classToAccess, fieldName, fieldObfName).get(instance);
} catch (Exception e) {
throw new UnableToAccessFieldException(e);
}
}
public static <T, E> void setPrivateValue(Class<? super T> classToAccess, T instance, E value, int fieldIndex) {
try {
Field f = classToAccess.getDeclaredFields()[fieldIndex];
f.setAccessible(true);
f.set(instance, value);
} catch (Exception e) {
throw new UnableToAccessFieldException(e);
}
}
public static <T, E> void setPrivateValue(Class<? super T> classToAccess, T instance, E value, String... fieldNames) {
try {
findField(classToAccess, fieldNames).set(instance, value);
} catch (Exception e) {
throw new UnableToAccessFieldException(fieldNames, e);
}
}
public static <T, E> void setPrivateValue(Class<? super T> classToAccess, @Nullable T instance, @Nullable E value, String fieldName, @Nullable String fieldObfName) {
try {
findField(classToAccess, fieldName, fieldObfName).set(instance, value);
} catch (Exception e) {
throw new UnableToAccessFieldException(e);
}
}
@SuppressWarnings("unchecked")
public static Class<? super Object> getClass(ClassLoader loader, String... classNames) {
Exception err = null;
for (String className : classNames) {
try {
return (Class<? super Object>) Class.forName(className, false, loader);
} catch (Exception e) {
err = e;
}
}
throw new UnableToFindClassException(classNames, err);
}
/**
* Finds a method with the specified name and parameters in the given class and makes it accessible.
* Note: for performance, store the returned value and avoid calling this repeatedly.
* <p>
* Throws an exception if the method is not found.
*
* @param clazz The class to find the method on.
* @param methodName The name of the method to find (used in developer environments, i.e. "getWorldTime").
* @param methodObfName The obfuscated name of the method to find (used in obfuscated environments, i.e. "getWorldTime").
* If the name you are looking for is on a class that is never obfuscated, this should be null.
* @param parameterTypes The parameter types of the method to find.
* @return The method with the specified name and parameters in the given class.
*/
@Nonnull
public static Method findMethod(@Nonnull Class<?> clazz, @Nonnull String methodName, @Nullable String methodObfName, Class<?>... parameterTypes) {
Preconditions.checkNotNull(clazz);
Preconditions.checkArgument(StringUtils.isNotEmpty(methodName), "Method name cannot be empty");
String nameToFind = FMLLaunchHandler.isDeobfuscatedEnvironment() ? methodName : MoreObjects.firstNonNull(methodObfName, methodName);
try {
Method m = clazz.getDeclaredMethod(nameToFind, parameterTypes);
m.setAccessible(true);
return m;
} catch (Exception e) {
throw new UnableToFindMethodException(e);
}
}
/**
* Finds a constructor in the specified class that has matching parameter types.
*
* @param klass The class to find the constructor in
* @param parameterTypes The parameter types of the constructor.
* @param <T> The type
* @return The constructor
* @throws NullPointerException if {@code klass} is null
* @throws NullPointerException if {@code parameterTypes} is null
* @throws UnknownConstructorException if the constructor could not be found
*/
@Nonnull
public static <T> Constructor<T> findConstructor(@Nonnull final Class<T> klass, @Nonnull final Class<?>... parameterTypes) {
Preconditions.checkNotNull(klass, "class");
Preconditions.checkNotNull(parameterTypes, "parameter types");
try {
Constructor<T> constructor = klass.getDeclaredConstructor(parameterTypes);
constructor.setAccessible(true);
return constructor;
} catch (final NoSuchMethodException e) {
final StringBuilder desc = new StringBuilder();
desc.append(klass.getSimpleName());
StringJoiner joiner = new StringJoiner(", ", "(", ")");
for (Class<?> type : parameterTypes) {
joiner.add(type.getSimpleName());
}
desc.append(joiner);
throw new UnknownConstructorException("Could not find constructor '" + desc.toString() + "' in " + klass);
}
}
}

View file

@ -10,12 +10,9 @@
package de.ellpeck.actuallyadditions.mod.util;
import java.util.Locale;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import net.minecraft.item.EnumRarity;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.common.IRarity;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.oredict.OreDictionary;
@ -25,17 +22,17 @@ public final class Util{
public static final int WILDCARD = OreDictionary.WILDCARD_VALUE;
public static final int BUCKET = Fluid.BUCKET_VOLUME;
public static final EnumRarity CRYSTAL_RED_RARITY = addRarity("crystalRed", TextFormatting.DARK_RED, ActuallyAdditions.NAME+" Red Crystal");
public static final EnumRarity CRYSTAL_BLUE_RARITY = addRarity("crystalBlue", TextFormatting.DARK_BLUE, ActuallyAdditions.NAME+" Blue Crystal");
public static final EnumRarity CRYSTAL_LIGHT_BLUE_RARITY = addRarity("crystalLightBlue", TextFormatting.BLUE, ActuallyAdditions.NAME+" Light Blue Crystal");
public static final EnumRarity CRYSTAL_BLACK_RARITY = addRarity("crystalBlack", TextFormatting.DARK_GRAY, ActuallyAdditions.NAME+" Black Crystal");
public static final EnumRarity CRYSTAL_GREEN_RARITY = addRarity("crystalGreen", TextFormatting.DARK_GREEN, ActuallyAdditions.NAME+" Green Crystal");
public static final EnumRarity CRYSTAL_WHITE_RARITY = addRarity("crystalWhite", TextFormatting.GRAY, ActuallyAdditions.NAME+" White Crystal");
public static final IRarity CRYSTAL_RED_RARITY = addRarity("crystalRed", TextFormatting.DARK_RED, ActuallyAdditions.NAME + " Red Crystal");
public static final IRarity CRYSTAL_BLUE_RARITY = addRarity("crystalBlue", TextFormatting.DARK_BLUE, ActuallyAdditions.NAME + " Blue Crystal");
public static final IRarity CRYSTAL_LIGHT_BLUE_RARITY = addRarity("crystalLightBlue", TextFormatting.BLUE, ActuallyAdditions.NAME + " Light Blue Crystal");
public static final IRarity CRYSTAL_BLACK_RARITY = addRarity("crystalBlack", TextFormatting.DARK_GRAY, ActuallyAdditions.NAME + " Black Crystal");
public static final IRarity CRYSTAL_GREEN_RARITY = addRarity("crystalGreen", TextFormatting.DARK_GREEN, ActuallyAdditions.NAME + " Green Crystal");
public static final IRarity CRYSTAL_WHITE_RARITY = addRarity("crystalWhite", TextFormatting.GRAY, ActuallyAdditions.NAME + " White Crystal");
public static final EnumRarity FALLBACK_RARITY = addRarity("fallback", TextFormatting.STRIKETHROUGH, ActuallyAdditions.NAME+" Fallback");
public static final IRarity FALLBACK_RARITY = addRarity("fallback", TextFormatting.STRIKETHROUGH, ActuallyAdditions.NAME + " Fallback");
private static EnumRarity addRarity(String name, TextFormatting color, String displayName){
return EnumHelper.addRarity((ActuallyAdditions.MODID+"_"+name).toUpperCase(Locale.ROOT), color, displayName);
private static IRarity addRarity(String name, TextFormatting color, String displayName) {
return new Rarity(color, displayName);
}
public static boolean isDevVersion() {