Jump to content

[1.8.x] Shooting Custom Bullets while riding mobs


Darkflame

Recommended Posts

Hi!

 

I've been working on a Rideable Mech mod, and I looked into making the  battle mech shoot. I looked at some gun tutorials, and followed them. So I have a gun Item. However, I tried to make it so when the person was riding the mech, they would be able to right click and the bullet entity would be created, and work as if it was fired from a gun. Naturally, this didn't work. How could it work? Maybe if I made an item that only was able to create the bullet entity when I was riding the mech? but how would I make it recognize that I was in the mech?  :-\ Help Please! D:>

 

Here's my mob class:

package com.mech.entity;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class BattleMechMob extends EntityMob {

public BattleMechMob(World worldIn) {
	super(worldIn);
	// TODO Auto-generated constructor stub
}

public boolean interact(EntityPlayer entityplayer)
  {
    if (riddenByEntity == null || riddenByEntity == entityplayer)
    {
      entityplayer.mountEntity(this);
      
      return true;
    }
    else
    {
      return false;
    }
  }

public void moveEntityWithHeading(float p_70612_1_, float p_70612_2_)
{
if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityLivingBase)
{
this.prevRotationYaw = this.rotationYaw = this.riddenByEntity.rotationYaw;
this.rotationPitch = this.riddenByEntity.rotationPitch * 0.5F;
this.setRotation(this.rotationYaw, this.rotationPitch);
this.rotationYawHead = this.renderYawOffset = this.rotationYaw;
//this.posY = this.rotationPitch; new addition
//this.posY = ((EntityLivingBase)this.riddenByEntity).moveFlying(p_70612_1_, p_70612_2_, );
//this.posY = ((EntityLivingBase)this.riddenByEntity).moveFlying(strafe, forward, friction);
p_70612_1_ = ((EntityLivingBase)this.riddenByEntity).moveStrafing * 0.1F; //initial value 0.5F
p_70612_2_ = ((EntityLivingBase)this.riddenByEntity).moveForward * 0.50F; //Forward move speed

if (p_70612_2_ <= 0.0F)
{
  p_70612_2_ *= 0.25F; //Reverse move speed
}

this.stepHeight = 1.0F;
this.jumpMovementFactor = this.getAIMoveSpeed() * 0.1F;

if (!this.worldObj.isRemote)
{
  this.setAIMoveSpeed((float)this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue());
  super.moveEntityWithHeading(p_70612_1_, p_70612_2_);
}

this.prevLimbSwingAmount = this.limbSwingAmount;
double d1 = this.posX - this.prevPosX;
double d0 = this.posZ - this.prevPosZ;
float f4 = MathHelper.sqrt_double(d1 * d1 + d0 * d0) * 4.0F;

if (f4 > 1.0F)
{
  f4 = 1.0F;
}

this.limbSwingAmount += (f4 - this.limbSwingAmount) * 0.4F;
this.limbSwing += this.limbSwingAmount;
}
else
{
this.stepHeight = 0.5F;
this.jumpMovementFactor = 0.02F;
super.moveEntityWithHeading(p_70612_1_, p_70612_2_);
}
}

}

 

Here's my gun class:

package com.mech.item;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;

import com.mech.entity.EntityBlasterBolt;

public class ItemBlasterRifle extends Item
{
  public ItemBlasterRifle()
  {
    super();
    setCreativeTab(CreativeTabs.tabCombat);
    setUnlocalizedName("blasterRifle");
  }
  
  @Override
  public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World,EntityPlayer par3EntityPlayer) {
      if(par3EntityPlayer.capabilities.isCreativeMode||par3EntityPlayer.inventory.consumeInventoryItem(Items.redstone))
      {
          par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
          if (!par2World.isRemote)
          {
              par2World.spawnEntityInWorld(new EntityBlasterBolt(par2World, par3EntityPlayer));
          }
          
      }
          return par1ItemStack;
  }
}

 

And here's my bullet class:

package com.mech.entity;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;

public class EntityBlasterBolt extends EntityThrowable
{
    private float explosionRadius = 1.5F;
public EntityBlasterBolt(World par1World)
    {
        super(par1World);
    }
    public EntityBlasterBolt(World par1World, EntityLivingBase par2EntityLivingBase)
    {
        super(par1World, par2EntityLivingBase);
    }
    public EntityBlasterBolt(World par1World, double par2, double par4, double par6)
    {
        super(par1World, par2, par4, par6);
    }
    
    @Override
    protected void onImpact(MovingObjectPosition par1MovingObjectPosition) 
    {
    	if(true){
    		this.attackEntityFrom(DamageSource.generic, 100);
    	}
        this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, (float)this.explosionRadius , false);
        this.setDead();
    }
    
    public void onUpdate()
    {
    	super.onUpdate();
    	this.worldObj.spawnParticle(EnumParticleTypes.CRIT_MAGIC, this.posX, this.posY, this.posZ, 100.0D, 100.0D, 100.0D, new int[100]);

    }

}

 

