本帖最后由 数据system 于 2020-10-16 23:25 编辑
复制代码复制代码
设置似乎对生成的实体也没有什么作用
使用shoot方法似乎实体一直都保持不动。
Forge1.12.2-14.23.5.2847
- public EntityMagicBullet(World worldIn, EntityLivingBase throwerIn)
- {
- super(worldIn, throwerIn);
- shoot((Entity)throwerIn, throwerIn.rotationPitch, throwerIn.rotationYaw, 0.0f, 1.5f, 1.0f);
- }
- protected float getVelocity()
- {
- return 1.5F;
- }
-
- protected float getGravityVelocity()
- {
- return 1.0F; //重力影响极小
- }
-
- protected float getInaccuracy() {
- return 1.0F;
- }
设置似乎对生成的实体也没有什么作用
使用shoot方法似乎实体一直都保持不动。
Forge1.12.2-14.23.5.2847
本帖最后由 赤刃泉润CQR 于 2020-10-17 00:07 编辑
可以参考原版雪球的发射写法
复制代码发射雪球实体的是这段(从上段中提取的)复制代码
可以参考原版雪球的发射写法
- public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
- {
- ItemStack itemstack = playerIn.getHeldItem(handIn);
- if (!playerIn.capabilities.isCreativeMode)
- {
- itemstack.shrink(1);
- }
- 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));
- if (!worldIn.isRemote)
- {
- EntitySnowball entitysnowball = new EntitySnowball(worldIn, playerIn);
- entitysnowball.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);
- worldIn.spawnEntity(entitysnowball);
- }
- playerIn.addStat(StatList.getObjectUseStats(this));
- return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
- }
- if (!worldIn.isRemote)
- {
- EntitySnowball entitysnowball = new EntitySnowball(worldIn, playerIn);
- entitysnowball.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);
- worldIn.spawnEntity(entitysnowball);
- }
本帖最后由 数据system 于 2020-10-17 09:17 编辑
复制代码在事件里似乎无法发射出去,只能生成和改变角度,但实体不会移动。
赤刃泉润CQR 发表于 2020-10-17 00:05
可以参考原版雪球的发射写法
发射雪球实体的是这段(从上段中提取的)
- @SubscribeEvent
- public void onUseItem(RightClickItem event) {
- EntityLivingBase player=event.getEntityPlayer();
- World world=player.getEntityWorld();
- ItemStack Mainhand=player.getHeldItemMainhand();
- if(Mainhand.getDisplayName()=="book") {
- if (!world.isRemote) {
- EntityMagicBullet entity=new EntityMagicBullet(world, (EntityLivingBase)player);
- entity.shoot((Entity)player, player.rotationPitch, player.rotationYaw, 0.0f, 1.5f, 1.0f);
- world.spawnEntity(entity);
- //entity.shoot(0, 10, 0, 1.5f, 0f);
- }
- }
-
- }
数据system 发表于 2020-10-17 09:16
在事件里似乎无法发射出去,只能生成和改变角度,但实体不会移动。
我有疑问,你这是在服务端还是在客户端?
https://github.com/MinecraftForg ... rInteractEvent.java
根据这里,这个RightClickItem事件应该是双端触发的
但是你的代码明显是只应该在服务端执行的代码
洞穴夜莺 发表于 2020-10-17 09:43
我有疑问,你这是在服务端还是在客户端?
https://github.com/MinecraftForge/MinecraftForge/blob/1.12. ...
实体生成不是只要在服务端吗?
在客户端也执行会产生有bug的实体。
数据system 发表于 2020-10-17 10:15
实体生成不是只要在服务端吗?
在客户端也执行会产生有bug的实体。
但是你监听的是RightClickItem,这个事件是双端的啊
洞穴夜莺 发表于 2020-10-17 10:20
但是你监听的是RightClickItem,这个事件是双端的啊
if (!world.isRemote) {}可是我添加了客户端判断了呀?
本帖最后由 数据system 于 2020-10-17 11:04 编辑
大佬,实体使用shoot方法后会根据玩家视角生成实体,但重力,速度这些值都没有用,实体依然会停留在原地一动不动
暮色森林里的黄昏法杖似乎直接写在实体的类里的,但我无论是写在实体的类里还是事件中都实体不会移动
洞穴夜莺 发表于 2020-10-17 09:43
我有疑问,你这是在服务端还是在客户端?
https://github.com/MinecraftForge/MinecraftForge/blob/1.12. ...
大佬,实体使用shoot方法后会根据玩家视角生成实体,但重力,速度这些值都没有用,实体依然会停留在原地一动不动
暮色森林里的黄昏法杖似乎直接写在实体的类里的,但我无论是写在实体的类里还是事件中都实体不会移动


