添加手雷

This commit is contained in:
Atsuihsio 2024-07-30 02:29:46 +08:00
parent 160815c1e6
commit 1907458a11
8 changed files with 267 additions and 11 deletions

View file

@ -25,29 +25,29 @@ public class ModelHandGrenade<T extends Entity> extends EntityModel<T> {
MeshDefinition meshdefinition = new MeshDefinition();
PartDefinition partdefinition = meshdefinition.getRoot();
PartDefinition group = partdefinition.addOrReplaceChild("group", CubeListBuilder.create().texOffs(6, 8).addBox(-0.4375F, -1.5976F, -0.5375F, 0.875F, 0.3F, 1.075F, new CubeDeformation(0.0F))
.texOffs(11, 13).addBox(-0.45F, -2.45F, -0.6F, 0.9F, 0.85F, 1.35F, new CubeDeformation(0.0F))
.texOffs(13, 14).addBox(-0.45F, -2.45F, 0.75F, 0.9F, 0.85F, 0.3F, new CubeDeformation(0.0F))
.texOffs(12, 15).addBox(-0.45F, -1.95F, 1.05F, 0.9F, 0.35F, 0.3F, new CubeDeformation(0.0F))
.texOffs(11, 14).addBox(-0.45F, -2.25F, 1.05F, 0.9F, 0.3F, 0.2F, new CubeDeformation(0.0F))
.texOffs(9, 13).addBox(-0.5F, -2.65F, -1.1F, 1.0F, 0.2F, 2.2F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 16.0F, 0.0F));
PartDefinition group = partdefinition.addOrReplaceChild("group", CubeListBuilder.create().texOffs(6, 8).addBox(-0.4375F, 0.424F, -1.0258F, 0.875F, 0.3F, 1.075F, new CubeDeformation(0.0F))
.texOffs(11, 13).addBox(-0.45F, -0.4283F, -1.0883F, 0.9F, 0.85F, 1.35F, new CubeDeformation(0.0F))
.texOffs(13, 14).addBox(-0.45F, -0.4283F, 0.2617F, 0.9F, 0.85F, 0.3F, new CubeDeformation(0.0F))
.texOffs(12, 15).addBox(-0.45F, 0.0717F, 0.5617F, 0.9F, 0.35F, 0.3F, new CubeDeformation(0.0F))
.texOffs(11, 14).addBox(-0.45F, -0.2283F, 0.5617F, 0.9F, 0.3F, 0.2F, new CubeDeformation(0.0F))
.texOffs(9, 13).addBox(-0.5F, -0.6283F, -1.5883F, 1.0F, 0.2F, 2.2F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, -0.0217F, 0.4883F));
PartDefinition cube_r1 = group.addOrReplaceChild("cube_r1", CubeListBuilder.create().texOffs(11, 14).addBox(-1.5F, -0.2F, 1.5F, 1.0F, 1.0F, 0.2F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(1.0F, -1.8147F, -0.3941F, 0.3927F, 0.0F, 0.0F));
PartDefinition cube_r1 = group.addOrReplaceChild("cube_r1", CubeListBuilder.create().texOffs(11, 14).addBox(-1.5F, -0.2F, 1.5F, 1.0F, 1.0F, 0.2F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(1.0F, 0.207F, -0.8823F, 0.3927F, 0.0F, 0.0F));
PartDefinition cube_r2 = group.addOrReplaceChild("cube_r2", CubeListBuilder.create().texOffs(12, 14).addBox(-1.45F, -1.3391F, 0.4F, 0.9F, 0.9391F, 0.3508F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(1.0F, -1.0774F, -0.8165F, 0.3927F, 0.0F, 0.0F));
PartDefinition cube_r2 = group.addOrReplaceChild("cube_r2", CubeListBuilder.create().texOffs(12, 14).addBox(-1.45F, -1.3391F, 0.4F, 0.9F, 0.9391F, 0.3508F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(1.0F, 0.9443F, -1.3048F, 0.3927F, 0.0F, 0.0F));
PartDefinition bone2 = group.addOrReplaceChild("bone2", CubeListBuilder.create(), PartPose.offset(0.0F, 0.0078F, -25.7281F));
PartDefinition bone2 = group.addOrReplaceChild("bone2", CubeListBuilder.create(), PartPose.offset(0.0F, 2.0295F, -26.2164F));
PartDefinition bone178_r1 = bone2.addOrReplaceChild("bone178_r1", CubeListBuilder.create().texOffs(0, 8).addBox(-1.2976F, -0.5375F, -0.5375F, 2.5953F, 1.075F, 1.075F, new CubeDeformation(0.0F))
.texOffs(10, 0).addBox(-0.5375F, -1.2976F, -0.5375F, 1.075F, 2.5953F, 1.075F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, -0.0078F, 25.7281F, 0.0F, 0.0F, 0.7854F));
PartDefinition bone3 = group.addOrReplaceChild("bone3", CubeListBuilder.create().texOffs(0, 10).addBox(-0.5375F, -1.3054F, 25.1906F, 1.075F, 2.5953F, 1.075F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 0.0078F, -25.7281F));
PartDefinition bone3 = group.addOrReplaceChild("bone3", CubeListBuilder.create().texOffs(0, 10).addBox(-0.5375F, -1.3054F, 25.1906F, 1.075F, 2.5953F, 1.075F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 2.0295F, -26.2164F));
PartDefinition bone179_r1 = bone3.addOrReplaceChild("bone179_r1", CubeListBuilder.create().texOffs(5, 1).addBox(-0.5375F, -0.5375F, -1.2976F, 1.075F, 1.075F, 2.5953F, new CubeDeformation(0.0F))
.texOffs(7, 9).addBox(-0.5375F, -1.2976F, -0.5375F, 1.075F, 2.5953F, 1.075F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, -0.0078F, 25.7281F, 0.7854F, 0.0F, 0.0F));
PartDefinition bone175 = group.addOrReplaceChild("bone175", CubeListBuilder.create().texOffs(7, 7).addBox(-1.2976F, -0.5453F, 25.1906F, 2.5953F, 1.075F, 1.075F, new CubeDeformation(0.0F))
.texOffs(0, 4).addBox(-0.5375F, -0.5453F, 24.4305F, 1.075F, 1.075F, 2.5953F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 0.0078F, -25.7281F));
.texOffs(0, 4).addBox(-0.5375F, -0.5453F, 24.4305F, 1.075F, 1.075F, 2.5953F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 2.0295F, -26.2164F));
PartDefinition bone180_r1 = bone175.addOrReplaceChild("bone180_r1", CubeListBuilder.create().texOffs(0, 0).addBox(-0.5375F, -0.5375F, -1.2976F, 1.075F, 1.075F, 2.5953F, new CubeDeformation(0.0F))
.texOffs(5, 5).addBox(-1.2976F, -0.5375F, -0.5375F, 2.5953F, 1.075F, 1.075F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, -0.0078F, 25.7281F, 0.0F, 0.7854F, 0.0F));

View file

@ -0,0 +1,40 @@
package net.mcreator.superbwarfare.client.renderer.entity;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis;
import net.mcreator.superbwarfare.client.model.entity.ModelHandGrenade;
import net.mcreator.superbwarfare.entity.HandGrenadeEntity;
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.resources.ResourceLocation;
import net.minecraft.util.Mth;
public class HandGrenadeEntityRenderer extends EntityRenderer<HandGrenadeEntity> {
private static final ResourceLocation texture = new ResourceLocation("superbwarfare:textures/entity/hand_grenade.png");
private final ModelHandGrenade<HandGrenadeEntity> model;
public HandGrenadeEntityRenderer(EntityRendererProvider.Context context) {
super(context);
model = new ModelHandGrenade<>(context.bakeLayer(ModelHandGrenade.LAYER_LOCATION));
}
@Override
public void render(HandGrenadeEntity 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));
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(HandGrenadeEntity entity) {
return texture;
}
}

View file

@ -0,0 +1,149 @@
package net.mcreator.superbwarfare.entity;
import net.mcreator.superbwarfare.init.ModDamageTypes;
import net.mcreator.superbwarfare.init.ModEntities;
import net.mcreator.superbwarfare.init.ModItems;
import net.mcreator.superbwarfare.tools.CustomExplosion;
import net.mcreator.superbwarfare.tools.ParticleTool;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
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.Explosion;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraftforge.network.NetworkHooks;
import net.minecraftforge.network.PlayMessages;
public class HandGrenadeEntity extends ThrowableItemProjectile {
private int fuse = 100;
public HandGrenadeEntity(EntityType<? extends HandGrenadeEntity> type, Level world) {
super(type, world);
}
public HandGrenadeEntity(EntityType<? extends HandGrenadeEntity> type, LivingEntity entity, Level world) {
super(type, entity, world);
}
public HandGrenadeEntity(LivingEntity entity, Level level, int fuse) {
super(ModEntities.HAND_GRENADE_ENTITY.get(), entity, level);
this.fuse = fuse;
}
public HandGrenadeEntity(PlayMessages.SpawnEntity spawnEntity, Level level) {
this(ModEntities.HAND_GRENADE_ENTITY.get(), level);
}
@Override
public Packet<ClientGamePacketListener> getAddEntityPacket() {
return NetworkHooks.getEntitySpawningPacket(this);
}
@Override
protected Item getDefaultItem() {
return ModItems.HAND_GRENADE.get();
}
@Override
protected void onHit(HitResult result)
{
switch(result.getType())
{
case BLOCK:
BlockHitResult blockResult = (BlockHitResult) result;
BlockPos resultPos = blockResult.getBlockPos();
BlockState state = this.level().getBlockState(resultPos);
SoundEvent event = state.getBlock().getSoundType(state, this.level(), resultPos, this).getStepSound();
double speed = this.getDeltaMovement().length();
if(speed > 0.1)
{
this.level().playSound(null, result.getLocation().x, result.getLocation().y, result.getLocation().z, event, SoundSource.AMBIENT, 1.0F, 1.0F);
}
this.bounce(blockResult.getDirection());
break;
case ENTITY:
EntityHitResult entityResult = (EntityHitResult) result;
Entity entity = entityResult.getEntity();
double speed_e = this.getDeltaMovement().length();
if(speed_e > 0.1)
{
entity.hurt(entity.damageSources().thrown(this, this.getOwner()), 1.0F);
}
this.bounce(Direction.getNearest(this.getDeltaMovement().x(), this.getDeltaMovement().y(), this.getDeltaMovement().z()).getOpposite());
this.setDeltaMovement(this.getDeltaMovement().multiply(0.25, 1.0, 0.25));
break;
default:
break;
}
}
private void bounce(Direction direction)
{
switch(direction.getAxis())
{
case X:
this.setDeltaMovement(this.getDeltaMovement().multiply(-0.5, 0.75, 0.75));
break;
case Y:
this.setDeltaMovement(this.getDeltaMovement().multiply(0.75, -0.25, 0.75));
if(this.getDeltaMovement().y() < this.getGravity())
{
this.setDeltaMovement(this.getDeltaMovement().multiply(1, 0, 1));
}
break;
case Z:
this.setDeltaMovement(this.getDeltaMovement().multiply(0.75, 0.75, -0.5));
break;
}
}
@Override
public void tick() {
super.tick();
--this.fuse;
if (this.fuse <= 0) {
this.discard();
if (!this.level().isClientSide) {
causeExplode();
}
}
if (!this.level().isClientSide() && this.level() instanceof ServerLevel serverLevel) {
ParticleTool.sendParticle(serverLevel, ParticleTypes.SMOKE, this.xo, this.yo, this.zo,
1, 0, 0, 0, 0.01, true);
}
}
private void causeExplode() {
CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()), 90,
this.getX(), this.getY(), this.getZ(), 10f, Explosion.BlockInteraction.KEEP).setDamageMultiplier(2);
explosion.explode();
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnMediumExplosionParticles(this.level(), this.position());
this.discard();
}
@Override
protected float getGravity() {
return 0.07F;
}
}

View file

@ -53,6 +53,8 @@ public class ModEntities {
EntityType.Builder.<ProjectileEntity>of(ProjectileEntity::new, MobCategory.MISC).setCustomClientFactory(ProjectileEntity::new).setTrackingRange(512).sized(0.5f, 0.5f));
public static final RegistryObject<EntityType<CannonShellEntity>> CANNON_SHELL = register("projectile_cannon_shell",
EntityType.Builder.<CannonShellEntity>of(CannonShellEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).setCustomClientFactory(CannonShellEntity::new).sized(0.5f, 0.5f));
public static final RegistryObject<EntityType<HandGrenadeEntity>> HAND_GRENADE_ENTITY = register("projectile_hand_grenade_entity",
EntityType.Builder.<HandGrenadeEntity>of(HandGrenadeEntity::new, MobCategory.MISC).setShouldReceiveVelocityUpdates(true).setTrackingRange(64).setUpdateInterval(1).setCustomClientFactory(HandGrenadeEntity::new).sized(0.3f, 0.3f));
private static <T extends Entity> RegistryObject<EntityType<T>> register(String registryname, EntityType.Builder<T> entityTypeBuilder) {

View file

@ -26,5 +26,6 @@ public class ModEntityRenderers {
event.registerEntityRenderer(ModEntities.MK_42.get(), Mk42Renderer::new);
event.registerEntityRenderer(ModEntities.DRONE.get(), DroneRenderer::new);
event.registerEntityRenderer(ModEntities.DRONE_GRENADE.get(), DroneGrenadeRenderer::new);
event.registerEntityRenderer(ModEntities.HAND_GRENADE_ENTITY.get(), HandGrenadeEntityRenderer::new);
}
}

View file

@ -114,6 +114,7 @@ public class ModItems {
public static final RegistryObject<Item> SCHEELITE = ITEMS.register("scheelite", () -> new Item(new Item.Properties()));
public static final RegistryObject<Item> DOG_TAG = ITEMS.register("dog_tag", DogTag::new);
public static final RegistryObject<Item> SHIELD_CELL = ITEMS.register("shield_cell", () -> new Item(new Item.Properties().rarity(Rarity.RARE)));
public static final RegistryObject<Item> HAND_GRENADE = ITEMS.register("hand_grenade", HandGrenade::new);
public static final RegistryObject<Item> IRON_BARREL = ITEMS.register("iron_barrel", () -> new Item(new Item.Properties()));
public static final RegistryObject<Item> IRON_ACTION = ITEMS.register("iron_action", () -> new Item(new Item.Properties()));

View file

@ -17,5 +17,6 @@ public class ModModels {
event.registerLayerDefinition(ModelGrenade.LAYER_LOCATION, ModelGrenade::createBodyLayer);
event.registerLayerDefinition(ModelBocekArrow.LAYER_LOCATION, ModelBocekArrow::createBodyLayer);
event.registerLayerDefinition(ModelClaymore.LAYER_LOCATION, ModelClaymore::createBodyLayer);
event.registerLayerDefinition(ModelHandGrenade.LAYER_LOCATION, ModelHandGrenade::createBodyLayer);
}
}

View file

@ -0,0 +1,62 @@
package net.mcreator.superbwarfare.item;
import net.mcreator.superbwarfare.entity.HandGrenadeEntity;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
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.item.Rarity;
import net.minecraft.world.item.UseAnim;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
public class HandGrenade extends Item {
public HandGrenade() {
super(new Properties().rarity(Rarity.UNCOMMON));
}
@Override
public @NotNull InteractionResultHolder<ItemStack> use(Level worldIn, Player playerIn, InteractionHand handIn) {
ItemStack stack = playerIn.getItemInHand(handIn);
playerIn.startUsingItem(handIn);
return InteractionResultHolder.consume(stack);
}
@Override
public @NotNull UseAnim getUseAnimation(@NotNull ItemStack stack) {
return UseAnim.SPEAR;
}
@Override
public void releaseUsing(ItemStack stack, Level worldIn, LivingEntity entityLiving, int timeLeft) {
if (!worldIn.isClientSide) {
if (entityLiving instanceof Player player) {
int usingTime = this.getUseDuration(stack) - timeLeft;
float power = Math.min(usingTime / 10.0f, 1.5f);
HandGrenadeEntity handGrenade = new HandGrenadeEntity(player, worldIn, 100 - usingTime);
handGrenade.shootFromRotation(player, player.getXRot(), player.getYRot(), 0.0f, power, 0.0f);
worldIn.addFreshEntity(handGrenade);
if (!player.isCreative()) {
stack.shrink(1);
}
player.getCooldowns().addCooldown(stack.getItem(), 25);
}
}
}
@Override
public int getUseDuration(ItemStack stack) {
return 100;
}
}