临时移植了激光
This commit is contained in:
parent
4fc4d7bbef
commit
433c5b0e05
5 changed files with 55 additions and 31 deletions
|
@ -26,7 +26,7 @@ public class LaserEntityRenderer extends AbstractLaserEntityRenderer<LaserEntity
|
|||
private static final float TEXTURE_WIDTH = 256;
|
||||
private static final float TEXTURE_HEIGHT = 32;
|
||||
|
||||
public static final ResourceLocation TEXTURE = ModUtils.loc("textures/entity/laser.png");
|
||||
public static final ResourceLocation TEXTURE = ModUtils.loc("textures/entity/temp_laser.png");
|
||||
|
||||
public LaserEntityRenderer(EntityRendererProvider.Context context) {
|
||||
super(context, 0.8f, 0.6f);
|
||||
|
@ -41,9 +41,7 @@ public class LaserEntityRenderer extends AbstractLaserEntityRenderer<LaserEntity
|
|||
public void render(LaserEntity beam, float entityYaw, float delta, PoseStack matrixStackIn, MultiBufferSource bufferIn, int packedLightIn) {
|
||||
this.playerView = beam.caster instanceof Player && Minecraft.getInstance().player == beam.caster
|
||||
&& Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON;
|
||||
if (this.playerView) {
|
||||
return;
|
||||
}
|
||||
// if (this.playerView) return;
|
||||
super.render(beam, entityYaw, delta, matrixStackIn, bufferIn, packedLightIn);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,11 +16,11 @@ public class LaserEntity extends AbstractLaserEntity {
|
|||
public static final double RADIUS = 512D;
|
||||
|
||||
public LaserEntity(EntityType<? extends LaserEntity> type, Level level) {
|
||||
super(type, level, 0);
|
||||
super(type, level, 1);
|
||||
}
|
||||
|
||||
public LaserEntity(Level level, LivingEntity caster, double x, double y, double z, float yaw, float pitch, int duration) {
|
||||
super(ModEntities.LASER.get(), level, 0);
|
||||
super(ModEntities.LASER.get(), level, 1);
|
||||
this.caster = caster;
|
||||
this.setYaw(yaw);
|
||||
this.setPitch(pitch);
|
||||
|
|
|
@ -350,7 +350,7 @@ public class ClientEventHandler {
|
|||
}
|
||||
|
||||
public static void beamShoot(Player player, ItemStack stack) {
|
||||
if (stack.is(ModItems.BEAM_TEST.get()) && stack.getOrCreateTag().getBoolean("Using")) {
|
||||
if (stack.is(ModItems.BEAM_TEST.get()) && stack.getOrCreateTag().getBoolean("LaserFiring")) {
|
||||
Entity lookingEntity = TraceTool.laserfindLookingEntity(player, 512);
|
||||
|
||||
if (player.isCrouching()) {
|
||||
|
@ -466,7 +466,7 @@ public class ClientEventHandler {
|
|||
randomShell[2] = (0.7 + (Math.random() - 0.5));
|
||||
}
|
||||
|
||||
public static void handleShakeClient(double time, double radius, double amplitude, double x, double y,double z, Supplier<NetworkEvent.Context> ctx) {
|
||||
public static void handleShakeClient(double time, double radius, double amplitude, double x, double y, double z, Supplier<NetworkEvent.Context> ctx) {
|
||||
if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) {
|
||||
Player player = Minecraft.getInstance().player;
|
||||
if (player == null) return;
|
||||
|
@ -619,18 +619,16 @@ public class ClientEventHandler {
|
|||
shakeTime = Mth.lerp(0.25 * times, shakeTime, 0);
|
||||
|
||||
if (player != null && shakeTime > 0) {
|
||||
shakeRadiusAmplitude = (float) Mth.clamp(1 - player.position().distanceTo(new Vec3(shakePos[0], shakePos[1], shakePos[2])) / shakeRadius, 0 ,1);
|
||||
|
||||
// player.displayClientMessage(Component.literal(new java.text.DecimalFormat("##.##").format(shakeRadiusAmplitude)), true);
|
||||
shakeRadiusAmplitude = (float) Mth.clamp(1 - player.position().distanceTo(new Vec3(shakePos[0], shakePos[1], shakePos[2])) / shakeRadius, 0, 1);
|
||||
|
||||
if (shakeType > 0) {
|
||||
event.setYaw((float) (yaw + (shakeTime * Math.sin(0.5 *Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * 0.75 * shakeType)));
|
||||
event.setPitch((float) (pitch - (shakeTime * Math.sin(0.5 *Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * shakeType)));
|
||||
event.setRoll((float) (roll - (shakeTime * Math.sin(0.5 *Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude)));
|
||||
event.setYaw((float) (yaw + (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * 0.75 * shakeType)));
|
||||
event.setPitch((float) (pitch - (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * shakeType)));
|
||||
event.setRoll((float) (roll - (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude)));
|
||||
} else {
|
||||
event.setYaw((float) (yaw - (shakeTime * Math.sin(0.5 *Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * 0.75 * shakeType)));
|
||||
event.setPitch((float) (pitch + (shakeTime * Math.sin(0.5 *Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * shakeType)));
|
||||
event.setRoll((float) (roll + (shakeTime * Math.sin(0.5 *Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude)));
|
||||
event.setYaw((float) (yaw - (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * 0.75 * shakeType)));
|
||||
event.setPitch((float) (pitch + (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * shakeType)));
|
||||
event.setRoll((float) (roll + (shakeTime * Math.sin(0.5 * Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude)));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
package com.atsuishio.superbwarfare.item;
|
||||
|
||||
import com.atsuishio.superbwarfare.capability.LaserCapability;
|
||||
import com.atsuishio.superbwarfare.capability.LaserHandler;
|
||||
import com.atsuishio.superbwarfare.capability.ModCapabilities;
|
||||
import com.atsuishio.superbwarfare.entity.projectile.LaserEntity;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
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;
|
||||
|
||||
public class BeamTest extends Item {
|
||||
|
||||
public BeamTest() {
|
||||
super(new Properties());
|
||||
}
|
||||
|
@ -17,23 +22,46 @@ public class BeamTest extends Item {
|
|||
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
|
||||
ItemStack stack = player.getItemInHand(hand);
|
||||
|
||||
if (!stack.getOrCreateTag().getBoolean("Using")) {
|
||||
stack.getOrCreateTag().putBoolean("Using", true);
|
||||
player.getCooldowns().addCooldown(this, 10);
|
||||
} else {
|
||||
stack.getOrCreateTag().putBoolean("Using", false);
|
||||
}
|
||||
player.getCapability(ModCapabilities.LASER_CAPABILITY).ifPresent(capability -> {
|
||||
player.startUsingItem(hand);
|
||||
|
||||
return InteractionResultHolder.consume(stack);
|
||||
if (!level.isClientSide) {
|
||||
double px = player.getX();
|
||||
double py = player.getY() + player.getBbHeight() * 0.6F;
|
||||
double pz = player.getZ();
|
||||
float yHeadRotAngle = (float) Math.toRadians(player.yHeadRot + 90);
|
||||
float xHeadRotAngle = (float) (float) -Math.toRadians(player.getXRot());
|
||||
LaserEntity laserEntity = new LaserEntity(player.level(), player, px, py, pz, yHeadRotAngle, xHeadRotAngle, 6000);
|
||||
capability.init(new LaserHandler(player, laserEntity, 0));
|
||||
capability.start();
|
||||
|
||||
stack.getOrCreateTag().putBoolean("LaserFiring", true);
|
||||
}
|
||||
});
|
||||
|
||||
return InteractionResultHolder.consume(player.getItemInHand(hand));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inventoryTick(ItemStack itemstack, Level world, Entity entity, int slot, boolean selected) {
|
||||
super.inventoryTick(itemstack, world, entity, slot, selected);
|
||||
if (!selected) {
|
||||
if (itemstack.getOrCreateTag().getBoolean("Using")) {
|
||||
itemstack.getOrCreateTag().putBoolean("Using", false);
|
||||
}
|
||||
public void releaseUsing(ItemStack stack, Level level, LivingEntity livingEntity, int timeCharged) {
|
||||
if (livingEntity instanceof Player player) {
|
||||
player.getCapability(ModCapabilities.LASER_CAPABILITY).ifPresent(LaserCapability.ILaserCapability::stop);
|
||||
stack.getOrCreateTag().putBoolean("LaserFiring", false);
|
||||
}
|
||||
super.releaseUsing(stack, level, livingEntity, timeCharged);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack finishUsingItem(ItemStack pStack, Level pLevel, LivingEntity pLivingEntity) {
|
||||
if (pLivingEntity instanceof Player player) {
|
||||
player.getCapability(ModCapabilities.LASER_CAPABILITY).ifPresent(LaserCapability.ILaserCapability::stop);
|
||||
pStack.getOrCreateTag().putBoolean("LaserFiring", false);
|
||||
}
|
||||
return super.finishUsingItem(pStack, pLevel, pLivingEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUseDuration(ItemStack stack) {
|
||||
return 6000;
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
Loading…
Add table
Reference in a new issue