洞穴夜莺 发表于 2020-10-17 09:43
我有疑问,你这是在服务端还是在客户端?
https://github.com/MinecraftForge/MinecraftForge/blob/1.12. ...
- package com.data.dataextension.entity;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.projectile.EntityThrowable;
- import net.minecraft.network.datasync.DataParameter;
- import net.minecraft.network.datasync.DataSerializers;
- import net.minecraft.network.datasync.EntityDataManager;
- import net.minecraft.util.EnumParticleTypes;
- import net.minecraft.util.math.RayTraceResult;
- import net.minecraft.world.World;
- public class EntityMagicBullet extends EntityThrowable {
- private static final DataParameter<Integer> Time = EntityDataManager.<Integer>createKey(EntityMagicBullet.class, DataSerializers.VARINT);
- private static final DataParameter<Float> Yaw = EntityDataManager.<Float>createKey(EntityMagicBullet.class, DataSerializers.FLOAT);
- private static final DataParameter<Float> Pitch = EntityDataManager.<Float>createKey(EntityMagicBullet.class, DataSerializers.FLOAT);
- private static final DataParameter<String> Name = EntityDataManager.<String>createKey(EntityMagicBullet.class, DataSerializers.STRING);
- //int w=0;
-
- protected void entityInit() {
- this.dataManager.register(Time,Integer.valueOf(120));
- this.dataManager.register(Yaw,Float.valueOf(0.0f) );
- this.dataManager.register(Pitch, Float.valueOf(0.0f));
- this.dataManager.register(Name, "magicbullet.png");
- }
-
- public void setrotation(Float t1,Float t2) {
- this.dataManager.set(Yaw, t1);
- this.dataManager.set(Pitch, t2);
- }
- public Float getYaw() {
- return (Float)this.dataManager.get(Yaw);
- }
- public Float getPitch() {
- return (Float)this.dataManager.get(Pitch);
- }
- public void setname(String t) {
- this.dataManager.set(Name, t);
- }
- public String getname() {
- return (String)this.dataManager.get(Name);
- }
- public void setTime(int t) {
- this.dataManager.set(Time, t);
- }
- public int getTime() {
- return (Integer)this.dataManager.get(Time);
- }
-
- public EntityMagicBullet(World worldIn)
- {
- super(worldIn);
- }
- public EntityMagicBullet(World worldIn, EntityLivingBase throwerIn)
- {
- super(worldIn, throwerIn);
- //shoot((Entity)throwerIn, throwerIn.rotationPitch, throwerIn.rotationYaw, 0.0f, 1.5f, 1.0f);
- }
- public EntityMagicBullet(World worldIn, double x, double y, double z)
- {
- super(worldIn, x, y, z);
- }
- @Override
- protected void onImpact(RayTraceResult result) {
-
- }
-
- protected float getVelocity()
- {
- return 1.5F;
- }
-
- protected float getGravityVelocity()
- {
- return 1.0F; //重力影响极小
- }
-
- protected float getInaccuracy() {
- return 1.0F;
- }
-
- public void onUpdate(){
- int i=this.getTime();
- this.setTime(--i);
- if(i<=0) {if(!this.world.isRemote) {this.setDead();}}
- World world=this.getEntityWorld();
- double[] pos= {this.posX,this.posY,this.posZ};
- world.spawnParticle(EnumParticleTypes.DRAGON_BREATH, true, pos[0], pos[1], pos[2], 0, 0, 0, 1);
- //this.setPosition(pos[0], pos[1]+(w+0.3f), pos[2]);
- }
-
- }
- private static final DataParameter<Float> Yaw = EntityDataManager.<Float>createKey(EntityMagicBullet.class, DataSerializers.FLOAT);
- private static final DataParameter<Float> Pitch = EntityDataManager.<Float>createKey(EntityMagicBullet.class, DataSerializers.FLOAT);
Yaw和Pitch不需要自己管理,EntityThrowable已经处理好Yaw和Pitch的问题,你这样反而容易出错

- public void onUpdate(){
- int i=this.getTime();
- this.setTime(--i);
- if(i<=0) {if(!this.world.isRemote) {this.setDead();}}
- World world=this.getEntityWorld();
- double[] pos= {this.posX,this.posY,this.posZ};
- world.spawnParticle(EnumParticleTypes.DRAGON_BREATH, true, pos[0], pos[1], pos[2], 0, 0, 0, 1);
- //this.setPosition(pos[0], pos[1]+(w+0.3f), pos[2]);
- }
这里最好调用一下super.onUpdate()