数据system
本帖最后由 数据system 于 2020-10-16 23:25 编辑
  1. public EntityMagicBullet(World worldIn, EntityLivingBase throwerIn)
  2.     {
  3.         super(worldIn, throwerIn);
  4.         shoot((Entity)throwerIn, throwerIn.rotationPitch, throwerIn.rotationYaw, 0.0f, 1.5f, 1.0f);
  5.     }
复制代码
  1. protected float getVelocity()
  2.         {
  3.                 return 1.5F;
  4.         }
  5.         
  6.     protected float getGravityVelocity()
  7.     {
  8.         return 1.0F; //重力影响极小
  9.     }
  10.    
  11.     protected float getInaccuracy() {
  12.             return 1.0F;
  13.     }
复制代码

设置似乎对生成的实体也没有什么作用
使用shoot方法似乎实体一直都保持不动。
Forge1.12.2-14.23.5.2847

=赤刃=
本帖最后由 赤刃泉润CQR 于 2020-10-17 00:07 编辑

可以参考原版雪球的发射写法
  1.     public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
  2.     {
  3.         ItemStack itemstack = playerIn.getHeldItem(handIn);

  4.         if (!playerIn.capabilities.isCreativeMode)
  5.         {
  6.             itemstack.shrink(1);
  7.         }

  8.         worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

  9. if (!worldIn.isRemote)
  10.         {
  11.             EntitySnowball entitysnowball = new EntitySnowball(worldIn, playerIn);
  12.             entitysnowball.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);
  13.             worldIn.spawnEntity(entitysnowball);
  14.       }

  15.         playerIn.addStat(StatList.getObjectUseStats(this));
  16.         return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
  17.     }
复制代码
发射雪球实体的是这段(从上段中提取的)
  1. if (!worldIn.isRemote)
  2.         {
  3.             EntitySnowball entitysnowball = new EntitySnowball(worldIn, playerIn);
  4.             entitysnowball.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);
  5.             worldIn.spawnEntity(entitysnowball);
  6.       }
复制代码




数据system
本帖最后由 数据system 于 2020-10-17 09:17 编辑
赤刃泉润CQR 发表于 2020-10-17 00:05
可以参考原版雪球的发射写法
发射雪球实体的是这段(从上段中提取的)
  1. @SubscribeEvent
  2.     public void onUseItem(RightClickItem event) {
  3.             EntityLivingBase player=event.getEntityPlayer();
  4.             World world=player.getEntityWorld();
  5.             ItemStack Mainhand=player.getHeldItemMainhand();
  6.             if(Mainhand.getDisplayName()=="book") {
  7.                     if (!world.isRemote) {
  8.                     EntityMagicBullet entity=new EntityMagicBullet(world, (EntityLivingBase)player);
  9.                     entity.shoot((Entity)player, player.rotationPitch, player.rotationYaw, 0.0f, 1.5f, 1.0f);
  10.                     world.spawnEntity(entity);
  11.                     //entity.shoot(0, 10, 0, 1.5f, 0f);
  12.                     }
  13.             }
  14.             
  15.     }
复制代码
在事件里似乎无法发射出去,只能生成和改变角度,但实体不会移动。

洞穴夜莺
数据system 发表于 2020-10-17 09:16
在事件里似乎无法发射出去,只能生成和改变角度,但实体不会移动。

我有疑问,你这是在服务端还是在客户端?
https://github.com/MinecraftForg ... rInteractEvent.java
根据这里,这个RightClickItem事件应该是双端触发的
但是你的代码明显是只应该在服务端执行的代码

数据system
洞穴夜莺 发表于 2020-10-17 09:43
我有疑问,你这是在服务端还是在客户端?
https://github.com/MinecraftForge/MinecraftForge/blob/1.12. ...

实体生成不是只要在服务端吗?
在客户端也执行会产生有bug的实体。

洞穴夜莺
数据system 发表于 2020-10-17 10:15
实体生成不是只要在服务端吗?
在客户端也执行会产生有bug的实体。

但是你监听的是RightClickItem,这个事件是双端的啊

数据system
洞穴夜莺 发表于 2020-10-17 10:20
但是你监听的是RightClickItem,这个事件是双端的啊

if (!world.isRemote) {}可是我添加了客户端判断了呀?

数据system
本帖最后由 数据system 于 2020-10-17 11:04 编辑

大佬,实体使用shoot方法后会根据玩家视角生成实体,但重力,速度这些值都没有用,实体依然会停留在原地一动不动
暮色森林里的黄昏法杖似乎直接写在实体的类里的,但我无论是写在实体的类里还是事件中都实体不会移动



