New implementation of Meta Tools, much cleaner and without overhead, because it extends MetaItem directly. Also cleaned some code and reorganized some item textures.
|
@ -721,20 +721,20 @@ public class Materials implements ISubTagContainer, Comparable<Materials> {
|
|||
public List<TC_Aspects.TC_AspectStack> mAspects = new ArrayList<TC_Aspects.TC_AspectStack>();
|
||||
public ArrayList<ItemStack> mMaterialItems = new ArrayList<ItemStack>();
|
||||
public Collection<SubTag> mSubTags = new LinkedHashSet<SubTag>();
|
||||
public Enchantment mEnchantmentTools = null, mEnchantmentArmors = null;
|
||||
public byte mEnchantmentToolsLevel = 0, mEnchantmentArmorsLevel = 0;
|
||||
public Enchantment toolEnchantment = null;
|
||||
public int toolEnchantmentLevel = 0;
|
||||
public boolean mBlastFurnaceRequired = false, mTransparent = false;
|
||||
public float mToolSpeed = 1.0F, mHeatDamage = 0.0F;
|
||||
public float toolSpeed = 1.0F, heatDamage = 0.0F;
|
||||
public String mChemicalFormula = "?", mName = "null", mDefaultLocalName = "null", mCustomID = "null", mConfigSection = "null";
|
||||
public Dyes mColor = Dyes._NULL;
|
||||
public short mMeltingPoint = 0, mBlastFurnaceTemp = 0, mGasTemp = 0;
|
||||
public int mTypes = 0;
|
||||
public int mDurability = 16, mFuelPower = 0, mFuelType = 0, mExtraData = 0, mOreValue = 0, mOreMultiplier = 1, mByProductMultiplier = 1, mSmeltingMultiplier = 1;
|
||||
public int durability = 16, mFuelPower = 0, mFuelType = 0, mExtraData = 0, mOreValue = 0, mOreMultiplier = 1, mByProductMultiplier = 1, mSmeltingMultiplier = 1;
|
||||
public int mDensityMultiplier = 1, mDensityDivider = 1;
|
||||
public long mDensity = M;
|
||||
public Element mElement = null;
|
||||
public Materials mDirectSmelting = this, mOreReplacement = this, mMacerateInto = this, mSmeltInto = this, mArcSmeltInto = this, mHandleMaterial = this;
|
||||
public byte mToolQuality = 0;
|
||||
public byte toolQuality = 0;
|
||||
public boolean mHasParentMod = true, mHasPlasma = false, mHasGas = false, mCustomOre = false;
|
||||
public Fluid mSolid = null, mFluid = null, mGas = null, mPlasma = null;
|
||||
|
||||
|
@ -1322,9 +1322,9 @@ public class Materials implements ISubTagContainer, Comparable<Materials> {
|
|||
aMaterial.mDensityMultiplier = GregTech_API.sMaterialProperties.get(aConfigPath, "DensityMultiplier", aMaterial.mDensityMultiplier);
|
||||
aMaterial.mDensityDivider = GregTech_API.sMaterialProperties.get(aConfigPath, "DensityDivider", aMaterial.mDensityDivider);
|
||||
aMaterial.mDensity = (long) GregTech_API.sMaterialProperties.get(aConfigPath, "Density", (M * aMaterial.mDensityMultiplier) / aMaterial.mDensityDivider);
|
||||
aMaterial.mDurability = GregTech_API.sMaterialProperties.get(aConfigPath, "ToolDurability", aMaterial.mDurability);
|
||||
aMaterial.mToolSpeed = (float) GregTech_API.sMaterialProperties.get(aConfigPath, "ToolSpeed", aMaterial.mToolSpeed);
|
||||
aMaterial.mToolQuality = (byte) GregTech_API.sMaterialProperties.get(aConfigPath, "ToolQuality", aMaterial.mToolQuality);
|
||||
aMaterial.durability = GregTech_API.sMaterialProperties.get(aConfigPath, "ToolDurability", aMaterial.durability);
|
||||
aMaterial.toolSpeed = (float) GregTech_API.sMaterialProperties.get(aConfigPath, "ToolSpeed", aMaterial.toolSpeed);
|
||||
aMaterial.toolQuality = (byte) GregTech_API.sMaterialProperties.get(aConfigPath, "ToolQuality", aMaterial.toolQuality);
|
||||
//aMaterial.mIconSet = MaterialSet.valueOf(GregTech_API.sMaterialProperties.get(aConfigPath.toString(), "IconSet", aMaterial.mIconSet.mSetName));
|
||||
aMaterial.mTransparent = GregTech_API.sMaterialProperties.get(aConfigPath, "Transparent", aMaterial.mTransparent);
|
||||
String aColor = GregTech_API.sMaterialProperties.get(aConfigPath, "DyeColor", aMaterial.mColor == Dyes._NULL ? "None" : aMaterial.mColor.toString());
|
||||
|
@ -1341,7 +1341,7 @@ public class Materials implements ISubTagContainer, Comparable<Materials> {
|
|||
aMaterial.setOreMultiplier(GregTech_API.sMaterialProperties.get(aConfigPath, "OreMultiplier", aMaterial.mOreMultiplier));
|
||||
aMaterial.setSmeltingMultiplier(GregTech_API.sMaterialProperties.get(aConfigPath, "OreSmeltingMultiplier", aMaterial.mSmeltingMultiplier));
|
||||
aMaterial.setByProductMultiplier(GregTech_API.sMaterialProperties.get(aConfigPath, "OreByProductMultiplier", aMaterial.mByProductMultiplier));
|
||||
aMaterial.setHeatDamage((float) GregTech_API.sMaterialProperties.get(aConfigPath, "HeatDamage", aMaterial.mHeatDamage));
|
||||
aMaterial.setHeatDamage((float) GregTech_API.sMaterialProperties.get(aConfigPath, "HeatDamage", aMaterial.heatDamage));
|
||||
aMaterial.mSmeltInto = MATERIALS_MAP.get(GregTech_API.sMaterialProperties.get(aConfigPath, "MaterialSmeltInto", aMaterial.mSmeltInto.mName));
|
||||
aMaterial.mMacerateInto = MATERIALS_MAP.get(GregTech_API.sMaterialProperties.get(aConfigPath, "MaterialMacerateInto", aMaterial.mMacerateInto.mName));
|
||||
aMaterial.mArcSmeltInto = MATERIALS_MAP.get(GregTech_API.sMaterialProperties.get(aConfigPath, "MaterialArcSmeltInto", aMaterial.mArcSmeltInto.mName));
|
||||
|
@ -1350,11 +1350,11 @@ public class Materials implements ISubTagContainer, Comparable<Materials> {
|
|||
if (aMaterial.mHasPlasma = GregTech_API.sMaterialProperties.get(aConfigPath, "AddPlasma", aMaterial.mHasPlasma)) GT_Mod.gregtechproxy.addAutogeneratedPlasmaFluid(aMaterial);
|
||||
if (aMaterial.mHasGas = GregTech_API.sMaterialProperties.get(aConfigPath, "AddGas", aMaterial.mHasGas)) GT_Mod.gregtechproxy.addFluid(aMaterial.mName.toLowerCase(), aMaterial.mDefaultLocalName, aMaterial, 2, aMaterial.mGasTemp);
|
||||
//TODO
|
||||
/*aMaterial.mEnchantmentToolsLevel = (byte) GregTech_API.sMaterialProperties.get(aConfigPath, "EnchantmentLevel", aMaterial.mEnchantmentToolsLevel);
|
||||
String aEnchantmentName = GregTech_API.sMaterialProperties.get(aConfigPath, "Enchantment", aMaterial.mEnchantmentTools != null ? aMaterial.mEnchantmentTools.getName() : "");
|
||||
if (aMaterial.mEnchantmentTools != null && !aEnchantmentName.equals(aMaterial.mEnchantmentTools.getName())) {
|
||||
/*aMaterial.toolEnchantmentLevel = (byte) GregTech_API.sMaterialProperties.get(aConfigPath, "EnchantmentLevel", aMaterial.toolEnchantmentLevel);
|
||||
String aEnchantmentName = GregTech_API.sMaterialProperties.get(aConfigPath, "Enchantment", aMaterial.toolEnchantment != null ? aMaterial.toolEnchantment.getName() : "");
|
||||
if (aMaterial.toolEnchantment != null && !aEnchantmentName.equals(aMaterial.toolEnchantment.getName())) {
|
||||
for (int i = 0; i < getEnchantment(enchantmentsList.length; i++) {
|
||||
if (aEnchantmentName.equals(getEnchantment(enchantmentsList[i].getName())) aMaterial.mEnchantmentTools = getEnchantment(enchantmentsList[i]);
|
||||
if (aEnchantmentName.equals(getEnchantment(enchantmentsList[i].getName())) aMaterial.toolEnchantment = getEnchantment(enchantmentsList[i]);
|
||||
}
|
||||
}*/
|
||||
/**
|
||||
|
@ -1430,8 +1430,8 @@ public class Materials implements ISubTagContainer, Comparable<Materials> {
|
|||
}
|
||||
}
|
||||
/** Moved the harvest level changes from GT_Mod to have less things iterating over MATERIALS_ARRAY **/
|
||||
if (GT_Mod.gregtechproxy.mChangeHarvestLevels && aMaterial.mToolQuality > 0 && aMaterial.mMetaItemSubID < GT_Mod.gregtechproxy.mHarvestLevel.length && aMaterial.mMetaItemSubID >= 0) {
|
||||
GT_Mod.gregtechproxy.mHarvestLevel[aMaterial.mMetaItemSubID] = GregTech_API.sMaterialProperties.get(aConfigPath, "HarvestLevel", aMaterial.mToolQuality);
|
||||
if (GT_Mod.gregtechproxy.mChangeHarvestLevels && aMaterial.toolQuality > 0 && aMaterial.mMetaItemSubID < GT_Mod.gregtechproxy.mHarvestLevel.length && aMaterial.mMetaItemSubID >= 0) {
|
||||
GT_Mod.gregtechproxy.mHarvestLevel[aMaterial.mMetaItemSubID] = GregTech_API.sMaterialProperties.get(aConfigPath, "HarvestLevel", aMaterial.toolQuality);
|
||||
}
|
||||
/** Moved from GT_Proxy? (Not sure)**/
|
||||
aMaterial.mHandleMaterial = (aMaterial == Desh ? aMaterial.mHandleMaterial : aMaterial == Diamond || aMaterial == Thaumium ? Wood : aMaterial.contains(SubTag.BURNING) ? Blaze : aMaterial.contains(SubTag.MAGICAL) && aMaterial.contains(SubTag.CRYSTAL) && Loader.isModLoaded(GT_Values.MOD_ID_TC) ? Thaumium : aMaterial.getMass() > Element.Tc.getMass() * 2 ? TungstenSteel : aMaterial.getMass() > Element.Tc.getMass() ? Steel : Wood);
|
||||
|
@ -1453,9 +1453,9 @@ public class Materials implements ISubTagContainer, Comparable<Materials> {
|
|||
mCustomID = aCustomID;
|
||||
mConfigSection = aConfigSection;
|
||||
mUnificatable = aUnificatable;
|
||||
mDurability = aDurability;
|
||||
mToolSpeed = aToolSpeed;
|
||||
mToolQuality = (byte) aToolQuality;
|
||||
durability = aDurability;
|
||||
toolSpeed = aToolSpeed;
|
||||
toolQuality = (byte) aToolQuality;
|
||||
mMaterialInto = this;
|
||||
mIconSet = aIconSet;
|
||||
}
|
||||
|
@ -1756,7 +1756,7 @@ public class Materials implements ISubTagContainer, Comparable<Materials> {
|
|||
* Sets the Heat Damage for this Material (negative = frost)
|
||||
*/
|
||||
public Materials setHeatDamage(float aHeatDamage) {
|
||||
mHeatDamage = aHeatDamage;
|
||||
heatDamage = aHeatDamage;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -1846,8 +1846,8 @@ public class Materials implements ISubTagContainer, Comparable<Materials> {
|
|||
}
|
||||
|
||||
public Materials setEnchantmentForTools(Enchantment aEnchantment, int aEnchantmentLevel) {
|
||||
mEnchantmentTools = aEnchantment;
|
||||
mEnchantmentToolsLevel = (byte) aEnchantmentLevel;
|
||||
toolEnchantment = aEnchantment;
|
||||
toolEnchantmentLevel = (byte) aEnchantmentLevel;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
15
src/main/java/gregtech/api/interfaces/IIconContainer.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package gregtech.api.interfaces;
|
||||
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public interface IIconContainer {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
TextureAtlasSprite getIcon();
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
TextureAtlasSprite getOverlayIcon();
|
||||
|
||||
}
|
|
@ -34,7 +34,7 @@ public interface ISimpleRenderedItem {
|
|||
* @return RGB color for ItemStack rendering.
|
||||
* Default color modifier is absolute white (i.e has no effect)
|
||||
*/
|
||||
default int getColor(ItemStack itemStack) {
|
||||
default int getColor(ItemStack itemStack, int pass) {
|
||||
return 0xFFFFFF;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,20 +1,17 @@
|
|||
package gregtech.api.interfaces;
|
||||
|
||||
import gregtech.api.items.toolitem.ToolMetaItem;
|
||||
import ic2.api.tile.IWrenchable;
|
||||
import gregtech.api.items.metaitem.MetaItem;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The Stats for GT Tools. Not including any Material Modifiers.
|
||||
|
@ -31,79 +28,67 @@ public interface IToolStats {
|
|||
/**
|
||||
* Called when this gets added to a Tool Item
|
||||
*/
|
||||
void onStatsAddedToTool(ToolMetaItem item, int ID);
|
||||
void onStatsAddedToTool(MetaItem.MetaValueItem metaValueItem, int ID);
|
||||
|
||||
/**
|
||||
* @return Damage the Tool receives when breaking a Block. 100 is one Damage Point (or 100 EU).
|
||||
*/
|
||||
int getToolDamagePerBlockBreak();
|
||||
int getToolDamagePerBlockBreak(ItemStack stack);
|
||||
|
||||
/**
|
||||
* @return Damage the Tool receives when converting the drops of a Block. 100 is one Damage Point (or 100 EU).
|
||||
*/
|
||||
int getToolDamagePerDropConversion();
|
||||
int getToolDamagePerDropConversion(ItemStack stack);
|
||||
|
||||
/**
|
||||
* @return Damage the Tool receives when being used as Container Item. 100 is one use, however it is usually 8 times more than normal.
|
||||
*/
|
||||
int getToolDamagePerContainerCraft();
|
||||
int getToolDamagePerContainerCraft(ItemStack stack);
|
||||
|
||||
/**
|
||||
* @return Damage the Tool receives when being used as Weapon, 200 is the normal Value, 100 for actual Weapons.
|
||||
*/
|
||||
int getToolDamagePerEntityAttack();
|
||||
int getToolDamagePerEntityAttack(ItemStack stack);
|
||||
|
||||
/**
|
||||
* @return Basic Quality of the Tool, 0 is normal. If increased, it will increase the general quality of all Tools of this Type. Decreasing is also possible.
|
||||
*/
|
||||
int getBaseQuality();
|
||||
int getBaseQuality(ItemStack stack);
|
||||
|
||||
/**
|
||||
* @return The Damage Bonus for this Type of Tool against Mobs. 1.0F is normal punch.
|
||||
*/
|
||||
float getBaseDamage();
|
||||
|
||||
/**
|
||||
* @return This gets the Hurt Resistance time for Entities getting hit. (always does 1 as minimum)
|
||||
*/
|
||||
int getHurtResistanceTime(int originalHurtResistance, Entity entity);
|
||||
float getBaseDamage(ItemStack stack);
|
||||
|
||||
/**
|
||||
* @return This is a multiplier for the Tool Speed. 1.0F = no special Speed.
|
||||
*/
|
||||
float getSpeedMultiplier();
|
||||
float getSpeedMultiplier(ItemStack stack);
|
||||
|
||||
/**
|
||||
* @return This is a multiplier for the Tool Durability. 1.0F = no special Durability.
|
||||
*/
|
||||
float getMaxDurabilityMultiplier();
|
||||
float getMaxDurabilityMultiplier(ItemStack stack);
|
||||
|
||||
DamageSource getDamageSource(EntityLivingBase player, Entity entity);
|
||||
ResourceLocation getMiningSound(ItemStack stack);
|
||||
|
||||
ResourceLocation getMiningSound();
|
||||
ResourceLocation getCraftingSound(ItemStack stack);
|
||||
|
||||
ResourceLocation getCraftingSound();
|
||||
ResourceLocation getEntityHitSound(ItemStack stack);
|
||||
|
||||
ResourceLocation getEntityHitSound();
|
||||
ResourceLocation getBreakingSound(ItemStack stack);
|
||||
|
||||
ResourceLocation getBreakingSound();
|
||||
|
||||
ImmutablePair<Enchantment, Integer>[] getEnchantments(ItemStack stack);
|
||||
Map<Enchantment, Integer> getEnchantments(ItemStack stack);
|
||||
|
||||
/**
|
||||
* @return If this Tool can be used as an RC Crowbar.
|
||||
*/
|
||||
boolean isCrowbar();
|
||||
boolean isCrowbar(ItemStack stack);
|
||||
|
||||
/**
|
||||
* @return If this Tool can be used as an FR Grafter.
|
||||
*/
|
||||
boolean isGrafter();
|
||||
|
||||
/**
|
||||
* @return If this Tool can be used as an BC Wrench.
|
||||
*/
|
||||
boolean isWrench();
|
||||
boolean isGrafter(ItemStack stack);
|
||||
|
||||
/**
|
||||
* aBlock.getHarvestTool(aMetaData) can return the following Values for example.
|
||||
|
@ -111,7 +96,7 @@ public interface IToolStats {
|
|||
*
|
||||
* @return If this is a minable Block. Tool Quality checks (like Diamond Tier or something) are separate from this check.
|
||||
*/
|
||||
boolean isMinableBlock(IBlockState block);
|
||||
boolean isMinableBlock(IBlockState block, ItemStack stack);
|
||||
|
||||
/**
|
||||
* This lets you modify the Drop List, when this type of Tool has been used.
|
||||
|
@ -127,13 +112,20 @@ public interface IToolStats {
|
|||
/**
|
||||
* @return the Damage actually done to the Mob.
|
||||
*/
|
||||
float getNormalDamageAgainstEntity(float originalDamage, Entity entity, ItemStack stack, EntityPlayer player);
|
||||
float getNormalDamageBonus(EntityLivingBase entity, ItemStack stack, EntityLivingBase attacker);
|
||||
|
||||
/**
|
||||
* @return the Damage actually done to the Mob.
|
||||
*/
|
||||
float getMagicDamageAgainstEntity(float originalDamage, Entity entity, ItemStack stack, EntityPlayer player);
|
||||
float getMagicDamageBonus(EntityLivingBase entity, ItemStack stack, EntityLivingBase player);
|
||||
|
||||
/**
|
||||
* @return attack speed of weapon
|
||||
*/
|
||||
float getAttackSpeed(ItemStack stack);
|
||||
|
||||
int getColor(boolean isToolHead, ItemStack stack);
|
||||
|
||||
IIconContainer getIcon(boolean isToolHead, ItemStack stack);
|
||||
|
||||
}
|
|
@ -1,171 +0,0 @@
|
|||
package gregtech.api.items;
|
||||
|
||||
import gregtech.api.GregTech_API;
|
||||
import gregtech.api.enums.Dyes;
|
||||
import gregtech.api.enums.Materials;
|
||||
import gregtech.api.enums.OrePrefixes;
|
||||
import gregtech.api.render.SimpleItemModelLoader;
|
||||
import gregtech.api.util.GT_LanguageManager;
|
||||
import gregtech.api.util.GT_OreDictUnificator;
|
||||
import gregtech.api.util.GT_Utility;
|
||||
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.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static gregtech.api.enums.GT_Values.M;
|
||||
|
||||
/**
|
||||
* @author Gregorius Techneticies
|
||||
* <p/>
|
||||
* One Item for everything!
|
||||
* <p/>
|
||||
* This brilliant Item Class is used for automatically generating all possible variations of Material Items, like Dusts, Ingots, Gems, Plates and similar.
|
||||
* It saves me a ton of work, when adding Items, because I always have to make a new Item SubType for each OreDict Prefix, when adding a new Material.
|
||||
* <p/>
|
||||
* As you can see, up to 32766 Items can be generated using this Class. And the last 766 Items can be custom defined, just to save space and MetaData.
|
||||
* <p/>
|
||||
* These Items can also have special RightClick abilities, electric Charge or even be set to become a Food alike Item.
|
||||
*/
|
||||
public abstract class GT_MetaGenerated_Item_X32 extends GT_MetaGenerated_Item {
|
||||
|
||||
protected final OrePrefixes[] mGeneratedPrefixList;
|
||||
|
||||
/**
|
||||
* Creates the Item using these Parameters.
|
||||
*
|
||||
* @param aUnlocalized The Unlocalized Name of this Item.
|
||||
* @param aGeneratedPrefixList The OreDict Prefixes you want to have generated.
|
||||
*/
|
||||
public GT_MetaGenerated_Item_X32(String aUnlocalized, OrePrefixes... aGeneratedPrefixList) {
|
||||
super(aUnlocalized, (short) 32000, (short) 766);
|
||||
mGeneratedPrefixList = Arrays.copyOf(aGeneratedPrefixList, 32);
|
||||
|
||||
for (int i = 0; i < 32000; i++) {
|
||||
OrePrefixes tPrefix = mGeneratedPrefixList[i / 1000];
|
||||
if (tPrefix == null) continue;
|
||||
Materials tMaterial = GregTech_API.sGeneratedMaterials[i % 1000];
|
||||
if (tMaterial == null) continue;
|
||||
if (doesMaterialAllowGeneration(tPrefix, tMaterial)) {
|
||||
ItemStack tStack = new ItemStack(this, 1, i);
|
||||
GT_LanguageManager.addStringLocalization(getUnlocalizedName(tStack) + ".name", getDefaultLocalization(tPrefix, tMaterial, i));
|
||||
GT_LanguageManager.addStringLocalization(getUnlocalizedName(tStack) + ".tooltip", tMaterial.getToolTip(tPrefix.mMaterialAmount / M));
|
||||
final int aMetaData = i;
|
||||
invokeOnClient(() -> assignRenderer(aMetaData, tMaterial, tPrefix));
|
||||
if (tPrefix.mIsUnificatable) {
|
||||
GT_OreDictUnificator.set(tPrefix, tMaterial, tStack);
|
||||
} else {
|
||||
GT_OreDictUnificator.registerOre(tPrefix.get(tMaterial), tStack);
|
||||
}
|
||||
if (tPrefix == OrePrefixes.lens) {
|
||||
Dyes materialColor = tMaterial.mColor;
|
||||
if (materialColor != null) {
|
||||
GT_OreDictUnificator.registerOre("craftingLens" + materialColor.mName.replace(' ', '\0'), tStack);
|
||||
}
|
||||
}
|
||||
if ((tPrefix == OrePrefixes.stick || tPrefix == OrePrefixes.wireFine || tPrefix == OrePrefixes.ingot) && (tMaterial == Materials.Lead || tMaterial == Materials.Tin || tMaterial == Materials.SolderingAlloy)) {
|
||||
GregTech_API.sSolderingMetalList.add(tStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private void assignRenderer(int aMetaData, Materials material, OrePrefixes prefixes) {
|
||||
ModelResourceLocation location = SimpleItemModelLoader.registerX32ModelForGeneration(this, material.mIconSet, prefixes);
|
||||
mModelDefinitions.put((short) aMetaData, (itemstack) -> location);
|
||||
}
|
||||
|
||||
/* ---------- OVERRIDEABLE FUNCTIONS ---------- */
|
||||
|
||||
/**
|
||||
* @return the Color Modulation the Material is going to be rendered with.
|
||||
*/
|
||||
@Override
|
||||
public int getRGBa(ItemStack aStack, int tint) {
|
||||
if(aStack.getItemDamage() < 32000 && tint == 0) {
|
||||
Materials tMaterial = GregTech_API.sGeneratedMaterials[getDamage(aStack) % 1000];
|
||||
return tMaterial == null ? Materials._NULL.getColorInt() : tMaterial.getColorInt();
|
||||
}
|
||||
return super.getRGBa(aStack, tint);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param aPrefix this can be null, you have to return false in that case
|
||||
* @param aMaterial this can be null, you have to return false in that case
|
||||
* @return if this Item should be generated and visible.
|
||||
*/
|
||||
public boolean doesMaterialAllowGeneration(OrePrefixes aPrefix, Materials aMaterial) {
|
||||
// You have to check for at least these Conditions in every Case! So add a super Call like the following for this before executing your Code:
|
||||
// if (!super.doesMaterialAllowGeneration(aPrefix, aMaterial)) return false;
|
||||
return aPrefix != null && aMaterial != null && aPrefix.doGenerateItem(aMaterial);
|
||||
}
|
||||
|
||||
/* ---------- OVERRIDEABLE FUNCTIONS ---------- */
|
||||
|
||||
/**
|
||||
* @param aPrefix the OreDict Prefix
|
||||
* @param aMaterial the Material
|
||||
* @param aMetaData a Index from [0 - 31999]
|
||||
* @return the Localized Name when default LangFiles are used.
|
||||
*/
|
||||
public String getDefaultLocalization(OrePrefixes aPrefix, Materials aMaterial, int aMetaData) {
|
||||
return aPrefix.getDefaultLocalNameForItem(aMaterial);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param aPrefix always != null
|
||||
* @param aMaterial always != null
|
||||
* @param aDoShowAllItems this is the Configuration Setting of the User, if he wants to see all the Stuff like Tiny Dusts or Crushed Ores as well.
|
||||
* @return if this Item should be visible in NEI or Creative
|
||||
*/
|
||||
public boolean doesShowInCreative(OrePrefixes aPrefix, Materials aMaterial, boolean aDoShowAllItems) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ---------- INTERNAL OVERRIDES ---------- */
|
||||
|
||||
@Override
|
||||
public ItemStack getContainerItem(ItemStack aStack) {
|
||||
int aDamage = aStack.getItemDamage();
|
||||
if (aDamage < 32000 && aDamage >= 0) {
|
||||
Materials aMaterial = GregTech_API.sGeneratedMaterials[aDamage % 1000];
|
||||
if (aMaterial != null && aMaterial != Materials.Empty && aMaterial != Materials._NULL) {
|
||||
OrePrefixes aPrefix = mGeneratedPrefixList[aDamage / 1000];
|
||||
if (aPrefix != null) return GT_Utility.copyAmount(1, aPrefix.mContainerItem);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public final void getSubItems(Item var1, CreativeTabs aCreativeTab, List<ItemStack> aList) {
|
||||
for (int i = 0; i < 32000; i++) {
|
||||
OrePrefixes aPrefix = mGeneratedPrefixList[i / 1000];
|
||||
Materials aMaterial = GregTech_API.sGeneratedMaterials[i % 1000];
|
||||
if (aPrefix != null && aMaterial != null) {
|
||||
if (doesMaterialAllowGeneration(aPrefix, aMaterial) && doesShowInCreative(aPrefix, aMaterial, GregTech_API.sDoShowAllItemsInCreative)) {
|
||||
ItemStack tStack = new ItemStack(this, 1, i);
|
||||
isItemStackUsable(tStack);
|
||||
aList.add(tStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.getSubItems(var1, aCreativeTab, aList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemStackLimit(ItemStack aStack) {
|
||||
int tDamage = getDamage(aStack);
|
||||
if (tDamage < 32000 && mGeneratedPrefixList[tDamage / 1000] != null)
|
||||
return Math.min(super.getItemStackLimit(aStack), mGeneratedPrefixList[tDamage / 1000].mDefaultStackSize);
|
||||
return super.getItemStackLimit(aStack);
|
||||
}
|
||||
|
||||
}
|
|
@ -54,13 +54,13 @@ import static gregtech.api.enums.GT_Values.MODID;
|
|||
* You can also extend this class and occupy some of it's MetaData, and just pass an meta offset in constructor, and everything will work properly.
|
||||
*
|
||||
* Items are added in MetaItem via {@link #addItem(short)}. You will get {@link MetaValueItem} instance, which you can configure in builder-alike pattern:
|
||||
* {@code addItem(0).setHandheld().setElectricStats(new ElectricStats(10000, 1, false)) }
|
||||
* {@code addItem(0).setHandheld().addStats(new ElectricStats(10000, 1, false)) }
|
||||
* This will add single-use handheld-rendered (unchargeable) LV battery with initial capacity 10000 EU
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class MetaItem extends GenericItem implements ISpecialElectricItem, IFluidContainerItem, IFuelHandler, IReactorComponent, IBoxable {
|
||||
public class MetaItem<T extends MetaItem.MetaValueItem> extends GenericItem implements ISpecialElectricItem, IFluidContainerItem, IFuelHandler, IReactorComponent, IBoxable {
|
||||
|
||||
private TShortObjectMap<MetaValueItem> metaItems = new TShortObjectHashMap<>();
|
||||
private TShortObjectMap<T> metaItems = new TShortObjectHashMap<>();
|
||||
|
||||
private final short metaItemOffset;
|
||||
|
||||
|
@ -71,17 +71,21 @@ public class MetaItem extends GenericItem implements ISpecialElectricItem, IFlui
|
|||
this.metaItemOffset = metaItemOffset;
|
||||
}
|
||||
|
||||
public MetaValueItem addItem(short metaValue) {
|
||||
MetaValueItem metaValueItem = new MetaValueItem(metaValue);
|
||||
protected T constructMetaValueItem(short metaValue) {
|
||||
return (T) new MetaValueItem(metaValue);
|
||||
}
|
||||
|
||||
public final T addItem(short metaValue) {
|
||||
T metaValueItem = constructMetaValueItem(metaValue);
|
||||
metaItems.put(metaValue, metaValueItem);
|
||||
return metaValueItem;
|
||||
}
|
||||
|
||||
public MetaValueItem getItem(short metaValue) {
|
||||
public final T getItem(short metaValue) {
|
||||
return metaItems.get(metaValue);
|
||||
}
|
||||
|
||||
public MetaValueItem getItem(ItemStack itemStack) {
|
||||
public final T getItem(ItemStack itemStack) {
|
||||
return getItem((short) (itemStack.getItemDamage() - metaItemOffset));
|
||||
}
|
||||
|
||||
|
@ -470,10 +474,10 @@ public class MetaItem extends GenericItem implements ISpecialElectricItem, IFlui
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getColor(ItemStack itemStack) {
|
||||
public int getColor(ItemStack itemStack, int pass) {
|
||||
MetaValueItem metaValueItem = getItem(itemStack);
|
||||
if(metaValueItem != null) {
|
||||
return metaValueItem.getColor(itemStack);
|
||||
return metaValueItem.getColor(itemStack, pass);
|
||||
}
|
||||
return 0xFFFFFF;
|
||||
}
|
||||
|
@ -486,7 +490,11 @@ public class MetaItem extends GenericItem implements ISpecialElectricItem, IFlui
|
|||
return false;
|
||||
}
|
||||
|
||||
public final class MetaValueItem {
|
||||
public class MetaValueItem {
|
||||
|
||||
public MetaItem<T> getMetaItem() {
|
||||
return MetaItem.this;
|
||||
}
|
||||
|
||||
public final int metaValue;
|
||||
|
||||
|
@ -504,12 +512,12 @@ public class MetaItem extends GenericItem implements ISpecialElectricItem, IFlui
|
|||
@SideOnly(Side.CLIENT)
|
||||
private TextureAtlasSprite[] icons;
|
||||
|
||||
private MetaValueItem(int metaValue) {
|
||||
protected MetaValueItem(int metaValue) {
|
||||
this.metaValue = metaValue;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private void registerIcons(TextureMap textureMap) {
|
||||
protected void registerIcons(TextureMap textureMap) {
|
||||
if(electricStats != null) {
|
||||
this.icons = new TextureAtlasSprite[fluidStats != null ? 9 : 8];
|
||||
for(int i = 0; i < 8; i++) {
|
||||
|
@ -529,7 +537,7 @@ public class MetaItem extends GenericItem implements ISpecialElectricItem, IFlui
|
|||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private TextureAtlasSprite getIcon(ItemStack itemStack, int renderPass) {
|
||||
protected TextureAtlasSprite getIcon(ItemStack itemStack, int renderPass) {
|
||||
switch (renderPass) {
|
||||
case 0:
|
||||
if(electricStats != null) {
|
||||
|
@ -546,12 +554,12 @@ public class MetaItem extends GenericItem implements ISpecialElectricItem, IFlui
|
|||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private int getRenderPasses(ItemStack itemStack) {
|
||||
protected int getRenderPasses(ItemStack itemStack) {
|
||||
return fluidStats != null ? 2 : 1;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private int getColor(ItemStack itemStack) {
|
||||
protected int getColor(ItemStack itemStack, int pass) {
|
||||
if(fluidStats != null) {
|
||||
FluidStack fluidInside = getFluid(itemStack);
|
||||
if(fluidInside != null)
|
||||
|
@ -559,8 +567,8 @@ public class MetaItem extends GenericItem implements ISpecialElectricItem, IFlui
|
|||
}
|
||||
return 0xFFFFFF;
|
||||
}
|
||||
|
||||
public boolean isHandheld() {
|
||||
|
||||
protected boolean isHandheld() {
|
||||
return handheld;
|
||||
}
|
||||
|
||||
|
@ -627,11 +635,11 @@ public class MetaItem extends GenericItem implements ISpecialElectricItem, IFlui
|
|||
return this;
|
||||
}
|
||||
|
||||
private void setFoodStats(IFoodStats foodStats) {
|
||||
protected void setFoodStats(IFoodStats foodStats) {
|
||||
addBehaviour(new FoodUseManager(foodStats));
|
||||
}
|
||||
|
||||
private void setDurabilityManager(IItemDurabilityManager durabilityManager) {
|
||||
protected void setDurabilityManager(IItemDurabilityManager durabilityManager) {
|
||||
if(durabilityManager == null) {
|
||||
throw new IllegalArgumentException("Cannot set Durability Manager to null.");
|
||||
}
|
||||
|
@ -641,7 +649,7 @@ public class MetaItem extends GenericItem implements ISpecialElectricItem, IFlui
|
|||
this.durabilityManager = durabilityManager;
|
||||
}
|
||||
|
||||
private void setElectricStats(IElectricStats electricStats) {
|
||||
protected void setElectricStats(IElectricStats electricStats) {
|
||||
if(electricStats == null) {
|
||||
throw new IllegalArgumentException("Cannot set Electric Stats to null.");
|
||||
}
|
||||
|
@ -651,7 +659,7 @@ public class MetaItem extends GenericItem implements ISpecialElectricItem, IFlui
|
|||
this.electricStats = electricStats;
|
||||
}
|
||||
|
||||
private MetaValueItem setFluidStats(IFluidStats fluidStats) {
|
||||
protected MetaValueItem setFluidStats(IFluidStats fluidStats) {
|
||||
if(fluidStats == null) {
|
||||
throw new IllegalArgumentException("Cannot set Fluid Stats to null.");
|
||||
}
|
||||
|
@ -662,7 +670,7 @@ public class MetaItem extends GenericItem implements ISpecialElectricItem, IFlui
|
|||
return this;
|
||||
}
|
||||
|
||||
private void setNuclearStats(INuclearStats nuclearStats) {
|
||||
protected void setNuclearStats(INuclearStats nuclearStats) {
|
||||
if(nuclearStats == null) {
|
||||
throw new IllegalArgumentException("Cannot set Nuclear Stats to null.");
|
||||
}
|
||||
|
@ -670,14 +678,14 @@ public class MetaItem extends GenericItem implements ISpecialElectricItem, IFlui
|
|||
setMaxStackSize(1);
|
||||
}
|
||||
|
||||
private void setUseManager(IItemUseManager useManager) {
|
||||
protected void setUseManager(IItemUseManager useManager) {
|
||||
if(this.useManager != null) {
|
||||
throw new IllegalStateException("Tried to set Use Manager to " + useManager + ", but it's already set to " + this.useManager);
|
||||
}
|
||||
this.useManager = useManager;
|
||||
}
|
||||
|
||||
private void addBehaviour(IItemBehaviour behaviour) {
|
||||
protected void addBehaviour(IItemBehaviour behaviour) {
|
||||
if (behaviour == null) {
|
||||
throw new IllegalArgumentException("Cannot add null behaviour.");
|
||||
}
|
||||
|
|
|
@ -1,13 +1,335 @@
|
|||
package gregtech.api.items.toolitem;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import gregtech.api.enums.Materials;
|
||||
import gregtech.api.interfaces.IDamagableItem;
|
||||
import gregtech.api.interfaces.IIconContainer;
|
||||
import gregtech.api.interfaces.IToolStats;
|
||||
import gregtech.api.items.metaitem.MetaItem;
|
||||
import gregtech.api.util.GT_Utility;
|
||||
import ic2.api.item.IElectricItemManager;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EntityDamageSource;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ToolMetaItem extends MetaItem {
|
||||
import java.util.HashMap;
|
||||
|
||||
import static gregtech.api.enums.GT_Values.MODID;
|
||||
|
||||
/**
|
||||
* ToolMetaItem is item that can have up to Short.MAX_VALUE tools inside it
|
||||
* These tools can be made from different materials, have special behaviours, and basically do everything that standard MetaItem can do.
|
||||
*
|
||||
* Tool behaviours are implemented by {@link IToolStats} objects
|
||||
*
|
||||
* As example, with this code you can add LV electric drill tool:
|
||||
* {@code addItem(0).addStats(new ElectricStats(10000, 1, true, false)).setToolStats(new ToolStatsExampleDrill()) }
|
||||
*
|
||||
* @see IToolStats
|
||||
* @see MetaItem
|
||||
*/
|
||||
public class ToolMetaItem<T extends ToolMetaItem.MetaToolValueItem> extends MetaItem<T> implements IDamagableItem {
|
||||
|
||||
public ToolMetaItem(String unlocalizedName) {
|
||||
super(unlocalizedName, (short) 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected T constructMetaValueItem(short metaValue) {
|
||||
return (T) new MetaToolValueItem(metaValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreated(ItemStack stack, World world, EntityPlayer player) {
|
||||
MetaToolValueItem metaToolValueItem = getItem(stack);
|
||||
if(metaToolValueItem != null) {
|
||||
IToolStats toolStats = metaToolValueItem.getToolStats();
|
||||
toolStats.onToolCrafted(stack, player);
|
||||
HashMap<Enchantment, Integer> enchants = new HashMap<>(toolStats.getEnchantments(stack));
|
||||
Materials material = getMaterial(stack);
|
||||
if(material.toolEnchantment != null) {
|
||||
if(enchants.containsKey(material.toolEnchantment)) {
|
||||
enchants.put(material.toolEnchantment, enchants.get(material.toolEnchantment) + material.toolEnchantmentLevel);
|
||||
} else enchants.put(material.toolEnchantment, material.toolEnchantmentLevel);
|
||||
}
|
||||
for(Enchantment enchantment : enchants.keySet()) {
|
||||
stack.addEnchantment(enchantment, enchants.get(enchantment));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getContainerItem(ItemStack stack) {
|
||||
MetaToolValueItem metaToolValueItem = getItem(stack);
|
||||
if(metaToolValueItem != null) {
|
||||
IToolStats toolStats = metaToolValueItem.getToolStats();
|
||||
if(!doDamageToItem(stack, toolStats.getToolDamagePerContainerCraft(stack)) && getManager(stack).getMaxCharge(stack) == 0) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockDestroyed(ItemStack stack, World world, IBlockState state, BlockPos pos, EntityLivingBase entity) {
|
||||
MetaToolValueItem metaToolValueItem = getItem(stack);
|
||||
if(metaToolValueItem != null) {
|
||||
IToolStats toolStats = metaToolValueItem.getToolStats();
|
||||
if(toolStats.isMinableBlock(state, stack)) {
|
||||
doDamageToItem(stack, toolStats.getToolDamagePerBlockBreak(stack));
|
||||
ResourceLocation mineSound = toolStats.getMiningSound(stack);
|
||||
if(mineSound != null) {
|
||||
GT_Utility.playSound(world, pos.getX() + 0.5f, pos.getY() + 0.5f, pos.getZ() + 0.5f, mineSound, SoundCategory.PLAYERS, 0.27f, 1.0f);
|
||||
}
|
||||
if(!isUsable(stack, toolStats.getToolDamagePerBlockBreak(stack))) {
|
||||
ResourceLocation breakSound = toolStats.getBreakingSound(stack);
|
||||
if(breakSound != null) {
|
||||
GT_Utility.playSound(world, pos.getX() + 0.5f, pos.getY() + 0.5f, pos.getZ() + 0.5f, breakSound, SoundCategory.PLAYERS, 1.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getStrVsBlock(ItemStack stack, IBlockState state) {
|
||||
MetaToolValueItem metaToolValueItem = getItem(stack);
|
||||
if(metaToolValueItem != null) {
|
||||
IToolStats toolStats = metaToolValueItem.getToolStats();
|
||||
if(isUsable(stack, toolStats.getToolDamagePerBlockBreak(stack)) && toolStats.isMinableBlock(state, stack)) {
|
||||
return getMaterial(stack).toolSpeed * toolStats.getSpeedMultiplier(stack);
|
||||
}
|
||||
}
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHarvestLevel(ItemStack stack, String toolClass, EntityPlayer player, IBlockState blockState) {
|
||||
MetaToolValueItem metaToolValueItem = getItem(stack);
|
||||
if(metaToolValueItem != null) {
|
||||
IToolStats toolStats = metaToolValueItem.getToolStats();
|
||||
if(isUsable(stack, toolStats.getToolDamagePerBlockBreak(stack)) && toolStats.isMinableBlock(blockState, stack)) {
|
||||
return toolStats.getBaseQuality(stack) + getMaterial(stack).toolQuality;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot slot, ItemStack stack) {
|
||||
MetaToolValueItem metaValueItem = getItem(stack);
|
||||
if(metaValueItem != null && slot == EntityEquipmentSlot.MAINHAND) {
|
||||
IToolStats toolStats = metaValueItem.getToolStats();
|
||||
float attackDamage = toolStats.getBaseDamage(stack);
|
||||
float attackSpeed = toolStats.getAttackSpeed(stack);
|
||||
|
||||
HashMultimap<String, AttributeModifier> modifiers = HashMultimap.create();
|
||||
modifiers.put(SharedMonsterAttributes.ATTACK_DAMAGE.getAttributeUnlocalizedName(), new AttributeModifier("Weapon modifier", attackDamage, 0));
|
||||
modifiers.put(SharedMonsterAttributes.ATTACK_SPEED.getAttributeUnlocalizedName(), new AttributeModifier("Weapon modifier", attackSpeed, 0));
|
||||
return modifiers;
|
||||
}
|
||||
return HashMultimap.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) {
|
||||
//cancel attack if broken or out of charge
|
||||
MetaToolValueItem metaToolValueItem = getItem(stack);
|
||||
if(metaToolValueItem != null) {
|
||||
int damagePerAttack = metaToolValueItem.getToolStats().getToolDamagePerEntityAttack(stack);
|
||||
if(!isUsable(stack, damagePerAttack)) return true;
|
||||
}
|
||||
return super.onLeftClickEntity(stack, player, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
|
||||
MetaToolValueItem metaValueItem = getItem(stack);
|
||||
if(metaValueItem != null) {
|
||||
IToolStats toolStats = metaValueItem.getToolStats();
|
||||
doDamageToItem(stack, toolStats.getToolDamagePerEntityAttack(stack));
|
||||
ResourceLocation hitSound = toolStats.getEntityHitSound(stack);
|
||||
if(hitSound != null) {
|
||||
GT_Utility.playSound(target.worldObj, target.posX, target.posY, target.posZ, hitSound, SoundCategory.PLAYERS, 0.27f, 1.0f);
|
||||
}
|
||||
if(!isUsable(stack, toolStats.getToolDamagePerEntityAttack(stack))) {
|
||||
ResourceLocation breakSound = toolStats.getBreakingSound(stack);
|
||||
if(breakSound != null) {
|
||||
GT_Utility.playSound(target.worldObj, target.posX, target.posY, target.posZ, breakSound, SoundCategory.PLAYERS, 1.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
float additionalDamage = toolStats.getNormalDamageBonus(target, stack, attacker);
|
||||
float additionalMagicDamage = toolStats.getMagicDamageBonus(target, stack, attacker);
|
||||
if(additionalDamage > 0.0f) {
|
||||
target.attackEntityFrom(new EntityDamageSource(attacker instanceof EntityPlayer ? "player" : "mob", attacker), additionalDamage);
|
||||
}
|
||||
if(additionalMagicDamage > 0.0f) {
|
||||
target.attackEntityFrom(new EntityDamageSource("indirectMagic", attacker), additionalMagicDamage);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doDamageToItem(ItemStack stack, int vanillaDamage) {
|
||||
if(!isUsable(stack, vanillaDamage)) {
|
||||
return false;
|
||||
}
|
||||
MetaToolValueItem metaToolValueItem = getItem(stack);
|
||||
IElectricItemManager electricItemManager = getManager(stack);
|
||||
if(electricItemManager.getMaxCharge(stack) == 0) {
|
||||
setInternalDamage(stack, getInternalDamage(stack) + vanillaDamage);
|
||||
} else {
|
||||
electricItemManager.discharge(stack, vanillaDamage, electricItemManager.getTier(stack), true, false, false);
|
||||
setInternalDamage(stack, getInternalDamage(stack) + (vanillaDamage / 10));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isUsable(ItemStack stack, int damage) {
|
||||
MetaToolValueItem metaToolValueItem = getItem(stack);
|
||||
IElectricItemManager electricItemManager = getManager(stack);
|
||||
if(electricItemManager.getMaxCharge(stack) == 0) {
|
||||
return getInternalDamage(stack) + damage < getMaxInternalDamage(stack);
|
||||
}
|
||||
return electricItemManager.canUse(stack, damage) && getInternalDamage(stack) + (damage / 10) < getMaxInternalDamage(stack);
|
||||
}
|
||||
|
||||
|
||||
private int getMaxInternalDamage(ItemStack itemStack) {
|
||||
MetaToolValueItem metaToolValueItem = getItem(itemStack);
|
||||
if (metaToolValueItem != null) {
|
||||
Materials toolMaterial = getMaterial(itemStack);
|
||||
return (int) (toolMaterial.durability * metaToolValueItem.getToolStats().getMaxDurabilityMultiplier(itemStack));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int getInternalDamage(ItemStack itemStack) {
|
||||
if(!itemStack.hasTagCompound() || !itemStack.getTagCompound().hasKey("GT.ToolDamage", Constants.NBT.TAG_INT))
|
||||
return 0;
|
||||
return itemStack.getTagCompound().getInteger("GT.ToolDamage");
|
||||
}
|
||||
|
||||
private void setInternalDamage(ItemStack itemStack, int damage) {
|
||||
if(!itemStack.hasTagCompound()) {
|
||||
itemStack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
NBTTagCompound tagCompound = itemStack.getTagCompound();
|
||||
tagCompound.setInteger("GT.ToolDamage", damage);
|
||||
}
|
||||
|
||||
public Materials getMaterial(ItemStack itemStack) {
|
||||
if(!itemStack.hasTagCompound() || !itemStack.getTagCompound().hasKey("GT.ToolMaterial", Constants.NBT.TAG_STRING))
|
||||
return Materials._NULL;
|
||||
return Materials.get(itemStack.getTagCompound().getString("GT.ToolMaterial"));
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private TextureAtlasSprite[] durabilityBar;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private TextureAtlasSprite[] energyBar;
|
||||
|
||||
@Override
|
||||
public void registerIcons(TextureMap textureMap) {
|
||||
super.registerIcons(textureMap);
|
||||
this.durabilityBar = new TextureAtlasSprite[9];
|
||||
this.energyBar = new TextureAtlasSprite[9];
|
||||
for(int i = 0; i < this.durabilityBar.length; i++) {
|
||||
this.durabilityBar[i] = textureMap.registerSprite(new ResourceLocation(MODID, "items/durability_bar/DURABILITY_BAR_" + i));
|
||||
this.energyBar[i] = textureMap.registerSprite(new ResourceLocation(MODID, "items/energy_bar/ENERGY_BAR_" + i));
|
||||
}
|
||||
}
|
||||
|
||||
public class MetaToolValueItem extends MetaValueItem {
|
||||
|
||||
private IToolStats toolStats;
|
||||
|
||||
private MetaToolValueItem(int metaValue) {
|
||||
super(metaValue);
|
||||
setNoUnification();
|
||||
setHandheld();
|
||||
}
|
||||
|
||||
public MetaToolValueItem setToolStats(IToolStats toolStats) {
|
||||
if(toolStats == null) {
|
||||
throw new IllegalArgumentException("Cannot set Tool Stats to null.");
|
||||
}
|
||||
this.toolStats = toolStats;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
protected void registerIcons(TextureMap textureMap) {}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
protected TextureAtlasSprite getIcon(ItemStack itemStack, int pass) {
|
||||
if(pass == 4) {
|
||||
float maxInternalDamage = getMaxInternalDamage(itemStack);
|
||||
if(maxInternalDamage > 0) {
|
||||
return durabilityBar[(int) ((getInternalDamage(itemStack) / maxInternalDamage) * 8)];
|
||||
}
|
||||
return durabilityBar[0];
|
||||
}
|
||||
|
||||
if(pass == 5) {
|
||||
IElectricItemManager electricItemManager = getManager(itemStack);
|
||||
double maxCharge = electricItemManager.getMaxCharge(itemStack);
|
||||
if(maxCharge > 0) {
|
||||
return energyBar[(int) ((electricItemManager.getCharge(itemStack) / maxCharge) * 8)];
|
||||
}
|
||||
return energyBar[0];
|
||||
}
|
||||
|
||||
IIconContainer container = toolStats.getIcon(pass / 2 == 1, itemStack);
|
||||
if(container == null) {
|
||||
return null;
|
||||
}
|
||||
if(pass % 2 == 0) {
|
||||
return container.getIcon();
|
||||
}
|
||||
return container.getOverlayIcon();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
protected int getRenderPasses(ItemStack itemStack) {
|
||||
return getManager(itemStack).getMaxCharge(itemStack) > 0 ? 6 : 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getColor(ItemStack itemStack, int pass) {
|
||||
if(pass % 2 == 0) {
|
||||
return toolStats.getColor(pass / 2 == 1, itemStack);
|
||||
}
|
||||
return 0xFFFFFF;
|
||||
}
|
||||
|
||||
public IToolStats getToolStats() {
|
||||
return toolStats;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Before Width: | Height: | Size: 176 B After Width: | Height: | Size: 176 B |
Before Width: | Height: | Size: 157 B After Width: | Height: | Size: 157 B |
Before Width: | Height: | Size: 172 B After Width: | Height: | Size: 172 B |
Before Width: | Height: | Size: 204 B After Width: | Height: | Size: 204 B |
Before Width: | Height: | Size: 180 B After Width: | Height: | Size: 180 B |
Before Width: | Height: | Size: 182 B After Width: | Height: | Size: 182 B |
Before Width: | Height: | Size: 190 B After Width: | Height: | Size: 190 B |
Before Width: | Height: | Size: 191 B After Width: | Height: | Size: 191 B |
Before Width: | Height: | Size: 186 B After Width: | Height: | Size: 186 B |
Before Width: | Height: | Size: 143 B After Width: | Height: | Size: 143 B |
Before Width: | Height: | Size: 157 B After Width: | Height: | Size: 157 B |
Before Width: | Height: | Size: 169 B After Width: | Height: | Size: 169 B |
Before Width: | Height: | Size: 190 B After Width: | Height: | Size: 190 B |
Before Width: | Height: | Size: 183 B After Width: | Height: | Size: 183 B |
Before Width: | Height: | Size: 186 B After Width: | Height: | Size: 186 B |
Before Width: | Height: | Size: 191 B After Width: | Height: | Size: 191 B |
Before Width: | Height: | Size: 193 B After Width: | Height: | Size: 193 B |
Before Width: | Height: | Size: 189 B After Width: | Height: | Size: 189 B |
Before Width: | Height: | Size: 176 B |
Before Width: | Height: | Size: 157 B |
Before Width: | Height: | Size: 172 B |
Before Width: | Height: | Size: 204 B |
Before Width: | Height: | Size: 180 B |
Before Width: | Height: | Size: 182 B |
Before Width: | Height: | Size: 190 B |
Before Width: | Height: | Size: 191 B |
Before Width: | Height: | Size: 186 B |
Before Width: | Height: | Size: 143 B |
Before Width: | Height: | Size: 157 B |
Before Width: | Height: | Size: 169 B |
Before Width: | Height: | Size: 190 B |
Before Width: | Height: | Size: 183 B |
Before Width: | Height: | Size: 186 B |
Before Width: | Height: | Size: 191 B |
Before Width: | Height: | Size: 193 B |
Before Width: | Height: | Size: 189 B |
Before Width: | Height: | Size: 143 B |
Before Width: | Height: | Size: 322 B After Width: | Height: | Size: 322 B |
Before Width: | Height: | Size: 251 B After Width: | Height: | Size: 251 B |
Before Width: | Height: | Size: 258 B After Width: | Height: | Size: 258 B |
Before Width: | Height: | Size: 211 B After Width: | Height: | Size: 211 B |
Before Width: | Height: | Size: 369 B After Width: | Height: | Size: 369 B |
Before Width: | Height: | Size: 236 B After Width: | Height: | Size: 236 B |
Before Width: | Height: | Size: 569 B After Width: | Height: | Size: 569 B |
Before Width: | Height: | Size: 268 B After Width: | Height: | Size: 268 B |
Before Width: | Height: | Size: 337 B After Width: | Height: | Size: 337 B |
Before Width: | Height: | Size: 196 B After Width: | Height: | Size: 196 B |
Before Width: | Height: | Size: 300 B After Width: | Height: | Size: 300 B |
Before Width: | Height: | Size: 143 B After Width: | Height: | Size: 143 B |
Before Width: | Height: | Size: 291 B After Width: | Height: | Size: 291 B |
Before Width: | Height: | Size: 143 B After Width: | Height: | Size: 143 B |
Before Width: | Height: | Size: 300 B After Width: | Height: | Size: 300 B |
Before Width: | Height: | Size: 143 B After Width: | Height: | Size: 143 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 143 B After Width: | Height: | Size: 143 B |
Before Width: | Height: | Size: 284 B After Width: | Height: | Size: 284 B |
Before Width: | Height: | Size: 143 B After Width: | Height: | Size: 143 B |
Before Width: | Height: | Size: 332 B After Width: | Height: | Size: 332 B |
Before Width: | Height: | Size: 406 B After Width: | Height: | Size: 406 B |
Before Width: | Height: | Size: 399 B After Width: | Height: | Size: 399 B |
Before Width: | Height: | Size: 263 B After Width: | Height: | Size: 263 B |
Before Width: | Height: | Size: 401 B After Width: | Height: | Size: 401 B |
Before Width: | Height: | Size: 385 B After Width: | Height: | Size: 385 B |
Before Width: | Height: | Size: 270 B After Width: | Height: | Size: 270 B |
Before Width: | Height: | Size: 357 B After Width: | Height: | Size: 357 B |
Before Width: | Height: | Size: 375 B After Width: | Height: | Size: 375 B |
Before Width: | Height: | Size: 200 B After Width: | Height: | Size: 200 B |
Before Width: | Height: | Size: 375 B After Width: | Height: | Size: 375 B |
Before Width: | Height: | Size: 200 B After Width: | Height: | Size: 200 B |
Before Width: | Height: | Size: 375 B After Width: | Height: | Size: 375 B |
Before Width: | Height: | Size: 200 B After Width: | Height: | Size: 200 B |
Before Width: | Height: | Size: 161 B After Width: | Height: | Size: 161 B |
Before Width: | Height: | Size: 161 B After Width: | Height: | Size: 161 B |
Before Width: | Height: | Size: 484 B After Width: | Height: | Size: 484 B |
Before Width: | Height: | Size: 143 B After Width: | Height: | Size: 143 B |
Before Width: | Height: | Size: 268 B After Width: | Height: | Size: 268 B |
Before Width: | Height: | Size: 266 B After Width: | Height: | Size: 266 B |
Before Width: | Height: | Size: 492 B After Width: | Height: | Size: 492 B |
Before Width: | Height: | Size: 251 B After Width: | Height: | Size: 251 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 143 B After Width: | Height: | Size: 143 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 143 B After Width: | Height: | Size: 143 B |
Before Width: | Height: | Size: 143 B After Width: | Height: | Size: 143 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 143 B After Width: | Height: | Size: 143 B |
Before Width: | Height: | Size: 143 B After Width: | Height: | Size: 143 B |
Before Width: | Height: | Size: 225 B After Width: | Height: | Size: 225 B |
Before Width: | Height: | Size: 359 B After Width: | Height: | Size: 359 B |
Before Width: | Height: | Size: 236 B After Width: | Height: | Size: 236 B |
Before Width: | Height: | Size: 143 B After Width: | Height: | Size: 143 B |