Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Minecraftschurli committed Jun 14, 2024
1 parent 851f19e commit 1459d29
Show file tree
Hide file tree
Showing 26 changed files with 224 additions and 58 deletions.
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pluginManagement {
plugins {
id("net.neoforged.gradle.userdev") version "7.0.+"
id("net.neoforged.gradle.userdev") version "7.0.133"
id("com.github.minecraftschurlimods.helperplugin") version "1.13"
}
repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,51 @@
import com.github.minecraftschurlimods.bibliocraft.datagen.data.BCItemTagsProvider;
import com.github.minecraftschurlimods.bibliocraft.datagen.data.BCLootTableProvider;
import com.github.minecraftschurlimods.bibliocraft.datagen.data.BCRecipeProvider;
import com.mojang.datafixers.util.Function4;
import net.minecraft.core.HolderLookup;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.DataProvider;
import net.minecraft.data.PackOutput;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.common.data.ExistingFileHelper;
import net.neoforged.neoforge.data.event.GatherDataEvent;
import org.apache.commons.lang3.function.TriFunction;

import java.util.concurrent.CompletableFuture;
import java.util.function.BiFunction;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, modid = BibliocraftApi.MOD_ID)
public final class BCDatagen {
@SubscribeEvent
private static void gatherData(GatherDataEvent event) {
DataGenerator generator = event.getGenerator();
PackOutput output = generator.getPackOutput();
ExistingFileHelper existingFileHelper = event.getExistingFileHelper();
CompletableFuture<HolderLookup.Provider> lookupProvider = event.getLookupProvider();
BibliocraftApi.getDatagenHelper().addWoodTypesToGenerateByModid("minecraft");
DataGenerator.PackGenerator client = generator.getVanillaPack(event.includeClient());
DataGenerator.PackGenerator server = generator.getVanillaPack(event.includeServer());

generator.addProvider(event.includeClient(), new BCEnglishLanguageProvider(output));
generator.addProvider(event.includeClient(), new BCBlockStateProvider(output, existingFileHelper));
generator.addProvider(event.includeClient(), new BCItemModelProvider(output, existingFileHelper));
generator.addProvider(event.includeClient(), new BCSoundDefinitionsProvider(output, existingFileHelper));
client.addProvider(BCEnglishLanguageProvider::new);
client.addProvider(wrapWith(BCBlockStateProvider::new, existingFileHelper));
client.addProvider(wrapWith(BCItemModelProvider::new, existingFileHelper));
client.addProvider(wrapWith(BCSoundDefinitionsProvider::new, existingFileHelper));

generator.addProvider(event.includeServer(), new BCLootTableProvider(output));
generator.addProvider(event.includeServer(), new BCRecipeProvider(output));
BCBlockTagsProvider blockTags = generator.addProvider(event.includeServer(), new BCBlockTagsProvider(output, lookupProvider, existingFileHelper));
generator.addProvider(event.includeServer(), new BCItemTagsProvider(output, lookupProvider, blockTags.contentsGetter(), existingFileHelper));
server.addProvider(BCLootTableProvider::new);
server.addProvider(BCRecipeProvider::new);
BCBlockTagsProvider blockTags = server.addProvider(wrapWith(BCBlockTagsProvider::new, lookupProvider, existingFileHelper));
server.addProvider(wrapWith(BCItemTagsProvider::new, lookupProvider, blockTags.contentsGetter(), existingFileHelper));
}

private static <T extends DataProvider, S> DataProvider.Factory<T> wrapWith(BiFunction<PackOutput, S, T> factory, S s) {
return (output) -> factory.apply(output, s);
}

private static <T extends DataProvider, S, U> DataProvider.Factory<T> wrapWith(TriFunction<PackOutput, S, U, T> factory, S s, U u) {
return (output) -> factory.apply(output, s, u);
}

private static <T extends DataProvider, S, U, V> DataProvider.Factory<T> wrapWith(Function4<PackOutput, S, U, V, T> factory, S s, U u, V v) {
return (output) -> factory.apply(output, s, u, v);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.neoforged.fml.ModList;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.FMLConstructModEvent;
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;
import net.neoforged.neoforge.event.entity.EntityAttributeCreationEvent;
import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent;

Expand Down Expand Up @@ -58,6 +59,11 @@ private static void registerBibliocraftWoodTypes(RegisterBibliocraftWoodTypesEve
registerVanilla(event, WoodType.CHERRY, Blocks.CHERRY_PLANKS, BlockFamilies.CHERRY_PLANKS);
}

@SubscribeEvent
private static void registerCapabilities(RegisterCapabilitiesEvent event) {
//event.registerBlockEntity(Capabilities.ItemHandler.BLOCK, BCBlockEntities.BOOKCASE.get(), (be, dir) -> be.getBlockState().getValue(BookcaseBlock.FACING) != dir ? new InvWrapper(be) : null);
}

/**
* Private helper for registering the vanilla variants.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.minecraftschurlimods.bibliocraft.util.ShapeUtil;
import com.github.minecraftschurlimods.bibliocraft.util.content.BCFacingEntityBlock;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
Expand All @@ -25,11 +26,17 @@ public class BookcaseBlock extends BCFacingEntityBlock {
private static final VoxelShape EAST_SHAPE = ShapeUtil.rotate(NORTH_SHAPE, Rotation.CLOCKWISE_90);
private static final VoxelShape SOUTH_SHAPE = ShapeUtil.rotate(NORTH_SHAPE, Rotation.CLOCKWISE_180);
private static final VoxelShape WEST_SHAPE = ShapeUtil.rotate(NORTH_SHAPE, Rotation.COUNTERCLOCKWISE_90);
public static final MapCodec<BookcaseBlock> CODEC = simpleCodec(BookcaseBlock::new);

public BookcaseBlock(Properties properties) {
super(properties);
}

@Override
protected MapCodec<BookcaseBlock> codec() {
return CODEC;
}

@Override
@Nullable
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public BookcaseBlockEntity(BlockPos pos, BlockState state) {
super(BCBlockEntities.BOOKCASE.get(), 16, defaultName("bookcase"), pos, state);
}

@Override
public void setChanged() {
super.setChanged();
requestModelDataUpdate();
}

@Override
public AbstractContainerMenu createMenu(int id, Inventory inventory) {
return new BookcaseMenu(id, inventory, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;

import java.util.Objects;

public class ClipboardItem extends Item {
public ClipboardItem() {
super(new Properties().stacksTo(1));
Expand All @@ -28,8 +26,7 @@ public InteractionResultHolder<ItemStack> use(Level level, Player player, Intera

@Override
public InteractionResult useOn(UseOnContext context) {
Player player = Objects.requireNonNull(context.getPlayer());
if (player.isSecondaryUseActive()) {
if (context.getPlayer() != null && context.getPlayer().isSecondaryUseActive()) {
// TODO place block
}
return super.useOn(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.minecraftschurlimods.bibliocraft.util.ShapeUtil;
import com.github.minecraftschurlimods.bibliocraft.util.content.BCEntityBlock;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
Expand All @@ -24,12 +25,18 @@ public class CookieJarBlock extends BCEntityBlock {
Shapes.box(0.25, 0.625, 0.25, 0.75, 0.75, 0.75));
private static final VoxelShape CLOSED_SHAPE = ShapeUtil.combine(OPEN_SHAPE,
Shapes.box(0.1875, 0.75, 0.1875, 0.8125, 0.875, 0.8125));
public static final MapCodec<CookieJarBlock> CODEC = simpleCodec(CookieJarBlock::new);

public CookieJarBlock(Properties properties) {
super(properties);
registerDefaultState(getStateDefinition().any().setValue(OPEN, false).setValue(WATERLOGGED, false));
}

@Override
protected MapCodec<CookieJarBlock> codec() {
return CODEC;
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.github.minecraftschurlimods.bibliocraft.content;
package com.github.minecraftschurlimods.bibliocraft.content.deskbell;

import com.github.minecraftschurlimods.bibliocraft.init.BCSoundEvents;
import com.github.minecraftschurlimods.bibliocraft.util.ShapeUtil;
import com.github.minecraftschurlimods.bibliocraft.util.content.BCWaterloggedBlock;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
Expand All @@ -16,6 +19,7 @@
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 DeskBellBlock extends BCWaterloggedBlock {
Expand All @@ -27,10 +31,22 @@ public class DeskBellBlock extends BCWaterloggedBlock {
Shapes.box(0.34375, 0, 0.40625, 0.375, 0.09375, 0.59375),
Shapes.box(0.625, 0, 0.40625, 0.65625, 0.09375, 0.59375),
Shapes.box(0.484375, 0.15625, 0.484375, 0.515625, 0.171875, 0.515625),
Shapes.box(0.46875, 0.171875, 0.46875, 0.53125, 0.203125, 0.53125));
Shapes.box(0.46875, 0.171875, 0.46875, 0.53125, 0.203125, 0.53125)
);
public static final MapCodec<DeskBellBlock> CODEC = RecordCodecBuilder.mapCodec(inst -> inst.group(
SoundEvent.CODEC.fieldOf("ding_sound").forGetter(b -> b.ding),
propertiesCodec()
).apply(inst, DeskBellBlock::new));
private final Holder<SoundEvent> ding;

public DeskBellBlock(Properties properties) {
public DeskBellBlock(Holder<SoundEvent> ding, Properties properties) {
super(properties);
this.ding = ding;
}

@Override
protected MapCodec<? extends Block> codec() {
return CODEC;
}

@Override
Expand All @@ -42,17 +58,20 @@ public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos,
public void neighborChanged(BlockState state, Level level, BlockPos pos, Block neighborBlock, BlockPos neighborPos, boolean movedByPiston) {
super.neighborChanged(state, level, pos, neighborBlock, neighborPos, movedByPiston);
if (!level.isClientSide() && level.hasNeighborSignal(pos.below())) {
playSound(level, pos);
ding(level, pos, null);
}
}

@Override
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
playSound(level, pos);
if (player.isSecondaryUseActive()) {
return InteractionResult.PASS;
}
ding(level, pos, player);
return InteractionResult.SUCCESS;
}

private void playSound(Level level, BlockPos pos) {
level.playSound(null, pos, BCSoundEvents.DESK_BELL.get(), SoundSource.BLOCKS, 1, 1);
private void ding(Level level, BlockPos pos, @Nullable Player player) {
level.playSound(player, pos, ding.value(), SoundSource.BLOCKS);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
package com.github.minecraftschurlimods.bibliocraft.content.deskbell;

import net.minecraft.MethodsReturnNonnullByDefault;

import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import com.github.minecraftschurlimods.bibliocraft.util.ShapeUtil;
import com.github.minecraftschurlimods.bibliocraft.util.content.BCEntityBlock;
import com.mojang.serialization.MapCodec;
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.ItemInteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.UseAnim;
Expand Down Expand Up @@ -44,12 +45,18 @@ public class DinnerPlateBlock extends BCEntityBlock {
Shapes.box(0.65625, 0.03125, 0.59375, 0.71875, 0.09375, 0.65625),
Shapes.box(0.28125, 0.03125, 0.65625, 0.40625, 0.09375, 0.71875),
Shapes.box(0.28125, 0.03125, 0.59375, 0.34375, 0.09375, 0.65625));
public static final MapCodec<DinnerPlateBlock> CODEC = simpleCodec(DinnerPlateBlock::new);

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

@Override
protected MapCodec<DinnerPlateBlock> codec() {
return CODEC;
}

@Override
public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) {
return SHAPE;
Expand All @@ -62,12 +69,11 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
}

@Override
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
protected ItemInteractionResult useItemOn(ItemStack stack, 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);
return super.useItemOn(stack, state, level, pos, player, hand, hit);
ItemStack slotStack = plate.getItem(0);
if (stack.getFoodProperties(player) != null) {
if (slotStack.isEmpty()) {
Expand All @@ -91,7 +97,7 @@ public InteractionResult use(BlockState state, Level level, BlockPos pos, Player
plate.setItem(0, ItemStack.EMPTY);
}
level.setBlock(pos, newState, Block.UPDATE_ALL);
return InteractionResult.SUCCESS;
return ItemInteractionResult.SUCCESS;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.minecraftschurlimods.bibliocraft.content.displaycase;

import com.github.minecraftschurlimods.bibliocraft.util.ShapeUtil;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.BlockGetter;
Expand All @@ -14,11 +15,17 @@
public class DisplayCaseBlock extends AbstractDisplayCaseBlock {
private static final VoxelShape Z_SHAPE = Shapes.box(0.0625, 0, 0, 0.9375, 0.5, 1);
private static final VoxelShape X_SHAPE = ShapeUtil.rotate(Z_SHAPE, Rotation.CLOCKWISE_90);
public static final MapCodec<DisplayCaseBlock> CODEC = simpleCodec(DisplayCaseBlock::new);

public DisplayCaseBlock(Properties properties) {
super(properties);
}

@Override
protected MapCodec<DisplayCaseBlock> codec() {
return CODEC;
}

@Override
protected boolean canAccessFromDirection(BlockState state, Direction direction) {
return direction == Direction.UP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftWoodType;
import com.github.minecraftschurlimods.bibliocraft.init.BCItems;
import com.github.minecraftschurlimods.bibliocraft.util.ShapeUtil;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.player.Player;
Expand All @@ -24,6 +25,7 @@ public class WallDisplayCaseBlock extends AbstractDisplayCaseBlock {
private static final VoxelShape EAST_SHAPE = ShapeUtil.rotate(NORTH_SHAPE, Rotation.CLOCKWISE_90);
private static final VoxelShape SOUTH_SHAPE = ShapeUtil.rotate(NORTH_SHAPE, Rotation.CLOCKWISE_180);
private static final VoxelShape WEST_SHAPE = ShapeUtil.rotate(NORTH_SHAPE, Rotation.COUNTERCLOCKWISE_90);
public static final MapCodec<WallDisplayCaseBlock> CODEC = simpleCodec(WallDisplayCaseBlock::new);
private final BibliocraftWoodType woodType;
private final DyeColor color;

Expand All @@ -37,6 +39,11 @@ public WallDisplayCaseBlock(Properties properties, @Nullable BibliocraftWoodType
this.color = color;
}

@Override
protected MapCodec<WallDisplayCaseBlock> codec() {
return CODEC;
}

@Override
protected boolean canAccessFromDirection(BlockState state, Direction direction) {
return state.getValue(FACING) == direction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.minecraftschurlimods.bibliocraft.util.ShapeUtil;
import com.github.minecraftschurlimods.bibliocraft.util.content.BCBlockEntity;
import com.github.minecraftschurlimods.bibliocraft.util.content.BCFacingInteractibleBlock;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.sounds.SoundSource;
Expand Down Expand Up @@ -44,13 +45,19 @@ public class FancyArmorStandBlock extends BCFacingInteractibleBlock {
Shapes.box(0.0625, 0.125, 0.375, 0.9375, 0.5, 0.625));
private static final VoxelShape X_SHAPE_BOTTOM = ShapeUtil.rotate(Z_SHAPE_BOTTOM, Rotation.CLOCKWISE_90);
private static final VoxelShape X_SHAPE_TOP = ShapeUtil.rotate(Z_SHAPE_TOP, Rotation.CLOCKWISE_90);
public static final MapCodec<FancyArmorStandBlock> CODEC = simpleCodec(FancyArmorStandBlock::new);
public static final EnumProperty<DoubleBlockHalf> HALF = BlockStateProperties.DOUBLE_BLOCK_HALF;

public FancyArmorStandBlock(Properties properties) {
super(properties);
registerDefaultState(getStateDefinition().any().setValue(FACING, Direction.NORTH).setValue(WATERLOGGED, false).setValue(HALF, DoubleBlockHalf.LOWER));
}

@Override
protected MapCodec<FancyArmorStandBlock> codec() {
return CODEC;
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
Expand Down
Loading

0 comments on commit 1459d29

Please sign in to comment.