数据system
洞穴夜莺 发表于 2020-10-17 09:43
我有疑问,你这是在服务端还是在客户端?
https://github.com/MinecraftForge/MinecraftForge/blob/1.12. ...
  1. package com.data.dataextension.entity;

  2. import net.minecraft.entity.Entity;
  3. import net.minecraft.entity.EntityLivingBase;
  4. import net.minecraft.entity.projectile.EntityThrowable;
  5. import net.minecraft.network.datasync.DataParameter;
  6. import net.minecraft.network.datasync.DataSerializers;
  7. import net.minecraft.network.datasync.EntityDataManager;
  8. import net.minecraft.util.EnumParticleTypes;
  9. import net.minecraft.util.math.RayTraceResult;
  10. import net.minecraft.world.World;

  11. public class EntityMagicBullet extends EntityThrowable {
  12.         private static final DataParameter<Integer> Time = EntityDataManager.<Integer>createKey(EntityMagicBullet.class, DataSerializers.VARINT);
  13.         private static final DataParameter<Float> Yaw = EntityDataManager.<Float>createKey(EntityMagicBullet.class, DataSerializers.FLOAT);
  14.         private static final DataParameter<Float> Pitch = EntityDataManager.<Float>createKey(EntityMagicBullet.class, DataSerializers.FLOAT);
  15.         private static final DataParameter<String> Name = EntityDataManager.<String>createKey(EntityMagicBullet.class, DataSerializers.STRING);
  16.         //int w=0;
  17.        
  18.         protected void entityInit() {
  19.                 this.dataManager.register(Time,Integer.valueOf(120));
  20.                 this.dataManager.register(Yaw,Float.valueOf(0.0f) );
  21.                 this.dataManager.register(Pitch, Float.valueOf(0.0f));
  22.                 this.dataManager.register(Name, "magicbullet.png");
  23.         }
  24.        
  25.         public void setrotation(Float t1,Float t2) {
  26.                 this.dataManager.set(Yaw, t1);
  27.                 this.dataManager.set(Pitch, t2);
  28.         }
  29.         public Float getYaw() {
  30.                 return (Float)this.dataManager.get(Yaw);
  31.         }
  32.         public Float getPitch() {
  33.                 return (Float)this.dataManager.get(Pitch);
  34.         }
  35.         public void setname(String t) {
  36.                 this.dataManager.set(Name, t);
  37.         }
  38.         public String getname() {
  39.                 return (String)this.dataManager.get(Name);
  40.         }
  41.         public void setTime(int t) {
  42.                 this.dataManager.set(Time, t);
  43.         }
  44.         public int getTime() {
  45.                 return (Integer)this.dataManager.get(Time);
  46.         }
  47.        
  48.     public EntityMagicBullet(World worldIn)
  49.     {
  50.         super(worldIn);
  51.     }

  52.     public EntityMagicBullet(World worldIn, EntityLivingBase throwerIn)
  53.     {
  54.         super(worldIn, throwerIn);
  55.         //shoot((Entity)throwerIn, throwerIn.rotationPitch, throwerIn.rotationYaw, 0.0f, 1.5f, 1.0f);
  56.     }

  57.     public EntityMagicBullet(World worldIn, double x, double y, double z)
  58.     {
  59.         super(worldIn, x, y, z);
  60.     }

  61.         @Override
  62.         protected void onImpact(RayTraceResult result) {
  63.                
  64.         }
  65.        
  66.         protected float getVelocity()
  67.         {
  68.                 return 1.5F;
  69.         }
  70.        
  71.     protected float getGravityVelocity()
  72.     {
  73.         return 1.0F; //重力影响极小
  74.     }
  75.    
  76.     protected float getInaccuracy() {
  77.             return 1.0F;
  78.     }
  79.    
  80.     public void onUpdate(){
  81.                 int i=this.getTime();
  82.                 this.setTime(--i);
  83.                 if(i<=0) {if(!this.world.isRemote) {this.setDead();}}
  84.                 World world=this.getEntityWorld();
  85.                 double[] pos= {this.posX,this.posY,this.posZ};
  86.                 world.spawnParticle(EnumParticleTypes.DRAGON_BREATH, true, pos[0], pos[1], pos[2], 0, 0, 0, 1);
  87.                 //this.setPosition(pos[0], pos[1]+(w+0.3f), pos[2]);
  88.         }
  89.        
  90. }
复制代码



洞穴夜莺
  1. private static final DataParameter<Float> Yaw = EntityDataManager.<Float>createKey(EntityMagicBullet.class, DataSerializers.FLOAT);
  2.         private static final DataParameter<Float> Pitch = EntityDataManager.<Float>createKey(EntityMagicBullet.class, DataSerializers.FLOAT);
  3.         
复制代码

Yaw和Pitch不需要自己管理,EntityThrowable已经处理好Yaw和Pitch的问题,你这样反而容易出错



  1.     public void onUpdate(){
  2.                 int i=this.getTime();
  3.                 this.setTime(--i);
  4.                 if(i<=0) {if(!this.world.isRemote) {this.setDead();}}
  5.                 World world=this.getEntityWorld();
  6.                 double[] pos= {this.posX,this.posY,this.posZ};
  7.                 world.spawnParticle(EnumParticleTypes.DRAGON_BREATH, true, pos[0], pos[1], pos[2], 0, 0, 0, 1);
  8.                 //this.setPosition(pos[0], pos[1]+(w+0.3f), pos[2]);
  9.         }
复制代码

这里最好调用一下super.onUpdate()

第一页 上一页 下一页 最后一页