Skip to content

Commit

Permalink
bookcase model and shape
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabeHunger54 committed Nov 22, 2023
1 parent d5767dc commit b13eaf6
Show file tree
Hide file tree
Showing 19 changed files with 440 additions and 10 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ tasks.withType(ProcessResources).configureEach {
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}

processResources {
exclude '**.bbmodel'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// 1.20.2 2023-11-22T00:19:22.115925 Item Models: bibliocraft
3018c76a3e657cac2cad157f27ccf08a59c0298c assets/bibliocraft/models/item/bookcase.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.20.2 2023-11-20T00:28:31.9668292 Languages: en_us
65c47d4769f2f8bb084ac170910d820ce7ce68d0 assets/bibliocraft/lang/en_us.json
// 1.20.2 2023-11-22T00:19:22.1200511 Languages: en_us
9da1efd79dd924566c3065f8004a268d7ceafb32 assets/bibliocraft/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// 1.20.2 2023-11-22T01:55:15.7354547 Block States: bibliocraft
99446d42e0f41275c3ef8ddcf75356e8c8b4278a assets/bibliocraft/blockstates/bookcase.json
028b6953729c8c439a526fbaeb1d45c5231ef865 assets/bibliocraft/models/block/oak_bookcase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"variants": {
"facing=east,waterlogged=false": {
"model": "bibliocraft:block/oak_bookcase",
"uvlock": true,
"y": 90
},
"facing=east,waterlogged=true": {
"model": "bibliocraft:block/oak_bookcase",
"uvlock": true,
"y": 90
},
"facing=north,waterlogged=false": {
"model": "bibliocraft:block/oak_bookcase",
"uvlock": true
},
"facing=north,waterlogged=true": {
"model": "bibliocraft:block/oak_bookcase",
"uvlock": true
},
"facing=south,waterlogged=false": {
"model": "bibliocraft:block/oak_bookcase",
"uvlock": true,
"y": 180
},
"facing=south,waterlogged=true": {
"model": "bibliocraft:block/oak_bookcase",
"uvlock": true,
"y": 180
},
"facing=west,waterlogged=false": {
"model": "bibliocraft:block/oak_bookcase",
"uvlock": true,
"y": 270
},
"facing=west,waterlogged=true": {
"model": "bibliocraft:block/oak_bookcase",
"uvlock": true,
"y": 270
}
}
}
2 changes: 1 addition & 1 deletion src/generated/resources/assets/bibliocraft/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"block.bibliocraft.bookcase": "bookcase",
"block.bibliocraft.bookcase": "Bookcase",
"container.bibliocraft.bookcase": "Bookcase"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "bibliocraft:block/bookcase",
"textures": {
"texture": "minecraft:block/oak_planks"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "bibliocraft:block/oak_bookcase"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import net.minecraft.world.InteractionResult;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.world.level.block.state.BlockState;
Expand Down Expand Up @@ -48,6 +50,16 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
builder.add(FACING, WATERLOGGED);
}

@Override
public BlockState getStateForPlacement(BlockPlaceContext p_52501_) {
return this.defaultBlockState().setValue(FACING, p_52501_.getHorizontalDirection().getOpposite());
}

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

