Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ****;
- import java.io.File;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockGrass;
- import net.minecraft.block.BlockPane;
- import net.minecraft.block.BlockWeb;
- import net.minecraft.block.material.Material;
- import net.minecraft.client.Minecraft;
- import net.minecraft.creativetab.CreativeTabs;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.projectile.EntityArrow;
- import net.minecraft.item.EnumArmorMaterial;
- import net.minecraft.item.EnumToolMaterial;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemAppleGold;
- import net.minecraft.item.ItemArmor;
- import net.minecraft.item.ItemBow;
- import net.minecraft.item.ItemCarrotOnAStick;
- import net.minecraft.item.ItemSaddle;
- import net.minecraft.item.ItemSnowball;
- import net.minecraft.item.ItemStack;
- import net.minecraft.item.ItemSword;
- import net.minecraft.potion.Potion;
- import net.minecraft.potion.PotionHealth;
- import net.minecraft.src.ModLoader;
- import net.minecraft.util.DamageSource;
- import net.minecraft.util.EntityDamageSourceIndirect;
- import net.minecraft.world.biome.BiomeGenBase;
- import net.minecraft.world.biome.BiomeGenForest;
- import net.minecraft.world.biome.BiomeGenPlains;
- import net.minecraftforge.client.MinecraftForgeClient;
- import net.minecraftforge.common.EnumHelper;
- import net.minecraftforge.common.MinecraftForge;
- import cpw.mods.fml.client.registry.RenderingRegistry;
- import cpw.mods.fml.common.Mod;
- import cpw.mods.fml.common.Mod.Init;
- import cpw.mods.fml.common.Mod.PostInit;
- import cpw.mods.fml.common.Mod.PreInit;
- import cpw.mods.fml.common.event.FMLInitializationEvent;
- import cpw.mods.fml.common.event.FMLPostInitializationEvent;
- import cpw.mods.fml.common.event.FMLPreInitializationEvent;
- import cpw.mods.fml.common.network.NetworkMod;
- import cpw.mods.fml.common.registry.EntityRegistry;
- import cpw.mods.fml.common.registry.GameRegistry;
- import cpw.mods.fml.common.registry.LanguageRegistry;
- import java.io.File;
- import java.util.Random;
- import javax.sound.sampled.Clip;
- @Mod (modid = "****", name = "****", version = "****")
- @NetworkMod(
- clientSideRequired = true,
- serverSideRequired = true,
- versionBounds = "[1.5]")
- public class BaseXZ {
- //guns
- public static Itemdeserteagle = (new Itemdeserteagle(4899, 8, 10, 4599, 1, "/soundsXZ/deserteagleshoot.ogg", null).setItemName("deserteagle").setIconIndex(14).setCreativeTab(CreativeTabs.tabCombat).setFull3D());
- public static Itemdeserteagleclip = new xzItems(4599).setMaxStackSize(1).setItemName("deserteagleclip").setIconIndex(16).setCreativeTab(CreativeTabs.tabCombat);
- public static Itemgrenade = (new Itemgrenade(4020).setItemName("grenade").setIconIndex(20).setCreativeTab(CreativeTabs.tabCombat));
- @PreInit
- public void Init(FMLPreInitializationEvent preEvent) {
- }
- @Init
- public void Init(FMLInitializationEvent event) {
- LanguageRegistry.addName(deserteagle, "Desert Eagle");
- LanguageRegistry.addName(deserteagleclip, "Desert Eagle Clip");
- RenderingRegistry.registerEntityRenderingHandler(Entitygrenade.class, new RenderGrenade(20));
- EntityRegistry.registerModEntity(Entitygrenade.class, "Grenade", 4020, this, 8, 1, true);
- }
- @PostInit
- public void Init(FMLPostInitializationEvent event) {
- }
- }
- -----------------------Itemdeserteagle----------------------------------------------------
- package ****;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.world.World;
- public class Itemdeserteagle extends Item{
- //These are all of our base variables for our gun
- private int damage; //Damage in half-hearts
- private int reloadtick; //The current value of our reloading timer
- private int reloadmax; //The value that the reloadtick variable needs to be in order for the gun to reload
- private int clipid; //The item id of our clip
- private int ammo; //The amount of ammo avaliable per clip (used in setting durability)
- private int firetick; //The current value of our shooting timer
- private int firemax; //The value that the firetick variable needs to be in order for the gun to fire
- //Fire delay is completely ignored when firemax is set to 0
- private String firesound; //The String that notch uses in his code to figure out what sound to play when we shoot our gun
- private String reloadsound; //Firesound but with reloading
- //The parameters for our constructor are:
- //int i (the id), int damage (damage in half-hearts), int ammo (how much ammo per clip)
- //int clipid (the item id of the clip this gun uses), int firedelay (the value of firemax)
- //String firesound (the value of firesound), String reloadsound (the value of reloadsound)
- public Itemdeserteagle(int i, int damage, int ammo, int clipid, int firedelay, String firesound, String reloadsound){
- super(i); //calls the Item.java constructor and passes in the item id for a parameter
- this.damage = 8; //sets the damage value
- firemax = 1; //sets the firemax value
- firetick = firemax; //sets the firetick value equal to firemax (so you don't need to wait for the delay on the first shot)
- reloadmax = 10; //sets the reload max
- reloadtick = 0; //sets the reloadtick to 0
- this.ammo = 10; //sets the ammo
- this.clipid = 4599; //sets the clipid
- this.firesound = firesound; //sets the firesound
- this.reloadsound = reloadsound; //sets the reloadsound
- setMaxStackSize(1); //sets the max stack size to one
- setMaxDamage(ammo + 1); //sets the durability of our gun to the ammo count + 1
- }
- public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer){
- //Checks if the player has enough ammo
- if(!par2World.isRemote && par1ItemStack.getItemDamage() < ammo){
- //if the firemax isn't 0, and the fireing counter is done, then this is true
- if(firetick == firemax && firemax != 0){
- //spawns the bullet
- par2World.spawnEntityInWorld(new Entitybullet(par2World, par3EntityPlayer, damage, 1));
- //plays the sound effect
- par2World.playSoundAtEntity(par3EntityPlayer, firesound, 1F, 1F);
- //damages the gun
- par1ItemStack.damageItem(1, par3EntityPlayer);
- //resets the fire delay counter
- firetick = 0;
- }else{
- //if the fire delay counter isn't done, then this is called, which increases the fire delay counter
- ++firetick;
- }
- //if firemax is 0 none of the above was called, so call this instead
- if(firemax == 0){
- par2World.spawnEntityInWorld(new Entitybullet(par2World, par3EntityPlayer, damage, 1));
- par2World.playSoundAtEntity(par3EntityPlayer, firesound, 1F, 1F);
- par1ItemStack.damageItem(1, par3EntityPlayer);
- //already explained...
- }
- //If the player is out of ammo in the current clip, and the player has the correct clip, run this code
- }else if(!par2World.isRemote && par3EntityPlayer.inventory.hasItem(clipid) && par1ItemStack.getItemDamage() == ammo){
- //checks for the reload timer to complete
- if(reloadtick == reloadmax){
- //resets the reload timer
- reloadtick = 0;
- //plays the reload sound
- par2World.playSoundAtEntity(par3EntityPlayer, reloadsound, 1F, 1F);
- //consumes the item of the clipid
- par3EntityPlayer.inventory.consumeInventoryItem(clipid);
- //resets the ammo of the gun
- par1ItemStack.setItemDamage(0);
- }else{
- //just like with firetick and firemax...
- ++reloadtick;
- }
- }
- //just some housekeeping stuff
- return par1ItemStack;
- }
- public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int i){
- //this resets the firetick. I originally planned on using this method for non-automatic weapons
- //but the method didn't seem to end up being called at all... if someone could clarify why this is
- //happening I would appreciate it...
- firetick = firemax;
- }
- public String getTextureFile(){
- return "/****.png";
- }
- }
- ----------------------------------Entitybullet----------------------------------------------
- package ****;
- import java.util.List;
- import java.util.Random;
- import net.minecraft.block.Block;
- import net.minecraft.client.Minecraft;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityLiving;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.util.AxisAlignedBB;
- import net.minecraft.util.EntityDamageSource;
- import net.minecraft.util.MathHelper;
- import net.minecraft.util.MovingObjectPosition;
- import net.minecraft.util.Vec3;
- import net.minecraft.world.World;
- public class Entitybullet extends Entity
- {
- private int xTile;
- private int yTile;
- private int zTile;
- private int inTile;
- private boolean inGround;
- public int arrowShake;
- public EntityLiving shootingEntity;
- private int timeTillDeath;
- private int flyTime;
- private EntityPlayer owner;
- private int damage;
- private final float size = 1F;
- public Entitybullet(World world)
- {
- super(world);
- xTile = -1;
- yTile = -1;
- zTile = -1;
- inTile = 0;
- inGround = false;
- arrowShake = 0;
- flyTime = 0;
- setSize(size, size);
- }
- public Entitybullet(World world, double d, double d1, double d2,
- double d3, double d4, double d5, EntityPlayer entityplayer)
- {
- super(world);
- xTile = -1;
- yTile = -1;
- zTile = -1;
- inTile = 0;
- inGround = false;
- arrowShake = 0;
- flyTime = 0;
- setSize(size, size);
- setPosition(d, d1, d2);
- yOffset = 0.0F;
- setVelocity(d3, d4, d5);
- owner = entityplayer;
- }
- public Entitybullet(World world, double d, double d1, double d2)
- {
- super(world);
- xTile = -1;
- yTile = -1;
- zTile = -1;
- inTile = 0;
- inGround = false;
- arrowShake = 0;
- flyTime = 0;
- setSize(size, size);
- setPosition(d, d1, d2);
- yOffset = 0.0F;
- }
- public Entitybullet(World world, EntityLiving entityliving, int damage, int accuracy)
- {
- super(world);
- this.damage = damage;
- xTile = -1;
- yTile = -1;
- zTile = -1;
- inTile = 0;
- inGround = false;
- arrowShake = 0;
- flyTime = 0;
- shootingEntity = entityliving;
- setSize(size, size);
- setLocationAndAngles(entityliving.posX, entityliving.posY + (double)entityliving.getEyeHeight(), entityliving.posZ, entityliving.rotationYaw, entityliving.rotationPitch);
- posX -= MathHelper.cos((rotationYaw / 180F) * 3.141593F) * 0.16F;
- posY -= 0.10000000149011612D;
- posZ -= MathHelper.sin((rotationYaw / 180F) * 3.141593F) * 0.16F;
- setPosition(posX, posY, posZ);
- yOffset = 0.0F;
- motionX = 1000F * -MathHelper.sin((rotationYaw / 180F) * 3.141593F) * MathHelper.cos((rotationPitch / 180F) * 3.141593F);
- motionZ = 1000F * MathHelper.cos((rotationYaw / 180F) * 3.141593F) * MathHelper.cos((rotationPitch / 180F) * 3.141593F);
- motionY = 1000F * -MathHelper.sin((rotationPitch / 180F) * 3.141593F);
- setArrowHeading(motionX, motionY, motionZ, 200.0F, 1.5F, accuracy);
- }
- protected void entityInit()
- {
- }
- public void setArrowHeading(double d, double d1, double d2, float f,
- float f1, int i)
- {
- float f2 = MathHelper.sqrt_double(d * d + d1 * d1 + d2 * d2);
- d /= f2;
- d1 /= f2;
- d2 /= f2;
- d += rand.nextGaussian() * 0.0034999998323619365D * (double)f1 * (double)i / 5;
- d1 += rand.nextGaussian() * 0.0034999998323619365D * (double)f1 * (double)i / 5;
- d2 += rand.nextGaussian() * 0.0034999998323619365D * (double)f1 * (double)i / 5;
- d *= f;
- d1 *= f;
- d2 *= f;
- motionX = d;
- motionY = d1;
- motionZ = d2;
- float f3 = MathHelper.sqrt_double(d * d + d2 * d2);
- prevRotationYaw = rotationYaw = (float)((Math.atan2(d, d2) * 180D) / 3.1415927410125732D);
- prevRotationPitch = rotationPitch = (float)((Math.atan2(d1, f3) * 180D) / 3.1415927410125732D);
- timeTillDeath = 0;
- }
- public void setVelocity(double d, double d1, double d2)
- {
- motionX = d;
- motionY = d1;
- motionZ = d2;
- if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F)
- {
- float f = MathHelper.sqrt_double(d * d + d2 * d2);
- prevRotationYaw = rotationYaw = (float)((Math.atan2(d, d2) * 180D) / 3.1415927410125732D);
- prevRotationPitch = rotationPitch = (float)((Math.atan2(d1, f) * 180D) / 3.1415927410125732D);
- }
- }
- public void onUpdate()
- {
- super.onUpdate();
- if (flyTime > 1000)
- {
- setDead();
- }
- if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F)
- {
- float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
- prevRotationYaw = rotationYaw = (float)((Math.atan2(motionX, motionZ) * 180D) / 3.1415927410125732D);
- prevRotationPitch = rotationPitch = (float)((Math.atan2(motionY, f) * 180D) / 3.1415927410125732D);
- }
- if (arrowShake > 0)
- {
- arrowShake--;
- }
- if (inGround)
- {
- int i = worldObj.getBlockId(xTile, yTile, zTile);
- if (i != inTile)
- {
- inGround = false;
- motionX *= rand.nextFloat() * 0.2F;
- motionY *= rand.nextFloat() * 0.2F;
- motionZ *= rand.nextFloat() * 0.2F;
- timeTillDeath = 0;
- flyTime = 0;
- }
- else
- {
- timeTillDeath++;
- if (timeTillDeath == 1200)
- {
- setDead();
- }
- return;
- }
- }
- else
- {
- flyTime++;
- }
- Vec3 vec3d = Vec3.createVectorHelper(posX, posY, posZ);
- Vec3 vec3d1 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ);
- MovingObjectPosition movingobjectposition = worldObj.rayTraceBlocks(vec3d, vec3d1);
- vec3d = Vec3.createVectorHelper(posX, posY, posZ);
- vec3d1 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ);
- if (movingobjectposition != null)
- {
- vec3d1 = Vec3.createVectorHelper(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
- }
- Entity entity = null;
- List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D));
- double d = 0.0D;
- for (int j = 0; j < list.size(); j++)
- {
- Entity entity1 = (Entity)list.get(j);
- if (!entity1.canBeCollidedWith() || entity1 == shootingEntity && flyTime < 5)
- {
- continue;
- }
- float f4 = 0.3F;
- AxisAlignedBB axisalignedbb = entity1.boundingBox.expand(f4, f4, f4);
- MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3d, vec3d1);
- if (movingobjectposition1 == null)
- {
- continue;
- }
- double d1 = vec3d.distanceTo(movingobjectposition1.hitVec);
- if (d1 < d || d == 0.0D)
- {
- entity = entity1;
- d = d1;
- }
- }
- if (entity != null)
- {
- movingobjectposition = new MovingObjectPosition(entity);
- }
- if (movingobjectposition != null)
- {
- if (movingobjectposition.entityHit != null)
- {
- if (movingobjectposition.entityHit.attackEntityFrom(new EntityDamageSource("player", owner), damage))
- {
- worldObj.playSoundAtEntity(this, "random.hurt", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F));
- setDead();
- }
- else
- {
- motionX *= 0.10000000149011612D;
- motionY *= 0.10000000149011612D;
- motionZ *= 0.10000000149011612D;
- flyTime = 0;
- setDead();
- }
- }
- else
- {
- xTile = movingobjectposition.blockX;
- yTile = movingobjectposition.blockY;
- zTile = movingobjectposition.blockZ;
- inTile = worldObj.getBlockId(xTile, yTile, zTile);
- if (inTile == Block.glass.blockID || inTile == Block.glowStone.blockID)
- {
- Block block = Block.blocksList[inTile];
- //ModLoader.getMinecraftInstance().sndManager.playSound(block.stepSound.stepSoundDir(), (float)xTile + 0.5F, (float)yTile + 0.5F, (float)zTile + 0.5F, (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
- worldObj.setBlockWithNotify(xTile, yTile, zTile, 0);
- }
- else
- {
- motionX = (float)(movingobjectposition.hitVec.xCoord - posX);
- motionY = (float)(movingobjectposition.hitVec.yCoord - posY);
- motionZ = (float)(movingobjectposition.hitVec.zCoord - posZ);
- float f1 = MathHelper.sqrt_double(motionX * motionX + motionY * motionY + motionZ * motionZ);
- posX -= (motionX / (double)f1) * 0.05000000074505806D;
- posY -= (motionY / (double)f1) * 0.05000000074505806D;
- posZ -= (motionZ / (double)f1) * 0.05000000074505806D;
- worldObj.playSoundAtEntity(this, "Bullet2Hit", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F));
- setDead();
- }
- }
- }
- posX += motionX * 3D;
- posY += motionY * 3D;
- posZ += motionZ * 3D;
- float f2 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
- rotationYaw = (float)((Math.atan2(motionX, motionZ) * 180D) / 3.1415927410125732D);
- for (rotationPitch = (float)((Math.atan2(motionY, f2) * 180D) / 3.1415927410125732D); rotationPitch - prevRotationPitch < -180F; prevRotationPitch -= 360F) { }
- for (; rotationPitch - prevRotationPitch >= 180F; prevRotationPitch += 360F) { }
- for (; rotationYaw - prevRotationYaw < -180F; prevRotationYaw -= 360F) { }
- for (; rotationYaw - prevRotationYaw >= 180F; prevRotationYaw += 360F) { }
- rotationPitch = prevRotationPitch + (rotationPitch - prevRotationPitch) * 0.2F;
- rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.2F;
- float f3 = 0.99F;
- float f5 = 0.03F;
- if (handleWaterMovement())
- {
- for (int k = 0; k < 4; k++)
- {
- float f6 = 0.25F;
- worldObj.spawnParticle("smoke", posX - motionX * (double)f6, posY - motionY * (double)f6, posZ - motionZ * (double)f6, motionX, motionY, motionZ);
- }
- f3 = 0.8F;
- }
- motionX *= f3;
- motionY *= f3;
- motionZ *= f3;
- setPosition(posX, posY, posZ);
- }
- public void writeEntityToNBT1(NBTTagCompound nbttagcompound)
- {
- nbttagcompound.setShort("xTile", (short)xTile);
- nbttagcompound.setShort("yTile", (short)yTile);
- nbttagcompound.setShort("zTile", (short)zTile);
- nbttagcompound.setByte("inTile", (byte)inTile);
- nbttagcompound.setByte("shake", (byte)arrowShake);
- nbttagcompound.setByte("inGround", (byte)(inGround ? 1 : 0));
- }
- public void readEntityFromNBT1(NBTTagCompound nbttagcompound)
- {
- xTile = nbttagcompound.getShort("xTile");
- yTile = nbttagcompound.getShort("yTile");
- zTile = nbttagcompound.getShort("zTile");
- inTile = nbttagcompound.getByte("inTile") & 0xff;
- arrowShake = nbttagcompound.getByte("shake") & 0xff;
- inGround = nbttagcompound.getByte("inGround") == 1;
- }
- public void onCollideWithPlayer(EntityPlayer entityplayer)
- {
- if (worldObj.isRemote)
- {
- return;
- }
- if (inGround && shootingEntity == entityplayer && arrowShake <= 0 && entityplayer.inventory.addItemStackToInventory(new ItemStack(Item.arrow, 1)))
- {
- worldObj.playSoundAtEntity(this, "random.pop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
- entityplayer.onItemPickup(this, 1);
- setDead();
- }
- }
- public float getShadowSize()
- {
- return 0.0F;
- }
- @Override
- protected void readEntityFromNBT(NBTTagCompound var1) {
- }
- @Override
- protected void writeEntityToNBT(NBTTagCompound var1) {
- }
- {
- this.worldObj.spawnParticle("smoke", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
- }
- }
- ---------------------------Itemgrenade------------------------------------
- package ****;
- import net.minecraft.creativetab.CreativeTabs;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.world.World;
- public class Itemgrenade extends Item
- {
- public Itemgrenade(int i)
- {
- super(i);
- this.maxStackSize = 4;
- this.setCreativeTab(CreativeTabs.tabCombat);
- }
- public ItemStack onItemRightClick(ItemStack var1, World var2, EntityPlayer var3)
- {
- if (!var3.capabilities.isCreativeMode)
- {
- --var1.stackSize;
- }
- var2.playSoundAtEntity(var3, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
- if (!var2.isRemote)
- {
- var2.spawnEntityInWorld(new Entitygrenade(var2, var3));
- }
- return var1;
- }
- public String getTextureFile()
- {
- return "/****.png";
- }
- }
- ----------------------------------------Entitygrenade-------------------------------
- package ****;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityLiving;
- import net.minecraft.entity.projectile.EntityThrowable;
- import net.minecraft.util.DamageSource;
- import net.minecraft.util.MovingObjectPosition;
- import net.minecraft.world.World;
- public class Entitygrenade extends Entitybombthrow
- {
- private static final int var2 = 0;
- private EntityLiving thrower;
- public Entitygrenade(World var1)
- {
- super(var1);
- }
- public Entitygrenade(World var1, EntityLiving var2)
- {
- super(var1, var2);
- }
- public Entitygrenade(World var1, double var2, double var4, double var6)
- {
- super(var1, var2, var4, var6);
- }
- /**
- * Called when this EntityThrowable hits a block or entity.
- */
- protected void onImpact(MovingObjectPosition var1)
- {
- if (var1.entityHit != null)
- {
- {
- }
- if (!var1.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.thrower), var2))
- {
- ;
- }
- }
- for (int var3 = 0; var3 < 8; ++var3)
- {
- this.worldObj.spawnParticle("smoke", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
- }
- if (!this.worldObj.isRemote)
- {
- this.setDead();
- if (!this.worldObj.isRemote)
- {
- this.worldObj.createExplosion((Entity)null, this.posX, this.posY, this.posZ, 2.0F, true);
- }
- }
- }
- public String getTextureFile()
- {
- return "/****.png";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment