Skip to content

Commit

Permalink
add mother trophy
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheaterpaul committed Nov 8, 2023
1 parent 89ec7ae commit e9a6496
Show file tree
Hide file tree
Showing 23 changed files with 389 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "vampirism:block/mother_trophy"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,56 @@
},
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "vampirism:pure_blood_4"
},
"name": "vampirism:mother_trophy"
}
],
"rolls": 1.0
},
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "vampirism:human_heart",
"name": "vampirism:soul_orb_vampire",
"quality": 10
},
}
],
"name": "souls",
"rolls": 1.0
},
{
"bonus_rolls": 0.0,
"entries": [
{
"type": "minecraft:item",
"name": "minecraft:diamond_block"
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"name": "vampirism:pure_blood_4",
"quality": 2
},
{
"type": "minecraft:item",
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"name": "vampirism:vampire_blood_bottle",
"quality": 10
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "vampirism:mother_trophy"
}
],
"rolls": 1.0
}
],
"random_sequence": "vampirism:blocks/mother_trophy"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.teamlapen.vampirism.blockentity;

import de.teamlapen.vampirism.core.ModTiles;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;

public class MotherTrophyBlockEntity extends BlockEntity {

public MotherTrophyBlockEntity(BlockPos pPos, BlockState pBlockState) {
super(ModTiles.MOTHER_TROPHY.get(), pPos, pBlockState);
}
}
73 changes: 73 additions & 0 deletions src/main/java/de/teamlapen/vampirism/blocks/MotherTrophyBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package de.teamlapen.vampirism.blocks;

import de.teamlapen.vampirism.blockentity.MotherTrophyBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.block.state.properties.RotationSegment;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class MotherTrophyBlock extends BaseEntityBlock {

public static final int MAX = RotationSegment.getMaxSegmentIndex();
private static final int ROTATIONS = MAX + 1;
public static final IntegerProperty ROTATION = BlockStateProperties.ROTATION_16;
private static final VoxelShape SHAPE = makeShape();

public MotherTrophyBlock(Properties pProperties) {
super(pProperties);
this.registerDefaultState(this.stateDefinition.any().setValue(ROTATION, 0));
}

@NotNull
@Override
public RenderShape getRenderShape(@NotNull BlockState state) {
return RenderShape.MODEL;
}

@Nullable
@Override
public BlockEntity newBlockEntity(@NotNull BlockPos pPos, @NotNull BlockState pState) {
return new MotherTrophyBlockEntity(pPos, pState);
}

@Override
public @NotNull VoxelShape getShape(@NotNull BlockState pState, @NotNull BlockGetter pLevel, @NotNull BlockPos pPos, @NotNull CollisionContext pContext) {
return SHAPE;
}

public @NotNull VoxelShape getOcclusionShape(@NotNull BlockState pState, @NotNull BlockGetter pLevel, @NotNull BlockPos pPos) {
return Shapes.empty();
}

public BlockState getStateForPlacement(@NotNull BlockPlaceContext pContext) {
return this.defaultBlockState().setValue(ROTATION, RotationSegment.convertToSegment(pContext.getRotation()));
}

public @NotNull BlockState rotate(@NotNull BlockState pState, @NotNull Rotation pRotation) {
return pState.setValue(ROTATION, pRotation.rotate(pState.getValue(ROTATION), ROTATIONS));
}

public @NotNull BlockState mirror(@NotNull BlockState pState, @NotNull Mirror pMirror) {
return pState.setValue(ROTATION, pMirror.mirror(pState.getValue(ROTATION), ROTATIONS));
}

protected void createBlockStateDefinition(StateDefinition.@NotNull Builder<Block, BlockState> pBuilder) {
pBuilder.add(ROTATION);
}


private static @NotNull VoxelShape makeShape() {
return Shapes.box(0.375, 0, 0.375, 0.625, 0.75, 0.625);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.ComputeFovModifierEvent;
import net.minecraftforge.client.event.ModelEvent;
import net.minecraftforge.client.event.RegisterClientReloadListenersEvent;
import net.minecraftforge.client.event.RenderLevelStageEvent;
import net.minecraftforge.event.AddPackFindersEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.level.LevelEvent;
Expand Down Expand Up @@ -197,6 +199,14 @@ public void onItemToolTip(@NotNull ItemTooltipEvent event) {
});
}

