创建破片伤害
This commit is contained in:
parent
e3f42bff6c
commit
ac1c4f5f4b
9 changed files with 177 additions and 2 deletions
|
@ -0,0 +1,45 @@
|
|||
package net.mcreator.target.client.renderer.entity;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Axis;
|
||||
import net.mcreator.target.client.model.entity.ModelBullet;
|
||||
import net.mcreator.target.entity.FragEntity;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderer;
|
||||
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
|
||||
public class FragRenderer extends EntityRenderer<FragEntity> {
|
||||
private static final ResourceLocation texture = new ResourceLocation("target:textures/entity/bullet_tex.png");
|
||||
private final ModelBullet<FragEntity> model;
|
||||
|
||||
public FragRenderer(EntityRendererProvider.Context context) {
|
||||
super(context);
|
||||
model = new ModelBullet<>(context.bakeLayer(ModelBullet.LAYER_LOCATION));
|
||||
}
|
||||
|
||||
protected int getBlockLightLevel(FragEntity pEntity, BlockPos pPos) {
|
||||
return 15;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(FragEntity entityIn, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource bufferIn, int packedLightIn) {
|
||||
VertexConsumer vb = bufferIn.getBuffer(RenderType.eyes(this.getTextureLocation(entityIn)));
|
||||
poseStack.pushPose();
|
||||
poseStack.mulPose(Axis.YP.rotationDegrees(Mth.lerp(partialTicks, entityIn.yRotO, entityIn.getYRot()) - 90));
|
||||
poseStack.mulPose(Axis.ZP.rotationDegrees(90 + Mth.lerp(partialTicks, entityIn.xRotO, entityIn.getXRot())));
|
||||
model.renderToBuffer(poseStack, vb, packedLightIn, OverlayTexture.NO_OVERLAY, 1, 1, 1, 0.0625f);
|
||||
poseStack.popPose();
|
||||
super.render(entityIn, entityYaw, partialTicks, poseStack, bufferIn, packedLightIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getTextureLocation(FragEntity entity) {
|
||||
return texture;
|
||||
}
|
||||
}
|
|
@ -134,7 +134,7 @@ public class ClaymoreEntity extends TamableAnimal implements GeoEntity, Animated
|
|||
|
||||
private void destoryExplode() {
|
||||
CustomExplosion explosion = new CustomExplosion(this.level(), this,
|
||||
TargetModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()), 45f,
|
||||
TargetModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()), 15f,
|
||||
this.getX(), this.getY(), this.getZ(), 7.5f, Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
|
||||
explosion.explode();
|
||||
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion);
|
||||
|
@ -249,11 +249,29 @@ public class ClaymoreEntity extends TamableAnimal implements GeoEntity, Animated
|
|||
|
||||
private void triggerExplode(Entity target) {
|
||||
CustomExplosion explosion = new CustomExplosion(this.level(), this,
|
||||
TargetModDamageTypes.causeMineDamage(this.level().registryAccess(), this.getOwner()), 150f,
|
||||
TargetModDamageTypes.causeMineDamage(this.level().registryAccess(), this.getOwner()), 40f,
|
||||
target.getX(), target.getY(), target.getZ(), 4f, Explosion.BlockInteraction.KEEP).setDamageMultiplier(1);
|
||||
explosion.explode();
|
||||
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion);
|
||||
explosion.finalizeExplosion(false);
|
||||
for (int index0 = 0; index0 < 250; index0++) {
|
||||
fragShoot();
|
||||
}
|
||||
}
|
||||
|
||||
public void fragShoot() {
|
||||
|
||||
if (!this.level().isClientSide()) {
|
||||
|
||||
Vec3 vec3 = (this.position());
|
||||
|
||||
FragEntity frag = new FragEntity(this.getOwner(), level());
|
||||
|
||||
frag.setPos(this.getX(), this.getEyeY() + 0.1, this.getZ());
|
||||
frag.shoot(this.getLookAngle().x, this.getLookAngle().y + 0.5f, this.getLookAngle().z, 7,
|
||||
60);
|
||||
this.level().addFreshEntity(frag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
91
src/main/java/net/mcreator/target/entity/FragEntity.java
Normal file
91
src/main/java/net/mcreator/target/entity/FragEntity.java
Normal file
|
@ -0,0 +1,91 @@
|
|||
package net.mcreator.target.entity;
|
||||
|
||||
import net.mcreator.target.TargetMod;
|
||||
import net.mcreator.target.init.TargetModDamageTypes;
|
||||
import net.mcreator.target.init.TargetModEntities;
|
||||
import net.mcreator.target.init.TargetModItems;
|
||||
import net.mcreator.target.init.TargetModSounds;
|
||||
import net.mcreator.target.network.message.ClientIndicatorMessage;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.minecraftforge.network.PlayMessages;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class FragEntity extends ThrowableItemProjectile {
|
||||
|
||||
public FragEntity(EntityType<? extends FragEntity> type, Level world) {
|
||||
super(type, world);
|
||||
}
|
||||
|
||||
public FragEntity(EntityType<? extends FragEntity> type, LivingEntity entity, Level world) {
|
||||
super(type, entity, world);
|
||||
}
|
||||
|
||||
public FragEntity(LivingEntity entity, Level level) {
|
||||
super(TargetModEntities.FRAG.get(), entity, level);
|
||||
}
|
||||
|
||||
public FragEntity(PlayMessages.SpawnEntity spawnEntity, Level level) {
|
||||
this(TargetModEntities.FRAG.get(), level);
|
||||
}
|
||||
@Override
|
||||
public Packet<ClientGamePacketListener> getAddEntityPacket() {
|
||||
return NetworkHooks.getEntitySpawningPacket(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Item getDefaultItem() {
|
||||
return TargetModItems.GRENADE_40MM.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHitEntity(EntityHitResult result) {
|
||||
Entity entity = result.getEntity();
|
||||
|
||||
if (entity instanceof LivingEntity) {
|
||||
entity.invulnerableTime = 0;
|
||||
}
|
||||
|
||||
if (this.getOwner() != null && this.getOwner() instanceof LivingEntity living) {
|
||||
if (!living.level().isClientSide() && living instanceof ServerPlayer player) {
|
||||
living.level().playSound(null, living.blockPosition(), TargetModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1);
|
||||
TargetMod.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(0, 5));
|
||||
|
||||
entity.hurt(TargetModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()), 4 - (float) Mth.clamp(0.04 * this.position().distanceTo(this.getOwner().position()) * (entity instanceof LivingEntity living_ ? living_.getMaxHealth() : 1),0,3.5));
|
||||
}
|
||||
}
|
||||
|
||||
this.discard();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHitBlock(BlockHitResult blockHitResult) {
|
||||
super.onHitBlock(blockHitResult);
|
||||
|
||||
|
||||
this.discard();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (this.tickCount > 4 || this.isInWater()) {
|
||||
this.discard();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -178,5 +178,21 @@ public class GunGrenadeEntity extends ThrowableItemProjectile {
|
|||
explosion.finalizeExplosion(false);
|
||||
|
||||
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
|
||||
for (int index0 = 0; index0 < 200; index0++) {
|
||||
fragShoot();
|
||||
}
|
||||
}
|
||||
|
||||
public void fragShoot() {
|
||||
|
||||
if (!this.level().isClientSide()) {
|
||||
|
||||
FragEntity frag = new FragEntity((LivingEntity) this.getOwner(), level());
|
||||
|
||||
frag.setPos(this.getX(), this.getEyeY() + 0.1, this.getZ());
|
||||
frag.shoot(this.getLookAngle().x, this.getLookAngle().y, this.getLookAngle().z, 5,
|
||||
360);
|
||||
this.level().addFreshEntity(frag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@ public class TargetModEntities {
|
|||
.setUpdateInterval(1).sized(0.5f, 0.5f));
|
||||
public static final RegistryObject<EntityType<GunGrenadeEntity>> GUN_GRENADE = register("projectile_gun_grenade",
|
||||
EntityType.Builder.<GunGrenadeEntity>of(GunGrenadeEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).setCustomClientFactory(GunGrenadeEntity::new).sized(0.5f, 0.5f));
|
||||
public static final RegistryObject<EntityType<FragEntity>> FRAG = register("projectile_frag",
|
||||
EntityType.Builder.<FragEntity>of(FragEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).setCustomClientFactory(FragEntity::new).sized(0.5f, 0.5f));
|
||||
public static final RegistryObject<EntityType<TargetEntity>> TARGET = register("target",
|
||||
EntityType.Builder.<TargetEntity>of(TargetEntity::new, MobCategory.CREATURE).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(3).setCustomClientFactory(TargetEntity::new).fireImmune().sized(0.875f, 2f));
|
||||
public static final RegistryObject<EntityType<RpgRocketEntity>> RPG_ROCKET = register("projectile_rpg_rocket",
|
||||
|
|
|
@ -21,5 +21,6 @@ public class TargetModEntityRenderers {
|
|||
event.registerEntityRenderer(TargetModEntities.MORTAR_SHELL.get(), MortarShellRenderer::new);
|
||||
event.registerEntityRenderer(TargetModEntities.BOCEK_ARROW.get(), BocekArrowRenderer::new);
|
||||
event.registerEntityRenderer(TargetModEntities.PROJECTILE.get(), ProjectileRenderer::new);
|
||||
event.registerEntityRenderer(TargetModEntities.FRAG.get(), FragRenderer::new);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,6 +178,7 @@
|
|||
"gui.target.gun_recycle_gui.label_gun_recycle": "Gun Dismantle",
|
||||
|
||||
"entity.target.projectile": "Bullet",
|
||||
"entity.target.projectile_frag": "Frag",
|
||||
"entity.target.mortar": "Mortar",
|
||||
"entity.target.target": "Target",
|
||||
"entity.target.target_1": "Target",
|
||||
|
|
|
@ -178,6 +178,7 @@
|
|||
"gui.target.gun_recycle_gui.label_gun_recycle": "枪械拆解",
|
||||
|
||||
"entity.target.projectile": "子弹",
|
||||
"entity.target.projectile_frag": "破片",
|
||||
"entity.target.mortar": "迫击炮",
|
||||
"entity.target.target": "标靶",
|
||||
"entity.target.target_1": "标靶",
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 289 B After Width: | Height: | Size: 289 B |
Loading…
Add table
Reference in a new issue