Added rarity generalization

This commit is contained in:
Unknown 2019-04-11 16:28:58 +02:00 committed by unknown
parent c2669e7fd7
commit f23c08bbed
13 changed files with 70 additions and 51 deletions

View file

@ -2,19 +2,21 @@ package cr0s.warpdrive.api;
import cr0s.warpdrive.data.EnumTier;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraftforge.common.IRarity;
public interface IBlockBase {
@Nonnull
EnumTier getTier(final ItemStack itemStack);
EnumRarity getRarity(final ItemStack itemStack);
@Nonnull
IRarity getForgeRarity(final ItemStack itemStack);
@Nullable
ItemBlock createItemBlock();

View file

@ -18,7 +18,7 @@ public interface IItemBase {
@Nonnull
EnumTier getTier(final ItemStack itemStack);
// getRarity is defined in Item
// getForgeRarity is defined in Item
@SideOnly(Side.CLIENT)
void modelInitialisation();

View file

@ -4,12 +4,14 @@ import cr0s.warpdrive.Commons;
import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.data.Vector3;
import javax.annotation.Nonnull;
import java.util.Locale;
import net.minecraft.item.EnumRarity;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.common.IRarity;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@ -20,7 +22,7 @@ public class Particle {
protected int color;
protected int colorIndex;
protected EnumRarity enumRarity = EnumRarity.COMMON;
protected IRarity rarity = EnumRarity.COMMON;
private int entityLifespan;
private float radiationLevel = 0.0F;
private float explosionStrength = 0.0F;
@ -29,8 +31,8 @@ public class Particle {
this.registryName = registryName.toLowerCase(Locale.ENGLISH);
}
public Particle setRarity(final EnumRarity enumRarity) {
this.enumRarity = enumRarity;
public Particle setRarity(@Nonnull final IRarity rarity) {
this.rarity = rarity;
return this;
}
@ -40,7 +42,7 @@ public class Particle {
}
public Particle setColor(final int colorIndex) {
this.color = Commons.clamp(0x000000, 0xFFFFFF, color);
this.color = Commons.clamp(0x000000, 0xFFFFFF, colorIndex);
return this;
}
@ -88,18 +90,16 @@ public class Particle {
/* Default Accessors */
public EnumRarity getRarity()
{
return enumRarity;
@Nonnull
public IRarity getForgeRarity() {
return rarity;
}
public int getColorIndex()
{
public int getColorIndex() {
return colorIndex;
}
public int getColor()
{
public int getColor() {
return color;
}
@ -132,7 +132,7 @@ public class Particle {
public String toString() {
return String.format("Particle %s (%s, RGB 0x%x %d, %d ticks, %.3f Sv, strength %.3f)",
registryName,
enumRarity,
rarity,
color, colorIndex,
entityLifespan,
radiationLevel,

View file

@ -15,6 +15,7 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.IRarity;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@ -25,7 +26,6 @@ import cr0s.warpdrive.data.BlockProperties;
import cr0s.warpdrive.data.EnumTier;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
@ -111,8 +111,9 @@ public abstract class BlockAbstractBase extends Block implements IBlockBase {
return enumTier;
}
@Nonnull
@Override
public EnumRarity getRarity(final ItemStack itemStack) {
return getTier(itemStack).getRarity();
public IRarity getForgeRarity(@Nonnull final ItemStack itemStack) {
return getTier(itemStack).getForgeRarity();
}
}

View file

@ -27,13 +27,14 @@ import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraftforge.common.IRarity;
import net.minecraftforge.fml.common.Optional;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@ -278,9 +279,10 @@ public abstract class BlockAbstractContainer extends BlockContainer implements I
return enumTier;
}
@Nonnull
@Override
public EnumRarity getRarity(final ItemStack itemStack) {
return getTier(itemStack).getRarity();
public IRarity getForgeRarity(@Nonnull final ItemStack itemStack) {
return getTier(itemStack).getForgeRarity();
}
@Override

View file

@ -29,6 +29,7 @@ import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.common.IRarity;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@ -74,13 +75,17 @@ public class ItemBlockAbstractBase extends ItemBlock implements IItemBase {
@Nonnull
@Override
public EnumRarity getRarity(@Nonnull final ItemStack itemStack) {
final EnumRarity enumRarityDefault = super.getRarity(itemStack);
public IRarity getForgeRarity(@Nonnull final ItemStack itemStack) {
final IRarity rarityDefault = super.getForgeRarity(itemStack);
if ( !(block instanceof IBlockBase) ) {
return enumRarityDefault;
return rarityDefault;
}
final EnumRarity enumRarityStack = ((IBlockBase) block).getRarity(itemStack);
return enumRarityStack.ordinal() > enumRarityDefault.ordinal() ? enumRarityStack : enumRarityDefault;
final IRarity rarityItemStack = ((IBlockBase) block).getForgeRarity(itemStack);
if ( rarityItemStack instanceof EnumRarity
&& rarityDefault instanceof EnumRarity ) {
return ((EnumRarity) rarityItemStack).ordinal() > ((EnumRarity) rarityDefault).ordinal() ? rarityItemStack : rarityDefault;
}
return rarityItemStack;
}
public ITextComponent getStatus(final World world, @Nonnull final ItemStack itemStack) {
@ -115,7 +120,6 @@ public class ItemBlockAbstractBase extends ItemBlock implements IItemBase {
return ClientProxy.getModelResourceLocation(itemStack);
}
@SuppressWarnings("deprecation")
@Override
@SideOnly(Side.CLIENT)
public void addInformation(@Nonnull final ItemStack itemStack, @Nullable final World world,

View file

@ -16,7 +16,6 @@ import net.minecraft.block.BlockGlass;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.EnumPushReaction;
import net.minecraft.block.material.Material;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
@ -28,6 +27,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.IRarity;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@ -69,9 +69,10 @@ public class BlockHullGlass extends BlockColored implements IBlockBase, IDamageR
return enumTier;
}
@Nonnull
@Override
public EnumRarity getRarity(final ItemStack itemStack) {
return getTier(itemStack).getRarity();
public IRarity getForgeRarity(@Nonnull final ItemStack itemStack) {
return getTier(itemStack).getForgeRarity();
}
@Nullable

View file

@ -25,7 +25,6 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
@ -39,6 +38,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.IRarity;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@ -173,7 +173,7 @@ public class BlockHullSlab extends BlockSlab implements IBlockBase, IDamageRecei
@SuppressWarnings("deprecation")
@Override
public boolean isFullBlock(IBlockState blockState) {
public boolean isFullBlock(final IBlockState blockState) {
return ((BlockSlab) blockState.getBlock()).isDouble();
}
@ -301,9 +301,10 @@ public class BlockHullSlab extends BlockSlab implements IBlockBase, IDamageRecei
return enumTier;
}
@Nonnull
@Override
public EnumRarity getRarity(final ItemStack itemStack) {
return enumTier.getRarity();
public IRarity getForgeRarity(@Nonnull final ItemStack itemStack) {
return enumTier.getForgeRarity();
}
@Nullable

View file

@ -15,7 +15,6 @@ import net.minecraft.block.BlockStairs;
import net.minecraft.block.material.EnumPushReaction;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
@ -23,6 +22,7 @@ import net.minecraft.util.DamageSource;
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;
@ -55,9 +55,10 @@ public class BlockHullStairs extends BlockStairs implements IBlockBase, IDamageR
return enumTier;
}
@Nonnull
@Override
public EnumRarity getRarity(final ItemStack itemStack) {
return enumTier.getRarity();
public IRarity getForgeRarity(@Nonnull final ItemStack itemStack) {
return enumTier.getForgeRarity();
}
@Nullable

View file

@ -3,9 +3,10 @@ package cr0s.warpdrive.data;
import javax.annotation.Nonnull;
import java.util.HashMap;
import net.minecraft.item.EnumRarity;
import net.minecraft.util.IStringSerializable;
import net.minecraftforge.common.IRarity;
public enum EnumAirTankTier implements IStringSerializable {
CANISTER ("canister", 0, EnumTier.BASIC ),
@ -53,7 +54,8 @@ public enum EnumAirTankTier implements IStringSerializable {
return enumTier;
}
public EnumRarity getRarity() {
return enumTier.getRarity();
@Nonnull
public IRarity getForgeRarity() {
return enumTier.getForgeRarity();
}
}

View file

@ -7,6 +7,8 @@ import java.util.HashMap;
import net.minecraft.item.EnumRarity;
import net.minecraft.util.IStringSerializable;
import net.minecraftforge.common.IRarity;
public enum EnumTier implements IStringSerializable {
CREATIVE ("creative", 0, EnumRarity.EPIC ),
@ -16,7 +18,7 @@ public enum EnumTier implements IStringSerializable {
private final String name;
private final int index;
private final EnumRarity enumRarity;
private final IRarity rarity;
// cached values
public static final int length;
@ -36,10 +38,10 @@ public enum EnumTier implements IStringSerializable {
tblNonCreatives = list.toArray(new EnumTier[0]);
}
EnumTier(final String name, final int index, final EnumRarity enumRarity) {
EnumTier(final String name, final int index, @Nonnull final IRarity rarity) {
this.name = name;
this.index = index;
this.enumRarity = enumRarity;
this.rarity = rarity;
}
@Nonnull
@ -56,8 +58,9 @@ public enum EnumTier implements IStringSerializable {
return index;
}
public EnumRarity getRarity() {
return enumRarity;
@Nonnull
public IRarity getForgeRarity() {
return rarity;
}
public static EnumTier[] nonCreative() {

View file

@ -10,12 +10,12 @@ import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.common.IRarity;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@ -60,8 +60,9 @@ public class ItemAbstractBase extends Item implements IItemBase {
}
@Nonnull
public EnumRarity getRarity(final ItemStack itemStack) {
return getTier(itemStack).getRarity();
@Override
public IRarity getForgeRarity(@Nonnull final ItemStack itemStack) {
return getTier(itemStack).getForgeRarity();
}
@Override

View file

@ -13,10 +13,10 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.IRarity;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@ -50,8 +50,9 @@ public class ItemWarpArmor extends ItemArmor implements IItemBase, IBreathingHel
}
@Nonnull
public EnumRarity getRarity(final ItemStack itemStack) {
return getTier(itemStack).getRarity();
@Override
public IRarity getForgeRarity(@Nonnull final ItemStack itemStack) {
return getTier(itemStack).getForgeRarity();
}
@Override