-
Notifications
You must be signed in to change notification settings - Fork 16
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
1 parent
cb2ba56
commit 8289e31
Showing
8 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/main/java/com/uraneptus/sullysmod/client/model/CrackedAncientSkullModel.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 com.uraneptus.sullysmod.client.model;// Made with Blockbench 4.9.4 | ||
// Exported for Minecraft version 1.17 or later with Mojang mappings | ||
// Paste this class into your mod and generate all required imports | ||
|
||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.mojang.blaze3d.vertex.VertexConsumer; | ||
import com.uraneptus.sullysmod.SullysMod; | ||
import net.minecraft.client.model.SkullModelBase; | ||
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 CrackedAncientSkullModel extends SkullModelBase { | ||
// This layer location should be baked with EntityRendererProvider.Context in the entity renderer and passed into this model's constructor | ||
public static final ModelLayerLocation LAYER_LOCATION = new ModelLayerLocation(SullysMod.modPrefix("cracked_ancient_skull"), "main"); | ||
private final ModelPart head; | ||
|
||
public CrackedAncientSkullModel(ModelPart root) { | ||
this.head = root.getChild("head"); | ||
} | ||
|
||
public static LayerDefinition createBodyLayer() { | ||
MeshDefinition meshdefinition = new MeshDefinition(); | ||
PartDefinition partdefinition = meshdefinition.getRoot(); | ||
|
||
PartDefinition head = partdefinition.addOrReplaceChild("head", CubeListBuilder.create().texOffs(0, 25).addBox(-7.0F, -14.0F, -20.0F, 14.0F, 5.0F, 15.0F, new CubeDeformation(0.0F)) | ||
.texOffs(0, 0).addBox(-8.0F, -14.0F, -5.0F, 16.0F, 14.0F, 11.0F, new CubeDeformation(0.0F)) | ||
.texOffs(0, 45).addBox(4.0F, -12.0F, -10.0F, 5.0F, 12.0F, 5.0F, new CubeDeformation(0.0F)) | ||
.texOffs(0, 30).addBox(4.0F, -1.0F, -10.0F, 5.0F, 0.0F, 5.0F, new CubeDeformation(0.0F)) | ||
.texOffs(43, 25).addBox(-9.0F, -12.0F, -10.0F, 5.0F, 10.0F, 5.0F, new CubeDeformation(0.0F)) | ||
.texOffs(0, 25).addBox(-9.0F, -3.0F, -10.0F, 5.0F, 0.0F, 5.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 24.0F, 0.0F)); | ||
|
||
return LayerDefinition.create(meshdefinition, 64, 64); | ||
} | ||
|
||
|
||
@Override | ||
public void renderToBuffer(PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) { | ||
head.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); | ||
} | ||
|
||
@Override | ||
public void setupAnim(float pMouthAnimation, float pYRot, float pXRot) { | ||
|
||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
src/main/java/com/uraneptus/sullysmod/client/renderer/be/AncientSkullBER.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,98 @@ | ||
package com.uraneptus.sullysmod.client.renderer.be; | ||
|
||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.Maps; | ||
import com.mojang.authlib.GameProfile; | ||
import com.mojang.authlib.minecraft.MinecraftProfileTexture; | ||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.mojang.blaze3d.vertex.VertexConsumer; | ||
import com.uraneptus.sullysmod.client.model.CrackedAncientSkullModel; | ||
import com.uraneptus.sullysmod.common.blockentities.AncientSkullBE; | ||
import com.uraneptus.sullysmod.common.blocks.AncientSkullBlock; | ||
import net.minecraft.Util; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.model.PiglinHeadModel; | ||
import net.minecraft.client.model.SkullModel; | ||
import net.minecraft.client.model.SkullModelBase; | ||
import net.minecraft.client.model.dragon.DragonHeadModel; | ||
import net.minecraft.client.model.geom.EntityModelSet; | ||
import net.minecraft.client.model.geom.ModelLayers; | ||
import net.minecraft.client.renderer.MultiBufferSource; | ||
import net.minecraft.client.renderer.RenderType; | ||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; | ||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; | ||
import net.minecraft.client.renderer.texture.OverlayTexture; | ||
import net.minecraft.client.resources.DefaultPlayerSkin; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.core.UUIDUtil; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.block.AbstractSkullBlock; | ||
import net.minecraft.world.level.block.SkullBlock; | ||
import net.minecraft.world.level.block.WallSkullBlock; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.block.state.properties.RotationSegment; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.api.distmarker.OnlyIn; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.Map; | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
public class AncientSkullBER implements BlockEntityRenderer<AncientSkullBE> { | ||
private final Map<AncientSkullBlock.Type, SkullModelBase> modelByType; | ||
public static final Map<AncientSkullBlock.Type, ResourceLocation> SKIN_BY_TYPE = Util.make(Maps.newHashMap(), (p_261388_) -> { | ||
p_261388_.put(AncientSkullBlock.Types.CRACKED, new ResourceLocation("textures/entity/skeleton/skeleton.png")); | ||
}); | ||
|
||
public static Map<AncientSkullBlock.Type, SkullModelBase> createSkullRenderers(EntityModelSet pEntityModelSet) { | ||
ImmutableMap.Builder<AncientSkullBlock.Type, SkullModelBase> builder = ImmutableMap.builder(); | ||
builder.put(AncientSkullBlock.Types.CRACKED, new CrackedAncientSkullModel(pEntityModelSet.bakeLayer(CrackedAncientSkullModel.LAYER_LOCATION))); | ||
//net.minecraftforge.fml.ModLoader.get().postEvent(new net.minecraftforge.client.event.EntityRenderersEvent.CreateSkullModels(builder, pEntityModelSet)); | ||
return builder.build(); | ||
} | ||
|
||
public AncientSkullBER(BlockEntityRendererProvider.Context pContext) { | ||
this.modelByType = createSkullRenderers(pContext.getModelSet()); | ||
} | ||
|
||
public void render(AncientSkullBE pBlockEntity, float pPartialTick, PoseStack pPoseStack, MultiBufferSource pBuffer, int pPackedLight, int pPackedOverlay) { | ||
float f = pBlockEntity.getAnimation(pPartialTick); | ||
BlockState blockstate = pBlockEntity.getBlockState(); | ||
boolean flag = blockstate.getBlock() instanceof WallSkullBlock; | ||
Direction direction = flag ? blockstate.getValue(WallSkullBlock.FACING) : null; | ||
int i = flag ? RotationSegment.convertToSegment(direction.getOpposite()) : blockstate.getValue(SkullBlock.ROTATION); | ||
float f1 = RotationSegment.convertToDegrees(i); | ||
SkullBlock.Type skullblock$type = ((AbstractSkullBlock)blockstate.getBlock()).getType(); | ||
SkullModelBase skullmodelbase = this.modelByType.get(skullblock$type); | ||
RenderType rendertype = getRenderType(skullblock$type, pBlockEntity.getOwnerProfile()); | ||
renderSkull(direction, f1, f, pPoseStack, pBuffer, pPackedLight, skullmodelbase, rendertype); | ||
} | ||
|
||
public static void renderSkull(@Nullable Direction pDirection, float pYRot, float pMouthAnimation, PoseStack pPoseStack, MultiBufferSource pBufferSource, int pPackedLight, SkullModelBase pModel, RenderType pRenderType) { | ||
pPoseStack.pushPose(); | ||
if (pDirection == null) { | ||
pPoseStack.translate(0.5F, 0.0F, 0.5F); | ||
} else { | ||
float f = 0.25F; | ||
pPoseStack.translate(0.5F - (float)pDirection.getStepX() * 0.25F, 0.25F, 0.5F - (float)pDirection.getStepZ() * 0.25F); | ||
} | ||
|
||
pPoseStack.scale(-1.0F, -1.0F, 1.0F); | ||
VertexConsumer vertexconsumer = pBufferSource.getBuffer(pRenderType); | ||
pModel.setupAnim(pMouthAnimation, pYRot, 0.0F); | ||
pModel.renderToBuffer(pPoseStack, vertexconsumer, pPackedLight, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F); | ||
pPoseStack.popPose(); | ||
} | ||
|
||
public static RenderType getRenderType(SkullBlock.Type pSkullType, @Nullable GameProfile pGameProfile) { | ||
ResourceLocation resourcelocation = SKIN_BY_TYPE.get(pSkullType); | ||
if (pSkullType == SkullBlock.Types.PLAYER && pGameProfile != null) { | ||
Minecraft minecraft = Minecraft.getInstance(); | ||
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map = minecraft.getSkinManager().getInsecureSkinInformation(pGameProfile); | ||
return map.containsKey(MinecraftProfileTexture.Type.SKIN) ? RenderType.entityTranslucent(minecraft.getSkinManager().registerTexture(map.get(MinecraftProfileTexture.Type.SKIN), MinecraftProfileTexture.Type.SKIN)) : RenderType.entityCutoutNoCull(DefaultPlayerSkin.getDefaultSkin(UUIDUtil.getOrCreatePlayerUUID(pGameProfile))); | ||
} else { | ||
return RenderType.entityCutoutNoCullZOffset(resourcelocation); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/uraneptus/sullysmod/common/blockentities/AncientSkullBE.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,12 @@ | ||
package com.uraneptus.sullysmod.common.blockentities; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.block.entity.SkullBlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
|
||
public class AncientSkullBE extends SkullBlockEntity { | ||
public AncientSkullBE(BlockPos pPos, BlockState pBlockState) { | ||
super(pPos, pBlockState); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/uraneptus/sullysmod/common/blocks/AncientSkullBlock.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,21 @@ | ||
package com.uraneptus.sullysmod.common.blocks; | ||
|
||
import com.uraneptus.sullysmod.common.blockentities.AncientSkullBE; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.block.SkullBlock; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
|
||
public class AncientSkullBlock extends SkullBlock { | ||
public AncientSkullBlock(Type pType, Properties pProperties) { | ||
super(pType, pProperties); | ||
} | ||
@Override | ||
public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) { | ||
return new AncientSkullBE(pPos, pState); | ||
} | ||
|
||
public static enum Types implements SkullBlock.Type { | ||
CRACKED | ||
} | ||
} |
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
Binary file added
BIN
+1.19 KB
...ssets/sullysmod/textures/entity/cracked_ancient_skull/cracked_ancient_skull.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.