Skip to content

Commit

Permalink
dinner plate, pt 2, plus some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabeHunger54 committed Jun 2, 2024
1 parent 9f3c68a commit 0fd6d52
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 10 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ neogradle.subsystems.parchment.mappingsVersion=2024.02.25
mc_version=1.20.4
mc_version_range=[1.20.4,1.20.5)

neo_version=20.4.202
neo_version_range=[20.4.80-beta,20.5)
neo_version=20.4.233
neo_version_range=[20.4.233,20.5)

loader.version=[1,)
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pluginManagement {
plugins {
id("net.neoforged.gradle.userdev") version "7.0.+"
id("com.github.minecraftschurlimods.helperplugin") version "1.10"
id("com.github.minecraftschurlimods.helperplugin") version "1.13"
}
repositories {
mavenLocal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ public RegisterBibliocraftWoodTypesEvent(Map<ResourceLocation, BibliocraftWoodTy
this.woodTypes = woodTypes;
}

/**
* Registers a new wood type.
*
* @param woodType The vanilla {@link WoodType} associated with this wood type.
* @param properties A supplier for the {@link BlockBehaviour.Properties} associated with this wood type. Typically, this is a copy of the wood type's planks' properties.
* @param texture The location of the wood type's planks texture, for use in datagen.
* @param family The {@link BlockFamily} for the associated wood type, for use in datagen.
*/
public void register(WoodType woodType, Supplier<BlockBehaviour.Properties> properties, ResourceLocation texture, BlockFamily family) {
register(new ResourceLocation(woodType.name()), woodType, properties, texture, family);
}

/**
* Registers a new wood type. Must be called during the mod constructor.
* Registers a new wood type.
*
* @param id The id of the wood type. Should be the id of the mod the wood type comes from, and the name of the wood type.
* @param woodType The vanilla {@link WoodType} associated with this wood type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import java.util.concurrent.CompletableFuture;

public class BCBlockTagsProvider extends BlockTagsProvider {
public final class BCBlockTagsProvider extends BlockTagsProvider {
public BCBlockTagsProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> lookupProvider, ExistingFileHelper existingFileHelper) {
super(output, lookupProvider, BibliocraftApi.MOD_ID, existingFileHelper);
}
Expand All @@ -22,6 +22,6 @@ protected void addTags(HolderLookup.Provider lookupProvider) {
BibliocraftApi.getDatagenHelper().generateBlockTags(this::tag);
tag(BCTags.Blocks.FANCY_ARMOR_STANDS).addTag(BCTags.Blocks.FANCY_ARMOR_STANDS_WOOD).add(BCBlocks.IRON_FANCY_ARMOR_STAND.get());
tag(BlockTags.MINEABLE_WITH_AXE).addTags(BCTags.Blocks.BOOKCASES, BCTags.Blocks.DISPLAY_CASES, BCTags.Blocks.FANCY_ARMOR_STANDS_WOOD, BCTags.Blocks.LABELS, BCTags.Blocks.POTION_SHELVES, BCTags.Blocks.SEATS, BCTags.Blocks.SHELVES, BCTags.Blocks.TOOL_RACKS);
tag(BlockTags.MINEABLE_WITH_PICKAXE).add(BCBlocks.COOKIE_JAR.get(), BCBlocks.DESK_BELL.get(), BCBlocks.IRON_FANCY_ARMOR_STAND.get(), BCBlocks.SWORD_PEDESTAL.get());
tag(BlockTags.MINEABLE_WITH_PICKAXE).add(BCBlocks.COOKIE_JAR.get(), BCBlocks.DESK_BELL.get(), BCBlocks.DINNER_PLATE.get(), BCBlocks.IRON_FANCY_ARMOR_STAND.get(), BCBlocks.SWORD_PEDESTAL.get());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.4 2024-04-07T17:24:56.0841489 Tags for minecraft:block mod id bibliocraft
// 1.20.4 2024-06-02T03:06:12.2634348 Tags for minecraft:block mod id bibliocraft
dc932537352be3adc3e92269d526190a3da02a50 data/bibliocraft/tags/blocks/bookcases.json
5a8af07da9101bc61f37664975dbd42ea97db36b data/bibliocraft/tags/blocks/display_cases.json
474090b2b5b40b58b63496e56ed06e543323d894 data/bibliocraft/tags/blocks/fancy_armor_stands.json
Expand All @@ -11,4 +11,4 @@ b36437d21d0432b2ab7edfd7edff70b4ffa6e53b data/bibliocraft/tags/blocks/shelves.js
70a350b86a4e5ad8cd8eb0f62e66e6b83e927781 data/bibliocraft/tags/blocks/tables.json
45344246afda217d9e4e32c8437cf25b49cf9e9d data/bibliocraft/tags/blocks/tool_racks.json
590462d66e70ff61bbd9051470046192d8fce7d3 data/minecraft/tags/blocks/mineable/axe.json
736ef038af594c3362df60ee22cf24f7c799c64f data/minecraft/tags/blocks/mineable/pickaxe.json
a7fbdbce035ee9426512338f93b27fda0b8a3d11 data/minecraft/tags/blocks/mineable/pickaxe.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"values": [
"bibliocraft:cookie_jar",
"bibliocraft:desk_bell",
"bibliocraft:dinner_plate",
"bibliocraft:iron_fancy_armor_stand",
"bibliocraft:sword_pedestal"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftApi;
import com.github.minecraftschurlimods.bibliocraft.client.ber.CookieJarBER;
import com.github.minecraftschurlimods.bibliocraft.client.ber.DinnerPlateBER;
import com.github.minecraftschurlimods.bibliocraft.client.ber.DisplayCaseBER;
import com.github.minecraftschurlimods.bibliocraft.client.ber.FancyArmorStandBER;
import com.github.minecraftschurlimods.bibliocraft.client.ber.LabelBER;
Expand Down Expand Up @@ -71,6 +72,7 @@ private static void registerRenderers(EntityRenderersEvent.RegisterRenderers eve
event.registerEntityRenderer(BCEntities.FANCY_ARMOR_STAND.get(), ArmorStandRenderer::new);
event.registerEntityRenderer(BCEntities.SEAT.get(), EmptyEntityRenderer::new);
event.registerBlockEntityRenderer(BCBlockEntities.COOKIE_JAR.get(), $ -> new CookieJarBER());
event.registerBlockEntityRenderer(BCBlockEntities.DINNER_PLATE.get(), $ -> new DinnerPlateBER());
event.registerBlockEntityRenderer(BCBlockEntities.DISPLAY_CASE.get(), $ -> new DisplayCaseBER());
event.registerBlockEntityRenderer(BCBlockEntities.FANCY_ARMOR_STAND.get(), $ -> new FancyArmorStandBER());
event.registerBlockEntityRenderer(BCBlockEntities.LABEL.get(), $ -> new LabelBER());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.github.minecraftschurlimods.bibliocraft.client.ber;

import com.github.minecraftschurlimods.bibliocraft.content.dinnerplate.DinnerPlateBlockEntity;
import com.github.minecraftschurlimods.bibliocraft.util.ClientUtil;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;

public class DinnerPlateBER implements BlockEntityRenderer<DinnerPlateBlockEntity> {
@Override
public void render(DinnerPlateBlockEntity blockEntity, float partialTick, PoseStack stack, MultiBufferSource buffer, int light, int overlay) {
stack.pushPose();
stack.translate(0.5, 0.0625, 0.5);
stack.mulPose(Axis.XP.rotationDegrees(90));
stack.scale(0.4375f, 0.4375f, 0.4375f);
ClientUtil.renderFixedItem(blockEntity.getItem(0), stack, buffer, light, overlay);
stack.popPose();
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
package com.github.minecraftschurlimods.bibliocraft.content.dinnerplate;

import com.github.minecraftschurlimods.bibliocraft.util.ShapeUtil;
import com.github.minecraftschurlimods.bibliocraft.util.content.BCEntityBlock;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ItemParticleOption;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.UseAnim;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.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.IntegerProperty;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
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.Nullable;

@SuppressWarnings("deprecation")
public class DinnerPlateBlock extends Block {
public class DinnerPlateBlock extends BCEntityBlock {
public static final IntegerProperty PROGRESS = IntegerProperty.create("progress", 0, 3);
public static final VoxelShape SHAPE = ShapeUtil.combine(
Shapes.box(0.25, 0, 0.3125, 0.75, 0.0625, 0.6875),
Shapes.box(0.1875, 0, 0.375, 0.25, 0.0625, 0.625),
Expand All @@ -30,10 +47,74 @@ public class DinnerPlateBlock extends Block {

public DinnerPlateBlock(Properties properties) {
super(properties);
registerDefaultState(getStateDefinition().any().setValue(WATERLOGGED, false).setValue(PROGRESS, 0));
}

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

@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new DinnerPlateBlockEntity(pos, state);
}

@Override
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
BlockState newState = state;
ItemStack stack = player.getItemInHand(hand);
BlockEntity blockEntity = level.getBlockEntity(pos);
if (!(blockEntity instanceof DinnerPlateBlockEntity plate))
return super.use(state, level, pos, player, hand, hit);
ItemStack slotStack = plate.getItem(0);
if (stack.getFoodProperties(player) != null) {
if (slotStack.isEmpty()) {
ItemStack foodStack = stack.copy();
foodStack.setCount(1);
plate.setItem(0, foodStack);
stack.shrink(1);
newState = newState.setValue(PROGRESS, 0);
} else {
newState = newState.setValue(PROGRESS, newState.getValue(PROGRESS) + 1);
triggerItemUseEffects(player, slotStack, 5);
}
} else {
newState = newState.setValue(PROGRESS, newState.getValue(PROGRESS) + 1);
triggerItemUseEffects(player, slotStack, 5);
}
if (newState.getValue(PROGRESS) == 3) {
newState = newState.setValue(PROGRESS, 0);
triggerItemUseEffects(player, slotStack, 16);
player.eat(level, slotStack);
plate.setItem(0, ItemStack.EMPTY);
}
level.setBlock(pos, newState, Block.UPDATE_ALL);
return InteractionResult.SUCCESS;
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(PROGRESS);
}

/**
* @see net.minecraft.world.entity.LivingEntity#triggerItemUseEffects(ItemStack, int)
*/
private void triggerItemUseEffects(Player player, ItemStack stack, int amount) {
if (stack.getUseAnimation() == UseAnim.DRINK) {
player.playSound(stack.getDrinkingSound(), 0.5f, player.level().random.nextFloat() * 0.1f + 0.9f);
}
if (stack.getUseAnimation() == UseAnim.EAT) {
RandomSource random = player.getRandom();
for (int i = 0; i < amount; ++i) {
Vec3 speed = new Vec3(((double) random.nextFloat() - 0.5) * 0.1, Math.random() * 0.1 + 0.1, 0).xRot(-player.getXRot() * (float) (Math.PI / 180)).yRot(-player.getYRot() * (float) (Math.PI / 180));
Vec3 pos = new Vec3(((double) random.nextFloat() - 0.5) * 0.3, (double) (-random.nextFloat()) * 0.6 - 0.3, 0.6).xRot(-player.getXRot() * (float) (Math.PI / 180)).yRot(-player.getYRot() * (float) (Math.PI / 180)).add(player.getX(), player.getEyeY(), player.getZ());
player.level().addParticle(new ItemParticleOption(ParticleTypes.ITEM, stack), pos.x, pos.y, pos.z, speed.x, speed.y + 0.05, speed.z);
}
player.playSound(player.getEatingSound(stack), 0.5f + 0.5f * (float) random.nextInt(2), (random.nextFloat() - random.nextFloat()) * 0.2f + 1f);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.github.minecraftschurlimods.bibliocraft.content.dinnerplate;

import com.github.minecraftschurlimods.bibliocraft.init.BCBlockEntities;
import com.github.minecraftschurlimods.bibliocraft.util.content.BCBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState;

public class DinnerPlateBlockEntity extends BCBlockEntity {
public DinnerPlateBlockEntity(BlockPos pos, BlockState state) {
super(BCBlockEntities.DINNER_PLATE.get(), 1, pos, state);
}

@Override
public boolean canPlaceItem(int slot, ItemStack stack) {
return stack.getItem().getFoodProperties(stack, null) != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.minecraftschurlimods.bibliocraft.content.bookcase.BookcaseBlockEntity;
import com.github.minecraftschurlimods.bibliocraft.content.cookiejar.CookieJarBlockEntity;
import com.github.minecraftschurlimods.bibliocraft.content.dinnerplate.DinnerPlateBlockEntity;
import com.github.minecraftschurlimods.bibliocraft.content.displaycase.DisplayCaseBlockEntity;
import com.github.minecraftschurlimods.bibliocraft.content.fancyarmorstand.FancyArmorStandBlockEntity;
import com.github.minecraftschurlimods.bibliocraft.content.label.LabelBlockEntity;
Expand All @@ -22,6 +23,7 @@
public interface BCBlockEntities {
Supplier<BlockEntityType<BookcaseBlockEntity>> BOOKCASE = register("bookcase", BookcaseBlockEntity::new, BCBlocks.BOOKCASE.holders());
Supplier<BlockEntityType<CookieJarBlockEntity>> COOKIE_JAR = register("cookie_jar", CookieJarBlockEntity::new, BCBlocks.COOKIE_JAR);
Supplier<BlockEntityType<DinnerPlateBlockEntity>> DINNER_PLATE = register("dinner_plate", DinnerPlateBlockEntity::new, BCBlocks.DINNER_PLATE);
Supplier<BlockEntityType<DisplayCaseBlockEntity>> DISPLAY_CASE = register("display_case", DisplayCaseBlockEntity::new, BCUtil.mergeRaw(BCBlocks.DISPLAY_CASE.holders(), BCBlocks.WALL_DISPLAY_CASE.holders()));
Supplier<BlockEntityType<FancyArmorStandBlockEntity>> FANCY_ARMOR_STAND = register("fancy_armor_stand", FancyArmorStandBlockEntity::new, BCUtil.merge(BCBlocks.FANCY_ARMOR_STAND.holders(), BCBlocks.IRON_FANCY_ARMOR_STAND));
Supplier<BlockEntityType<LabelBlockEntity>> LABEL = register("label", LabelBlockEntity::new, BCBlocks.LABEL.holders());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Utility class holding various helper methods. Kept separate from {@link BCUtil} for classloading reasons.
*/
public class ClientUtil {
public final class ClientUtil {
/**
* Opens a {@link ClipboardScreen} on the client.
*
Expand Down

0 comments on commit 0fd6d52

Please sign in to comment.