Files
TinkersConstruct/src/main/java/tconstruct/items/tools/Arrow.java
T
miozuneGitHub GTNH Actionsgithub-actions[bot]
69bb974420 Use compileOnlyApi for CoFH (#84)
* Use compileOnlyApi for CoFH

* spotlessApply (#85)

Co-authored-by: GitHub GTNH Actions <>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-05-15 08:07:18 +02:00

218 lines
7.5 KiB
Java

package tconstruct.items.tools;
import java.util.List;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.*;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.*;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.crafting.ToolBuilder;
import tconstruct.library.tools.CustomMaterial;
import tconstruct.library.tools.FletchingMaterial;
import tconstruct.library.tools.ToolCore;
import tconstruct.weaponry.TinkerWeaponry;
@Deprecated
public class Arrow extends ToolCore {
public Arrow() {
super(3);
this.setUnlocalizedName("InfiTool.Arrow");
this.setMaxStackSize(64);
this.setMaxDamage(0);
}
@Override
public String getIconSuffix(int partType) {
switch (partType) {
case 0:
return "_arrow_head";
case 1:
return ""; // Doesn't break
case 2:
return "_arrow_shaft";
case 3:
return "_arrow_fletching";
default:
return "";
}
}
@Override
protected int getDefaultColor(int renderPass, int materialID) {
// fletchling uses custom material
if (renderPass == 2) {
CustomMaterial mat = TConstructRegistry.getCustomMaterial(materialID, FletchingMaterial.class);
if (mat != null) return mat.color;
}
return super.getDefaultColor(renderPass, materialID);
}
@Override
public String getEffectSuffix() {
return "_arrow_effect";
}
@Override
public String getDefaultFolder() {
return "arrow";
}
@Override
public void registerPartPaths(int index, String[] location) {
headStrings.put(index, location[0]);
handleStrings.put(index, location[2]);
}
@Override
public void registerAlternatePartPaths(int index, String[] location) {
accessoryStrings.put(index, location[3]);
}
@Override
public Item getHeadItem() {
return TinkerWeaponry.arrowhead;
}
@Override
public Item getAccessoryItem() {
return TinkerWeaponry.fletching;
}
@Override
public String[] getTraits() {
return new String[] { "ammo" };
}
@Override
public float getDamageModifier() {
return 0.5f;
}
@Override
public void getSubItems(Item id, CreativeTabs tab, List list) {
// Vanilla style arrow
Item accessory = getAccessoryItem();
ItemStack accessoryStack = accessory != null ? new ItemStack(getAccessoryItem(), 1, 0) : null;
Item extra = getExtraItem();
ItemStack extraStack = extra != null ? new ItemStack(extra, 1, 0) : null;
ItemStack tool = ToolBuilder.instance.buildTool(
new ItemStack(getHeadItem(), 1, 3),
new ItemStack(getHandleItem(), 1, 0),
accessoryStack,
extraStack,
"");
if (tool != null) {
tool.stackSize = 1;
tool.getTagCompound().getCompoundTag("InfiTool").setBoolean("Built", true);
list.add(tool);
}
// Random arrow
accessory = getAccessoryItem();
accessoryStack = accessory != null ? new ItemStack(getAccessoryItem(), 1, random.nextInt(4)) : null;
extra = getExtraItem();
extraStack = extra != null ? new ItemStack(extra, 1, 0) : null;
tool = ToolBuilder.instance.buildTool(
new ItemStack(getHeadItem(), 1, random.nextInt(18)),
new ItemStack(getHandleItem(), 1, random.nextInt(18)),
accessoryStack,
extraStack,
StatCollector.translateToLocal("item.tool.randomarrow"));
if (tool != null) {
tool.stackSize = 1;
tool.getTagCompound().getCompoundTag("InfiTool").setBoolean("Built", true);
list.add(tool);
}
super.getSubItems(id, tab, list);
}
@Override
public void buildTool(int id, String name, List list) {
Item accessory = getAccessoryItem();
ItemStack accessoryStack = accessory != null ? new ItemStack(getAccessoryItem(), 1, 0) : null;
Item extra = getExtraItem();
ItemStack extraStack = extra != null ? new ItemStack(getExtraItem(), 1, id) : null;
ItemStack tool = ToolBuilder.instance.buildTool(
new ItemStack(getHeadItem(), 1, id),
new ItemStack(getHandleItem(), 1, id),
accessoryStack,
extraStack,
name);
if (tool != null) {
tool.stackSize = 1;
tool.getTagCompound().getCompoundTag("InfiTool").setBoolean("Built", true);
list.add(tool);
}
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side,
float clickX, float clickY, float clickZ) {
return false;
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) {
if (!stack.hasTagCompound()) return;
NBTTagCompound tags = stack.getTagCompound();
if (tags.hasKey("Energy")) {
String color = "";
// double joules = this.getJoules(stack);
int power = tags.getInteger("Energy");
if (power != 0) {
if (power <= this.getMaxEnergyStored(stack) / 3) color = "\u00a74";
else if (power > this.getMaxEnergyStored(stack) * 2 / 3) color = "\u00a72";
else color = "\u00a76";
}
String energy = color + tags.getInteger("Energy") + "/" + getMaxEnergyStored(stack) + " RF";
list.add(energy);
}
if (tags.hasKey("InfiTool")) {
boolean broken = tags.getCompoundTag("InfiTool").getBoolean("Broken");
if (broken) list.add("\u00A7oBroken");
else {
int head = tags.getCompoundTag("InfiTool").getInteger("Head");
int handle = tags.getCompoundTag("InfiTool").getInteger("Handle");
String headName = getAbilityNameForType(head, 0);
if (!headName.equals("")) list.add(getStyleForType(head) + headName);
String handleName = getAbilityNameForType(handle, 0);
if (!handleName.equals("") && handle != head) list.add(getStyleForType(handle) + handleName);
boolean displayToolTips = true;
int tipNum = 0;
while (displayToolTips) {
tipNum++;
String tooltip = "Tooltip" + tipNum;
if (tags.getCompoundTag("InfiTool").hasKey(tooltip)) {
String tipName = tags.getCompoundTag("InfiTool").getString(tooltip);
if (!tipName.equals("")) list.add(tipName);
} else displayToolTips = false;
}
}
}
int attack = (int) (tags.getCompoundTag("InfiTool").getInteger("Attack") * this.getDamageModifier());
list.add(
"\u00A79+" + attack
+ " "
+ StatCollector.translateToLocalFormatted("attribute.name.generic.attackDamage"));
list.add(
"\u00A79+" + tags.getCompoundTag("InfiTool").getInteger("Attack")
+ " "
+ StatCollector.translateToLocalFormatted("attribute.name.ammo.attackDamage"));
}
}