Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mechcraft.items;
- import cpw.mods.fml.client.FMLClientHandler;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- import mechcraft.MechCraft;
- import mechcraft.entities.EntityBullet;
- import mechcraft.pcp.Inventories;
- import mechcraft.pcp.PacketReload;
- import net.minecraft.client.Minecraft;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.world.World;
- import java.util.List;
- public class ItemFirearm extends Item {
- private float recoil;
- private int delay = 20;
- private int ammoCount;
- private int reloadRate;
- private int capacity;
- private int reload;
- private int ammoConsumptionRate;
- private Item ammoType;
- public ItemFirearm(int maxAmmoCount, float recoil, int fireRate, int reloadRate, Item ammoType)
- {
- super();
- this.setMaxStackSize(1);
- this.ammoCount = 0;
- this.recoil = recoil;
- this.delay = fireRate;
- this.reloadRate = reloadRate;
- this.reload = 0;
- this.ammoConsumptionRate = 1;
- this.ammoType = ammoType;
- setMaxStackSize(1);
- }
- @Override
- @SuppressWarnings("unchecked")
- public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4) {
- if (itemStack.stackTagCompound != null) {
- int ammoleft = itemStack.stackTagCompound.getInteger("clip");
- list.add("Contains " + String.valueOf(ammoleft) + " round" + (ammoleft == 1 ? "" : "s"));
- }
- }
- @Override
- public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer entityPlayer) {
- // verify tag compound:
- if (!itemStack.hasTagCompound()) {
- // didn't have one, so make a new one:
- itemStack.setTagCompound(new NBTTagCompound());
- }
- if (world.getWorldTime() > itemStack.getTagCompound().getLong("lastShotTime")) {
- if (entityPlayer.capabilities.isCreativeMode || itemStack.getTagCompound().getInteger("clip") > 0) {
- world.playSoundAtEntity(entityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
- if (!world.isRemote) {
- world.spawnEntityInWorld(new EntityBullet(world, entityPlayer));
- itemStack.getTagCompound().setLong("lastShotTime", world.getWorldTime() + delay);
- itemStack.getTagCompound().setInteger("clip", itemStack.getTagCompound().getInteger("clip") - 1);
- renderRecoil();
- }
- }
- }
- return itemStack;
- }
- @SideOnly(Side.CLIENT)
- public void renderRecoil()
- {
- Minecraft client = FMLClientHandler.instance().getClient();
- client.thePlayer.renderArmPitch -= this.recoil * 40.0F;
- client.thePlayer.renderArmYaw += this.recoil * 5.0F;
- client.thePlayer.rotationPitch -= this.recoil * 1.4F;
- }
- public void reload(EntityPlayer entityPlayer) {
- if (!entityPlayer.worldObj.isRemote) {
- Inventories.consumeItem(entityPlayer, this.ammoType);
- }
- if (entityPlayer.worldObj.isRemote) {
- }
- ItemStack gun = entityPlayer.getCurrentEquippedItem();
- gun.getTagCompound().setInteger("clip", this.capacity);
- }
- public int getReload() {
- return reload;
- }
- @Override
- @SideOnly(Side.CLIENT)
- public boolean isFull3D() {
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement