Lots of integration. Graphics n stuff. Items. Everything.

This commit is contained in:
Bernhard Bonigl committed 2014-10-05 20:46:12 +02:00
1 parent 4bb32da4c8
commit 0bdf31912b
48 files changed
+119 -384

No files matched your search

@@ -1,7 +1,6 @@
package tconstruct.weaponry;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
@@ -12,6 +11,7 @@ import mantle.pulsar.pulse.Pulse;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
@@ -19,6 +19,7 @@ import tconstruct.TConstruct;
import tconstruct.library.TConstructCreativeTab;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.crafting.*;
import tconstruct.library.tools.DynamicToolPart;
import tconstruct.library.tools.ToolCore;
import tconstruct.library.util.IPattern;
import tconstruct.library.util.IToolPart;
@@ -27,13 +28,12 @@ import tconstruct.tools.TinkerTools;
import tconstruct.tools.items.Pattern;
import tconstruct.weaponry.ammo.ArrowAmmo;
import tconstruct.weaponry.ammo.BoltAmmo;
import tconstruct.weaponry.items.DualMaterialToolPart;
import tconstruct.library.tools.DualMaterialToolPart;
import tconstruct.weaponry.items.WeaponryPattern;
import tconstruct.weaponry.items.WeaponryToolPart;
import tconstruct.weaponry.library.weaponry.AmmoItem;
import tconstruct.weaponry.library.weaponry.AmmoWeapon;
import tconstruct.weaponry.library.weaponry.ArrowShaftMaterial;
import tconstruct.weaponry.library.weaponry.ProjectileWeapon;
import tconstruct.library.weaponry.AmmoItem;
import tconstruct.library.weaponry.AmmoWeapon;
import tconstruct.library.weaponry.ArrowShaftMaterial;
import tconstruct.library.weaponry.ProjectileWeapon;
import tconstruct.weaponry.weapons.*;
import java.util.Map;
@@ -48,7 +48,6 @@ public class TinkerWeaponry {
public static WeaponryCommonProxy proxy;
// Throwing Weapons
public static ToolCore throwArrow;
public static AmmoWeapon shuriken;
public static AmmoWeapon throwingknife;
public static AmmoWeapon javelin;
@@ -62,11 +61,11 @@ public class TinkerWeaponry {
public static AmmoItem boltAmmo;
// Tool Parts
public static WeaponryToolPart partShuriken;
public static WeaponryToolPart partArrowShaft; // not craftable, used internally
public static WeaponryToolPart partBowLimb;
public static WeaponryToolPart partCrossbowLimb;
public static WeaponryToolPart partCrossbowBody;
public static DynamicToolPart partShuriken;
public static DynamicToolPart partArrowShaft; // not craftable, used internally
public static DynamicToolPart partBowLimb;
public static DynamicToolPart partCrossbowLimb;
public static DynamicToolPart partCrossbowBody;
public static DualMaterialToolPart partBolt;
// patterns/casts
@@ -106,15 +105,14 @@ public class TinkerWeaponry {
private void registerItems()
{
// create tool part
partShuriken = new WeaponryToolPart("_shuriken", "Shuriken");
partArrowShaft = new WeaponryToolPart("_arrow_shaft", "Shaft");
partBowLimb = new WeaponryToolPart("_bow_limb", "BowLimb");
partCrossbowLimb = new WeaponryToolPart("_crossbow_limb", "CrossbowLimb");
partCrossbowBody = new WeaponryToolPart("_crossbow_body", "CrossbowBody");
partShuriken = new DynamicToolPart("_shuriken", "Shuriken");
partArrowShaft = new DynamicToolPart("_arrow_shaft", "Shaft");
partBowLimb = new DynamicToolPart("_bow_limb", "BowLimb");
partCrossbowLimb = new DynamicToolPart("_crossbow_limb", "CrossbowLimb");
partCrossbowBody = new DynamicToolPart("_crossbow_body", "CrossbowBody");
partBolt = new DualMaterialToolPart("_bolt", "Bolt");
// create throwing weapons
throwArrow = new ThrowArrowItem();
shuriken = new Shuriken();
throwingknife = new ThrowingKnife();
javelin = new Javelin();
@@ -136,7 +134,6 @@ public class TinkerWeaponry {
GameRegistry.registerItem(partCrossbowBody, "CrossbowBodyPart");
GameRegistry.registerItem(partBolt, "BoltPart");
// register throwing weapons
GameRegistry.registerItem(throwArrow, "ThrowArrow");
GameRegistry.registerItem(shuriken, "Shuriken");
GameRegistry.registerItem(throwingknife, "ThrowingKnife");
GameRegistry.registerItem(javelin, "Javelin");
@@ -308,4 +305,18 @@ public class TinkerWeaponry {
}
}
}
private void setupCreativeTab()
{
ItemStack tool = new ItemStack(TinkerWeaponry.longbow, 1, 0);
NBTTagCompound compound = new NBTTagCompound();
compound.setTag("InfiTool", new NBTTagCompound());
compound.getCompoundTag("InfiTool").setInteger("RenderHead", 0);
compound.getCompoundTag("InfiTool").setInteger("RenderHandle", 0);
compound.getCompoundTag("InfiTool").setInteger("RenderAccessory", 0);
tool.setTagCompound(compound);
TConstructRegistry.weaponryTab.init(tool);
}
}
@@ -1,15 +1,17 @@
package tconstruct.weaponry;
import tconstruct.client.AmmoItemRenderer;
import tconstruct.library.entity.ProjectileBase;
import tconstruct.weaponry.client.AmmoSlotHandler;
import tconstruct.weaponry.client.CrosshairHandler;
import tconstruct.weaponry.client.RenderEventHandler;
import tconstruct.weaponry.client.entityrenderer.ArrowEntityRenderer;
import tconstruct.weaponry.client.entityrenderer.JavelinEntityRenderer;
import tconstruct.weaponry.client.entityrenderer.ProjectileBaseRenderer;
import tconstruct.weaponry.client.entityrenderer.ShurikenEntityRenderer;
import tconstruct.weaponry.client.renderer.*;
import tconstruct.weaponry.client.entity.ArrowEntityRenderer;
import tconstruct.weaponry.client.entity.JavelinEntityRenderer;
import tconstruct.weaponry.client.entity.ProjectileBaseRenderer;
import tconstruct.weaponry.client.entity.ShurikenEntityRenderer;
import tconstruct.weaponry.client.item.*;
import tconstruct.weaponry.entity.*;
import tconstruct.weaponry.util.Reference;
import tconstruct.util.Reference;
import cpw.mods.fml.client.registry.RenderingRegistry;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.MinecraftForgeClient;
@@ -40,7 +42,6 @@ public class WeaponryClientProxy extends WeaponryCommonProxy {
private void registerRenderers()
{
renderer = new AmmoItemRenderer();
MinecraftForgeClient.registerItemRenderer(TinkerWeaponry.throwArrow, renderer);
MinecraftForgeClient.registerItemRenderer(TinkerWeaponry.shuriken, renderer);
MinecraftForgeClient.registerItemRenderer(TinkerWeaponry.throwingknife, new ThrowingKnifeRenderer());
MinecraftForgeClient.registerItemRenderer(TinkerWeaponry.javelin, new JavelinRenderer());
@@ -2,11 +2,11 @@ package tconstruct.weaponry;
import tconstruct.weaponry.ammo.ArrowAmmo;
import tconstruct.weaponry.ammo.BoltAmmo;
import tconstruct.weaponry.items.DualMaterialToolPart;
import tconstruct.weaponry.library.weaponry.ArrowShaftMaterial;
import tconstruct.weaponry.library.weaponry.BowBaseAmmo;
import tconstruct.weaponry.library.weaponry.ProjectileWeapon;
import tconstruct.weaponry.library.weaponry.IAmmo;
import tconstruct.library.tools.DualMaterialToolPart;
import tconstruct.library.weaponry.ArrowShaftMaterial;
import tconstruct.library.weaponry.BowBaseAmmo;
import tconstruct.library.weaponry.ProjectileWeapon;
import tconstruct.library.weaponry.IAmmo;
import tconstruct.weaponry.weapons.Crossbow;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.item.Item;
@@ -2,8 +2,8 @@ package tconstruct.weaponry.ammo;
import tconstruct.TConstruct;
import tconstruct.weaponry.TinkerWeaponry;
import tconstruct.weaponry.library.weaponry.AmmoItem;
import tconstruct.weaponry.util.Reference;
import tconstruct.library.weaponry.AmmoItem;
import tconstruct.util.Reference;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -49,11 +49,6 @@ public class ArrowAmmo extends AmmoItem {
return "arrow";
}
@Override
public String getDefaultTexturePath() {
return Reference.RESOURCE + ":" + getDefaultFolder();
}
@Override
public void registerPartPaths (int index, String[] location)
{
@@ -1,8 +1,8 @@
package tconstruct.weaponry.ammo;
import tconstruct.weaponry.TinkerWeaponry;
import tconstruct.weaponry.items.DualMaterialToolPart;
import tconstruct.weaponry.library.weaponry.AmmoItem;
import tconstruct.library.tools.DualMaterialToolPart;
import tconstruct.library.weaponry.AmmoItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import tconstruct.library.crafting.ToolBuilder;
@@ -1,6 +1,6 @@
package tconstruct.weaponry.client;
import tconstruct.weaponry.library.weaponry.ProjectileWeapon;
import tconstruct.library.weaponry.ProjectileWeapon;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
@@ -1,7 +1,7 @@
package tconstruct.weaponry.client;
import tconstruct.weaponry.util.Reference;
import tconstruct.weaponry.library.weaponry.IWindup;
import tconstruct.util.Reference;
import tconstruct.library.weaponry.IWindup;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
@@ -1,22 +0,0 @@
package tconstruct.weaponry.client;
import net.minecraft.util.IIcon;
// required to fix Mojansg bugs...
public class IconFlipped extends net.minecraft.client.renderer.IconFlipped {
private final IIcon baseIcon;
private final boolean flipV;
public IconFlipped(IIcon p_i1560_1_, boolean p_i1560_2_, boolean p_i1560_3_) {
super(p_i1560_1_, p_i1560_2_, p_i1560_3_);
this.baseIcon = p_i1560_1_;
this.flipV = p_i1560_3_;
}
// has a faulty implementation in original class
public float getMinV()
{
return this.flipV ? this.baseIcon.getMaxV() : this.baseIcon.getMinV();
}
}
@@ -1,8 +1,8 @@
package tconstruct.weaponry.client;
import tconstruct.weaponry.TinkerWeaponry;
import tconstruct.weaponry.library.weaponry.BowBaseAmmo;
import tconstruct.weaponry.library.weaponry.IWindup;
import tconstruct.library.weaponry.BowBaseAmmo;
import tconstruct.library.weaponry.IWindup;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.event.FOVUpdateEvent;
@@ -1,4 +1,4 @@
package tconstruct.weaponry.client.entityrenderer;
package tconstruct.weaponry.client.entity;
import tconstruct.weaponry.entity.ArrowEntity;
import org.lwjgl.opengl.GL11;
@@ -1,4 +1,4 @@
package tconstruct.weaponry.client.entityrenderer;
package tconstruct.weaponry.client.entity;
import tconstruct.weaponry.entity.JavelinEntity;
import org.lwjgl.opengl.GL11;
@@ -1,7 +1,7 @@
package tconstruct.weaponry.client.entityrenderer;
package tconstruct.weaponry.client.entity;
import tconstruct.weaponry.client.renderer.FlexibleToolRenderer;
import tconstruct.weaponry.entity.ProjectileBase;
import tconstruct.client.FlexibleToolRenderer;
import tconstruct.library.entity.ProjectileBase;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.Entity;
@@ -1,4 +1,4 @@
package tconstruct.weaponry.client.entityrenderer;
package tconstruct.weaponry.client.entity;
import tconstruct.weaponry.entity.ShurikenEntity;
import org.lwjgl.opengl.GL11;
@@ -1,10 +1,11 @@
package tconstruct.weaponry.client.renderer;
package tconstruct.weaponry.client.item;
import tconstruct.client.FlexibleToolRenderer;
import tconstruct.weaponry.TinkerWeaponry;
import tconstruct.weaponry.ammo.ArrowAmmo;
import tconstruct.weaponry.entity.ArrowEntity;
import tconstruct.weaponry.library.weaponry.ProjectileWeapon;
import tconstruct.weaponry.library.weaponry.IWindup;
import tconstruct.library.weaponry.ProjectileWeapon;
import tconstruct.library.weaponry.IWindup;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
@@ -1,5 +1,6 @@
package tconstruct.weaponry.client.renderer;
package tconstruct.weaponry.client.item;
import tconstruct.client.FlexibleToolRenderer;
import tconstruct.weaponry.entity.ArrowEntity;
import tconstruct.weaponry.entity.BoltEntity;
import tconstruct.weaponry.weapons.Crossbow;
@@ -1,6 +1,7 @@
package tconstruct.weaponry.client.renderer;
package tconstruct.weaponry.client.item;
import tconstruct.weaponry.library.weaponry.IWindup;
import tconstruct.client.AmmoItemRenderer;
import tconstruct.library.weaponry.IWindup;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import org.lwjgl.opengl.GL11;
@@ -1,6 +1,7 @@
package tconstruct.weaponry.client.renderer;
package tconstruct.weaponry.client.item;
import tconstruct.weaponry.library.weaponry.IWindup;
import tconstruct.client.AmmoItemRenderer;
import tconstruct.library.weaponry.IWindup;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.entity.RenderPlayer;
@@ -1,56 +0,0 @@
package tconstruct.weaponry.client.renderer;
import tconstruct.weaponry.library.weaponry.IAmmo;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.item.ItemStack;
import org.lwjgl.opengl.GL11;
public class AmmoItemRenderer extends FlexibleToolRenderer {
//public static FontRenderer fontRenderer;
public AmmoItemRenderer() {
// super(true);
//fontRenderer = new FontRenderer(Minecraft.getMinecraft().gameSettings, new ResourceLocation(Reference.RESOURCE, "textures/font/border_numbers.png"), Minecraft.getMinecraft().renderEngine, false);
}
@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
if(type == ItemRenderType.INVENTORY)
return true;
return super.handleRenderType(item, type);
}
@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
// render the item regularly
super.renderItem(type, item, data);
//RenderItem.getInstance().renderItemIntoGUI(Minecraft.getMinecraft().fontRenderer, Minecraft.getMinecraft().renderEngine, item, 0,0);
if(item.getTagCompound() == null || type != ItemRenderType.INVENTORY)
return;
// render custom stacksize
renderAmmoCount(item);
}
public void renderAmmoCount(ItemStack item)
{
if(!(item.getItem() instanceof IAmmo))
return;
int amount = ((IAmmo) item.getItem()).getAmmoCount(item);
String str = String.valueOf(amount);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_BLEND);
GL11.glScalef(0.7f, 0.7f, 0.7f);
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
fontRenderer.drawStringWithShadow(str, 7 + 19 - 2 - fontRenderer.getStringWidth(str), 7 + 6 + 3, 16777215);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_DEPTH_TEST);
}
}
@@ -1,310 +0,0 @@
package tconstruct.weaponry.client.renderer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraftforge.client.IItemRenderer;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import tconstruct.TConstruct;
import tconstruct.library.tools.ToolCore;
public class FlexibleToolRenderer implements IItemRenderer {
public float depth = 1/32f;
public void setDepth(float d) { depth = d; }
@Override
public boolean handleRenderType (ItemStack item, ItemRenderType type)
{
if(!item.hasTagCompound())
return false;
switch (type)
{
case ENTITY:
//GL11.glTranslatef(-0.0625F, -0.0625F, 0F);
return true;
case EQUIPPED:
//GL11.glTranslatef(0.03f, 0F, -0.09375F);
case EQUIPPED_FIRST_PERSON:
return true;
case INVENTORY:
return true;
default:
TConstruct.logger.warn("[TCon] Unhandled render case!");
case FIRST_PERSON_MAP:
return false;
}
}
@Override
public boolean shouldUseRenderHelper (ItemRenderType type, ItemStack item, ItemRendererHelper helper)
{
return handleRenderType(item, type) & helper.ordinal() < ItemRendererHelper.EQUIPPED_BLOCK.ordinal();
}
private static final int toolIcons = 10;
protected void specialAnimation(ItemRenderType type, ItemStack item) {}
@Override
public void renderItem (ItemRenderType type, ItemStack item, Object... data) {
Entity ent = null;
if (data.length > 1)
ent = (Entity) data[1];
IIcon[] parts = new IIcon[toolIcons];
int iconParts = getIcons(item, type, ent, parts);
// drawing the inventory is a simple procedure
if (type == ItemRenderType.INVENTORY) {
renderInventory(iconParts, parts, item);
return;
}
Tessellator tess = Tessellator.instance;
float[] xMax = new float[iconParts];
float[] yMin = new float[iconParts];
float[] xMin = new float[iconParts];
float[] yMax = new float[iconParts];
float[] width = new float[iconParts];
float[] height = new float[iconParts];
float[] xDiff = new float[iconParts];
float[] yDiff = new float[iconParts];
float[] xSub = new float[iconParts];
float[] ySub = new float[iconParts];
for (int i = 0; i < iconParts; ++i)
{
IIcon icon = parts[i];
xMin[i] = icon.getMinU();
xMax[i] = icon.getMaxU();
yMin[i] = icon.getMinV();
yMax[i] = icon.getMaxV();
width[i] = icon.getIconWidth();
height[i] = icon.getIconHeight();
xDiff[i] = xMin[i] - xMax[i];
yDiff[i] = yMin[i] - yMax[i];
xSub[i] = 0.5f * (xMax[i] - xMin[i]) / width[i];
ySub[i] = 0.5f * (yMax[i] - yMin[i]) / height[i];
}
GL11.glPushMatrix();
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
if(type != ItemRenderType.ENTITY) {
GL11.glTranslatef(0.5f, 0.5f, 0);
GL11.glScalef(0.5f, 0.5f, 0.5f);
specialAnimation(type, item);
}
// prepare colors
int[] color = new int[iconParts];
for(int i = 0; i < iconParts; i++)
color[i] = item.getItem().getColorFromItemStack(item, i);
// one side
tess.startDrawingQuads();
tess.setNormal(0, 0, 1);
for (int i = 0; i < iconParts; ++i)
{
tess.setColorOpaque_I(color[i]);
tess.addVertexWithUV(-0.5, -0.5, +depth, xMax[i], yMax[i]);
tess.addVertexWithUV(+0.5, -0.5, +depth, xMin[i], yMax[i]);
tess.addVertexWithUV(+0.5, +0.5, +depth, xMin[i], yMin[i]);
tess.addVertexWithUV(-0.5, +0.5, +depth, xMax[i], yMin[i]);
}
tess.draw();
// other side
tess.startDrawingQuads();
tess.setNormal(0, 0, -1);
for (int i = 0; i < iconParts; ++i)
{
tess.setColorOpaque_I(color[i]);
tess.addVertexWithUV(-0.5, +0.5, -depth, xMax[i], yMin[i]);
tess.addVertexWithUV(+0.5, +0.5, -depth, xMin[i], yMin[i]);
tess.addVertexWithUV(+0.5, -0.5, -depth, xMin[i], yMax[i]);
tess.addVertexWithUV(-0.5, -0.5, -depth, xMax[i], yMax[i]);
}
tess.draw();
// make it have "depth"
tess.startDrawingQuads();
tess.setNormal(-1, 0, 0);
float pos;
float iconPos;
for (int i = 0; i < iconParts; ++i)
{
tess.setColorOpaque_I(color[i]);
float w = width[i], m = xMax[i], d = xDiff[i], s = xSub[i];
for (int k = 0, e = (int)w; k < e; ++k)
{
pos = k / w;
iconPos = m + d * pos - s;
pos -= 0.5f;
tess.addVertexWithUV(pos, -0.5, -depth, iconPos, yMax[i]);
tess.addVertexWithUV(pos, -0.5, +depth, iconPos, yMax[i]);
tess.addVertexWithUV(pos, +0.5, +depth, iconPos, yMin[i]);
tess.addVertexWithUV(pos, +0.5, -depth, iconPos, yMin[i]);
}
}
tess.draw();
tess.startDrawingQuads();
tess.setNormal(1, 0, 0);
float posEnd;
for (int i = 0; i < iconParts; ++i)
{
tess.setColorOpaque_I(color[i]);
float w = width[i], m = xMax[i], d = xDiff[i], s = xSub[i];
float d2 = 1f / w;
for (int k = 0, e = (int)w; k < e; ++k)
{
pos = k / w;
iconPos = m + d * pos - s;
pos -= 0.5f;
posEnd = pos + d2;
tess.addVertexWithUV(posEnd, +0.5, -depth, iconPos, yMin[i]);
tess.addVertexWithUV(posEnd, +0.5, +depth, iconPos, yMin[i]);
tess.addVertexWithUV(posEnd, -0.5, +depth, iconPos, yMax[i]);
tess.addVertexWithUV(posEnd, -0.5, -depth, iconPos, yMax[i]);
}
}
tess.draw();
tess.startDrawingQuads();
tess.setNormal(0, 1, 0);
for (int i = 0; i < iconParts; ++i)
{
tess.setColorOpaque_I(color[i]);
float h = height[i], m = yMax[i], d = yDiff[i], s = ySub[i];
float d2 = 1f / h;
for (int k = 0, e = (int)h; k < e; ++k)
{
pos = k / h;
iconPos = m + d * pos - s;
pos -= 0.5f;
posEnd = pos + d2;
tess.addVertexWithUV(-0.5, posEnd, +depth, xMax[i], iconPos);
tess.addVertexWithUV(+0.5, posEnd, +depth, xMin[i], iconPos);
tess.addVertexWithUV(+0.5, posEnd, -depth, xMin[i], iconPos);
tess.addVertexWithUV(-0.5, posEnd, -depth, xMax[i], iconPos);
}
}
tess.draw();
tess.startDrawingQuads();
tess.setNormal(0, -1, 0);
for (int i = 0; i < iconParts; ++i)
{
tess.setColorOpaque_I(color[i]);
float h = height[i], m = yMax[i], d = yDiff[i], s = ySub[i];
for (int k = 0, e = (int)h; k < e; ++k)
{
pos = k / h;
iconPos = m + d * pos - s;
pos -= 0.5f;
tess.addVertexWithUV(+0.5, pos, +depth, xMin[i], iconPos);
tess.addVertexWithUV(-0.5, pos, +depth, xMax[i], iconPos);
tess.addVertexWithUV(-0.5, pos, -depth, xMax[i], iconPos);
tess.addVertexWithUV(+0.5, pos, -depth, xMin[i], iconPos);
}
}
tess.draw();
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
GL11.glPopMatrix();
}
public void renderInventory(int count, IIcon[] icons, ItemStack item)
{
Tessellator tess = Tessellator.instance;
GL11.glPushMatrix();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glAlphaFunc(GL11.GL_GREATER, 0.5F);
GL11.glDisable(GL11.GL_BLEND);
tess.startDrawingQuads();
// draw a simple rectangle for the inventory icon
for (int i = 0; i < count; ++i)
{
tess.setColorOpaque_I(item.getItem().getColorFromItemStack(item, i));
final IIcon icon = icons[i];
final float xmin = icon.getMinU();
final float xmax = icon.getMaxU();
final float ymin = icon.getMinV();
final float ymax = icon.getMaxV();
tess.addVertexWithUV( 0, 16, 0, xmin, ymax);
tess.addVertexWithUV(16, 16, 0, xmax, ymax);
tess.addVertexWithUV(16, 0, 0, xmax, ymin);
tess.addVertexWithUV( 0, 0, 0, xmin, ymin);
}
tess.draw();
GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
}
public int getIcons(ItemStack item, ItemRenderType type, Entity ent, IIcon[] parts)
{
int iconParts = toolIcons;//tool.getRenderPasses(item.getItemDamage());
// TODO: have the tools define how many render passes they have
// (requires more logic rewrite than it sounds like)
boolean isInventory = type == ItemRenderType.INVENTORY;
ToolCore tool = (ToolCore) item.getItem();
IIcon[] tempParts = new IIcon[iconParts];
label:
{
if (!isInventory && ent instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) ent;
ItemStack itemInUse = player.getItemInUse();
if (itemInUse != null)
{
int useCount = player.getItemInUseCount();
for (int i = iconParts; i-- > 0;)
tempParts[i] = tool.getIcon(item, i, player, itemInUse, useCount);
break label;
}
}
for (int i = iconParts; i-- > 0;)
tempParts[i] = tool.getIcon(item, i);
}
int count = 0;
for (int i = 0; i < iconParts; ++i)
{
IIcon part = tempParts[i];
if (part == null || part == ToolCore.blankSprite || part == ToolCore.emptyIcon)
++count;
else
parts[i - count] = part;
}
iconParts -= count;
if (iconParts <= 0)
{
iconParts = 1;
parts[0] = ToolCore.blankSprite;
}
return iconParts;
}
}
@@ -1,9 +1,7 @@
package tconstruct.weaponry.entity;
import tconstruct.weaponry.library.util.PiercingArrowDamage;
import cpw.mods.fml.common.network.ByteBufUtils;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import tconstruct.library.entity.ProjectileBase;
import tconstruct.library.util.PiercingArrowDamage;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@@ -12,7 +10,6 @@ import net.minecraft.util.DamageSource;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import tconstruct.TConstruct;
import tconstruct.library.tools.AbilityHelper;
import tconstruct.library.tools.ToolCore;
public class ArrowEntity extends ProjectileBase {
@@ -1,5 +1,6 @@
package tconstruct.weaponry.entity;
import tconstruct.library.entity.ProjectileBase;
import tconstruct.weaponry.TinkerWeaponry;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
@@ -1,627 +0,0 @@
package tconstruct.weaponry.entity;
import tconstruct.weaponry.library.weaponry.AmmoItem;
import tconstruct.weaponry.util.Reference;
import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.play.server.S2BPacketChangeGameState;
import net.minecraft.util.*;
import net.minecraft.world.World;
import tconstruct.library.ActiveToolMod;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.tools.AbilityHelper;
import tconstruct.library.tools.ToolCore;
import java.util.List;
// have to base this on EntityArrow, otherwise minecraft does derp things because everything is handled based on class.
public abstract class ProjectileBase extends EntityArrow implements IEntityAdditionalSpawnData {
public final static String woodSound = Reference.resource("woodHit");
public final static String stoneSound = Reference.resource("stoneHit");
public ItemStack returnStack;
public int returnStackSlot;
public boolean bounceOnNoDamage = true;
public ProjectileBase(World world) {
super(world);
}
public ProjectileBase(World world, double d, double d1, double d2) {
this(world);
this.setPosition(d, d1, d2);
}
public ProjectileBase(World world, EntityPlayer player, float speed, float accuracy, ItemStack stack) {
this(world);
this.shootingEntity = player;
canBePickedUp = 1;
// stuff from the arrow
this.setLocationAndAngles(player.posX, player.posY + (double)player.getEyeHeight(), player.posZ, player.rotationYaw, player.rotationPitch);
this.posX -= MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * 0.16F;
this.posY -= 0.10000000149011612D;
this.posZ -= MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * 0.16F;
this.setPosition(this.posX, this.posY, this.posZ);
this.yOffset = 0.0F;
this.motionX = -MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI);
this.motionZ = +MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI);
this.motionY = -MathHelper.sin(this.rotationPitch / 180.0F * (float)Math.PI);
this.setThrowableHeading(this.motionX, this.motionY, this.motionZ, speed, accuracy);
// our stuff
returnStackSlot = player.inventory.currentItem;
returnStack = stack;
/*
// fix upward default angle
motionY = -MathHelper.sin((rotationPitch / 180F) * 3.141593F - 0.2f);
setArrowHeading(motionX, motionY, motionZ, speed, 0.0f);
// set better position and move it a tad so we don't hit ourselves.
this.setPosition(player.posX, player.posY + player.getEyeHeight(), player.posZ);
*/
/*
double l = Math.sqrt(motionX*motionX + motionY*motionY + motionZ*motionZ);
double vx = motionX/l;
double vy = motionY/l;
double vz = motionZ/l;
posX += vx*1.5f;
posY += vy*1.5f;
posZ += vz*1.5f;
*/
//init();
}
public ItemStack getEntityItem ()
{
return returnStack;
}
protected void playHitBlockSound(int x, int y, int z)
{
Block block = worldObj.getBlock(x,y,z);
if(block != null && block.blockMaterial == Material.wood)
worldObj.playSoundAtEntity(this, woodSound, 1.0f, 1.0f);
else {
worldObj.playSoundAtEntity(this, stoneSound, 1.0f, 1.0f);
}
if(block != null)
worldObj.playSoundAtEntity(this, block.stepSound.getBreakSound(), 0.7f, 1.0f);
}
protected void playHitEntitySound()
{
}
/**
* How deep the item enters stuff it hits. Should be bigger for bigger objects, and smaller for smaller objects.
* 1.0f is exactly halfway in.
*/
protected double getStuckDepth() { return 0.5f; }
protected void doLivingHit(EntityLivingBase entityHit)
{
if (!this.worldObj.isRemote)
{
entityHit.setArrowCountInEntity(entityHit.getArrowCountInEntity() + 1);
}
if (this.knockbackStrength > 0)
{
double horizontalSpeed = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
if (horizontalSpeed > 0.0F)
{
entityHit.addVelocity(this.motionX * (double) this.knockbackStrength * 0.6000000238418579D / (double) horizontalSpeed, 0.1D, this.motionZ * (double) this.knockbackStrength * 0.6000000238418579D / (double) horizontalSpeed);
}
}
if (this.shootingEntity != null && this.shootingEntity instanceof EntityLivingBase)
{
EnchantmentHelper.func_151384_a(entityHit, this.shootingEntity);
EnchantmentHelper.func_151385_b((EntityLivingBase)this.shootingEntity, entityHit);
}
if (this.shootingEntity != null && entityHit != this.shootingEntity && entityHit instanceof EntityPlayer && this.shootingEntity instanceof EntityPlayerMP)
{
((EntityPlayerMP)this.shootingEntity).playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(6, 0.0F));
}
}
public void onHitBlock(MovingObjectPosition movingobjectposition) {
this.field_145791_d = movingobjectposition.blockX;
this.field_145792_e = movingobjectposition.blockY;
this.field_145789_f = movingobjectposition.blockZ;
this.field_145790_g = this.worldObj.getBlock(this.field_145791_d, this.field_145792_e, this.field_145789_f);
this.inData = this.worldObj.getBlockMetadata(this.field_145791_d, this.field_145792_e, this.field_145789_f);
this.motionX = movingobjectposition.hitVec.xCoord - this.posX;
this.motionY = movingobjectposition.hitVec.yCoord - this.posY;
this.motionZ = movingobjectposition.hitVec.zCoord - this.posZ;
double speed = getStuckDepth() * MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
this.posX -= this.motionX / speed * 0.05000000074505806D;
this.posY -= this.motionY / speed * 0.05000000074505806D;
this.posZ -= this.motionZ / speed * 0.05000000074505806D;
playHitBlockSound(movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ);
this.inGround = true;
this.arrowShake = 7;
this.setIsCritical(false);
if (this.field_145790_g.getMaterial() != Material.air)
{
this.field_145790_g.onEntityCollidedWithBlock(this.worldObj, this.field_145791_d, this.field_145792_e, this.field_145789_f, this);
}
}
public void onHitEntity(MovingObjectPosition movingobjectposition) {
NBTTagCompound tags = returnStack.getTagCompound().getCompoundTag("InfiTool");
double speed = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
int damage = MathHelper.ceiling_double_int(speed * tags.getInteger("Attack"));
// Damage calculations and stuff. For reference see AbilityHelper.onLeftClickEntity
ToolCore ammo = (ToolCore)returnStack.getItem();
// factor in modified stuff for base damage
// basically we pass the base damage to all modifiers and take the highest one
int baseDamage = 0;
for(ActiveToolMod toolmod : TConstructRegistry.activeModifiers) {
int dmg = toolmod.baseAttackDamage(baseDamage, damage, ammo, returnStack.getTagCompound(), tags, returnStack, (EntityPlayer)this.shootingEntity, movingobjectposition.entityHit);
if(dmg > baseDamage)
baseDamage = dmg;
}
damage += baseDamage;
// damage modification from the weapon itself
damage *= ammo.getDamageModifier();
// unlike the regular weapons, we do no gain more damage from potion of strength/weakness since we don't hit stuff directly
// stonebound decreases, jagged increases damage too
float bonusDamage = -AbilityHelper.calcStoneboundBonus(ammo, tags);
// enchantments might add too
if(shootingEntity != null)
bonusDamage += EnchantmentHelper.getEnchantmentModifierLiving((EntityLivingBase)this.shootingEntity, (EntityLivingBase)movingobjectposition.entityHit);
damage += bonusDamage;
// ensure we still have damage
if(damage < 1)
damage = 1;
// the regular tool modifier damage stuff
int modDamage = 0;
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
{
modDamage += mod.attackDamage(modDamage, damage, ammo, returnStack.getTagCompound(), tags, returnStack, (EntityPlayer)this.shootingEntity, movingobjectposition.entityHit);
}
damage += modDamage;
// calculate critical damaaage
if (this.getIsCritical())
damage += this.rand.nextInt(damage / 2 + 2);
// and now we come to the part where we actually deal the damage!
if(!dealDamage(damage, ammo, tags, movingobjectposition.entityHit))
{
if(!bounceOnNoDamage)
this.setDead();
// bounce off if we didn't deal damage
this.motionX *= -0.10000000149011612D;
this.motionY *= -0.10000000149011612D;
this.motionZ *= -0.10000000149011612D;
this.rotationYaw += 180.0F;
this.prevRotationYaw += 180.0F;
this.ticksInAir = 0;
return;
}
if (movingobjectposition.entityHit instanceof EntityLivingBase)
doLivingHit((EntityLivingBase)movingobjectposition.entityHit);
playHitEntitySound();
if (!(movingobjectposition.entityHit instanceof EntityEnderman))
{
this.setDead();
}
}
// returns true if it was successful
public boolean dealDamage(float damage, ToolCore ammo, NBTTagCompound tags, Entity entityHit)
{
boolean dealtDamage = false;
// deal regular damage
DamageSource damagesource;
if (this.shootingEntity == null)
damagesource = DamageSource.causeArrowDamage(this, this);
else
damagesource = DamageSource.causeArrowDamage(this, this.shootingEntity);
dealtDamage = entityHit.attackEntityFrom(damagesource, damage);
return dealtDamage;
}
@Override
// this function is the same as the vanilla EntityArrow
public void onUpdate() {
// call the entity update routine
// luckily we can call this directly and take the arrow-code, since we'd have to call super.onUpdate otherwise. Which would not work.
onEntityUpdate();
// boioioiooioing
if (this.arrowShake > 0)
--this.arrowShake;
// If we don't have our rotation set correctly, infer it from our motion direction
if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
{
float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(this.motionY, (double)f) * 180.0D / Math.PI);
}
// we previously hit something. Check if the block is still there.
Block block = this.worldObj.getBlock(this.field_145791_d, this.field_145792_e, this.field_145789_f);
if (block.getMaterial() != Material.air)
{
block.setBlockBoundsBasedOnState(this.worldObj, this.field_145791_d, this.field_145792_e, this.field_145789_f);
AxisAlignedBB axisalignedbb = block.getCollisionBoundingBoxFromPool(this.worldObj, this.field_145791_d, this.field_145792_e, this.field_145789_f);
// we are stuck in a block. yay.
if (axisalignedbb != null && axisalignedbb.isVecInside(Vec3.createVectorHelper(this.posX, this.posY, this.posZ)))
this.inGround = true;
}
if (this.inGround)
updateInGround();
else
updateInAir();
}
// Update while we're stuck in a block
protected void updateInGround()
{
Block block = this.worldObj.getBlock(this.field_145791_d, this.field_145792_e, this.field_145789_f);
int j = this.worldObj.getBlockMetadata(this.field_145791_d, this.field_145792_e, this.field_145789_f);
// check if it's still the same block
if (block == this.field_145790_g && j == this.inData)
{
++this.ticksInGround;
if (this.ticksInGround == 1200)
{
this.setDead();
}
}
else
{
this.inGround = false;
this.motionX *= (double)(this.rand.nextFloat() * 0.2F);
this.motionY *= (double)(this.rand.nextFloat() * 0.2F);
this.motionZ *= (double)(this.rand.nextFloat() * 0.2F);
this.ticksInGround = 0;
this.ticksInAir = 0;
}
}
// update while traveling
protected void updateInAir()
{
// tick tock
++this.ticksInAir;
// do a raytrace from old to new position
Vec3 curPos = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
Vec3 newPos = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
MovingObjectPosition movingobjectposition = this.worldObj.func_147447_a(curPos, newPos, false, true, false);
// raytrace messes with the positions. get new ones!
curPos = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
// if we hit something, the collision point is our new position
if (movingobjectposition != null)
newPos = Vec3.createVectorHelper(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
else
newPos = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
// Check all the entities we on our way
Entity entity = null;
List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D));
double distance = 0.0D;
float f1;
for(Entity ent : list)
{
if(!ent.canBeCollidedWith())
continue;
// we don't shoot ourselves into the foot.
if(ent == this.shootingEntity && this.ticksInAir < 5)
continue;
f1 = 0.3F;
AxisAlignedBB axisalignedbb1 = ent.boundingBox.expand((double)f1, (double)f1, (double)f1);
MovingObjectPosition movingobjectposition1 = axisalignedbb1.calculateIntercept(curPos, newPos);
// did we actually collide with the entity, or was it just really close nearby?
if (movingobjectposition1 != null)
{
// check if this entity is closer than the other one we already hit
double otherDistance = curPos.distanceTo(movingobjectposition1.hitVec);
if (otherDistance < distance || distance == 0.0D)
{
entity = ent;
distance = otherDistance;
}
}
}
// if we hit something, new collision point!
if (entity != null)
movingobjectposition = new MovingObjectPosition(entity);
// did we hit a player?
if (movingobjectposition != null && movingobjectposition.entityHit != null && movingobjectposition.entityHit instanceof EntityPlayer)
{
EntityPlayer entityplayer = (EntityPlayer)movingobjectposition.entityHit;
// can we attack said player?
if (entityplayer.capabilities.disableDamage || this.shootingEntity instanceof EntityPlayer && !((EntityPlayer)this.shootingEntity).canAttackPlayer(entityplayer))
movingobjectposition = null;
// this check should probably done inside of the loop for accuracy..
}
// time to hit the object
if (movingobjectposition != null)
{
if (movingobjectposition.entityHit != null)
onHitEntity(movingobjectposition);
else
onHitBlock(movingobjectposition);
}
// crithit particles
if (this.getIsCritical())
drawCritParticles();
// MOVEMENT! yay.
doMoveUpdate();
double slowdown = 1.0d - getSlowdown();
// bubblez
if (this.isInWater())
{
for (int l = 0; l < 4; ++l)
{
float f4 = 0.25F;
this.worldObj.spawnParticle("bubble", this.posX - this.motionX * (double)f4, this.posY - this.motionY * (double)f4, this.posZ - this.motionZ * (double)f4, this.motionX, this.motionY, this.motionZ);
}
// more slowdown in water
slowdown = 1d - 20d*getSlowdown();
}
// phshshshshshs
if (this.isWet())
this.extinguish();
// minimalistic slowdown!
this.motionX *= slowdown;
this.motionY *= slowdown;
this.motionZ *= slowdown;
// gravity
this.motionY -= getGravity();
this.setPosition(this.posX, this.posY, this.posZ);
// tell blocks we collided with, that we collided with them!
this.func_145775_I();
}
public void drawCritParticles()
{
for (int i = 0; i < 4; ++i)
{
this.worldObj.spawnParticle("crit", this.posX + this.motionX * (double)i / 4.0D, this.posY + this.motionY * (double)i / 4.0D, this.posZ + this.motionZ * (double)i / 4.0D, -this.motionX, -this.motionY + 0.2D, -this.motionZ);
}
}
protected void doMoveUpdate()
{
this.posX += this.motionX;
this.posY += this.motionY;
this.posZ += this.motionZ;
double f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.rotationYaw = (float)(Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
this.rotationPitch = (float)(Math.atan2(this.motionY, f2) * 180.0D / Math.PI);
// normalize rotations
while (this.rotationPitch - this.prevRotationPitch < -180.0F)
this.prevRotationPitch -= 360.0F;
while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
this.prevRotationPitch += 360.0F;
while (this.rotationYaw - this.prevRotationYaw < -180.0F)
this.prevRotationYaw -= 360.0F;
while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
this.prevRotationYaw += 360.0F;
this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
}
/**
* Factor for the slowdown. 0 = no slowdown, >0 = (1-slowdown)*speed slowdown, <0 = speedup
*/
protected double getSlowdown() { return 0.01; }
/**
* Added to the y-velocity as gravitational pull. Otherwise stuff would simply float midair.
*/
protected double getGravity() { return 0.05; }
/**
* Called by a player entity when they collide with an entity
*/
public void onCollideWithPlayer(EntityPlayer player)
{
if (!this.worldObj.isRemote && this.inGround && this.arrowShake <= 0)
{
boolean flag = this.canBePickedUp == 1 || this.canBePickedUp == 2 && player.capabilities.isCreativeMode;
if (this.canBePickedUp == 1)
{
// ammo pickup
if(this.returnStack != null && this.returnStack.getItem() instanceof AmmoItem)
{
if(!((AmmoItem) this.returnStack.getItem()).pickupAmmo(returnStack, null, player))
flag = false;
}
// regular pickup.
// Note that you can't pick up ammo items without the proper itemstack in your inventory to prevent dupes
else if(!player.inventory.addItemStackToInventory(new ItemStack(Items.arrow, 1)))
{
flag = false;
}
}
if (flag)
{
this.playSound("random.pop", 0.2F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
player.onItemPickup(this, 1);
this.setDead();
}
}
}
/** NBT stuff **/
@Override
public void writeEntityToNBT (NBTTagCompound tags)
{
super.writeEntityToNBT(tags);
tags.setTag("Throwable", this.returnStack.writeToNBT(new NBTTagCompound()));
tags.setByte("onGround", (byte) (onGround ? 1 : 0));
//tags.setBoolean("Retrieval", doNotRetrieve);
}
@Override
public void readEntityFromNBT(NBTTagCompound tags) {
super.readEntityFromNBT(tags);
this.returnStack = ItemStack.loadItemStackFromNBT(tags.getCompoundTag("Throwable"));
onGround = tags.getByte("onGround") == 1;
//doNotRetrieve = tags.getBoolean("Retrieval");
}
@Override
public void writeSpawnData(ByteBuf data) {
NBTTagCompound tags = returnStack.getTagCompound().getCompoundTag("InfiTool");
ByteBufUtils.writeItemStack(data, returnStack);
data.writeFloat(rotationYaw);
/*
data.writeInt(tags.getInteger("RenderHandle"));
data.writeInt(tags.getInteger("RenderHead"));
data.writeInt(tags.getInteger("RenderAccessory"));
data.writeInt(tags.getInteger("RenderExtra"));
int effects = 0;
if (tags.hasKey("Effect1"))
effects++;
if (tags.hasKey("Effect2"))
effects++;
if (tags.hasKey("Effect3"))
effects++;
if (tags.hasKey("Effect4"))
effects++;
if (tags.hasKey("Effect5"))
effects++;
if (tags.hasKey("Effect6"))
effects++;
data.writeInt(effects);
switch (effects)
{
case 6:
data.writeInt(tags.getInteger("Effect6"));
case 5:
data.writeInt(tags.getInteger("Effect5"));
case 4:
data.writeInt(tags.getInteger("Effect4"));
case 3:
data.writeInt(tags.getInteger("Effect3"));
case 2:
data.writeInt(tags.getInteger("Effect2"));
case 1:
data.writeInt(tags.getInteger("Effect1"));
}
*/
// shooting entity
int id = shootingEntity == null ? this.getEntityId() : shootingEntity.getEntityId();
data.writeInt(id);
}
@Override
public void readSpawnData(ByteBuf data) {
returnStack = ByteBufUtils.readItemStack(data);
rotationYaw = data.readFloat();
/*
NBTTagCompound compound = new NBTTagCompound();
NBTTagCompound toolTag = new NBTTagCompound();
toolTag.setInteger("RenderHandle", data.readInt());
toolTag.setInteger("RenderHead", data.readInt());
toolTag.setInteger("RenderAccessory", data.readInt());
toolTag.setInteger("RenderExtra", data.readInt());
switch (data.readInt())
{
case 6:
toolTag.setInteger("Effect6", data.readInt());
case 5:
toolTag.setInteger("Effect5", data.readInt());
case 4:
toolTag.setInteger("Effect4", data.readInt());
case 3:
toolTag.setInteger("Effect3", data.readInt());
case 2:
toolTag.setInteger("Effect2", data.readInt());
case 1:
toolTag.setInteger("Effect1", data.readInt());
}
compound.setTag("InfiTool", toolTag);
returnStack.setTagCompound(compound);
*/
shootingEntity = worldObj.getEntityByID(data.readInt());
}
}
@@ -1,5 +1,6 @@
package tconstruct.weaponry.entity;
import tconstruct.library.entity.ProjectileBase;
import tconstruct.weaponry.TinkerWeaponry;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
@@ -1,5 +1,6 @@
package tconstruct.weaponry.entity;
import tconstruct.library.entity.ProjectileBase;
import tconstruct.weaponry.TinkerWeaponry;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@@ -1,26 +0,0 @@
package tconstruct.weaponry.items;
import net.minecraft.item.ItemStack;
import tconstruct.TConstruct;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.tools.CustomMaterial;
import tconstruct.library.tools.DynamicToolPart;
public class CustomToolPart extends WeaponryToolPart {
private final Class<? extends CustomMaterial> customMat;
public CustomToolPart(String texture, String name, Class<? extends CustomMaterial> customMatClass) {
super(texture, name);
this.customMat = customMatClass;
}
@Override
public int getMaterialID (ItemStack stack)
{
if(TConstructRegistry.getCustomMaterial(stack.getItemDamage(), customMat) != null)
return stack.getItemDamage();
return -1;
}
}
@@ -1,124 +0,0 @@
package tconstruct.weaponry.items;
import tconstruct.weaponry.TinkerWeaponry;
import tconstruct.weaponry.util.Reference;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.tools.DynamicToolPart;
import tconstruct.library.util.TextureHelper;
import tconstruct.tools.TinkerTools;
import tconstruct.util.config.PHConstruct;
import java.util.List;
import java.util.Map;
public class DualMaterialToolPart extends WeaponryToolPart {
public IIcon defaultIcon2;
public IIcon[] icons2;
public DualMaterialToolPart(String textureType, String name) {
super(textureType, name);
}
public static ItemStack createDualMaterial(Item item, int mat1, int mat2)
{
ItemStack stack = new ItemStack(item, 1, mat1);
NBTTagCompound tags = new NBTTagCompound();
NBTTagCompound subtag = new NBTTagCompound();
subtag.setInteger("Material2", mat2);
tags.setTag("DualMat", subtag);
stack.setTagCompound(tags);
return stack;
}
public int getMaterialID2(ItemStack stack)
{
if(!stack.hasTagCompound())
return -1;
int id = stack.getTagCompound().getCompoundTag("DualMat").getInteger("Material2");
if (TConstructRegistry.toolMaterials.keySet().contains(id))
return id;
return -1;
}
@Override
public void getSubItems (Item item, CreativeTabs tab, List list)
{
// material id == metadata
for(Integer matID : TConstructRegistry.toolMaterials.keySet())
list.add(createDualMaterial(item, matID, TinkerTools.MaterialID.Iron));
}
@Override
public int getRenderPasses(int metadata) {
return 2;
}
@Override
public boolean requiresMultipleRenderPasses() {
return true;
}
@SideOnly(Side.CLIENT)
@Override
public void registerIcons(IIconRegister iconRegister) {
super.registerIcons(iconRegister);
// same as in super, secondary icon :I
this.icons2 = new IIcon[icons.length];
// register icon for each material that has one
if(!PHConstruct.minimalTextures)
for(Map.Entry<Integer, tconstruct.library.tools.ToolMaterial> entry : TConstructRegistry.toolMaterials.entrySet())
{
String tex = modTexPrefix + ":" + folder + entry.getValue().materialName.toLowerCase() + texture + "_2";
if(TextureHelper.itemTextureExists(tex))
this.icons2[entry.getKey()] = iconRegister.registerIcon(tex);
}
this.defaultIcon2 = iconRegister.registerIcon(modTexPrefix + ":" + folder + texture + "_2");
}
@Override
public IIcon getIconFromDamageForRenderPass(int meta, int pass) {
// secondary item
if(pass > 0) {
if(meta > icons.length)
return defaultIcon2;
if(icons2[meta] == null)
return defaultIcon2;
return icons2[meta];
}
return super.getIconFromDamageForRenderPass(meta, pass);
}
@Override
public int getColorFromItemStack(ItemStack stack, int renderpass) {
if(renderpass > 0)
{
int matId = getMaterialID2(stack);
if(matId > icons2.length)
return super.getColorFromItemStack(stack, renderpass);
if(icons[matId] == null)
return TConstructRegistry.getMaterial(matId).primaryColor();
return super.getColorFromItemStack(stack, renderpass);
}
return super.getColorFromItemStack(stack, renderpass);
}
}
@@ -1,11 +1,9 @@
package tconstruct.weaponry.items;
import tconstruct.weaponry.util.Reference;
import tconstruct.util.Reference;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.crafting.PatternBuilder;
import tconstruct.tools.items.Pattern;
import java.util.List;
@@ -15,7 +13,6 @@ public class WeaponryPattern extends Pattern {
public WeaponryPattern(String patternType, String name) {
super(patternName, getPatternNames(patternName, patternType), "patterns/");
this.modTexPrefix = Reference.RESOURCE;
this.setUnlocalizedName(Reference.prefix(name));
}
@@ -1,14 +0,0 @@
package tconstruct.weaponry.items;
import tconstruct.weaponry.TinkerWeaponry;
import tconstruct.weaponry.util.Reference;
import tconstruct.library.tools.DynamicToolPart;
public class WeaponryToolPart extends DynamicToolPart {
public WeaponryToolPart(String textureType, String name) {
super(textureType, name, Reference.RESOURCE);
this.setUnlocalizedName(Reference.prefix(name));
this.setCreativeTab(TinkerWeaponry.creativeTab);
}
}
@@ -1,12 +0,0 @@
package tconstruct.weaponry.library.util;
import net.minecraft.entity.Entity;
import net.minecraft.util.EntityDamageSourceIndirect;
public class PiercingArrowDamage extends EntityDamageSourceIndirect {
public PiercingArrowDamage(String p_i1568_1_, Entity p_i1568_2_, Entity p_i1568_3_) {
super(p_i1568_1_, p_i1568_2_, p_i1568_3_);
this.setDamageBypassesArmor();
this.setProjectile();
}
}
@@ -1,118 +0,0 @@
package tconstruct.weaponry.library.weaponry;
import tconstruct.weaponry.TinkerWeaponry;
import tconstruct.weaponry.util.Reference;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.tools.ToolCore;
public abstract class AmmoItem extends ToolCore implements IAmmo {
public AmmoItem(int baseDamage, String name) {
super(baseDamage);
this.setUnlocalizedName(Reference.prefix(name));
this.setCreativeTab(TinkerWeaponry.creativeTab);
}
@Override
public int getAmmoCount(ItemStack stack) {
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
return tags.getInteger("Ammo");
}
@Override
public int getMaxAmmo(ItemStack stack) {
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
return getMaxAmmo(tags);
}
@Override
public int getMaxAmmo(NBTTagCompound tags) {
float dur = tags.getInteger("TotalDurability");
return (int)Math.ceil(dur*getAmmoModifier());
}
@Override
public int addAmmo(int toAdd, ItemStack stack) {
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
int oldCount = tags.getInteger("Ammo");
int newCount = Math.min(oldCount + toAdd, getMaxAmmo(stack));
tags.setInteger("Ammo", newCount);
return toAdd - (newCount - oldCount);
}
@Override
public int consumeAmmo(int toUse, ItemStack stack) {
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
int oldCount = tags.getInteger("Ammo");
int newCount = Math.max(oldCount - toUse, 0);
tags.setInteger("Ammo", newCount);
return toUse - (oldCount - newCount);
}
public float getAmmoModifier() { return 0.1f; }
public boolean pickupAmmo(ItemStack stack, ItemStack candidate, EntityPlayer player)
{
if(stack.getItem() == null || !(stack.getItem() instanceof IAmmo))
return false;
// check if our candidate fits
if(candidate != null)
{
// same item
if(testIfAmmoMatches(stack, candidate)) {
IAmmo pickedup = ((IAmmo) stack.getItem());
IAmmo ininventory = ((IAmmo) candidate.getItem());
// we can be sure that it's ammo, since stack is ammo and they're equal
ininventory.addAmmo(pickedup.getAmmoCount(stack), candidate);
return true;
}
}
// search the players inventory
for(ItemStack invItem : player.inventory.mainInventory) {
if (testIfAmmoMatches(stack, invItem)) {
IAmmo pickedup = ((IAmmo) stack.getItem());
IAmmo ininventory = ((IAmmo) invItem.getItem());
// we can be sure that it's ammo, since stack is ammo and they're equal
ininventory.addAmmo(pickedup.getAmmoCount(stack), invItem);
return true;
}
}
// couldn't find a matching thing.
return false;
}
private boolean testIfAmmoMatches(ItemStack reference, ItemStack candidate)
{
if(candidate == null)
return false;
if(!candidate.hasTagCompound() || !candidate.getTagCompound().hasKey("InfiTool"))
return false;
// create a stack to test against
ItemStack testsubject = candidate.copy();
// all NBT has to match, but the ammo-count obviously differs. So we set our testsubject to the same
// this ensures that it's the one to collect and the one we have matches.
testsubject.getTagCompound().getCompoundTag("InfiTool").setInteger("Ammo", getAmmoCount(reference));
return ItemStack.areItemStacksEqual(reference, testsubject);
}
@Override
public boolean onLeftClickEntity (ItemStack stack, EntityPlayer player, Entity entity)
{
// ammo doesn't hurt on smacking stuff with it
return false;
}
@Override
public String getDefaultTexturePath() {
return Reference.RESOURCE + ":" + getDefaultFolder();
}
}
@@ -1,146 +0,0 @@
package tconstruct.weaponry.library.weaponry;
import tconstruct.weaponry.client.CrosshairType;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
/**
* Throwing weapons that utilize the ammo system on themselves.
* Throwing knifes etc.
*/
public abstract class AmmoWeapon extends AmmoItem implements IAccuracy, IWindup {
public AmmoWeapon(int baseDamage, String name) {
super(baseDamage, name);
}
@Override
public EnumAction getItemUseAction(ItemStack par1ItemStack) {
return EnumAction.none;
} // we use custom animation renderiiing!
@Override
public int getMaxItemUseDuration(ItemStack par1ItemStack) {
return 72000;
}
@Override
public ItemStack onItemRightClick (ItemStack stack, World world, EntityPlayer player)
{
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
return stack;
}
@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;
}
/**
* How long it takes to "ready" the weapon. To reach the point, where holding the right mouse button any longer doesn't have an impact.
*/
@Override
public int getWindupTime(ItemStack itemStack) { return 0; }
@Override
public float getMinWindupProgress(ItemStack itemStack) {
return 0;
}
public float getWindupProgress(ItemStack itemStack, int timeInUse)
{
float time = (float) timeInUse;
float windup = getWindupTime(itemStack);
if(time > windup)
time = windup;
return time/windup;
}
public float minAccuracy(ItemStack itemStack) { return 0.5f; }
public float maxAccuracy(ItemStack itemStack) { return 0.5f; }
public float getWindupProgress(ItemStack itemStack, EntityPlayer player)
{
// what are you doing!
if(player.inventory.getCurrentItem() != itemStack)
return 0f;
// are we using it?
if(player.getItemInUse() == null)
return 0f;
return getWindupProgress(itemStack, getMaxItemUseDuration(itemStack) - player.getItemInUseCount());
}
public float getAccuracy(ItemStack itemStack, EntityPlayer player)
{
float dif = minAccuracy(itemStack) - maxAccuracy(itemStack);
return minAccuracy(itemStack) - dif * getWindupProgress(itemStack, player);
}
@Override
public String[] getTraits() {
return new String[] {"weapon", "throwing", "ammo"};
}
@Override
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int durationLeft) {
int time = this.getMaxItemUseDuration(stack) - durationLeft;
if(getWindupProgress(stack, time) >= getMinWindupProgress(stack))
launchProjectile(stack, world, player);
}
protected void launchProjectile(ItemStack stack, World world, EntityPlayer player) {
// spawn projectile on server
if(!world.isRemote) {
ItemStack reference = stack.copy();
reference.stackSize = 1;
reference.getTagCompound().getCompoundTag("InfiTool").setInteger("Ammo", 1);
Entity projectile = createProjectile(reference, world, player, getAccuracy(stack, player));
world.spawnEntityInWorld(projectile);
}
// reduce ammo
this.consumeAmmo(1, stack);
}
protected abstract Entity createProjectile(ItemStack reference, World world, EntityPlayer player, float accuracy);
@Override
public void registerPartPaths(int index, String[] location) {
}
@Override
public void registerAlternatePartPaths(int index, String[] location) {
headStrings.put(index, location[0]);
brokenPartStrings.put(index, location[1]);
handleStrings.put(index, location[2]);
if (location.length > 3)
accessoryStrings.put(index, location[3]);
if (location.length > 4)
extraStrings.put(index, location[4]);
}
@SideOnly(Side.CLIENT)
public CrosshairType getCrosshairType() { return CrosshairType.SQUARE; }
@Override
public boolean zoomOnWindup(ItemStack itemStack) {
return false;
}
@Override
public float getZoom(ItemStack itemStack) {
return 1.0f;
}
}
@@ -1,29 +0,0 @@
package tconstruct.weaponry.library.weaponry;
import tconstruct.weaponry.TinkerWeaponry;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import tconstruct.library.tools.CustomMaterial;
public class ArrowShaftMaterial extends CustomMaterial {
public final float durabilityModifier; // like the durability modifier of handles, but for arrows!
public final float fragility; // 1.0 = breaks 100%, 0.0 = never breaks
public final float weight; // baseline: 1.0 = default, smaller = lighter, higher = heavier
public ArrowShaftMaterial(int materialID, int value, ItemStack input, ItemStack craftingItem, float durabilityModifier, float weight, float fragility, int color) {
super(materialID, value, input, craftingItem, color);
this.durabilityModifier = durabilityModifier;
this.fragility = fragility;
this.weight = weight;
}
public static ArrowShaftMaterial createMaterial(int id, Item input, float durabilityModifier, float weight, float fragility, int color)
{
return createMaterial(id, input, 0, durabilityModifier, weight, fragility, color);
}
public static ArrowShaftMaterial createMaterial(int id, Item input, int inputMeta, float durabilityModifier, float weight, float fragility, int color)
{
return new ArrowShaftMaterial(id, 2, new ItemStack(input, 1, inputMeta), new ItemStack(TinkerWeaponry.partArrowShaft, 0, id), durabilityModifier, weight, fragility, color);
}
}
@@ -1,167 +0,0 @@
package tconstruct.weaponry.library.weaponry;
import tconstruct.weaponry.ammo.ArrowAmmo;
import tconstruct.weaponry.entity.ArrowEntity;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import tconstruct.library.crafting.ToolBuilder;
import java.util.List;
public abstract class BowBaseAmmo extends ProjectileWeapon {
public BowBaseAmmo(int baseDamage, String name) {
super(baseDamage, name);
}
@Override
public int durabilityTypeAccessory() {
return 2; // head-type
}
@Override
public int durabilityTypeExtra() {
return 1; // handle-type
}
@Override
public boolean zoomOnWindup(ItemStack itemStack) {
return true;
}
@Override
public float getZoom(ItemStack itemStack) {
return 1.2f;
}
@Override
public float getMinWindupProgress(ItemStack itemStack) {
return 0.5f;
}
@Override
public ItemStack searchForAmmo(EntityPlayer player, ItemStack weapon)
{
// arrow priority: hotbar > inventory, tinker arrows > regular arrows
ItemStack[] inventory = player.inventory.mainInventory;
// check hotbar for tinker arrows
for(int i = 0; i < InventoryPlayer.getHotbarSize(); i++)
if(checkTinkerArrow(inventory[i]))
return inventory[i];
// check hotbar for vanilla arrows
for(int i = 0; i < InventoryPlayer.getHotbarSize(); i++)
if(checkVanillaArrow(inventory[i]))
return inventory[i];
// check the rest of the inventory for tinker arrows
for(int i = InventoryPlayer.getHotbarSize(); i < inventory.length; i++)
if(checkTinkerArrow(inventory[i]))
return inventory[i];
// check the rest of the inventory for vanilla arrows
for(int i = InventoryPlayer.getHotbarSize(); i < inventory.length; i++)
if(checkVanillaArrow(inventory[i]))
return inventory[i];
// creative mode
if(player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, weapon) > 0)
return new ItemStack(Items.arrow);
return null;
}
private boolean checkTinkerArrow(ItemStack stack)
{
// null
if(stack == null)
return false;
// no tinker arrow
if(!(stack.getItem() instanceof ArrowAmmo))
return false;
// no ammo left
if(((IAmmo) stack.getItem()).getAmmoCount(stack) <= 0)
return false;
return true;
}
private boolean checkVanillaArrow(ItemStack stack)
{
// null
if(stack == null)
return false;
// no arrow
if(!(stack.getItem() == Items.arrow))
return false;
// inventory shouldn't contain stacksize 0 items so we don't have to check that.
return true;
}
@Override
protected Entity createProjectile(ItemStack arrows, World world, EntityPlayer player, float speed, float accuracy) {
EntityArrow arrow;
if(arrows.getItem() == Items.arrow) {
arrow = new EntityArrow(world, player, speed/1.5f); // vanilla arrows internally do x1.5
}
else {
ItemStack reference = arrows.copy();
reference.stackSize = 1;
reference.getTagCompound().getCompoundTag("InfiTool").setInteger("Ammo", 1);
arrow = new ArrowEntity(world, player, speed, accuracy, reference);
}
if(player.capabilities.isCreativeMode)
arrow.canBePickedUp = 2;
return arrow;
}
@Override
public void playFiringSound(World world, EntityPlayer player, ItemStack weapon, ItemStack ammo, float speed, float accuracy) {
world.playSoundAtEntity(player, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + speed * 0.5F);
}
@Override
public void buildTool (int id, String name, List list)
{
// all creative bows use regular bowstring
ItemStack handleStack = new ItemStack(getHandleItem(), 1, 0); // regular bowstring
ItemStack accessoryStack = getPartAmount() > 2 ? new ItemStack(getAccessoryItem(), 1, id) : null;
ItemStack extraStack = getPartAmount() > 3 ? new ItemStack(getExtraItem(), 1, id) : null;
ItemStack tool = ToolBuilder.instance.buildTool(new ItemStack(getHeadItem(), 1, id), handleStack, accessoryStack, extraStack, "");
if (tool != null)
{
tool.getTagCompound().getCompoundTag("InfiTool").setBoolean("Built", true);
list.add(tool);
}
}
/*
@Override
public int getColorFromItemStack(ItemStack stack, int renderPass) {
if(renderPass != 0 || !stack.hasTagCompound())
return super.getColorFromItemStack(stack, renderPass);
// bowstring: custom material -> custom coloring
// todo: move this into the custom material itself
int mat = stack.getTagCompound().getCompoundTag("InfiTool").getInteger("Handle");
switch(mat)
{
case 0: return 0xffffffff; // string = white
case 1: return 0xffccccff; // macig string = light blue
case 2: return 0xffffcccc; // flamestring = light red
}
return super.getColorFromItemStack(stack, renderPass);
}
*/
}
@@ -1,10 +0,0 @@
package tconstruct.weaponry.library.weaponry;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
public interface IAccuracy {
public float minAccuracy(ItemStack itemStack);
public float maxAccuracy(ItemStack itemStack);
public float getAccuracy(ItemStack itemStack, EntityPlayer player);
}
@@ -1,38 +0,0 @@
package tconstruct.weaponry.library.weaponry;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public interface IAmmo {
/**
* Returns the current ammo amount of the item.
*/
int getAmmoCount(ItemStack stack);
/**
* Returns the maximum amount of ammo the item can have
*/
int getMaxAmmo(ItemStack stack);
/**
* Returns the maximum amount of ammo the item can have
* @param tags InfiTool tag compound of the item
*/
int getMaxAmmo(NBTTagCompound tags);
/**
* Adds the given amount of ammo cache. Will not go over max-ammo.
* @param count How much to add
* @param stack The itemstack to add the ammo to. Has to have the proper NBT.
* @return The amount of ammo that couldn't be added.
*/
int addAmmo(int count, ItemStack stack);
/**
* Removes the given amount fro the ammo cache. Will not go below zero.
* @param count How much to remove
* @param stack The itemstack to add the ammo to. Has to have the proper NBT.
* @return The amount of ammo that couldn't be removed. If you try to remove 5, but only 3 are left, it'll return 2.
*/
int consumeAmmo(int count, ItemStack stack);
}
@@ -1,20 +0,0 @@
package tconstruct.weaponry.library.weaponry;
import tconstruct.weaponry.client.CrosshairType;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
/**
* This class has a windup time, meaning it takes some time to reach full potency.
* Windup progress is visualized with a special crosshair.
*/
public interface IWindup {
public int getWindupTime(ItemStack itemStack); // how long it takes to fully wind up
public float getWindupProgress(ItemStack itemStack, EntityPlayer player); // how far we've winded up, 0.0-1.0
public float getMinWindupProgress(ItemStack itemStack); // how long it has been winded up at least to fire (0.0-1.0)
public CrosshairType getCrosshairType();
public boolean zoomOnWindup(ItemStack itemStack);
public float getZoom(ItemStack itemStack);
}
@@ -1,320 +0,0 @@
package tconstruct.weaponry.library.weaponry;
import tconstruct.weaponry.TinkerWeaponry;
import tconstruct.weaponry.client.CrosshairType;
import tconstruct.weaponry.util.Reference;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.ArrowLooseEvent;
import tconstruct.library.tools.AbilityHelper;
import tconstruct.library.tools.ToolCore;
import tconstruct.library.util.TextureHelper;
import java.util.HashMap;
import java.util.Map;
/**
* Weapons that utilize ammo that uses the ammo system to shoot projectiles.
* Bows,...
*/
public abstract class ProjectileWeapon extends ToolCore implements IAccuracy, IWindup {
public ProjectileWeapon(int baseDamage, String name) {
super(baseDamage);
this.setUnlocalizedName(Reference.prefix(name));
this.setCreativeTab(TinkerWeaponry.creativeTab);
}
@SideOnly(Side.CLIENT)
public CrosshairType getCrosshairType() {
return CrosshairType.SQUARE;
}
@Override
public boolean zoomOnWindup(ItemStack itemStack) {
return false;
}
@Override
public float getZoom(ItemStack itemStack) {
return 1.0f;
}
/**
* Searches the player for ammo to use
* @param player the player
* @return the itemstack found to be ammo
*/
public abstract ItemStack searchForAmmo(EntityPlayer player, ItemStack weapon);
/**
* Creates the projectile to be fired.
* @param ammo The ammo used
* @param world world.
* @param player player.
* @param speed the speed calculated for the projectile
* @param accuracy the accuracy calculated for the projectile
* @return A banana.
*/
protected abstract Entity createProjectile(ItemStack ammo, World world, EntityPlayer player, float speed, float accuracy);
/* Accuracy */
public abstract float minAccuracy(ItemStack itemStack);
public abstract float maxAccuracy(ItemStack itemStack);
public float getAccuracy(ItemStack itemStack, EntityPlayer player)
{
return getAccuracy(itemStack, getMaxItemUseDuration(itemStack) - player.getItemInUseCount());
}
public float getAccuracy(ItemStack itemStack, int time)
{
float dif = minAccuracy(itemStack) - maxAccuracy(itemStack);
return minAccuracy(itemStack) - dif * getWindupProgress(itemStack, time);
}
/* Windup */
public int getWindupTime(ItemStack itemStack) {
NBTTagCompound toolTag = itemStack.getTagCompound().getCompoundTag("InfiTool");
return (int)((float)toolTag.getInteger("DrawSpeed")*windupModifier(itemStack));
}
protected float windupModifier(ItemStack itemStack) { return 1.0f; }
public float getWindupProgress(ItemStack itemStack, EntityPlayer player)
{
// what are you doing!
if(player.inventory.getCurrentItem() != itemStack)
return 0f;
// are we using it?
if(player.getItemInUse() == null)
return 0f;
return getWindupProgress(itemStack, getMaxItemUseDuration(itemStack) - player.getItemInUseCount());
}
public float getWindupProgress(ItemStack itemStack, int timeInUse)
{
float time = (float) timeInUse;
float windup = getWindupTime(itemStack);
if(time > windup)
return 1.0f;
return time/windup;
}
public float getProjectileSpeed(ItemStack itemStack)
{
NBTTagCompound toolTag = itemStack.getTagCompound().getCompoundTag("InfiTool");
return toolTag.getFloat("FlightSpeed") * projectileSpeedModifier(itemStack);
}
protected float projectileSpeedModifier(ItemStack itemStack) { return 1.0f; }
/* Bow usage */
@Override
public EnumAction getItemUseAction(ItemStack par1ItemStack) {
return EnumAction.none;
}
@Override
public int getMaxItemUseDuration(ItemStack par1ItemStack) {
return 72000;
}
@Override
public ItemStack onItemRightClick (ItemStack stack, World world, EntityPlayer player)
{
if(getWindupTime(stack) == 0.0f)
return stack;
// only if ammo is present
if(searchForAmmo(player, stack) != null)
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
return stack;
}
@Override
public void onPlayerStoppedUsing (ItemStack weapon, World world, EntityPlayer player, int useRemaining)
{
int time = this.getMaxItemUseDuration(weapon) - useRemaining;
// we abuse the arrowLooseEvent for all projectiles
ArrowLooseEvent event = new ArrowLooseEvent(player, weapon, time);
MinecraftForge.EVENT_BUS.post(event);
if (event.isCanceled())
{
return;
}
time = event.charge;
// find ammo
ItemStack ammo = searchForAmmo(player, weapon);
// no ammo found. :(
if(ammo == null)
return;
NBTTagCompound toolTag = weapon.getTagCompound().getCompoundTag("InfiTool");
float projectileSpeed = getProjectileSpeed(weapon);
float windup = getWindupProgress(weapon, time);
float accuracy = getAccuracy(weapon, time);
// needs a minimum windup
if(windup < this.getMinWindupProgress(weapon))
return;
// take windup time into account
projectileSpeed *= windup;
Entity projectile = createProjectile(ammo, world, player, projectileSpeed, accuracy);
int reinforced = 0;
if (toolTag.hasKey("Unbreaking"))
reinforced = toolTag.getInteger("Unbreaking");
if (random.nextInt(10) < 10 - reinforced)
AbilityHelper.damageTool(weapon, 1, player, false);
playFiringSound(world, player, weapon, ammo, projectileSpeed, accuracy);
// use up ammo
if(ammo.getItem() instanceof IAmmo)
((IAmmo) ammo.getItem()).consumeAmmo(1, ammo);
else
player.inventory.consumeInventoryItem(ammo.getItem());
// FIREEEEEEE
if (!world.isRemote)
world.spawnEntityInWorld(projectile);
}
public abstract void playFiringSound(World world, EntityPlayer player, ItemStack weapon, ItemStack ammo, float speed, float accuracy);
public HashMap<Integer, IIcon[]> animationHeadIcons = new HashMap<Integer, IIcon[]>();
public HashMap<Integer, IIcon[]> animationHandleIcons = new HashMap<Integer, IIcon[]>();
public HashMap<Integer, IIcon[]> animationAccessoryIcons = new HashMap<Integer, IIcon[]>();
public HashMap<Integer, IIcon[]> animationExtraIcons = new HashMap<Integer, IIcon[]>();
// todo: animated effects
@Override
public String getDefaultTexturePath() {
return Reference.RESOURCE + ":" + getDefaultFolder();
}
/**
* return true if the current renderpass should use animations.
* 0 == handle
* 1 == head
* 2 == accessory
* 3 == extra
*/
protected boolean animateLayer(int renderPass)
{
return false;
}
@Override
public IIcon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining) {
// animate?
if(!animateLayer(renderPass))
return super.getIcon(stack, renderPass, player, usingItem, useRemaining);
if(usingItem == null || stack != usingItem || !stack.hasTagCompound())
return super.getIcon(stack, renderPass, player, usingItem, useRemaining);
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
// effects aren't animated
// todo: make effects animated
if(renderPass >= getPartAmount() || tags == null)
return super.getIcon(stack, renderPass, player, usingItem, useRemaining);
float progress = getWindupProgress(usingItem, getMaxItemUseDuration(usingItem) - useRemaining);
// get the correct icon
switch (renderPass)
{
case 0: return getCorrectAnimationIcon(animationHandleIcons, tags.getInteger("RenderHandle"), progress);
case 1: return getCorrectAnimationIcon(animationHeadIcons, tags.getInteger("renderHead"), progress);
case 2: return getCorrectAnimationIcon(animationAccessoryIcons, tags.getInteger("renderAccessory"), progress);
case 3: return getCorrectAnimationIcon(animationExtraIcons, tags.getInteger("renderExtra"), progress);
}
return emptyIcon;
}
protected IIcon getCorrectAnimationIcon(Map<Integer, IIcon[]> icons, int id, float progress)
{
// animation count, standard texture as reference
float count = icons.get(-1).length - 1;
int step = Math.round(progress * count);
if(icons.containsKey(id))
return icons.get(id)[step];
// default icon
return icons.get(-1)[step];
}
@Override
public void registerIcons(IIconRegister iconRegister) {
super.registerIcons(iconRegister);
addAnimationIcons(headStrings, animationHeadIcons, iconRegister, getIconSuffix(0));
addAnimationIcons(handleStrings, animationHandleIcons, iconRegister, getIconSuffix(2));
addAnimationIcons(accessoryStrings, animationAccessoryIcons, iconRegister, getIconSuffix(3));
addAnimationIcons(extraStrings, animationExtraIcons, iconRegister, getIconSuffix(4));
}
private void addAnimationIcons(HashMap<Integer, String> textures, HashMap<Integer, IIcon[]> icons, IIconRegister iconRegister, String standard)
{
icons.clear();
// we use the standard to determine how many animations there are
if(standard == null || standard.isEmpty())
return;
int count = 1;
standard = getDefaultTexturePath() + "/" + standard;
while(TextureHelper.itemTextureExists(standard + "_" + count))
count++;
count--;
// add the standard icons
IIcon[] anims = new IIcon[count];
for(int i = 0; i < count; i++)
anims[i] = iconRegister.registerIcon(standard + "_" + (i+1));
icons.put(-1, anims);
// now do the same for each entry
for(Map.Entry<Integer, String> entry : textures.entrySet())
{
anims = new IIcon[count];
boolean empty = true;
for(int i = 0; i < count; i++) {
String tex = entry.getValue() + "_" + (i+1);
if (TextureHelper.itemTextureExists(tex)) {
anims[i] = iconRegister.registerIcon(tex);
empty = false;
}
}
if(!empty)
icons.put(entry.getKey(), anims);
}
}
}
@@ -1,4 +0,0 @@
package tconstruct.weaponry.util;
public class Config {
}
@@ -1,17 +0,0 @@
package tconstruct.weaponry.util;
public final class Reference {
private Reference() {}
public static final String MOD_ID = "tinkersweaponry";
public static final String MOD_NAME = "Tinker's Weaponry";
public static final String TCON_MOD_ID = "TConstruct";
public static final String RESOURCE = MOD_ID.toLowerCase();
public static String resource(String res)
{
return String.format("%s:%s", RESOURCE, res);
}
public static String prefix(String name) { return String.format("tcon.weaponry.%s", name);}
}
@@ -3,10 +3,10 @@ package tconstruct.weaponry.weapons;
import tconstruct.weaponry.TinkerWeaponry;
import tconstruct.weaponry.ammo.BoltAmmo;
import tconstruct.weaponry.entity.BoltEntity;
import tconstruct.weaponry.library.weaponry.AmmoItem;
import tconstruct.weaponry.library.weaponry.ProjectileWeapon;
import tconstruct.weaponry.util.Reference;
import tconstruct.weaponry.library.weaponry.IAmmo;
import tconstruct.library.weaponry.AmmoItem;
import tconstruct.library.weaponry.ProjectileWeapon;
import tconstruct.util.Reference;
import tconstruct.library.weaponry.IAmmo;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
@@ -1,7 +1,7 @@
package tconstruct.weaponry.weapons;
import tconstruct.weaponry.entity.JavelinEntity;
import tconstruct.weaponry.library.weaponry.AmmoWeapon;
import tconstruct.library.weaponry.AmmoWeapon;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
@@ -2,7 +2,7 @@ package tconstruct.weaponry.weapons;
import tconstruct.weaponry.TinkerWeaponry;
import tconstruct.weaponry.ammo.ArrowAmmo;
import tconstruct.weaponry.library.weaponry.BowBaseAmmo;
import tconstruct.library.weaponry.BowBaseAmmo;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
@@ -2,7 +2,7 @@ package tconstruct.weaponry.weapons;
import tconstruct.weaponry.TinkerWeaponry;
import tconstruct.weaponry.ammo.ArrowAmmo;
import tconstruct.weaponry.library.weaponry.BowBaseAmmo;
import tconstruct.library.weaponry.BowBaseAmmo;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
@@ -2,9 +2,9 @@ package tconstruct.weaponry.weapons;
import tconstruct.weaponry.TinkerWeaponry;
import tconstruct.weaponry.client.CrosshairType;
import tconstruct.weaponry.client.IconFlipped;
import tconstruct.client.IconFlipped;
import tconstruct.weaponry.entity.ShurikenEntity;
import tconstruct.weaponry.library.weaponry.AmmoWeapon;
import tconstruct.library.weaponry.AmmoWeapon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
@@ -1,92 +0,0 @@
package tconstruct.weaponry.weapons;
import tconstruct.weaponry.entity.ArrowEntity;
import tconstruct.weaponry.library.weaponry.AmmoWeapon;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import tconstruct.tools.TinkerTools;
public class ThrowArrow extends AmmoWeapon {
public ThrowArrow() {
super(1, "ThrowArrow");
headIcons = TinkerTools.arrow.headIcons;
handleIcons = TinkerTools.arrow.handleIcons;
accessoryIcons = TinkerTools.arrow.accessoryIcons;
extraIcons = TinkerTools.arrow.extraIcons;
}
@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:
case 4:
return "_arrow_fletching";
default:
return "";
}
}
@Override
public String getEffectSuffix ()
{
return "_arrow_effect";
}
@Override
public String getDefaultFolder ()
{
return "arrow";
}
@Override
public int getPartAmount() {
return 4;
}
@Override
public Item getHeadItem ()
{
return TinkerTools.arrowhead;
}
@Override
public Item getAccessoryItem ()
{
return TinkerTools.fletching;
}
@Override
public Item getExtraItem ()
{
return TinkerTools.fletching;
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
ItemStack reference = stack.copy();
reference.stackSize = 1;
Entity projectile = new ArrowEntity(world, player, 1.9f, 0f, reference);
if(!world.isRemote)
world.spawnEntityInWorld(projectile);
return stack;
}
@Override
protected Entity createProjectile(ItemStack reference, World world, EntityPlayer player, float accuracy) {
return new ArrowEntity(world, player, 1.0f, accuracy, reference);
}
}
@@ -1,128 +0,0 @@
package tconstruct.weaponry.weapons;
import tconstruct.weaponry.entity.ArrowEntity;
import tconstruct.weaponry.util.Reference;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import tconstruct.library.crafting.ToolBuilder;
import tconstruct.library.tools.Weapon;
import tconstruct.tools.TinkerTools;
import java.util.List;
public class ThrowArrowItem extends Weapon {
public ThrowArrowItem() {
super(1);
this.setUnlocalizedName(Reference.prefix("ThrowArrow"));
headIcons = TinkerTools.arrow.headIcons;
handleIcons = TinkerTools.arrow.handleIcons;
accessoryIcons = TinkerTools.arrow.accessoryIcons;
extraIcons = TinkerTools.arrow.extraIcons;
}
@Override
public ItemStack onItemRightClick (ItemStack itemstack, World world, EntityPlayer player)
{
ItemStack stack = itemstack.copy();
if (!world.isRemote)
{
EntityArrow arrow = new ArrowEntity(world, player, 1.0f, 1.0f, stack);
world.spawnEntityInWorld(arrow);
}
return itemstack;
}
@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
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 TinkerTools.arrowhead;
}
@Override
public Item getAccessoryItem ()
{
return TinkerTools.fletching;
}
@Override
public EnumAction getItemUseAction (ItemStack par1ItemStack)
{
return EnumAction.bow;
}
@Override
public String[] getTraits ()
{
return new String[] { "weapon", "throwing" };
}
@Override
public void getSubItems (Item id, CreativeTabs tab, List list)
{
ItemStack toolMine = new ItemStack(this);
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);
toolMine.setTagCompound(tool.getTagCompound());
list.add(toolMine);
}
}
}
@@ -2,7 +2,7 @@ package tconstruct.weaponry.weapons;
import tconstruct.weaponry.client.CrosshairType;
import tconstruct.weaponry.entity.ThrowingKnifeEntity;
import tconstruct.weaponry.library.weaponry.AmmoWeapon;
import tconstruct.library.weaponry.AmmoWeapon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.Entity;