Skip to content

Commit

Permalink
Invisible skull
Browse files Browse the repository at this point in the history
  • Loading branch information
KekeCreations committed Mar 26, 2024
1 parent cb2ba56 commit 8289e31
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 0 deletions.
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) {

}
}
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);
}
}
}
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);
}

}
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
import com.uraneptus.sullysmod.client.particles.BlotEyesParticle;
import com.uraneptus.sullysmod.client.particles.RicochetParticle;
import com.uraneptus.sullysmod.client.renderer.be.AmberBER;
import com.uraneptus.sullysmod.client.renderer.be.AncientSkullBER;
import com.uraneptus.sullysmod.client.renderer.be.ItemStandBER;
import com.uraneptus.sullysmod.client.renderer.entities.*;
import com.uraneptus.sullysmod.common.blocks.AncientSkullBlock;
import com.uraneptus.sullysmod.common.items.VenomVialItem;
import com.uraneptus.sullysmod.core.registry.*;
import net.minecraft.client.model.geom.EntityModelSet;
import net.minecraft.client.renderer.blockentity.SkullBlockRenderer;
import net.minecraft.client.renderer.item.ItemProperties;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
Expand All @@ -33,6 +37,7 @@ public static void registerEntityRenderer(EntityRenderersEvent.RegisterRenderers
event.registerEntityRenderer(SMEntityTypes.THROWN_THROWING_KNIFE.get(), ThrownThrowingKnifeRenderer::new);
event.registerBlockEntityRenderer(SMBlockEntityTypes.AMBER.get(), AmberBER::new);
event.registerBlockEntityRenderer(SMBlockEntityTypes.ITEM_STAND.get(), ItemStandBER::new);
event.registerBlockEntityRenderer(SMBlockEntityTypes.ANCIENT_SKULL.get(), AncientSkullBER::new);
}

@SubscribeEvent
Expand All @@ -42,6 +47,7 @@ public static void registerLayerLocation(EntityRenderersEvent.RegisterLayerDefin
event.registerLayerDefinition(TortoiseShellModel.LAYER_LOCATION, TortoiseShellModel::createBodyLayer);
event.registerLayerDefinition(JungleSpiderModel.LAYER_LOCATION, JungleSpiderModel::createBodyLayer);
event.registerLayerDefinition(MinersHelmetModel.LAYER_LOCATION, MinersHelmetModel::createBodyLayer);
event.registerLayerDefinition(CrackedAncientSkullModel.LAYER_LOCATION, CrackedAncientSkullModel::createBodyLayer);
}

@SubscribeEvent
Expand All @@ -59,4 +65,11 @@ public static void onClientSetup(FMLClientSetupEvent event) {
public static void onItemColouring(RegisterColorHandlersEvent.Item event) {
event.register(((stack, tint) -> tint == 0 ? -1 : VenomVialItem.getEffectColours(stack, tint)), SMItems.VENOM_VIAL.get());
}

@SubscribeEvent
public static void onCreateSkullModels(EntityRenderersEvent.CreateSkullModels event) {
EntityModelSet entityModelSet = event.getEntityModelSet();
event.registerSkullModel(AncientSkullBlock.Types.CRACKED, new CrackedAncientSkullModel(entityModelSet.bakeLayer(CrackedAncientSkullModel.LAYER_LOCATION)));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.teamabnormals.blueprint.core.util.registry.BlockEntitySubRegistryHelper;
import com.uraneptus.sullysmod.SullysMod;
import com.uraneptus.sullysmod.common.blockentities.AncientSkullBE;
import com.uraneptus.sullysmod.common.blocks.*;
import com.uraneptus.sullysmod.common.blockentities.AmberBE;
import com.uraneptus.sullysmod.common.blockentities.FlingerTotemBE;
Expand All @@ -18,4 +19,5 @@ public class SMBlockEntityTypes {
public static final RegistryObject<BlockEntityType<FlingerTotemBE>> FLINGER_TOTEM = HELPER.createBlockEntity("flinger_totem", FlingerTotemBE::new, FlingerTotem.class);
public static final RegistryObject<BlockEntityType<AmberBE>> AMBER = HELPER.createBlockEntity("amber", AmberBE::new, AmberBlock.class);
public static final RegistryObject<BlockEntityType<ItemStandBE>> ITEM_STAND = HELPER.createBlockEntity("item_stand", ItemStandBE::new, ItemStandBlock.class);
public static final RegistryObject<BlockEntityType<AncientSkullBE>> ANCIENT_SKULL = HELPER.createBlockEntity("ancient_skull", AncientSkullBE::new, AncientSkullBlock.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.properties.BlockSetType;
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
import net.minecraft.world.level.block.state.properties.WoodType;
import net.minecraft.world.level.material.MapColor;
import net.minecraft.world.level.material.PushReaction;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.RegistryObject;

Expand Down Expand Up @@ -105,6 +107,8 @@ public class SMBlocks {
public static final RegistryObject<Block> PETRIFIED_SAPLING = HELPER.createBlock("petrified_sapling", () -> new PetrifiedSapling(SMProperties.Blocks.PETRIFIED_SAPLING));
public static final RegistryObject<Block> POTTED_PETRIFIED_SAPLING = HELPER.createBlockNoItem("potted_petrified_sapling", () -> new FlowerPotBlock(PETRIFIED_SAPLING.get(), PropertyUtil.flowerPot()));

//ANCIENT SKULLS
public static final RegistryObject<Block> CRACKED_ANCIENT_SKULL = HELPER.createBlock("cracked_ancient_skull", () -> new AncientSkullBlock(AncientSkullBlock.Types.CRACKED, BlockBehaviour.Properties.of().instrument(NoteBlockInstrument.ZOMBIE).strength(1.0F).pushReaction(PushReaction.DESTROY)));
//Misc
public static final RegistryObject<Block> TORTOISE_EGG = HELPER.createBlock("tortoise_egg", () -> new TortoiseEggBlock(BlockBehaviour.Properties.copy(Blocks.TURTLE_EGG)));
public static final RegistryObject<Block> ITEM_STAND = HELPER.createBlock("item_stand", () -> new ItemStandBlock(SMProperties.Blocks.ITEM_STAND));
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8289e31

Please sign in to comment.