generated from NeoForgeMDKs/MDK-1.21-ModDevGradle
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
357 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/net/kaupenjoe/tutorialmod/entity/client/TomahawkProjectileModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package net.kaupenjoe.tutorialmod.entity.client; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.mojang.blaze3d.vertex.VertexConsumer; | ||
import net.kaupenjoe.tutorialmod.TutorialMod; | ||
import net.kaupenjoe.tutorialmod.entity.custom.TomahawkProjectileEntity; | ||
import net.minecraft.client.model.EntityModel; | ||
import net.minecraft.client.model.geom.ModelLayerLocation; | ||
import net.minecraft.client.model.geom.ModelPart; | ||
import net.minecraft.client.model.geom.PartPose; | ||
import net.minecraft.client.model.geom.builders.*; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
public class TomahawkProjectileModel extends EntityModel<TomahawkProjectileEntity> { | ||
public static final ModelLayerLocation LAYER_LOCATION = | ||
new ModelLayerLocation(ResourceLocation.fromNamespaceAndPath(TutorialMod.MOD_ID, "tomahawk"), "main"); | ||
private final ModelPart tomahawk; | ||
|
||
public TomahawkProjectileModel(ModelPart root) { | ||
this.tomahawk = root.getChild("tomahawk"); | ||
} | ||
|
||
public static LayerDefinition createBodyLayer() { | ||
MeshDefinition meshdefinition = new MeshDefinition(); | ||
PartDefinition partdefinition = meshdefinition.getRoot(); | ||
|
||
PartDefinition tomahawk = partdefinition.addOrReplaceChild("tomahawk", CubeListBuilder.create(), PartPose.offset(0.0F, 16.5F, 0.0F)); | ||
|
||
PartDefinition cube_r1 = tomahawk.addOrReplaceChild("cube_r1", CubeListBuilder.create().texOffs(8, 7).addBox(1.5F, 2.5F, -0.5F, 1.0F, 1.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, -7.0F, -4.0F, 0.0F, -1.5708F, 0.0F)); | ||
|
||
PartDefinition cube_r2 = tomahawk.addOrReplaceChild("cube_r2", CubeListBuilder.create().texOffs(7, 9).addBox(0.5F, -1.5F, -0.5F, 2.0F, 5.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, -7.0F, -5.0F, 0.0F, -1.5708F, 0.0F)); | ||
|
||
PartDefinition cube_r3 = tomahawk.addOrReplaceChild("cube_r3", CubeListBuilder.create().texOffs(3, 10).addBox(-2.5F, -1.5F, -0.5F, 1.0F, 4.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, -7.0F, 5.0F, 0.0F, -1.5708F, 0.0F)); | ||
|
||
PartDefinition cube_r4 = tomahawk.addOrReplaceChild("cube_r4", CubeListBuilder.create().texOffs(1, 4).addBox(-2.5F, -1.5F, 0.0F, 5.0F, 3.0F, 0.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, -7.0F, 0.0F, 0.0F, -1.5708F, 0.0F)); | ||
|
||
PartDefinition cube_r5 = tomahawk.addOrReplaceChild("cube_r5", CubeListBuilder.create().texOffs(18, 1).addBox(-0.5F, -9.0F, -0.5F, 1.0F, 18.0F, 1.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, -1.5F, 0.0F, 0.0F, -0.7854F, 0.0F)); | ||
|
||
return LayerDefinition.create(meshdefinition, 32, 32); | ||
} | ||
|
||
@Override | ||
public void setupAnim(TomahawkProjectileEntity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { | ||
|
||
} | ||
|
||
@Override | ||
public void renderToBuffer(PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, int color) { | ||
tomahawk.render(poseStack, vertexConsumer, packedLight, packedOverlay, color); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/net/kaupenjoe/tutorialmod/entity/client/TomahawkProjectileRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package net.kaupenjoe.tutorialmod.entity.client; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.mojang.blaze3d.vertex.VertexConsumer; | ||
import com.mojang.math.Axis; | ||
import net.kaupenjoe.tutorialmod.TutorialMod; | ||
import net.kaupenjoe.tutorialmod.entity.custom.TomahawkProjectileEntity; | ||
import net.minecraft.client.renderer.MultiBufferSource; | ||
import net.minecraft.client.renderer.entity.EntityRenderer; | ||
import net.minecraft.client.renderer.entity.EntityRendererProvider; | ||
import net.minecraft.client.renderer.entity.ItemRenderer; | ||
import net.minecraft.client.renderer.texture.OverlayTexture; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.util.Mth; | ||
|
||
public class TomahawkProjectileRenderer extends EntityRenderer<TomahawkProjectileEntity> { | ||
private TomahawkProjectileModel model; | ||
|
||
public TomahawkProjectileRenderer(EntityRendererProvider.Context context) { | ||
super(context); | ||
this.model = new TomahawkProjectileModel(context.bakeLayer(TomahawkProjectileModel.LAYER_LOCATION)); | ||
} | ||
|
||
@Override | ||
public void render(TomahawkProjectileEntity pEntity, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight) { | ||
poseStack.pushPose(); | ||
|
||
if(!pEntity.isGrounded()) { | ||
poseStack.mulPose(Axis.YP.rotationDegrees(Mth.lerp(partialTicks, pEntity.yRotO, pEntity.getYRot()))); | ||
poseStack.mulPose(Axis.XP.rotationDegrees(pEntity.getRenderingRotation() * 5f)); | ||
poseStack.translate(0, -1.0f, 0); | ||
} else { | ||
poseStack.mulPose(Axis.YP.rotationDegrees(pEntity.groundedOffset.y)); | ||
poseStack.mulPose(Axis.XP.rotationDegrees(pEntity.groundedOffset.x)); | ||
poseStack.translate(0, -1.0f, 0); | ||
} | ||
|
||
VertexConsumer vertexconsumer = ItemRenderer.getFoilBufferDirect( | ||
buffer, this.model.renderType(this.getTextureLocation(pEntity)),false, false); | ||
this.model.renderToBuffer(poseStack, vertexconsumer, packedLight, OverlayTexture.NO_OVERLAY); | ||
poseStack.popPose(); | ||
super.render(pEntity, entityYaw, partialTicks, poseStack, buffer, packedLight); | ||
} | ||
|
||
@Override | ||
public ResourceLocation getTextureLocation(TomahawkProjectileEntity entity) { | ||
return ResourceLocation.fromNamespaceAndPath(TutorialMod.MOD_ID, "textures/entity/tomahawk/tomahawk.png"); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
src/main/java/net/kaupenjoe/tutorialmod/entity/custom/TomahawkProjectileEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package net.kaupenjoe.tutorialmod.entity.custom; | ||
|
||
import net.kaupenjoe.tutorialmod.entity.ModEntities; | ||
import net.kaupenjoe.tutorialmod.item.ModItems; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.EntityType; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.projectile.AbstractArrow; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.phys.BlockHitResult; | ||
import net.minecraft.world.phys.EntityHitResult; | ||
import net.minecraft.world.phys.Vec2; | ||
|
||
public class TomahawkProjectileEntity extends AbstractArrow { | ||
private float rotation; | ||
public Vec2 groundedOffset; | ||
|
||
public TomahawkProjectileEntity(EntityType<? extends AbstractArrow> entityType, Level level) { | ||
super(entityType, level); | ||
} | ||
|
||
public TomahawkProjectileEntity(LivingEntity shooter, Level level) { | ||
super(ModEntities.TOMAHAWK.get(), shooter, level, new ItemStack(ModItems.TOMAHAWK.get()), null); | ||
} | ||
|
||
@Override | ||
protected ItemStack getDefaultPickupItem() { | ||
return new ItemStack(ModItems.TOMAHAWK.get()); | ||
} | ||
|
||
public float getRenderingRotation() { | ||
rotation += 0.5f; | ||
if(rotation >= 360) { | ||
rotation = 0; | ||
} | ||
return rotation; | ||
} | ||
|
||
public boolean isGrounded() { | ||
return inGround; | ||
} | ||
|
||
@Override | ||
protected void onHitEntity(EntityHitResult result) { | ||
super.onHitEntity(result); | ||
Entity entity = result.getEntity(); | ||
entity.hurt(this.damageSources().thrown(this, this.getOwner()), 4); | ||
|
||
if (!this.level().isClientSide) { | ||
this.level().broadcastEntityEvent(this, (byte)3); | ||
this.discard(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onHitBlock(BlockHitResult result) { | ||
super.onHitBlock(result); | ||
|
||
if(result.getDirection() == Direction.SOUTH) { | ||
groundedOffset = new Vec2(215f,180f); | ||
} | ||
if(result.getDirection() == Direction.NORTH) { | ||
groundedOffset = new Vec2(215f, 0f); | ||
} | ||
if(result.getDirection() == Direction.EAST) { | ||
groundedOffset = new Vec2(215f,-90f); | ||
} | ||
if(result.getDirection() == Direction.WEST) { | ||
groundedOffset = new Vec2(215f,90f); | ||
} | ||
|
||
if(result.getDirection() == Direction.DOWN) { | ||
groundedOffset = new Vec2(115f,180f); | ||
} | ||
if(result.getDirection() == Direction.UP) { | ||
groundedOffset = new Vec2(285f,180f); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/net/kaupenjoe/tutorialmod/item/custom/TomahawkItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package net.kaupenjoe.tutorialmod.item.custom; | ||
|
||
import net.kaupenjoe.tutorialmod.entity.custom.TomahawkProjectileEntity; | ||
import net.minecraft.sounds.SoundEvents; | ||
import net.minecraft.sounds.SoundSource; | ||
import net.minecraft.stats.Stats; | ||
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; | ||
|
||
public class TomahawkItem extends Item { | ||
public TomahawkItem(Properties properties) { | ||
super(properties); | ||
} | ||
|
||
@Override | ||
public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) { | ||
ItemStack itemstack = pPlayer.getItemInHand(pUsedHand); | ||
pLevel.playSound(null, pPlayer.getX(), pPlayer.getY(), pPlayer.getZ(), | ||
SoundEvents.SNOWBALL_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (pLevel.getRandom().nextFloat() * 0.4F + 0.8F)); | ||
if (!pLevel.isClientSide) { | ||
TomahawkProjectileEntity tomahawkProjectile = new TomahawkProjectileEntity(pPlayer, pLevel); | ||
tomahawkProjectile.shootFromRotation(pPlayer, pPlayer.getXRot(), pPlayer.getYRot(), 0.0F, 1.5F, 0F); | ||
pLevel.addFreshEntity(tomahawkProjectile); | ||
} | ||
|
||
pPlayer.awardStat(Stats.ITEM_USED.get(this)); | ||
if (!pPlayer.getAbilities().instabuild) { | ||
itemstack.shrink(1); | ||
} | ||
|
||
return InteractionResultHolder.sidedSuccess(itemstack, pLevel.isClientSide()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.