use of net.silentchaos512.gems.api.lib.EnumPartPosition in project SilentGems by SilentChaos512.
the class ToolPartGem method getModel.
@Override
public ModelResourceLocation getModel(ItemStack tool, EnumPartPosition pos, int frame) {
String name = ((IRegistryObject) tool.getItem()).getName();
name = SilentGems.RESOURCE_PREFIX + name + "/" + name;
String gemNum = tool.getItem() instanceof ItemGemBow ? "" : "" + gem.ordinal();
String frameNum = frame == 3 ? "_3" : "";
switch(pos) {
case HEAD_LEFT:
name += gemNum + "l" + frameNum;
break;
case HEAD_MIDDLE:
name += gemNum + frameNum;
break;
case HEAD_RIGHT:
name += gemNum + "r" + frameNum;
break;
case ROD_DECO:
name += "deco" + gemNum;
break;
default:
return null;
}
if (modelMap.containsKey(name)) {
return modelMap.get(name);
}
name = name.toLowerCase();
ModelResourceLocation model = new ModelResourceLocation(name, "inventory");
modelMap.put(name, model);
return model;
}
use of net.silentchaos512.gems.api.lib.EnumPartPosition in project SilentGems by SilentChaos512.
the class ToolPartWool method getModel.
@Override
public ModelResourceLocation getModel(ItemStack tool, EnumPartPosition pos, int frame) {
if (tool.getItem() instanceof ItemGemBow)
return null;
String name = ((IRegistryObject) tool.getItem()).getName();
name = SilentGems.RESOURCE_PREFIX + name + "/" + name + "Wool" + color.getMetadata();
if (modelMap.containsKey(name)) {
return modelMap.get(name);
}
name = name.toLowerCase();
ModelResourceLocation model = new ModelResourceLocation(name, "inventory");
modelMap.put(name, model);
return model;
}
use of net.silentchaos512.gems.api.lib.EnumPartPosition in project SilentGems by SilentChaos512.
the class ToolRenderHelper method getModel.
/**
* Gets the model for the specified tool and position. Gets the animation frame on its own. Stores model index in tool
* NBT for fast acess.
*/
public ModelResourceLocation getModel(ItemStack tool, EnumPartPosition pos) {
if (tool == null || !tool.hasTagCompound()) {
return modelError;
}
NBTTagCompound tags = tool.getTagCompound().getCompoundTag(NBT_MODEL_INDEX);
int frame = getAnimationFrame(tool);
String key = "Layer" + pos.ordinal() + (frame > 0 ? "_" + frame : "");
boolean isBow = tool.getItem() instanceof ItemGemBow;
if (!tags.hasKey(key)) {
// Bow "arrow" models
if (pos == EnumPartPosition.ROD_GRIP && isBow) {
return getArrowModel(tool, frame);
}
// Get the render part for this position.
ToolPart part = ToolHelper.getRenderPart(tool, pos);
if (part == null) {
tags.setInteger(key, -1);
tool.getTagCompound().setTag(NBT_MODEL_INDEX, tags);
return null;
}
// Get the desired model for the current position and animation frame.
ModelResourceLocation target = part.getModel(tool, pos, frame);
// Find the model in the list. Store the index in NBT for fast access.
for (int i = 0; i < models.length; ++i) {
if (models[i].equals(target)) {
tags.setInteger(key, i);
tool.getTagCompound().setTag(NBT_MODEL_INDEX, tags);
return target;
}
}
return modelError;
}
// Grab the indexed model.
return getModel(tags.getInteger(key));
}
use of net.silentchaos512.gems.api.lib.EnumPartPosition in project SilentGems by SilentChaos512.
the class ToolRenderHelper method buildModelSet.
/**
* Creates the list of all possible models.
*/
protected void buildModelSet() {
if (modelSet != null) {
return;
}
Set<ModelResourceLocation> set = Sets.newConcurrentHashSet();
for (ToolPart part : ToolPartRegistry.getValues()) {
for (EnumPartPosition pos : EnumPartPosition.values()) {
for (Item itemTool : ModItems.tools) {
for (int frame = 0; frame < (itemTool instanceof ItemGemBow ? 4 : 1); ++frame) {
ModelResourceLocation model = part.getModel(new ItemStack(itemTool), pos, frame);
if (model != null) {
set.add(model);
}
}
}
}
}
// Bow "arrow" models
arrowModels = new ModelResourceLocation[8];
for (int i = 0; i < 8; ++i) {
String tier = i < 4 ? "regular" : "super";
ModelResourceLocation model = new ModelResourceLocation(SilentGems.RESOURCE_PREFIX + "bow/bowarrow" + tier + (i & 3));
if (model != null)
set.add(model);
arrowModels[i] = model;
}
modelSet = set;
models = set.toArray(new ModelResourceLocation[set.size()]);
}
use of net.silentchaos512.gems.api.lib.EnumPartPosition in project SilentGems by SilentChaos512.
the class ToolRenderHelper method addInformation.
@Override
public void addInformation(ItemStack tool, EntityPlayer player, List list, boolean advanced) {
LocalizationHelper loc = SilentGems.instance.localizationHelper;
boolean controlDown = KeyTracker.isControlDown();
boolean altDown = KeyTracker.isAltDown();
boolean shiftDown = KeyTracker.isShiftDown();
String line;
// Tipped upgrade
ToolPartTip partTip = (ToolPartTip) ToolHelper.getConstructionTip(tool);
if (partTip != null) {
String tipName = partTip.getUnlocalizedName().replaceFirst("[^:]+:", "");
tipName = loc.getMiscText("Tooltip." + tipName);
line = loc.getMiscText("Tooltip.Tipped", tipName);
list.add(line);
}
// Show original owner?
if (controlDown) {
String owner = ToolHelper.getOriginalOwner(tool);
if (owner.equals(SilentGems.localizationHelper.getMiscText("Tooltip.OriginalOwner.Creative")))
owner = TextFormatting.LIGHT_PURPLE + owner;
if (!owner.isEmpty())
list.add(loc.getMiscText("Tooltip.OriginalOwner", owner));
else
list.add(loc.getMiscText("Tooltip.OriginalOwner.Unknown"));
}
// Missing data?
if (ToolHelper.hasNoConstruction(tool)) {
list.add(loc.getMiscText("Tooltip.NoData1"));
list.add(loc.getMiscText("Tooltip.NoData2"));
} else // Broken?
if (ToolHelper.isBroken(tool)) {
line = loc.getMiscText("Tooltip.Broken");
list.add(line);
}
final Item item = tool.getItem();
final boolean isSword = item instanceof ItemGemSword;
final boolean isAxe = item instanceof ItemGemAxe;
final boolean isWeapon = isSword || isAxe;
final boolean isCaster = isSword && ToolHelper.getToolTier(tool).ordinal() >= EnumMaterialTier.SUPER.ordinal();
final boolean isBow = item instanceof ItemGemBow;
final boolean isDigger = item instanceof ItemTool;
final boolean isShield = item instanceof ItemGemShield;
final String sep = loc.getMiscText("Tooltip.Separator");
if (controlDown) {
// Properties Header
line = loc.getMiscText("Tooltip.Properties");
list.add(line);
TextFormatting color = TextFormatting.YELLOW;
// Tier
EnumMaterialTier tier = ToolHelper.getToolTier(tool);
line = TextFormatting.RESET + loc.getMiscText("ToolTier." + tier);
list.add(" " + color + loc.getMiscText("ToolTier", line));
int durabilityMax = ToolHelper.getMaxDamage(tool);
int durability = durabilityMax - tool.getItemDamage();
String s1 = String.format(durability > 9999 ? "%,d" : "%d", durability);
String s2 = String.format(durabilityMax > 9999 ? "%,d" : "%d", durabilityMax);
line = loc.getMiscText("Tooltip.Durability", s1 + " / " + s2);
list.add(color + " " + line);
if (isShield)
list.add(color + getTooltipLine("BlockingPower", ToolHelper.getBlockingPower(tool)));
if (isDigger) {
// @formatter:off
int harvestLevel = ToolHelper.getHarvestLevel(tool);
String str = color + getTooltipLine("HarvestLevel", harvestLevel);
String key = "Tooltip.level" + harvestLevel;
String val = SilentGems.localizationHelper.getMiscText(key);
if (!val.equals("misc.silentgems:" + key))
str += " (" + val + ")";
list.add(str);
list.add(color + getTooltipLine("HarvestSpeed", ToolHelper.getDigSpeedOnProperMaterial(tool)));
}
if (isWeapon) {
list.add(color + getTooltipLine("MeleeSpeed", ToolHelper.getMeleeSpeedModifier(tool) + 4).replaceFirst("%", ""));
list.add(color + getTooltipLine("MeleeDamage", ToolHelper.getMeleeDamageModifier(tool)));
if (isCaster)
list.add(color + getTooltipLine("MagicDamage", ToolHelper.getMagicDamageModifier(tool)));
}
if (isBow) {
list.add(color + getTooltipLine("DrawDelay", ModItems.bow.getDrawDelay(tool)));
list.add(color + getTooltipLine("ArrowDamage", 2f + ModItems.bow.getArrowDamage(tool)));
}
list.add(color + getTooltipLine("ChargeSpeed", ToolHelper.getChargeSpeed(tool)));
} else {
list.add(TextFormatting.GOLD + loc.getMiscText("Tooltip.CtrlForProp"));
}
if (altDown) {
// Statistics Header
list.add(sep);
line = loc.getMiscText("Tooltip.Statistics");
list.add(line);
list.add(getTooltipLine("BlocksMined", ToolHelper.getStatBlocksMined(tool)));
if (isDigger) {
list.add(getTooltipLine("BlocksPlaced", ToolHelper.getStatBlocksPlaced(tool)));
}
if (item instanceof ItemGemShovel) {
list.add(getTooltipLine("PathsMade", ToolHelper.getStatPathsMade(tool)));
}
if (item instanceof ItemGemHoe) {
list.add(getTooltipLine("BlocksTilled", ToolHelper.getStatBlocksTilled(tool)));
}
list.add(getTooltipLine("HitsLanded", ToolHelper.getStatHitsLanded(tool)));
if (isCaster || isBow)
list.add(getTooltipLine("ShotsFired", ToolHelper.getStatShotsFired(tool)));
if (item instanceof ItemGemTomahawk)
list.add(getTooltipLine("ThrownCount", ToolHelper.getStatThrownCount(tool)));
if (isWeapon)
list.add(getTooltipLine("KillCount", ToolHelper.getStatKillCount(tool)));
list.add(getTooltipLine("Redecorated", ToolHelper.getStatRedecorated(tool)));
list.add(sep);
line = loc.getMiscText("Tooltip.Construction");
list.add(line);
ToolPart[] parts = ToolHelper.getConstructionParts(tool);
EnumMaterialGrade[] grades = ToolHelper.getConstructionGrades(tool);
for (int i = 0; i < parts.length; ++i) {
ToolPart part = parts[i];
EnumMaterialGrade grade = grades[i];
line = " " + TextFormatting.YELLOW + part.getKey() + TextFormatting.GOLD + " (" + grade + ")";
list.add(line);
}
list.add(sep);
} else {
list.add(TextFormatting.GOLD + loc.getMiscText("Tooltip.AltForStat"));
}
// Debug render layers
if (controlDown && shiftDown && tool.hasTagCompound()) {
if (!altDown)
list.add(sep);
for (EnumPartPosition pos : EnumPartPosition.values()) {
NBTTagCompound tags = tool.getTagCompound().getCompoundTag(NBT_MODEL_INDEX);
if (tags != null) {
String key = "Layer" + pos.ordinal();
String str = "%s: %d, %X";
str = String.format(str, key, tags.getInteger(key), tags.getInteger(key + "Color"));
list.add(str);
}
}
}
}
Aggregations