@Override
public PushReaction getPistonPushReaction(BlockState state) {
return PushReaction.BLOCK;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
package com.github.minecraftschurlimods.bibliocraft.block.bookcase;

import com.github.minecraftschurlimods.bibliocraft.block.BCBlock;
import com.github.minecraftschurlimods.bibliocraft.util.ShapeUtil;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
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 BookcaseBlock extends BCBlock {
private static final VoxelShape NORTH_SHAPE = ShapeUtil.combine(
Shapes.box(0.0625, 0, 0.5, 0.9375, 0.0625, 0.9375),
Shapes.box(0, 0, 0.9375, 1, 1, 1),
Shapes.box(0.0625, 0.9375, 0.5, 0.9375, 1, 0.9375),
Shapes.box(0.0625, 0.4375, 0.5, 0.9375, 0.5625, 0.9375),
Shapes.box(0.9375, 0, 0.5, 1, 1, 0.9375),
Shapes.box(0, 0, 0.5, 0.0625, 1, 0.9375));
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 BookcaseBlock(Properties properties) {
super(properties);
}
Expand All @@ -16,4 +34,14 @@ public BookcaseBlock(Properties properties) {
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new BookcaseBlockEntity(pos, state);
}

@Override
public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return switch (state.getValue(FACING)) {
default -> NORTH_SHAPE;
case EAST -> EAST_SHAPE;
case SOUTH -> SOUTH_SHAPE;
case WEST -> WEST_SHAPE;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ static void clientSetup(FMLClientSetupEvent event) {
MenuScreens.register(BCMenuTypes.BOOKCASE.get(), BookcaseScreen::new);
}
}

/*
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, modid = Bibliocraft.MOD_ID)
public static final class NeoBus {
}
*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.github.minecraftschurlimods.bibliocraft.datagen;

import com.github.minecraftschurlimods.bibliocraft.Bibliocraft;
import com.github.minecraftschurlimods.bibliocraft.init.BCBlocks;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.neoforged.neoforge.client.model.generators.BlockStateProvider;
import net.neoforged.neoforge.client.model.generators.ConfiguredModel;
import net.neoforged.neoforge.client.model.generators.ModelFile;
import net.neoforged.neoforge.common.data.ExistingFileHelper;

import java.util.function.Supplier;

public class BCBlockStateProvider extends BlockStateProvider {
public BCBlockStateProvider(PackOutput output, ExistingFileHelper exFileHelper) {
super(output, Bibliocraft.MOD_ID, exFileHelper);
}

@Override
protected void registerStatesAndModels() {
horizontalBlock(BCBlocks.BOOKCASE, "oak_bookcase", modLoc("bookcase"), mcLoc("block/oak_planks"));
}

private void horizontalBlock(Supplier<? extends Block> block, String name, ResourceLocation parent, ResourceLocation texture) {
ModelFile model = models().withExistingParent(name, parent).texture("texture", texture);
getVariantBuilder(block.get()).forAllStates(state -> ConfiguredModel.builder()
.modelFile(model)
.rotationY(((int) state.getValue(BlockStateProperties.HORIZONTAL_FACING).toYRot() + 180) % 360)
.uvLock(true)
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, modid = Bibliocraft.MOD_ID)
Expand All @@ -13,6 +14,9 @@ public final class BCDatagen {
static void gatherData(GatherDataEvent event) {
DataGenerator generator = event.getGenerator();
PackOutput output = generator.getPackOutput();
ExistingFileHelper existingFileHelper = event.getExistingFileHelper();
generator.addProvider(event.includeClient(), new BCEnglishLanguageProvider(output));
generator.addProvider(event.includeClient(), new BCBlockStateProvider(output, existingFileHelper));
generator.addProvider(event.includeClient(), new BCItemModelProvider(output, existingFileHelper));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.github.minecraftschurlimods.bibliocraft.datagen;

import com.github.minecraftschurlimods.bibliocraft.Bibliocraft;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.neoforge.client.model.generators.ItemModelProvider;
import net.neoforged.neoforge.common.data.ExistingFileHelper;

public class BCItemModelProvider extends ItemModelProvider {
public BCItemModelProvider(PackOutput output, ExistingFileHelper existingFileHelper) {
super(output, Bibliocraft.MOD_ID, existingFileHelper);
}

@Override
protected void registerModels() {
withExistingParent("bookcase", new ResourceLocation(Bibliocraft.MOD_ID, "block/oak_bookcase"));
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.github.minecraftschurlimods.bibliocraft.handler;

import com.github.minecraftschurlimods.bibliocraft.Bibliocraft;
import net.neoforged.fml.common.Mod;

public final class EventHandler {
/*
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, modid = Bibliocraft.MOD_ID)
public static final class ModBus {
}
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, modid = Bibliocraft.MOD_ID)
public static final class NeoBus {
}
*/
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.github.minecraftschurlimods.bibliocraft.init;

import com.github.minecraftschurlimods.bibliocraft.block.bookcase.BookcaseBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.neoforged.neoforge.registries.DeferredHolder;

import java.util.function.Supplier;

public interface BCBlocks {
DeferredHolder<Block, BookcaseBlock> BOOKCASE = BCRegistries.BLOCKS.register("bookcase", () -> new BookcaseBlock(BlockBehaviour.Properties.copy(Blocks.OAK_PLANKS)));
Supplier<BookcaseBlock> BOOKCASE = BCRegistries.BLOCKS.register("bookcase", () -> new BookcaseBlock(BlockBehaviour.Properties.copy(Blocks.OAK_PLANKS).noOcclusion()));
//TODO Clock
//TODO Cookie Jar
//TODO Desk
Expand Down
Loading

0 comments on commit b13eaf6

Please sign in to comment.