Thank you to anyone that helps <:3

I. Am. A. Noob.

Noobs. :P

Link to comment
Share on other sites

i didnt read much of the post tbh but i found youre using a method called "onRightClickItem" and i would use this one ?

public boolean onItemUse(ItemStack is, EntityPlayer eplayer, World world, BlockPos pos, EnumFacing facing, float f1, float f2, float f3)
{
return false;
}

Link to comment
Share on other sites

Break your problem down into smaller problems, and describe it in more detail.

 

Do you want the player to shoot the bullet, or the mech?

 

Can the mech shoot on its own, or does it only fire when controlled by a player?

 

Do you really want the player to have to be holding a certain item to shoot while riding the mech, or would you rather it just happens when the player right clicks like they entered some commands on the mech's control panel?

 

Always explain EXACTLY what you want to happen and how you want it to happen so people can help you more effectively.

Link to comment
Share on other sites

Break your problem down into smaller problems, and describe it in more detail.

 

Do you want the player to shoot the bullet, or the mech?

 

Can the mech shoot on its own, or does it only fire when controlled by a player?

 

Do you really want the player to have to be holding a certain item to shoot while riding the mech, or would you rather it just happens when the player right clicks like they entered some commands on the mech's control panel?

 

Always explain EXACTLY what you want to happen and how you want it to happen so people can help you more effectively.

 

I want to make the bullet shoot when the player is riding the mech, and he right clicks.

I. Am. A. Noob.

Noobs. :P

Link to comment
Share on other sites

You didn't answer all questions, and yes - they are all important and will decide how to code it.

 

If the mech would shoot, the mech will be the one spawning enitity, if it's player - it would be player.

Both would trigger differently. Does mech have same rotation as player? What are height differences? Do you want to shoot from mech's arm, or center?

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

To shoot on right-click, you will need to use Events, specifically the MouseEvent and KeyInputEvent (to handle keyUseItem in the case that it is bound to a key other than the mouse).

 

Both of those events are CLIENT only, meaning you will have to send a packet to the server letting it know that the player right-clicked; from there, perform all necessary checks (e.g. is player riding mech? can he shoot this tick? etc.) and spawn the bullet based on decisions you make in response to Ernio's reply.

 

Just be aware that if you have never used Events or Packets before, it can be a daunting task as it seems far more complex at first than it actually is. Once you get the hang of them, they really are quite simple.

Link to comment
Share on other sites

To shoot on right-click, you will need to use Events, specifically the MouseEvent and KeyInputEvent (to handle keyUseItem in the case that it is bound to a key other than the mouse).

 

Both of those events are CLIENT only, meaning you will have to send a packet to the server letting it know that the player right-clicked; from there, perform all necessary checks (e.g. is player riding mech? can he shoot this tick? etc.) and spawn the bullet based on decisions you make in response to Ernio's reply.

 

Just be aware that if you have never used Events or Packets before, it can be a daunting task as it seems far more complex at first than it actually is. Once you get the hang of them, they really are quite simple.

 

I followed the event tutorial, but what event should I use? I can't use the interact event because that would shoot a bullet every time I mounted the mob.

I. Am. A. Noob.

Noobs. :P

Link to comment
Share on other sites

Client side:

1. Subscribe MouseEvent

2. Check if mouse event == left/right click.

3. Check if you are mounting mech entity

4. If yes - send packet to server using SimpleNetworkWrapper with simple "action ID", nothing more, nothing less (it can even be empty packet in this case).

Server side:

1. Receive and hanlde packet:

- Check AGAIN if player who send packet is mounting mech.

- Check any other requirements (server decides if you can shoot).

- Get that mech, use math to calculate arm position.

- Offset created bullet entity to position of hand.

- Spawn new bullet entity with some velocity at mech's entity (entities have constructor taking entity-to-spawn-on argument)

- BOOM, you spawned bullet from hand of mech!

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

To shoot on right-click, you will need to use Events, specifically the MouseEvent and KeyInputEvent (to handle keyUseItem in the case that it is bound to a key other than the mouse).

 

Both of those events are CLIENT only, meaning you will have to send a packet to the server letting it know that the player right-clicked; from there, perform all necessary checks (e.g. is player riding mech? can he shoot this tick? etc.) and spawn the bullet based on decisions you make in response to Ernio's reply.

 

Just be aware that if you have never used Events or Packets before, it can be a daunting task as it seems far more complex at first than it actually is. Once you get the hang of them, they really are quite simple.

 

I followed the event tutorial, but what event should I use? I can't use the interact event because that would shoot a bullet every time I mounted the mob.