public static void registerReloadListener(RegisterClientReloadListenersEvent event) {
event.registerReloadListener(ClientProxy.get().getBlockEntityItemRenderer());
}

public static void registerStageEvent(RenderLevelStageEvent.RegisterStageEvent event) {
ClientProxy.get().registerBlockEntityItemRenderer();
}

private static boolean shouldShowInTooltip(int p_242394_0_, @NotNull ItemStack.TooltipPart p_242394_1_) {
return (p_242394_0_ & p_242394_1_.getMask()) == 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ public static void init(){
modbus.addListener(ClientEventHandler::onModelRegistry);
modbus.addListener(ModItemsRender::registerItemDecorator);
modbus.addListener(ClientEventHandler::registerPackRepository);
modbus.addListener(ClientEventHandler::registerReloadListener);
modbus.addListener(ClientEventHandler::registerStageEvent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ static void registerBlockEntityRenderers(EntityRenderersEvent.@NotNull RegisterR
event.registerBlockEntityRenderer(ModTiles.BLOOD_PEDESTAL.get(), PedestalBESR::new);
event.registerBlockEntityRenderer(ModTiles.TOTEM.get(), TotemBESR::new);
event.registerBlockEntityRenderer(ModTiles.GARLIC_DIFFUSER.get(), GarlicDiffuserBESR::new);
event.registerBlockEntityRenderer(ModTiles.MOTHER_TROPHY.get(), MotherTrophyBESR::new);
}

private static void registerRenderType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ public void setupAnim(@NotNull GhostEntity pEntity, float pLimbSwing, float pLim
this.body.y += (float)Math.cos((double)f3) * 0.25F * f5;
}

public void setupAnim2(float pAgeInTicks) {
this.body.getAllParts().forEach(ModelPart::resetPose);
float f3 = pAgeInTicks * 5.0F * ((float) Math.PI / 180F);

this.body.y += (float) Math.cos((double) f3) * 0.25F;
}

@Override
public void renderToBuffer(@NotNull PoseStack pPoseStack, @NotNull VertexConsumer pBuffer, int pPackedLight, int pPackedOverlay, float pRed, float pGreen, float pBlue, float pAlpha) {
if (!this.isAggressive) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package de.teamlapen.vampirism.client.renderer.blockentity;

import com.mojang.blaze3d.vertex.PoseStack;
import de.teamlapen.vampirism.blockentity.MotherTrophyBlockEntity;
import de.teamlapen.vampirism.core.ModBlocks;
import net.minecraft.client.model.geom.EntityModelSet;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
import net.minecraft.core.BlockPos;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;

public class ModBlockEntityItemRenderer extends BlockEntityWithoutLevelRenderer {

private MotherTrophyBlockEntity mother_trophy;
private final BlockEntityRenderDispatcher pBlockEntityRenderDispatcher;

public ModBlockEntityItemRenderer(BlockEntityRenderDispatcher pBlockEntityRenderDispatcher, EntityModelSet pEntityModelSet) {
super(pBlockEntityRenderDispatcher, pEntityModelSet);
this.pBlockEntityRenderDispatcher = pBlockEntityRenderDispatcher;
}

@Override
public void onResourceManagerReload(@NotNull ResourceManager pResourceManager) {
this.mother_trophy = new MotherTrophyBlockEntity(BlockPos.ZERO, ModBlocks.MOTHER_TROPHY.get().defaultBlockState());
}

@Override
public void renderByItem(@NotNull ItemStack pStack, @NotNull ItemDisplayContext pDisplayContext, @NotNull PoseStack pPoseStack, @NotNull MultiBufferSource pBuffer, int pPackedLight, int pPackedOverlay) {
if (pStack.is(ModBlocks.MOTHER_TROPHY.get().asItem())) {
this.pBlockEntityRenderDispatcher.renderItem(mother_trophy, pPoseStack, pBuffer, pPackedLight, pPackedOverlay);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package de.teamlapen.vampirism.client.renderer.blockentity;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import de.teamlapen.vampirism.blockentity.MotherTrophyBlockEntity;
import de.teamlapen.vampirism.blocks.MotherTrophyBlock;
import de.teamlapen.vampirism.client.core.ModEntitiesRender;
import de.teamlapen.vampirism.client.model.GhostModel;
import de.teamlapen.vampirism.client.renderer.entity.GhostRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.world.level.block.state.properties.RotationSegment;
import org.jetbrains.annotations.NotNull;

public class MotherTrophyBESR extends VampirismBESR<MotherTrophyBlockEntity> {

private final GhostModel model;

public MotherTrophyBESR(BlockEntityRendererProvider.Context context) {
this.model = new GhostModel(context.bakeLayer(ModEntitiesRender.GHOST));
}

@Override
public void render(@NotNull MotherTrophyBlockEntity pBlockEntity, float pPartialTick, @NotNull PoseStack pPoseStack, @NotNull MultiBufferSource pBuffer, int pPackedLight, int pPackedOverlay) {
Integer value = pBlockEntity.getBlockState().getValue(MotherTrophyBlock.ROTATION);
pPoseStack.pushPose();
pPoseStack.translate(0.5, 0, 0.5);
pPoseStack.mulPose(Axis.ZP.rotationDegrees(180));
pPoseStack.translate(0.0F, -1.701F, 0.0F);
float f1 = RotationSegment.convertToDegrees(value);
pPoseStack.mulPose(Axis.YP.rotationDegrees(f1));
this.model.setupAnim2(pBlockEntity.getLevel() != null ? pBlockEntity.getLevel().getGameTime() : 0);
this.model.renderToBuffer(pPoseStack, pBuffer.getBuffer(RenderType.itemEntityTranslucentCull(GhostRenderer.TEXTURE)), pPackedLight, pPackedOverlay, 1, 1, 1, 1f);
pPoseStack.popPose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class GhostRenderer extends MobRenderer<GhostEntity, GhostModel> {

private static final ResourceLocation TEXTURE = new ResourceLocation(REFERENCE.MODID, "textures/entity/ghost.png");
public static final ResourceLocation TEXTURE = new ResourceLocation(REFERENCE.MODID, "textures/entity/ghost.png");

public GhostRenderer(EntityRendererProvider.Context pContext) {
super(pContext, new GhostModel(pContext.bakeLayer(ModEntitiesRender.GHOST)), 0.1f);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/de/teamlapen/vampirism/core/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import de.teamlapen.vampirism.blocks.mother.ActiveVulnerableRemainsBlock;
import de.teamlapen.vampirism.blocks.mother.MotherBlock;
import de.teamlapen.vampirism.blocks.mother.RemainsBlock;
import de.teamlapen.vampirism.items.MotherTrophyItem;
import de.teamlapen.vampirism.util.BlockVoxelshapes;
import de.teamlapen.vampirism.world.gen.CursedSpruceTree;
import de.teamlapen.vampirism.world.gen.DarkSpruceTreeGrower;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Rarity;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.properties.BlockSetType;
Expand Down Expand Up @@ -168,7 +170,8 @@ public class ModBlocks {
((FireBlock) Blocks.FIRE).setFlammable(block, 30, 60);
return block;
});
public static final RegistryObject<MotherBlock> MOTHER = BLOCKS.register("mother", MotherBlock::new); //TODO remove item, add models/textures
public static final RegistryObject<MotherBlock> MOTHER = BLOCKS.register("mother", MotherBlock::new);
public static final RegistryObject<Block> MOTHER_TROPHY = registerWithItem("mother_trophy", () -> new MotherTrophyBlock(BlockBehaviour.Properties.of().mapColor(MapColor.COLOR_GRAY).strength(3, 9).lightLevel(s -> 1).noOcclusion()), block -> new MotherTrophyItem(block, new Item.Properties().rarity(Rarity.EPIC).stacksTo(1)));


/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/teamlapen/vampirism/core/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public void appendHoverText(@NotNull ItemStack stack, @Nullable Level level, @No
public static final RegistryObject<HangingSignItem> DARK_SPRUCE_HANGING_SIGN = register("dark_spruce_hanging_sign", () -> new HangingSignItem(ModBlocks.DARK_SPRUCE_HANGING_SIGN.get(), ModBlocks.DARK_SPRUCE_WALL_HANGING_SIGN.get(), new Item.Properties().stacksTo(16)));
public static final RegistryObject<HangingSignItem> CURSED_SPRUCE_HANGING_SIGN = register("cursed_spruce_hanging_sign", () -> new HangingSignItem(ModBlocks.CURSED_SPRUCE_HANGING_SIGN.get(), ModBlocks.CURSED_SPRUCE_WALL_HANGING_SIGN.get(), new Item.Properties().stacksTo(16)));

public static final RegistryObject<Item> MOTHER_CORE = register("mother_core", () -> new Item(props().rarity(Rarity.EPIC)));
public static final RegistryObject<Item> MOTHER_CORE = register("mother_core", () -> new Item(props().rarity(Rarity.UNCOMMON)));

static void registerCraftingRecipes() {
// Brewing
Expand Down
1 change: 1 addition & 0 deletions src/main/java/de/teamlapen/vampirism/core/ModTiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class ModTiles {
public static final RegistryObject<BlockEntityType<AlchemyTableBlockEntity>> ALCHEMICAL_TABLE = BLOCK_ENTITY_TYPES.register("alchemical_table", () -> create(AlchemyTableBlockEntity::new, ModBlocks.ALCHEMY_TABLE.get()));
public static final RegistryObject<BlockEntityType<MotherBlockEntity>> MOTHER = BLOCK_ENTITY_TYPES.register("mother", () -> create(MotherBlockEntity::new, ModBlocks.MOTHER.get()));
public static final RegistryObject<BlockEntityType<VulnerableRemainsBlockEntity>> VULNERABLE_CURSED_ROOTED_DIRT = BLOCK_ENTITY_TYPES.register("vulnerable_cursed_rooted_dirt", () -> create(VulnerableRemainsBlockEntity::new, ModBlocks.ACTIVE_VULNERABLE_REMAINS.get()));
public static final RegistryObject<BlockEntityType<MotherTrophyBlockEntity>> MOTHER_TROPHY = BLOCK_ENTITY_TYPES.register("mother_trophy", () -> create(MotherTrophyBlockEntity::new, ModBlocks.MOTHER_TROPHY.get()));

static void register(IEventBus bus) {
BLOCK_ENTITY_TYPES.register(bus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ protected void registerStatesAndModels() {
simpleBlock(ModBlocks.ACTIVE_VULNERABLE_REMAINS.get(), models().cubeAll("active_vulnerable_remains", modLoc("block/active_vulnerable_remains")));
simpleBlock(ModBlocks.CURSED_HANGING_ROOTS.get(), models().cross("cursed_hanging_roots", modLoc("block/cursed_hanging_roots")));
simpleBlock(ModBlocks.MOTHER.get(), models().cubeAll("mother", modLoc("block/mother")));

simpleBlock(ModBlocks.MOTHER_TROPHY.get(), models().getExistingFile(modLoc("block/mother_trophy")));
}

private void createWoodStates() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,12 @@ protected void generate() {
this.add(ModBlocks.CURSED_HANGING_ROOTS.get(), ModBlockLootTables::createShearsOnlyDrop);
this.add(ModBlocks.MOTHER.get(),
createSingleItemTable(ModItems.MOTHER_CORE.get())
.withPool(LootPool.lootPool().name("souls").setRolls(ConstantValue.exactly(1)).add(LootItem.lootTableItem(ModItems.SOUL_ORB_VAMPIRE.get()).setQuality(10)))
.withPool(applyExplosionCondition(ModBlocks.MOTHER_TROPHY.get(), LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(ModBlocks.MOTHER_TROPHY.get()))))
.withPool(applyExplosionCondition(ModItems.SOUL_ORB_VAMPIRE.get(), LootPool.lootPool().name("souls").setRolls(ConstantValue.exactly(1)).add(LootItem.lootTableItem(ModItems.SOUL_ORB_VAMPIRE.get()).setQuality(10))))
.withPool(LootPool.lootPool().name("bonus").setRolls(UniformGenerator.between(1, 4))
.add(LootItem.lootTableItem(ModItems.PURE_BLOOD_4.get()).setQuality(2))
.add(LootItem.lootTableItem(ModItems.VAMPIRE_BLOOD_BOTTLE.get()).setQuality(10))));
.add(applyExplosionCondition(ModItems.PURE_BLOOD_4.get(), LootItem.lootTableItem(ModItems.PURE_BLOOD_4.get()).setQuality(2)))
.add(applyExplosionCondition(ModItems.VAMPIRE_BLOOD_BOTTLE.get(), LootItem.lootTableItem(ModItems.VAMPIRE_BLOOD_BOTTLE.get()).setQuality(10)))));
this.dropSelf(ModBlocks.MOTHER_TROPHY.get());
}

@NotNull
Expand Down
Loading

0 comments on commit e9a6496

Please sign in to comment.