Skip to content

Commit

Permalink
Breaking changes are breaking
Browse files Browse the repository at this point in the history
Good job no one uses this yet :)
Builder now has a generic to create any blocktype using the builder parameters. Very useful for building BlockEntities.
All Metro blocks are now abstract as a side effect of this. Anything extending a decorative block must remain abstract and be created using the builder instead - this is for the helper system to work.

Also added BlockEntities in (first pass, will probably change)
  • Loading branch information
Fureniku committed Jan 11, 2024
1 parent 858877e commit 0f0e296
Show file tree
Hide file tree
Showing 19 changed files with 205 additions and 225 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"multipart": [
{
"apply": {
"model": "metropolis:block/test_block_entity_decorative_standard"
}
},
{
"apply": {
"model": "metropolis:block/test_block_entity_decorative_connection",
"uvlock": true
},
"when": {
"north": "true"
}
},
{
"apply": {
"model": "metropolis:block/test_block_entity_decorative_connection",
"uvlock": true,
"y": 180
},
"when": {
"south": "true"
}
},
{
"apply": {
"model": "metropolis:block/test_block_entity_decorative_connection",
"uvlock": true,
"y": 270
},
"when": {
"west": "true"
}
},
{
"apply": {
"model": "metropolis:block/test_block_entity_decorative_connection",
"uvlock": true,
"y": 90
},
"when": {
"east": "true"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "metropolis:blocks/decorative/barrier_concrete_middle",
"textures": {
"texture": "metropolis:block/test_texture_1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "metropolis:blocks/decorative/barrier_concrete_middle_connection",
"textures": {
"texture": "metropolis:block/test_texture_1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "metropolis:blocks/decorative/barrier_concrete_middle",
"textures": {
"texture": "metropolis:block/test_texture_1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "metropolis:block/test_block_entity_decorative_standard"
}
14 changes: 12 additions & 2 deletions src/main/java/com/fureniku/metropolis/RegistrationBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public abstract class RegistrationBase {
protected final DeferredRegister<Block> blockRegistry;
protected final DeferredRegister<Item> itemRegistry;
protected final DeferredRegister<CreativeModeTab> creativeTabs;
protected static final DeferredRegister<BlockEntityType<?>> blockEntityRegistry = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, Metropolis.MODID);
protected final DeferredRegister<BlockEntityType<?>> blockEntityRegistry;

/**
* Used by registration groups
Expand All @@ -57,7 +57,7 @@ public RegistrationBase(String modid, IEventBus modEventBus) {
blockRegistry = DeferredRegister.create(ForgeRegistries.BLOCKS, modid);
itemRegistry = DeferredRegister.create(ForgeRegistries.ITEMS, modid);
creativeTabs = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, modid);
//blockEntityRegistry = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, modid);
blockEntityRegistry = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, modid);
modEventBus.addListener(this::common);
modEventBus.addListener(this::client);
modEventBus.addListener(this::buildCreativeTabs);
Expand Down Expand Up @@ -153,6 +153,16 @@ public <T extends MetroBlockEntity> RegistryObject<BlockEntityType<T>> registerB
return blockEntityRegistry.register(name, () -> BlockEntityType.Builder.of(blockEntity, validBlocks).build(null));
}

public <T extends MetroBlockEntity> RegistryObject<BlockEntityType<T>> registerBlockEntityWithBlock(String name, Supplier<Block> blockClass, BlockEntityType.BlockEntitySupplier<T> blockEntity) {
RegistryObject<Block> block = blockRegistry.register(name, blockClass);
RegistryObject<Item> blockItem = itemRegistry.register(name, () -> new BlockItem(block.get(), new Item.Properties()));

addBlock(name, block);
addItem(name, blockItem);

return blockEntityRegistry.register(name + "_entity", () -> BlockEntityType.Builder.of(blockEntity, block.get()).build(null));
}

/**
* Add all your blocks to the created creative tabs in here!
* <p>It may be neater to create a function for each tab, and call those functions from here.</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
package com.fureniku.metropolis.blockentity;

import com.fureniku.metropolis.Metropolis;
import com.fureniku.metropolis.test.RegistrationTest;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;

public class MetroBlockEntity extends BlockEntity {

private BlockEntityType _type;

public MetroBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
}

public MetroBlockEntity(BlockPos pos, BlockState state) {
super(Metropolis.registrationTest.TEST_BLOCK_ENTITY_DECORATIVE_ENTITY.get(), pos, state);
}

public BlockEntityType getBlockEntityType() {
return null;
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
package com.fureniku.metropolis.blocks.decorative;

import com.fureniku.metropolis.Metropolis;
import com.fureniku.metropolis.blockentity.MetroEntityBlockDecorative;
import com.fureniku.metropolis.blocks.IToggleable;
import com.fureniku.metropolis.blocks.MetroBlockBase;
import com.fureniku.metropolis.blocks.decorative.builders.MetroBlockDecorativeBuilder;
import com.fureniku.metropolis.blocks.decorative.helpers.*;
import com.fureniku.metropolis.datagen.MetroBlockStateProvider;
import com.fureniku.metropolis.datagen.TextureSet;
import com.fureniku.metropolis.enums.BlockOffsetDirection;
import com.fureniku.metropolis.enums.ToggleType;
import com.fureniku.metropolis.utils.Debug;
import com.fureniku.metropolis.utils.SimpleUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.context.BlockPlaceContext;
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.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.StateHolder;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.neoforged.neoforge.client.model.generators.BlockModelBuilder;
Expand All @@ -34,42 +25,41 @@
import java.util.Arrays;
import java.util.Optional;

public abstract class MetroBlockDecorative extends MetroBlockBase implements IToggleable {
/**
* All children of this need to be abstract, in order for the helper system to work.
* Abstract classes are made using MetroBlockDecorativeBuilder{@literal <ClassName>}.build()
*/
public abstract class MetroBlockDecorativeBase extends MetroBlockBase implements IToggleable {

private final VoxelShape BLOCK_SHAPE;
protected TextureSet[] _resources;
protected String _modelName;
protected String _modelDir;

private RotationHelper _rotationHelper;
private ToggleHelper _toggleHelper;
private ConnectHorizontalHelper _connectHorizontalHelper;
private OffsetHelper _offsetHelper;
protected RotationHelper _rotationHelper;
protected ToggleHelper _toggleHelper;
protected ConnectHorizontalHelper _connectHorizontalHelper;
protected OffsetHelper _offsetHelper;

private boolean _baseInitialized = false;

public MetroBlockDecorative(Properties props, VoxelShape shape, String modelDir, String modelName, String tag, boolean dynamicShape, TextureSet... textures) {
public MetroBlockDecorativeBase(Properties props, VoxelShape shape, String modelDir, String modelName, String tag, boolean dynamicShape, TextureSet... textures) {
super(dynamicShape ? props.dynamicShape() : props);
setupHelpers(getHelpers());
_baseInitialized = true;
BLOCK_SHAPE = shape != null ? shape : Block.box(0, 0, 0, 16, 16, 16);
_resources = textures;
_modelDir = modelDir;
_modelName = modelName;

//BlockState stateHolder = ;
setTag(tag);

this.registerDefaultState(this.getStateDefinition().any().setValue(ConnectHorizontalHelper.NORTH, false).setValue(ConnectHorizontalHelper.EAST, false).setValue(ConnectHorizontalHelper.SOUTH, false).setValue(ConnectHorizontalHelper.WEST, false));
}

@FunctionalInterface
public interface MetroBlockStateFactory {
MetroBlockDecorative makeBlock(Properties props, VoxelShape shape, String modelDir, String modelName, String tag, boolean dynamicShape, TextureSet... textures);
public interface MetroBlockStateFactory<T> {
T makeBlock(Properties props, VoxelShape shape, String modelDir, String modelName, String tag, boolean dynamicShape, TextureSet... textures);
}

public static MetroBlockStateFactory getBlockFactory(HelperBase... helpersIn) {
return (props, shape, modelDir, modelName, tag, dynamicShape, textures) -> new MetroBlockDecorative(props, shape, modelDir, modelName, tag, SimpleUtils.containsType(OffsetHelper.class, helpersIn), textures) {
return (props, shape, modelDir, modelName, tag, dynamicShape, textures) -> new MetroEntityBlockDecorative(props, shape, modelDir, modelName, tag, SimpleUtils.containsType(OffsetHelper.class, helpersIn), textures) {
@Override
public ArrayList<HelperBase> getHelpers() {
return new ArrayList<>(Arrays.asList(helpersIn));
Expand All @@ -81,7 +71,6 @@ public ArrayList<HelperBase> getHelpers() {

public void setupHelpers(ArrayList<HelperBase> helpers) {
for (int i = 0; i < helpers.size(); i++) {
//stateHolder = _helpers.get(i).setDefaultState(stateHolder);
assignHelper(helpers.get(i));
}
_helpers = helpers;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.fureniku.metropolis.blocks.decorative;

import com.fureniku.metropolis.blockentity.MetroBlockEntity;
import com.fureniku.metropolis.blocks.IToggleable;
import com.fureniku.metropolis.blocks.decorative.helpers.HelperBase;
import com.fureniku.metropolis.blocks.decorative.helpers.OffsetHelper;
import com.fureniku.metropolis.datagen.TextureSet;
import com.fureniku.metropolis.utils.SimpleUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Arrays;

public abstract class MetroEntityBlockDecorative extends MetroBlockDecorativeBase implements IToggleable, EntityBlock {

public MetroEntityBlockDecorative(Properties props, VoxelShape shape, String modelDir, String modelName, String tag, boolean dynamicShape, TextureSet... textures) {
super(props, shape, modelDir, modelName, tag, dynamicShape, textures);
}

@Nullable
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new MetroBlockEntity(pos, state);
}

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

0 comments on commit 0f0e296

Please sign in to comment.