I have now put the events needed in bold. Please read more carefully in the future.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • SPARTA88 adalah pilihan tepat bagi Anda yang menginginkan agen situs slot terbaik dengan RTP tinggi dan transaksi yang mudah melalui Bank BNI. Berikut adalah beberapa alasan mengapa Anda harus memilih SPARTA88: Tingkat Pengembalian (RTP) Tinggi Kami bangga menjadi salah satu agen situs slot dengan RTP tertinggi, mencapai 98%! Ini berarti Anda memiliki peluang lebih besar untuk meraih kemenangan dalam setiap putaran permainan. Beragam Pilihan Permainan SPARTA88 menyajikan koleksi permainan slot yang beragam dan menarik dari berbagai provider terkemuka. Mulai dari tema klasik hingga yang paling modern, Anda akan menemukan banyak pilihan permainan yang sesuai dengan selera dan preferensi Anda. Kemudahan Bertransaksi Melalui Bank BNI Proses deposit dan penarikan dana di SPARTA88 cepat, mudah, dan aman. Kami menyediakan layanan transaksi melalui Bank BNI untuk kenyamanan Anda. Dengan begitu, Anda dapat melakukan transaksi dengan lancar tanpa perlu khawatir.
    • Slot Bank ALADIN atau Daftar slot Bank ALADIN bisa anda lakukan pada situs WINNING303 kapanpun dan dimanapun, Bermodalkan Hp saja anda bisa mengakses chat ke agen kami selama 24 jam full. keuntungan bergabung bersama kami di WINNING303 adalah anda akan mendapatkan bonus 100% khusus member baru yang bergabung dan deposit. Tidak perlu banyak, 5 ribu rupiah saja anda sudah bisa bermain bersama kami di WINNING303 . Tunggu apa lagi ? Segera Klik DAFTAR dan anda akan jadi Jutawan dalam semalam.
    • Slot Bank PAPUA atau Daftar slot Bank PAPUA bisa anda lakukan pada situs WINNING303 kapanpun dan dimanapun, Bermodalkan Hp saja anda bisa mengakses chat ke agen kami selama 24 jam full. keuntungan bergabung bersama kami di WINNING303 adalah anda akan mendapatkan bonus 100% khusus member baru yang bergabung dan deposit. Tidak perlu banyak, 5 ribu rupiah saja anda sudah bisa bermain bersama kami di WINNING303 . Tunggu apa lagi ? Segera Klik DAFTAR dan anda akan jadi Jutawan dalam semalam.  
    • SLOT MAHJONG WAYS 3 SCATTER HITAM : POLA SLOT MAHJONG 3 SCATTER HITAM HARI INI - TRIK POLA SLOT GACOR x500 SCATTER HITAM KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << SITUS SLOT GACOR 88 MAXWIN X500 HARI INI TERBAIK DAN TERPERCAYA GAMPANG MENANG Dunia Game gacor terus bertambah besar seiring berjalannya waktu, dan sudah tentu dunia itu terus berkembang serta merta bersamaan dengan berkembangnya SLOT GACOR sebagai website number #1 yang pernah ada dan tidak pernah mengecewakan sekalipun. Dengan banyaknya member yang sudah mempercayakan untuk terus menghasilkan uang bersama dengan SLOT GACOR pastinya mereka sudah percaya untuk bermain Game online bersama dengan kami dengan banyaknya testimoni yang sudah membuktikan betapa seringnya member mendapatkan jackpot besar yang bisa mencapai ratusan juta rupiah. Best online Game website that give you more money everyday, itu lah slogan yang tepat untuk bermain bersama SLOT GACOR yang sudah pasti menang setiap harinya dan bisa menjadikan bandar ini sebagai patokan untuk mendapatkan penghasilan tambahan yang efisien dan juga sesuatu hal yang fix setiap hari nya. Kami juga mendapatkan julukan sebagai Number #1 website bocor yang berarti terus memberikan member uang asli dan jackpot setiap hari nya, tidak lupa bocor itu juga bisa diartikan dalam bentuk berbagi promosi untuk para official member yang terus setia bermain bersama dengan kami. Berbagai provider Game terus bertambah banyak setiap harinya dan terus melakukan support untuk membuat para official member terus bisa menang dan terus maxwin dalam bentuk apapun maka itu langsung untuk feel free to try yourself, play with SLOT GACOR now or never !
    • JANGKRIK4D >> SLOT DANA GOPAY OVO | SLOT GACOR GAMPANG MAXWIN X100 X250 X500  << DAFTAR JANGKRIK4D >> JANGKRIK4D SITUS SLOT PGSOFT GAMING TERPERCAYA JANGKRIK4D 🚀 SITUS PGSLOT DAN PGSOFT GAMING TERPERCAYA 🚀 – JANGKRIK4D situs pgslot paling gacor telah hadir bersama JANGKRIK4D yang karena telah memberikan berbagai macam permainan untuk mendapatkan jackpot yang besar karena sudah menjadi pioneer untuk penyedia game paling mujarab beserta jajaran pgsoft gaming terpercaya yang telah bersama dengan JANGKRIK4D menjalin kerja sama resmi serta berlisensi untuk memberikan kemenangan paling besar untuk para player yang mencoba menamatkan permainan yang telah memeberikan kemenangan fantastis saat ini. jangkrik4d slot gacor slot deposit dana demo slot gacor demo slot pg demo pg soft slot deposit gopay slot deposit pulsa slot server jepang
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.