正确发射蜂群无人机
This commit is contained in:
parent
61ba12084c
commit
31e6914868
2 changed files with 50 additions and 78 deletions
|
@ -324,6 +324,8 @@ public class ModItems {
|
|||
DispenserBlock.registerProjectileBehavior(item.get());
|
||||
}
|
||||
}
|
||||
|
||||
DispenserBlock.registerBehavior(SWARM_DRONE.get(), new SwarmDrone.SwarmDroneDispenseBehavior());
|
||||
}
|
||||
|
||||
public static void register(IEventBus bus) {
|
||||
|
|
|
@ -1,16 +1,25 @@
|
|||
package com.atsuishio.superbwarfare.item;
|
||||
|
||||
import com.atsuishio.superbwarfare.entity.projectile.SwarmDroneEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Position;
|
||||
import net.minecraft.core.dispenser.BlockSource;
|
||||
import net.minecraft.core.dispenser.ProjectileDispenseBehavior;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.entity.projectile.Projectile;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.ProjectileItem;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.ClipContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.DispenserBlock;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
@ -22,83 +31,41 @@ public class SwarmDrone extends Item implements ProjectileItem {
|
|||
super(new Properties());
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public AbstractProjectileDispenseBehavior getLaunchBehavior() {
|
||||
// return new AbstractProjectileDispenseBehavior() {
|
||||
//
|
||||
// @Override
|
||||
// public ItemStack execute(BlockSource blockSource, ItemStack pStack) {
|
||||
// Level level = blockSource.getLevel();
|
||||
// Position position = DispenserBlock.getDispensePosition(blockSource);
|
||||
// Direction direction = blockSource.getBlockState().getValue(DispenserBlock.FACING);
|
||||
// Projectile projectile = this.getProjectile(level, position, pStack);
|
||||
//
|
||||
// float yVec = direction.getStepY();
|
||||
// if (direction != Direction.DOWN) {
|
||||
// yVec += 1F;
|
||||
// }
|
||||
//
|
||||
// projectile.shoot(direction.getStepX(), yVec, direction.getStepZ(), this.getPower(), this.getUncertainty());
|
||||
//
|
||||
// BlockHitResult result = level.clip(new ClipContext(new Vec3(position.x(), position.y(), position.z()),
|
||||
// new Vec3(position.x(), position.y(), position.z()).add(new Vec3(direction.step().mul(128))),
|
||||
// ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, projectile));
|
||||
// Vec3 hitPos = result.getLocation();
|
||||
// ((SwarmDroneEntity) projectile).setGuideType(1);
|
||||
// ((SwarmDroneEntity) projectile).setTargetVec(hitPos);
|
||||
//
|
||||
// level.addFreshEntity(projectile);
|
||||
// pStack.shrink(1);
|
||||
// return pStack;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @ParametersAreNonnullByDefault
|
||||
// protected @NotNull Projectile getProjectile(Level pLevel, Position pos, ItemStack pStack) {
|
||||
// return new SwarmDroneEntity(pos.x(), pos.y(), pos.z(), pLevel);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void playSound(BlockSource blockSource) {
|
||||
// blockSource.getLevel().playSound(null, blockSource.getPos(), ModSounds.DECOY_FIRE.get(), SoundSource.BLOCKS, 2.0F, 1.0F);
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
public static class SwarmDroneDispenseBehavior extends ProjectileDispenseBehavior {
|
||||
|
||||
// public class SwarmDroneDispenseBehavior extends ProjectileDispenseBehavior {
|
||||
//
|
||||
// public SwarmDroneDispenseBehavior(Item projectile) {
|
||||
// super(projectile);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @ParametersAreNonnullByDefault
|
||||
// public @NotNull ItemStack execute(BlockSource blockSource, ItemStack stack) {
|
||||
// Level level = blockSource.level();
|
||||
// Position position = DispenserBlock.getDispensePosition(blockSource);
|
||||
// Direction direction = blockSource.state().getValue(DispenserBlock.FACING);
|
||||
// Projectile projectile = this.getProjectile(level, position, stack);
|
||||
//
|
||||
// float yVec = direction.getStepY();
|
||||
// if (direction != Direction.DOWN) {
|
||||
// yVec += 1F;
|
||||
// }
|
||||
//
|
||||
// projectile.shoot(direction.getStepX(), yVec, direction.getStepZ(), this.getPower(), this.getUncertainty());
|
||||
//
|
||||
// BlockHitResult result = level.clip(new ClipContext(new Vec3(position.x(), position.y(), position.z()),
|
||||
// new Vec3(position.x(), position.y(), position.z()).add(new Vec3(direction.step().mul(128))),
|
||||
// ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, projectile));
|
||||
// Vec3 hitPos = result.getLocation();
|
||||
// ((SwarmDroneEntity) projectile).setGuideType(1);
|
||||
// ((SwarmDroneEntity) projectile).setTargetVec(hitPos);
|
||||
//
|
||||
// level.addFreshEntity(projectile);
|
||||
// pStack.shrink(1);
|
||||
// return pStack;
|
||||
// return super.execute(blockSource, stack);
|
||||
// }
|
||||
// }
|
||||
public SwarmDroneDispenseBehavior() {
|
||||
super(ModItems.SWARM_DRONE.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public @NotNull ItemStack execute(BlockSource blockSource, ItemStack stack) {
|
||||
Level level = blockSource.level();
|
||||
Position position = DispenserBlock.getDispensePosition(blockSource);
|
||||
Direction direction = blockSource.state().getValue(DispenserBlock.FACING);
|
||||
SwarmDroneEntity projectile = createProjectile(level, position);
|
||||
|
||||
float yVec = direction.getStepY();
|
||||
if (direction != Direction.DOWN) {
|
||||
yVec += 1F;
|
||||
}
|
||||
|
||||
projectile.shoot(direction.getStepX(), yVec, direction.getStepZ(), 1.5f, 1);
|
||||
|
||||
BlockHitResult result = level.clip(new ClipContext(new Vec3(position.x(), position.y(), position.z()),
|
||||
new Vec3(position.x(), position.y(), position.z()).add(new Vec3(direction.step().mul(128))),
|
||||
ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, projectile));
|
||||
Vec3 hitPos = result.getLocation();
|
||||
projectile.setGuideType(1);
|
||||
projectile.setTargetVec(hitPos);
|
||||
|
||||
level.addFreshEntity(projectile);
|
||||
stack.shrink(1);
|
||||
|
||||
blockSource.level().playSound(null, blockSource.pos(), ModSounds.DECOY_FIRE.get(), SoundSource.BLOCKS, 2.0F, 1.0F);
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO 怎么发射?
|
||||
|
||||
|
@ -112,14 +79,17 @@ public class SwarmDrone extends Item implements ProjectileItem {
|
|||
public @NotNull DispenseConfig createDispenseConfig() {
|
||||
return ProjectileItem.DispenseConfig.builder()
|
||||
.uncertainty(1)
|
||||
.power(0.5f)
|
||||
.power(1.5f)
|
||||
.build();
|
||||
}
|
||||
|
||||
private static SwarmDroneEntity createProjectile(Level level, Position pos) {
|
||||
return new SwarmDroneEntity(pos.x(), pos.y(), pos.z(), level);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public @NotNull Projectile asProjectile(Level level, Position pos, ItemStack stack, Direction direction) {
|
||||
return new SwarmDroneEntity(pos.x(), pos.y(), pos.z(), level);
|
||||
return createProjectile(level, pos);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue