更改箭矢的伤害方法
This commit is contained in:
parent
e7fb6a0311
commit
ed952be5cd
6 changed files with 81 additions and 61 deletions
|
@ -4,7 +4,7 @@ import com.mojang.blaze3d.vertex.PoseStack;
|
|||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Axis;
|
||||
import net.mcreator.target.client.model.entity.ModelBocekArrow;
|
||||
import net.mcreator.target.entity.BocekarrowEntity;
|
||||
import net.mcreator.target.entity.BocekArrowEntity;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderer;
|
||||
|
@ -13,7 +13,7 @@ import net.minecraft.client.renderer.texture.OverlayTexture;
|
|||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
|
||||
public class BocekarrowRenderer extends EntityRenderer<BocekarrowEntity> {
|
||||
public class BocekarrowRenderer extends EntityRenderer<BocekArrowEntity> {
|
||||
private static final ResourceLocation texture = new ResourceLocation("target:textures/entities/bocekarrow.png");
|
||||
private final ModelBocekArrow model;
|
||||
|
||||
|
@ -23,7 +23,7 @@ public class BocekarrowRenderer extends EntityRenderer<BocekarrowEntity> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void render(BocekarrowEntity entityIn, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource bufferIn, int packedLightIn) {
|
||||
public void render(BocekArrowEntity entityIn, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource bufferIn, int packedLightIn) {
|
||||
VertexConsumer vb = bufferIn.getBuffer(RenderType.entityCutout(this.getTextureLocation(entityIn)));
|
||||
poseStack.pushPose();
|
||||
poseStack.mulPose(Axis.YP.rotationDegrees(Mth.lerp(partialTicks, entityIn.yRotO, entityIn.getYRot()) - 90));
|
||||
|
@ -34,7 +34,7 @@ public class BocekarrowRenderer extends EntityRenderer<BocekarrowEntity> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getTextureLocation(BocekarrowEntity entity) {
|
||||
public ResourceLocation getTextureLocation(BocekArrowEntity entity) {
|
||||
return texture;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,15 +2,17 @@ package net.mcreator.target.entity;
|
|||
|
||||
import net.mcreator.target.headshot.BoundingBoxManager;
|
||||
import net.mcreator.target.headshot.IHeadshotBox;
|
||||
import net.mcreator.target.init.TargetModDamageTypes;
|
||||
import net.mcreator.target.init.TargetModEntities;
|
||||
import net.mcreator.target.network.TargetModVariables;
|
||||
import net.minecraft.commands.CommandSource;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
|
@ -28,27 +30,26 @@ import net.minecraftforge.api.distmarker.Dist;
|
|||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import net.minecraftforge.network.PlayMessages;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@OnlyIn(value = Dist.CLIENT, _interface = ItemSupplier.class)
|
||||
public class BocekarrowEntity extends AbstractArrow implements ItemSupplier {
|
||||
public class BocekArrowEntity extends AbstractArrow implements ItemSupplier {
|
||||
public static final ItemStack PROJECTILE_ITEM = new ItemStack(Items.ARROW);
|
||||
|
||||
public BocekarrowEntity(PlayMessages.SpawnEntity packet, Level world) {
|
||||
super(TargetModEntities.BOCEKARROW.get(), world);
|
||||
public BocekArrowEntity(PlayMessages.SpawnEntity packet, Level world) {
|
||||
super(TargetModEntities.BOCEK_ARROW.get(), world);
|
||||
}
|
||||
|
||||
public BocekarrowEntity(EntityType<? extends BocekarrowEntity> type, Level world) {
|
||||
public BocekArrowEntity(EntityType<? extends BocekArrowEntity> type, Level world) {
|
||||
super(type, world);
|
||||
}
|
||||
|
||||
public BocekarrowEntity(EntityType<? extends BocekarrowEntity> type, double x, double y, double z, Level world) {
|
||||
public BocekArrowEntity(EntityType<? extends BocekArrowEntity> type, double x, double y, double z, Level world) {
|
||||
super(type, x, y, z, world);
|
||||
}
|
||||
|
||||
public BocekarrowEntity(EntityType<? extends BocekarrowEntity> type, LivingEntity entity, Level world) {
|
||||
public BocekArrowEntity(EntityType<? extends BocekArrowEntity> type, LivingEntity entity, Level world) {
|
||||
super(type, entity, world);
|
||||
}
|
||||
|
||||
|
@ -92,16 +93,26 @@ public class BocekarrowEntity extends AbstractArrow implements ItemSupplier {
|
|||
living.getName().getString(), living.getDisplayName(), living.level().getServer(), living), "playsound target:indication voice @a ~ ~ ~ 1 1");
|
||||
}
|
||||
}
|
||||
|
||||
float f = (float) this.getDeltaMovement().length();
|
||||
int i = Mth.ceil(Mth.clamp((double) f * this.getBaseDamage(), 0.0D, Integer.MAX_VALUE));
|
||||
|
||||
if (this.isCritArrow()) {
|
||||
long j = this.random.nextInt(i / 2 + 2);
|
||||
i = (int) Math.min(j + (long) i, 2147483647L);
|
||||
}
|
||||
|
||||
boolean headshot = false;
|
||||
|
||||
if (entity instanceof LivingEntity livingEntity) {
|
||||
livingEntity.invulnerableTime = 0;
|
||||
}
|
||||
AABB boundingBox = entity.getBoundingBox();
|
||||
Vec3 startVec = this.position();
|
||||
Vec3 endVec = startVec.add(this.getDeltaMovement());
|
||||
Vec3 hitPos = boundingBox.clip(startVec, endVec).orElse(null);
|
||||
/* Check for headshot */
|
||||
boolean headshot = false;
|
||||
if (entity instanceof LivingEntity) {
|
||||
|
||||
AABB boundingBox = entity.getBoundingBox();
|
||||
Vec3 startVec = this.position();
|
||||
Vec3 endVec = startVec.add(this.getDeltaMovement());
|
||||
Vec3 hitPos = boundingBox.clip(startVec, endVec).orElse(null);
|
||||
|
||||
/* Check for headshot */
|
||||
IHeadshotBox<LivingEntity> headshotBox = (IHeadshotBox<LivingEntity>) BoundingBoxManager.getHeadshotBoxes(entity.getType());
|
||||
if (headshotBox != null) {
|
||||
AABB box = headshotBox.getHeadshotBox((LivingEntity) entity);
|
||||
|
@ -117,7 +128,6 @@ public class BocekarrowEntity extends AbstractArrow implements ItemSupplier {
|
|||
}
|
||||
if (headshot) {
|
||||
if (this.getOwner() instanceof LivingEntity living) {
|
||||
setBaseDamage(getBaseDamage() * 2);
|
||||
living.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.headIndicator = 25;
|
||||
capability.syncPlayerVariables(living);
|
||||
|
@ -131,46 +141,68 @@ public class BocekarrowEntity extends AbstractArrow implements ItemSupplier {
|
|||
}
|
||||
}
|
||||
}
|
||||
super.onHitEntity(result);
|
||||
|
||||
boolean hurt;
|
||||
if (headshot) {
|
||||
hurt = entity.hurt(TargetModDamageTypes.causeArrowInBrainHeadshotDamage(this.level().registryAccess(), this.getOwner()), (float) i * 2);
|
||||
} else {
|
||||
hurt = entity.hurt(TargetModDamageTypes.causeArrowInBrainDamage(this.level().registryAccess(), this.getOwner()), (float) i);
|
||||
}
|
||||
|
||||
if (!hurt) {
|
||||
int k = entity.getRemainingFireTicks();
|
||||
entity.setRemainingFireTicks(k);
|
||||
this.setDeltaMovement(this.getDeltaMovement().scale(-0.1D));
|
||||
this.setYRot(this.getYRot() + 180.0F);
|
||||
this.yRotO += 180.0F;
|
||||
if (!this.level().isClientSide && this.getDeltaMovement().lengthSqr() < 1.0E-7D) {
|
||||
if (this.pickup == AbstractArrow.Pickup.ALLOWED) {
|
||||
this.spawnAtLocation(this.getPickupItem(), 0.1F);
|
||||
}
|
||||
|
||||
this.discard();
|
||||
}
|
||||
}
|
||||
|
||||
this.discard();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (this.tickCount > 200) {
|
||||
if (this.tickCount > 100) {
|
||||
this.discard();
|
||||
}
|
||||
}
|
||||
|
||||
public static BocekarrowEntity shoot(Level world, LivingEntity entity, RandomSource source) {
|
||||
public static BocekArrowEntity shoot(Level world, LivingEntity entity, RandomSource source) {
|
||||
return shoot(world, entity, source, 1f, 5, 0);
|
||||
}
|
||||
|
||||
public static BocekarrowEntity shoot(Level world, LivingEntity entity, RandomSource random, float power, double damage, int knockback) {
|
||||
BocekarrowEntity entityarrow = new BocekarrowEntity(TargetModEntities.BOCEKARROW.get(), entity, world);
|
||||
entityarrow.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y, entity.getViewVector(1).z, power * 2, 0);
|
||||
entityarrow.setSilent(true);
|
||||
entityarrow.setCritArrow(false);
|
||||
entityarrow.setBaseDamage(damage);
|
||||
entityarrow.setKnockback(knockback);
|
||||
world.addFreshEntity(entityarrow);
|
||||
world.playSound(null, entity.getX(), entity.getY(), entity.getZ(), ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.arrow.shoot")), SoundSource.PLAYERS, 1, 1f / (random.nextFloat() * 0.5f + 1) + (power / 2));
|
||||
return entityarrow;
|
||||
public static BocekArrowEntity shoot(Level world, LivingEntity entity, RandomSource random, float power, double damage, int knockback) {
|
||||
BocekArrowEntity bocekArrowEntity = new BocekArrowEntity(TargetModEntities.BOCEK_ARROW.get(), entity, world);
|
||||
bocekArrowEntity.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y, entity.getViewVector(1).z, power * 2, 0);
|
||||
bocekArrowEntity.setSilent(true);
|
||||
bocekArrowEntity.setCritArrow(false);
|
||||
bocekArrowEntity.setBaseDamage(damage);
|
||||
bocekArrowEntity.setKnockback(knockback);
|
||||
world.addFreshEntity(bocekArrowEntity);
|
||||
world.playSound(null, entity.getX(), entity.getY(), entity.getZ(), SoundEvents.ARROW_SHOOT, SoundSource.PLAYERS, 1, 1f / (random.nextFloat() * 0.5f + 1) + (power / 2));
|
||||
return bocekArrowEntity;
|
||||
}
|
||||
|
||||
public static BocekarrowEntity shoot(LivingEntity entity, LivingEntity target) {
|
||||
BocekarrowEntity entityarrow = new BocekarrowEntity(TargetModEntities.BOCEKARROW.get(), entity, entity.level());
|
||||
public static BocekArrowEntity shoot(LivingEntity entity, LivingEntity target) {
|
||||
BocekArrowEntity bocekArrowEntity = new BocekArrowEntity(TargetModEntities.BOCEK_ARROW.get(), entity, entity.level());
|
||||
double dx = target.getX() - entity.getX();
|
||||
double dy = target.getY() + target.getEyeHeight() - 1.1;
|
||||
double dz = target.getZ() - entity.getZ();
|
||||
entityarrow.shoot(dx, dy - entityarrow.getY() + Math.hypot(dx, dz) * 0.2F, dz, 1f * 2, 12.0F);
|
||||
entityarrow.setSilent(true);
|
||||
entityarrow.setBaseDamage(5);
|
||||
entityarrow.setKnockback(5);
|
||||
entityarrow.setCritArrow(false);
|
||||
entity.level().addFreshEntity(entityarrow);
|
||||
entity.level().playSound(null, entity.getX(), entity.getY(), entity.getZ(), ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.arrow.shoot")), SoundSource.PLAYERS, 1, 1f / (RandomSource.create().nextFloat() * 0.5f + 1));
|
||||
return entityarrow;
|
||||
bocekArrowEntity.shoot(dx, dy - bocekArrowEntity.getY() + Math.hypot(dx, dz) * 0.2F, dz, 1f * 2, 12.0F);
|
||||
bocekArrowEntity.setSilent(true);
|
||||
bocekArrowEntity.setBaseDamage(5);
|
||||
bocekArrowEntity.setKnockback(5);
|
||||
bocekArrowEntity.setCritArrow(false);
|
||||
entity.level().addFreshEntity(bocekArrowEntity);
|
||||
entity.level().playSound(null, entity.getX(), entity.getY(), entity.getZ(), SoundEvents.ARROW_SHOOT, SoundSource.PLAYERS, 1, 1f / (RandomSource.create().nextFloat() * 0.5f + 1));
|
||||
return bocekArrowEntity;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package net.mcreator.target.event;
|
||||
|
||||
import net.mcreator.target.TargetMod;
|
||||
import net.mcreator.target.entity.BocekarrowEntity;
|
||||
import net.mcreator.target.entity.Target1Entity;
|
||||
import net.mcreator.target.init.TargetModDamageTypes;
|
||||
import net.mcreator.target.init.TargetModItems;
|
||||
|
@ -49,7 +48,6 @@ public class LivingEntityEventHandler {
|
|||
public static void onEntityAttacked(LivingAttackEvent event) {
|
||||
if (event == null || event.getEntity() == null) return;
|
||||
arrowDamageImmuneForMine(event, event.getSource(), event.getSource().getEntity());
|
||||
arrowDamage(event, event.getEntity().level(), event.getSource(), event.getEntity(), event.getSource().getDirectEntity(), event.getSource().getEntity(), event.getAmount());
|
||||
claymoreDamage(event, event.getEntity().level(), event.getSource(), event.getEntity(), event.getSource().getEntity(), event.getAmount());
|
||||
}
|
||||
|
||||
|
@ -114,15 +112,6 @@ public class LivingEntityEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO 把伤害逻辑移植到箭类中
|
||||
private static void arrowDamage(LivingAttackEvent event, LevelAccessor world, DamageSource damagesource, Entity entity, Entity immediatesourceentity, Entity sourceentity, double amount) {
|
||||
if (damagesource == null || entity == null || immediatesourceentity == null || sourceentity == null) return;
|
||||
if (damagesource.is(DamageTypes.ARROW) && immediatesourceentity instanceof BocekarrowEntity) {
|
||||
event.setCanceled(true);
|
||||
entity.hurt(TargetModDamageTypes.causeArrowInBrainDamage(world.registryAccess(), sourceentity), (float) amount);
|
||||
}
|
||||
}
|
||||
|
||||
private static void killIndication(Entity sourceEntity) {
|
||||
if (sourceEntity == null) return;
|
||||
if (!sourceEntity.level().isClientSide() && sourceEntity.getServer() != null) {
|
||||
|
|
|
@ -26,7 +26,6 @@ public class TargetModEntities {
|
|||
EntityType.Builder.<MortarEntity>of(MortarEntity::new, MobCategory.CREATURE).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(3).setCustomClientFactory(MortarEntity::new).fireImmune().sized(0.8f, 1.4f));
|
||||
public static final RegistryObject<EntityType<SenpaiEntity>> SENPAI = register("senpai",
|
||||
EntityType.Builder.<SenpaiEntity>of(SenpaiEntity::new, MobCategory.MONSTER).setShouldReceiveVelocityUpdates(true).setTrackingRange(1024).setUpdateInterval(3).setCustomClientFactory(SenpaiEntity::new)
|
||||
|
||||
.sized(0.6f, 2f));
|
||||
public static final RegistryObject<EntityType<ClaymoreEntity>> CLAYMORE = register("claymore",
|
||||
EntityType.Builder.<ClaymoreEntity>of(ClaymoreEntity::new, MobCategory.CREATURE).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(3).setCustomClientFactory(ClaymoreEntity::new).fireImmune().sized(0.5f, 0.5f));
|
||||
|
@ -41,8 +40,8 @@ public class TargetModEntities {
|
|||
EntityType.Builder.<RpgRocketEntity>of(RpgRocketEntity::new, MobCategory.MISC).setCustomClientFactory(RpgRocketEntity::new).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).sized(0.5f, 0.5f));
|
||||
public static final RegistryObject<EntityType<MortarShellEntity>> MORTAR_SHELL = register("projectile_mortar_shell",
|
||||
EntityType.Builder.<MortarShellEntity>of(MortarShellEntity::new, MobCategory.MISC).setCustomClientFactory(MortarShellEntity::new).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).sized(0.5f, 0.5f));
|
||||
public static final RegistryObject<EntityType<BocekarrowEntity>> BOCEKARROW = register("projectile_bocekarrow",
|
||||
EntityType.Builder.<BocekarrowEntity>of(BocekarrowEntity::new, MobCategory.MISC).setCustomClientFactory(BocekarrowEntity::new).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).sized(0.5f, 0.5f));
|
||||
public static final RegistryObject<EntityType<BocekArrowEntity>> BOCEK_ARROW = register("projectile_bocekarrow",
|
||||
EntityType.Builder.<BocekArrowEntity>of(BocekArrowEntity::new, MobCategory.MISC).setCustomClientFactory(BocekArrowEntity::new).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).sized(0.5f, 0.5f));
|
||||
|
||||
|
||||
private static <T extends Entity> RegistryObject<EntityType<T>> register(String registryname, EntityType.Builder<T> entityTypeBuilder) {
|
||||
|
|
|
@ -19,6 +19,6 @@ public class TargetModEntityRenderers {
|
|||
event.registerEntityRenderer(TargetModEntities.TARGET.get(), TargetRenderer::new);
|
||||
event.registerEntityRenderer(TargetModEntities.RPG_ROCKET.get(), RpgRocketRenderer::new);
|
||||
event.registerEntityRenderer(TargetModEntities.MORTAR_SHELL.get(), MortarShellRenderer::new);
|
||||
event.registerEntityRenderer(TargetModEntities.BOCEKARROW.get(), BocekarrowRenderer::new);
|
||||
event.registerEntityRenderer(TargetModEntities.BOCEK_ARROW.get(), BocekarrowRenderer::new);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package net.mcreator.target.network.message;
|
||||
|
||||
import net.mcreator.target.entity.BocekarrowEntity;
|
||||
import net.mcreator.target.entity.BocekArrowEntity;
|
||||
import net.mcreator.target.init.TargetModEntities;
|
||||
import net.mcreator.target.init.TargetModItems;
|
||||
import net.mcreator.target.network.TargetModVariables;
|
||||
|
@ -89,7 +89,7 @@ public class FireMessage {
|
|||
if (!level.isClientSide()) {
|
||||
float damage = (float) (0.02 * stack.getOrCreateTag().getDouble("damage") * (1 + 0.05 * stack.getOrCreateTag().getInt("level")));
|
||||
|
||||
BocekarrowEntity arrow = new BocekarrowEntity(TargetModEntities.BOCEKARROW.get(), level);
|
||||
BocekArrowEntity arrow = new BocekArrowEntity(TargetModEntities.BOCEK_ARROW.get(), level);
|
||||
arrow.setOwner(player);
|
||||
arrow.setBaseDamage(damage);
|
||||
arrow.setKnockback(0);
|
||||
|
|
Loading…
Add table
Reference in a new issue