修复发射器相关行为
This commit is contained in:
parent
31e6914868
commit
1e0baa2a2d
7 changed files with 136 additions and 56 deletions
|
@ -326,6 +326,12 @@ public class ModItems {
|
|||
}
|
||||
|
||||
DispenserBlock.registerBehavior(SWARM_DRONE.get(), new SwarmDrone.SwarmDroneDispenseBehavior());
|
||||
DispenserBlock.registerBehavior(C4_BOMB.get(), new C4Bomb.C4DispenseItemBehavior());
|
||||
DispenserBlock.registerBehavior(CLAYMORE_MINE.get(), new ClaymoreMine.ClaymoreDispenseBehavior());
|
||||
DispenserBlock.registerBehavior(ROCKET.get(), new Rocket.RocketDispenseBehavior());
|
||||
DispenserBlock.registerBehavior(ROCKET_70.get(), new Rocket70.Rocket70DispenseBehavior());
|
||||
DispenserBlock.registerBehavior(MEDIUM_AERIAL_BOMB.get(), new MediumAerialBomb.MediumAerialBombDispenseBehavior());
|
||||
DispenserBlock.registerBehavior(RGO_GRENADE.get(), new RgoGrenade.RgoGrenadeDispenserBehavior());
|
||||
}
|
||||
|
||||
public static void register(IEventBus bus) {
|
||||
|
|
|
@ -1,30 +1,34 @@
|
|||
package com.atsuishio.superbwarfare.item;
|
||||
|
||||
import com.atsuishio.superbwarfare.entity.projectile.C4Entity;
|
||||
import com.atsuishio.superbwarfare.init.ModEntities;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
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.DefaultDispenseItemBehavior;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
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.Level;
|
||||
import net.minecraft.world.level.block.DispenserBlock;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.List;
|
||||
|
||||
public class C4Bomb extends Item implements ProjectileItem {
|
||||
public class C4Bomb extends Item {
|
||||
|
||||
public static final String TAG_CONTROL = "Control";
|
||||
|
||||
|
@ -78,18 +82,31 @@ public class C4Bomb extends Item implements ProjectileItem {
|
|||
return stack;
|
||||
}
|
||||
|
||||
// TODO play sound
|
||||
public static class C4DispenseItemBehavior extends DefaultDispenseItemBehavior {
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public @NotNull Projectile asProjectile(Level level, Position pos, ItemStack stack, Direction direction) {
|
||||
// TODO 重写发射器行为
|
||||
// var c4 = new C4Entity((LivingEntity) null, level);
|
||||
// c4.setPos(pos.x(), pos.y(), pos.z());
|
||||
return null;
|
||||
}
|
||||
protected @NotNull ItemStack execute(BlockSource blockSource, ItemStack stack) {
|
||||
Level level = blockSource.level();
|
||||
Position position = DispenserBlock.getDispensePosition(blockSource);
|
||||
Direction direction = blockSource.state().getValue(DispenserBlock.FACING);
|
||||
|
||||
@Override
|
||||
public @NotNull DispenseConfig createDispenseConfig() {
|
||||
return DispenseConfig.builder().power(0.15F).build();
|
||||
var entity = new C4Entity(ModEntities.C_4.get(), level);
|
||||
entity.setPos(position.x(), position.y(), position.z());
|
||||
|
||||
var pX = direction.getStepX();
|
||||
var pY = direction.getStepY() + 0.1F;
|
||||
var pZ = direction.getStepZ();
|
||||
Vec3 vec3 = (new Vec3(pX, pY, pZ)).normalize().scale(0.05);
|
||||
entity.setDeltaMovement(vec3);
|
||||
double d0 = vec3.horizontalDistance();
|
||||
entity.setYRot((float) (Mth.atan2(vec3.x, vec3.z) * (double) (180F / (float) Math.PI)));
|
||||
entity.setXRot((float) (Mth.atan2(vec3.y, d0) * (double) (180F / (float) Math.PI)));
|
||||
entity.yRotO = entity.getYRot();
|
||||
entity.xRotO = entity.getXRot();
|
||||
|
||||
level.addFreshEntity(entity);
|
||||
stack.shrink(1);
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,24 @@
|
|||
package com.atsuishio.superbwarfare.item;
|
||||
|
||||
import com.atsuishio.superbwarfare.entity.ClaymoreEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModEntities;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Position;
|
||||
import net.minecraft.core.dispenser.BlockSource;
|
||||
import net.minecraft.core.dispenser.DefaultDispenseItemBehavior;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.DispenserBlock;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
public class ClaymoreMine extends Item {
|
||||
public ClaymoreMine() {
|
||||
super(new Properties());
|
||||
|
@ -37,41 +47,31 @@ public class ClaymoreMine extends Item {
|
|||
return InteractionResultHolder.consume(stack);
|
||||
}
|
||||
|
||||
// TODO 发射器发射
|
||||
// @Override
|
||||
// public DispenseItemBehavior getLaunchBehavior() {
|
||||
// return new ProjectileDispenseBehavior() {
|
||||
// @Override
|
||||
// @ParametersAreNonnullByDefault
|
||||
// public @NotNull ItemStack execute(BlockSource pSource, ItemStack pStack) {
|
||||
// Level level = pSource.getLevel();
|
||||
// Position position = DispenserBlock.getDispensePosition(pSource);
|
||||
// Direction direction = pSource.getBlockState().getValue(DispenserBlock.FACING);
|
||||
//
|
||||
// var claymore = new ClaymoreEntity(ModEntities.CLAYMORE.get(), level);
|
||||
// claymore.setPos(position.x(), position.y(), position.z());
|
||||
//
|
||||
// var pX = direction.getStepX();
|
||||
// var pY = direction.getStepY() + 0.1F;
|
||||
// var pZ = direction.getStepZ();
|
||||
// Vec3 vec3 = (new Vec3(pX, pY, pZ)).normalize().scale(0.05);
|
||||
// claymore.setDeltaMovement(vec3);
|
||||
// double d0 = vec3.horizontalDistance();
|
||||
// claymore.setYRot((float) (Mth.atan2(vec3.x, vec3.z) * (double) (180F / (float) Math.PI)));
|
||||
// claymore.setXRot((float) (Mth.atan2(vec3.y, d0) * (double) (180F / (float) Math.PI)));
|
||||
// claymore.yRotO = claymore.getYRot();
|
||||
// claymore.xRotO = claymore.getXRot();
|
||||
//
|
||||
// level.addFreshEntity(claymore);
|
||||
// pStack.shrink(1);
|
||||
// return pStack;
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @ParametersAreNonnullByDefault
|
||||
// public @NotNull Projectile asProjectile(Level level, Position pos, ItemStack stack, Direction direction) {
|
||||
// return null;
|
||||
// }
|
||||
public static class ClaymoreDispenseBehavior extends DefaultDispenseItemBehavior {
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
protected @NotNull ItemStack execute(BlockSource blockSource, ItemStack stack) {
|
||||
Level level = blockSource.level();
|
||||
Position position = DispenserBlock.getDispensePosition(blockSource);
|
||||
Direction direction = blockSource.state().getValue(DispenserBlock.FACING);
|
||||
|
||||
var claymore = new ClaymoreEntity(ModEntities.CLAYMORE.get(), level);
|
||||
claymore.setPos(position.x(), position.y(), position.z());
|
||||
|
||||
var pX = direction.getStepX();
|
||||
var pY = direction.getStepY() + 0.1F;
|
||||
var pZ = direction.getStepZ();
|
||||
Vec3 vec3 = (new Vec3(pX, pY, pZ)).normalize().scale(0.05);
|
||||
claymore.setDeltaMovement(vec3);
|
||||
double d0 = vec3.horizontalDistance();
|
||||
claymore.setYRot((float) (Mth.atan2(vec3.x, vec3.z) * (double) (180F / (float) Math.PI)));
|
||||
claymore.setXRot((float) (Mth.atan2(vec3.y, d0) * (double) (180F / (float) Math.PI)));
|
||||
claymore.yRotO = claymore.getYRot();
|
||||
claymore.xRotO = claymore.getXRot();
|
||||
|
||||
level.addFreshEntity(claymore);
|
||||
stack.shrink(1);
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,15 @@ package com.atsuishio.superbwarfare.item;
|
|||
|
||||
import com.atsuishio.superbwarfare.entity.projectile.Mk82Entity;
|
||||
import com.atsuishio.superbwarfare.init.ModEntities;
|
||||
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;
|
||||
|
@ -29,7 +34,17 @@ public class MediumAerialBomb extends Item implements ProjectileItem {
|
|||
tooltipComponents.add(Component.translatable("des.superbwarfare.medium_aerial_bomb").withStyle(ChatFormatting.GRAY));
|
||||
}
|
||||
|
||||
// TODO 发射音效
|
||||
public static class MediumAerialBombDispenseBehavior extends ProjectileDispenseBehavior {
|
||||
public MediumAerialBombDispenseBehavior() {
|
||||
super(ModItems.MEDIUM_AERIAL_BOMB.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void playSound(BlockSource blockSource) {
|
||||
blockSource.level().playSound(null, blockSource.pos(), ModSounds.BOMB_RELEASE.get(), SoundSource.BLOCKS, 2.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull DispenseConfig createDispenseConfig() {
|
||||
return DispenseConfig.builder()
|
||||
|
|
|
@ -4,11 +4,14 @@ import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
|
|||
import com.atsuishio.superbwarfare.entity.projectile.RgoGrenadeEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModDamageTypes;
|
||||
import com.atsuishio.superbwarfare.init.ModEntities;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.tools.CustomExplosion;
|
||||
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
||||
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.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
|
@ -103,7 +106,17 @@ public class RgoGrenade extends Item implements ProjectileItem {
|
|||
return 80;
|
||||
}
|
||||
|
||||
// TODO 音效播放
|
||||
public static class RgoGrenadeDispenserBehavior extends ProjectileDispenseBehavior {
|
||||
public RgoGrenadeDispenserBehavior() {
|
||||
super(ModItems.RGO_GRENADE.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void playSound(BlockSource blockSource) {
|
||||
blockSource.level().playSound(null, blockSource.pos(), ModSounds.GRENADE_THROW.get(), SoundSource.BLOCKS, 1.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public @NotNull Projectile asProjectile(Level level, Position pos, ItemStack stack, Direction direction) {
|
||||
|
|
|
@ -2,8 +2,13 @@ package com.atsuishio.superbwarfare.item;
|
|||
|
||||
import com.atsuishio.superbwarfare.entity.projectile.HeliRocketEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModEntities;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
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.sounds.SoundSource;
|
||||
import net.minecraft.world.entity.projectile.Projectile;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
@ -19,13 +24,23 @@ public class Rocket70 extends Item implements ProjectileItem {
|
|||
super(new Properties());
|
||||
}
|
||||
|
||||
public static class Rocket70DispenseBehavior extends ProjectileDispenseBehavior {
|
||||
public Rocket70DispenseBehavior() {
|
||||
super(ModItems.ROCKET_70.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void playSound(BlockSource blockSource) {
|
||||
blockSource.level().playSound(null, blockSource.pos(), ModSounds.HELICOPTER_ROCKET_FIRE_3P.get(), SoundSource.BLOCKS, 2.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public @NotNull Projectile asProjectile(Level level, Position pos, ItemStack stack, Direction direction) {
|
||||
return new HeliRocketEntity(ModEntities.HELI_ROCKET.get(), pos.x(), pos.y(), pos.z(), level);
|
||||
}
|
||||
|
||||
// TODO 发射音效
|
||||
@Override
|
||||
public @NotNull DispenseConfig createDispenseConfig() {
|
||||
return DispenseConfig.builder()
|
||||
|
|
|
@ -7,13 +7,17 @@ import com.atsuishio.superbwarfare.entity.projectile.RpgRocketEntity;
|
|||
import com.atsuishio.superbwarfare.init.ModCriteriaTriggers;
|
||||
import com.atsuishio.superbwarfare.init.ModEntities;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModSounds;
|
||||
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
||||
import net.minecraft.client.model.HumanoidModel;
|
||||
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
|
||||
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.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.EquipmentSlotGroup;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
|
@ -125,13 +129,23 @@ public class Rocket extends Item implements GeoItem, ProjectileItem {
|
|||
return super.hurtEnemy(stack, entity, source);
|
||||
}
|
||||
|
||||
public static class RocketDispenseBehavior extends ProjectileDispenseBehavior {
|
||||
public RocketDispenseBehavior() {
|
||||
super(ModItems.ROCKET.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void playSound(BlockSource blockSource) {
|
||||
blockSource.level().playSound(null, blockSource.pos(), ModSounds.RPG_FIRE_3P.get(), SoundSource.BLOCKS, 1.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public @NotNull Projectile asProjectile(Level level, Position pos, ItemStack stack, Direction direction) {
|
||||
return new RpgRocketEntity(ModEntities.RPG_ROCKET.get(), pos.x(), pos.y(), pos.z(), level);
|
||||
}
|
||||
|
||||
// TODO 发射音效
|
||||
@Override
|
||||
public @NotNull DispenseConfig createDispenseConfig() {
|
||||
return DispenseConfig.builder().power(1.5F).build();
|
||||
|
|
Loading…
Add table
Reference in a new issue