diff --git a/src/generated/resources/assets/metropolis/blockstates/test_block_entity_decorative.json b/src/generated/resources/assets/metropolis/blockstates/test_block_entity_decorative.json new file mode 100644 index 0000000..88f3450 --- /dev/null +++ b/src/generated/resources/assets/metropolis/blockstates/test_block_entity_decorative.json @@ -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" + } + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/assets/metropolis/models/block/test_block_entity_decorative.json b/src/generated/resources/assets/metropolis/models/block/test_block_entity_decorative.json new file mode 100644 index 0000000..cf28b1a --- /dev/null +++ b/src/generated/resources/assets/metropolis/models/block/test_block_entity_decorative.json @@ -0,0 +1,6 @@ +{ + "parent": "metropolis:blocks/decorative/barrier_concrete_middle", + "textures": { + "texture": "metropolis:block/test_texture_1" + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/metropolis/models/block/test_block_entity_decorative_connection.json b/src/generated/resources/assets/metropolis/models/block/test_block_entity_decorative_connection.json new file mode 100644 index 0000000..142e471 --- /dev/null +++ b/src/generated/resources/assets/metropolis/models/block/test_block_entity_decorative_connection.json @@ -0,0 +1,6 @@ +{ + "parent": "metropolis:blocks/decorative/barrier_concrete_middle_connection", + "textures": { + "texture": "metropolis:block/test_texture_1" + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/metropolis/models/block/test_block_entity_decorative_standard.json b/src/generated/resources/assets/metropolis/models/block/test_block_entity_decorative_standard.json new file mode 100644 index 0000000..cf28b1a --- /dev/null +++ b/src/generated/resources/assets/metropolis/models/block/test_block_entity_decorative_standard.json @@ -0,0 +1,6 @@ +{ + "parent": "metropolis:blocks/decorative/barrier_concrete_middle", + "textures": { + "texture": "metropolis:block/test_texture_1" + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/metropolis/models/item/test_block_entity_decorative.json b/src/generated/resources/assets/metropolis/models/item/test_block_entity_decorative.json new file mode 100644 index 0000000..99b7036 --- /dev/null +++ b/src/generated/resources/assets/metropolis/models/item/test_block_entity_decorative.json @@ -0,0 +1,3 @@ +{ + "parent": "metropolis:block/test_block_entity_decorative_standard" +} \ No newline at end of file diff --git a/src/main/java/com/fureniku/metropolis/RegistrationBase.java b/src/main/java/com/fureniku/metropolis/RegistrationBase.java index 1437e04..5b016cd 100644 --- a/src/main/java/com/fureniku/metropolis/RegistrationBase.java +++ b/src/main/java/com/fureniku/metropolis/RegistrationBase.java @@ -37,7 +37,7 @@ public abstract class RegistrationBase { protected final DeferredRegister blockRegistry; protected final DeferredRegister itemRegistry; protected final DeferredRegister creativeTabs; - protected static final DeferredRegister> blockEntityRegistry = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, Metropolis.MODID); + protected final DeferredRegister> blockEntityRegistry; /** * Used by registration groups @@ -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); @@ -153,6 +153,16 @@ public RegistryObject> registerB return blockEntityRegistry.register(name, () -> BlockEntityType.Builder.of(blockEntity, validBlocks).build(null)); } + public RegistryObject> registerBlockEntityWithBlock(String name, Supplier blockClass, BlockEntityType.BlockEntitySupplier blockEntity) { + RegistryObject block = blockRegistry.register(name, blockClass); + RegistryObject 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! *

It may be neater to create a function for each tab, and call those functions from here.

diff --git a/src/main/java/com/fureniku/metropolis/blockentity/MetroBlockEntity.java b/src/main/java/com/fureniku/metropolis/blockentity/MetroBlockEntity.java index 5ff8141..0218df8 100644 --- a/src/main/java/com/fureniku/metropolis/blockentity/MetroBlockEntity.java +++ b/src/main/java/com/fureniku/metropolis/blockentity/MetroBlockEntity.java @@ -1,5 +1,7 @@ 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; @@ -7,7 +9,17 @@ 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; + } } diff --git a/src/main/java/com/fureniku/metropolis/blockentity/MetroEntityBlockBase.java b/src/main/java/com/fureniku/metropolis/blockentity/MetroEntityBlockBase.java deleted file mode 100644 index bf50d67..0000000 --- a/src/main/java/com/fureniku/metropolis/blockentity/MetroEntityBlockBase.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.fureniku.metropolis.blockentity; - -import com.fureniku.metropolis.blocks.MetroBlockBase; -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 org.jetbrains.annotations.Nullable; - -public abstract class MetroEntityBlockBase extends MetroBlockBase implements EntityBlock { - - public MetroEntityBlockBase(Properties props) { - super(props); - } - - @Nullable - public abstract BlockEntity createBlockEntity(BlockPos pos, BlockState state); - - /* - * FORGE START - * Everything below here is a Minecraft/Forge function, which will call MY functions above. - * My mods all use my functions. So on updates, I just change these, and everything is fixed... right? - */ - - @Nullable - @Override - public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { - return createBlockEntity(pos, state); - } -} diff --git a/src/main/java/com/fureniku/metropolis/blockentity/MetroEntityBlockDecorative.java b/src/main/java/com/fureniku/metropolis/blockentity/MetroEntityBlockDecorative.java deleted file mode 100644 index 06cf3ec..0000000 --- a/src/main/java/com/fureniku/metropolis/blockentity/MetroEntityBlockDecorative.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.fureniku.metropolis.blockentity; - -import com.fureniku.metropolis.blocks.decorative.MetroBlockDecorative; -import com.fureniku.metropolis.blocks.decorative.helpers.HelperBase; -import com.fureniku.metropolis.datagen.TextureSet; -import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.EntityBlock; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.entity.BlockEntityTicker; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.gameevent.GameEventListener; -import net.minecraft.world.phys.shapes.VoxelShape; -import org.jetbrains.annotations.Nullable; - -public abstract class MetroEntityBlockDecorative extends MetroBlockDecorative implements EntityBlock { - - Class _blockEntity; - BlockEntityType _blockEntityType; - - public MetroEntityBlockDecorative(Properties props, VoxelShape shape, String modelDir, String modelName, String tag, boolean dynamicShape, TextureSet... textures) { - super(props, shape, modelDir, modelName, tag, dynamicShape, textures); - } - - public void setBlockEntity(Class blockEntity, BlockEntityType type) { - _blockEntity = blockEntity; - _blockEntityType = type; - } - - @Nullable - public MetroBlockEntity createBlockEntity(BlockPos pos, BlockState state) { - try { - return _blockEntity.getDeclaredConstructor(BlockEntityType.class, BlockPos.class, BlockState.class).newInstance(_blockEntityType, pos, state); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - /* - * FORGE START - * Everything below here is a Minecraft/Forge function, which will call MY functions above. - * My mods all use my functions. So on updates, I just change these, and everything is fixed... right? - */ - @Nullable - @Override - public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { - return createBlockEntity(pos, state); - } - - @Nullable - @Override - public BlockEntityTicker getTicker(Level p_153212_, BlockState p_153213_, BlockEntityType p_153214_) { - return EntityBlock.super.getTicker(p_153212_, p_153213_, p_153214_); - } - - @Nullable - @Override - public GameEventListener getListener(ServerLevel p_221121_, T p_221122_) { - return EntityBlock.super.getListener(p_221121_, p_221122_); - } -} diff --git a/src/main/java/com/fureniku/metropolis/blocks/decorative/MetroBlockDecorative.java b/src/main/java/com/fureniku/metropolis/blocks/decorative/MetroBlockDecorativeBase.java similarity index 82% rename from src/main/java/com/fureniku/metropolis/blocks/decorative/MetroBlockDecorative.java rename to src/main/java/com/fureniku/metropolis/blocks/decorative/MetroBlockDecorativeBase.java index bc4f227..93bd08b 100644 --- a/src/main/java/com/fureniku/metropolis/blocks/decorative/MetroBlockDecorative.java +++ b/src/main/java/com/fureniku/metropolis/blocks/decorative/MetroBlockDecorativeBase.java @@ -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; @@ -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 }.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 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 getHelpers() { return new ArrayList<>(Arrays.asList(helpersIn)); @@ -81,7 +71,6 @@ public ArrayList getHelpers() { public void setupHelpers(ArrayList helpers) { for (int i = 0; i < helpers.size(); i++) { - //stateHolder = _helpers.get(i).setDefaultState(stateHolder); assignHelper(helpers.get(i)); } _helpers = helpers; diff --git a/src/main/java/com/fureniku/metropolis/blocks/decorative/MetroBlockDecorativeContainer.java b/src/main/java/com/fureniku/metropolis/blocks/decorative/MetroBlockDecorativeContainer.java deleted file mode 100644 index bad78b6..0000000 --- a/src/main/java/com/fureniku/metropolis/blocks/decorative/MetroBlockDecorativeContainer.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.fureniku.metropolis.blocks.decorative; - -import com.fureniku.metropolis.blocks.decorative.builders.MetroBlockDecorativeBuilder; - -public class MetroBlockDecorativeContainer { - - //take in construction stuff - //register to a special place - //keep a list of all helpers - //CONSTRUCT THE BLOCK - //blockstate checks the list for this entry - //gets the helpers and knows which ones to use. - - public MetroBlockDecorativeContainer(MetroBlockDecorativeBuilder builder) { - - } -} diff --git a/src/main/java/com/fureniku/metropolis/blocks/decorative/MetroEntityBlockDecorative.java b/src/main/java/com/fureniku/metropolis/blocks/decorative/MetroEntityBlockDecorative.java new file mode 100644 index 0000000..6f343bc --- /dev/null +++ b/src/main/java/com/fureniku/metropolis/blocks/decorative/MetroEntityBlockDecorative.java @@ -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); + } +} \ No newline at end of file diff --git a/src/main/java/com/fureniku/metropolis/blocks/decorative/builders/MetroBlockDecorativeBuilder.java b/src/main/java/com/fureniku/metropolis/blocks/decorative/builders/MetroBlockDecorativeBuilder.java index de1c8ad..2ca535b 100644 --- a/src/main/java/com/fureniku/metropolis/blocks/decorative/builders/MetroBlockDecorativeBuilder.java +++ b/src/main/java/com/fureniku/metropolis/blocks/decorative/builders/MetroBlockDecorativeBuilder.java @@ -1,7 +1,5 @@ package com.fureniku.metropolis.blocks.decorative.builders; -import com.fureniku.metropolis.blockentity.MetroBlockEntity; -import com.fureniku.metropolis.blockentity.MetroEntityBlockDecorative; import com.fureniku.metropolis.blocks.decorative.*; import com.fureniku.metropolis.blocks.decorative.helpers.ConnectHorizontalHelper; import com.fureniku.metropolis.blocks.decorative.helpers.HelperBase; @@ -12,14 +10,13 @@ import com.fureniku.metropolis.utils.SimpleUtils; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.phys.shapes.VoxelShape; import java.util.ArrayList; import java.util.Arrays; -public class MetroBlockDecorativeBuilder> { +public class MetroBlockDecorativeBuilder { protected BlockBehaviour.Properties _props; protected VoxelShape _blockShape = Block.box(0, 0, 0, 16, 16, 16); @@ -30,9 +27,6 @@ public class MetroBlockDecorativeBuilder _helpers = new ArrayList<>(); - Class _blockEntityClass; - protected BlockEntityType _blockEntityType; - public MetroBlockDecorativeBuilder(BlockBehaviour.Properties props) { this(props, DecorativeBuilderType.DECORATIVE); } @@ -51,74 +45,65 @@ public MetroBlockDecorativeBuilder(MetroBlockDecorativeBuilder partial) { _textures = partial._textures; _type = partial._type; _helpers = partial._helpers; - - _blockEntityClass = partial._blockEntityClass; - _blockEntityType = partial._blockEntityType; } //region Normal shapes - public T setHeight(float height) { return setShape(16, height, 16); } - public T setWidth(float width) { return setShape(width, 16, width); } - public T setShape(float width, float height) { return setShape(width, height, width); } + public MetroBlockDecorativeBuilder setHeight(float height) { return setShape(16, height, 16); } + public MetroBlockDecorativeBuilder setWidth(float width) { return setShape(width, 16, width); } + public MetroBlockDecorativeBuilder setShape(float width, float height) { return setShape(width, height, width); } - public T setShape(float width, float height, float depth) { + public MetroBlockDecorativeBuilder setShape(float width, float height, float depth) { float insetX = (16-width)/2; float insetZ = (16-depth)/2; return setShape(Block.box(insetX, 0, insetZ, 16-insetX, height, 16-insetZ)); } - public T setShape(VoxelShape shape) { + public MetroBlockDecorativeBuilder setShape(VoxelShape shape) { _blockShape = shape; - return (T) this; + return this; } //endregion - public T setModelDirectory(String modelDir) { + public MetroBlockDecorativeBuilder setModelDirectory(String modelDir) { _modelDir = modelDir; - return (T) this; + return this; } - public T setModelName(String modelName) { + public MetroBlockDecorativeBuilder setModelName(String modelName) { _modelName = modelName; - return (T) this; + return this; } - public T setTag(String tag) { + public MetroBlockDecorativeBuilder setTag(String tag) { _tag = tag; - return (T) this; + return this; } - public T setTextures(TextureSet... textures) { + public MetroBlockDecorativeBuilder setTextures(TextureSet... textures) { _textures = textures; - return (T) this; + return this; } - public T setTextures(ResourceLocation resource) { + public MetroBlockDecorativeBuilder setTextures(ResourceLocation resource) { return setTextures(new TextureSet("texture", resource)); } - public T setHelpers(HelperBase... helpers) { + public MetroBlockDecorativeBuilder setHelpers(HelperBase... helpers) { _helpers.addAll(Arrays.asList(helpers)); - return (T) this; + return this; } - public T setConnectHorizontalHelper(BlockConnectionType connectionType, VoxelShape[] shapes) { + public MetroBlockDecorativeBuilder setConnectHorizontalHelper(BlockConnectionType connectionType, VoxelShape[] shapes) { _helpers.add(new ConnectHorizontalHelper.Builder(connectionType, shapes).build()); - return (T) this; + return this; } //TODO - public T setConnectFullHelper() { - return (T) this; + public MetroBlockDecorativeBuilder setConnectFullHelper() { + return this; } - public T setBlockEntity(Class blockEntity, BlockEntityType type) { - _blockEntityClass = blockEntity; - _blockEntityType = type; - return (T) this; - } - - public T get() { return (T) this; } + public MetroBlockDecorativeBuilder get() { return this; } public BlockBehaviour.Properties getProps() { return _props; } public VoxelShape getShape() { return _blockShape; } public String getModelDirectory() { return _modelDir; } @@ -128,25 +113,12 @@ public T setBlockEntity(Class blockEntity, BlockEnti public ArrayList getHelpers() { return _helpers; } /** - * Internal level build function. Fine to use for any blocks which can just use the metro base classes directly. - * If you are making a derived block, create the builder instance as a separate object and pass it through the super + * Generic build function. Creates a block instance of whatever object was specified - or MetroBlockDecorativeBase otherwise. * @return The created block instance */ - public MetroBlockDecorative build() { + public T build() { HelperBase[] helpersArray = _helpers.toArray(new HelperBase[0]); - MetroBlockDecorative.MetroBlockStateFactory factory = MetroBlockDecorative.getBlockFactory(helpersArray); + MetroBlockDecorativeBase.MetroBlockStateFactory factory = MetroBlockDecorativeBase.getBlockFactory(helpersArray); return factory.makeBlock(_props, _blockShape, _modelDir, _modelName, _tag, SimpleUtils.containsType(OffsetHelper.class, helpersArray), _textures); } - - /** - * Build function for block entities. MUST call {@link MetroBlockDecorativeBuilder#setBlockEntity} to use this! - * @return - */ - public MetroEntityBlockDecorative buildEntity() { - HelperBase[] helpersArray = _helpers.toArray(new HelperBase[0]); - MetroBlockDecorative.MetroBlockStateFactory factory = MetroBlockDecorative.getBlockFactory(helpersArray); - MetroEntityBlockDecorative mebd = (MetroEntityBlockDecorative) factory.makeBlock(_props, _blockShape, _modelDir, _modelName, _tag, SimpleUtils.containsType(OffsetHelper.class, helpersArray), _textures); - mebd.setBlockEntity(_blockEntityClass, _blockEntityType); - return mebd; - } } \ No newline at end of file diff --git a/src/main/java/com/fureniku/metropolis/blocks/decorative/helpers/ConnectHorizontalHelper.java b/src/main/java/com/fureniku/metropolis/blocks/decorative/helpers/ConnectHorizontalHelper.java index 3d20473..964d5a9 100644 --- a/src/main/java/com/fureniku/metropolis/blocks/decorative/helpers/ConnectHorizontalHelper.java +++ b/src/main/java/com/fureniku/metropolis/blocks/decorative/helpers/ConnectHorizontalHelper.java @@ -1,7 +1,7 @@ package com.fureniku.metropolis.blocks.decorative.helpers; import com.fureniku.metropolis.blocks.MetroBlockBase; -import com.fureniku.metropolis.blocks.decorative.MetroBlockDecorative; +import com.fureniku.metropolis.blocks.decorative.MetroBlockDecorativeBase; import com.fureniku.metropolis.datagen.MetroBlockStateProvider; import com.fureniku.metropolis.datagen.TextureSet; import com.fureniku.metropolis.enums.BlockConnectionType; @@ -103,7 +103,7 @@ public VoxelShape getShapeFromBlockState(BlockState state) { return ShapeUtils.getShapeAtIndex(state, _shapeByIndex); } - public void neighbourChanged(BlockState state, Level level, BlockPos pos, MetroBlockDecorative block) { + public void neighbourChanged(BlockState state, Level level, BlockPos pos, MetroBlockDecorativeBase block) { BlockState newState = checkNewState(level, state, pos, block); if (newState != state) { block.setBlock(level, pos, newState); @@ -158,7 +158,7 @@ private boolean checkMatch(Level level, BlockPos posToCheck, Block block, Direct } return false; case METRO: - return blockCheck instanceof MetroBlockDecorative && block instanceof MetroBlockDecorative; + return blockCheck instanceof MetroBlockDecorativeBase && block instanceof MetroBlockDecorativeBase; case ALL: return !(blockCheck instanceof AirBlock); } diff --git a/src/main/java/com/fureniku/metropolis/blocks/decorative/helpers/RotationHelper.java b/src/main/java/com/fureniku/metropolis/blocks/decorative/helpers/RotationHelper.java index cc55e8f..c08524a 100644 --- a/src/main/java/com/fureniku/metropolis/blocks/decorative/helpers/RotationHelper.java +++ b/src/main/java/com/fureniku/metropolis/blocks/decorative/helpers/RotationHelper.java @@ -1,6 +1,6 @@ package com.fureniku.metropolis.blocks.decorative.helpers; -import com.fureniku.metropolis.blocks.decorative.MetroBlockDecorative; +import com.fureniku.metropolis.blocks.decorative.MetroBlockDecorativeBase; import com.fureniku.metropolis.datagen.MetroBlockStateProvider; import com.fureniku.metropolis.datagen.TextureSet; import com.fureniku.metropolis.enums.HelperType; @@ -22,7 +22,7 @@ public class RotationHelper extends HelperBlockstate { private final VoxelShape BLOCK_SHAPE_SOUTH; private final VoxelShape BLOCK_SHAPE_WEST; - public RotationHelper(VoxelShape shape, MetroBlockDecorative block) { + public RotationHelper(VoxelShape shape, MetroBlockDecorativeBase block) { BLOCK_SHAPE_NORTH = shape; BLOCK_SHAPE_EAST = ShapeUtils.rotateVoxelShape(shape, Direction.EAST); BLOCK_SHAPE_SOUTH = ShapeUtils.rotateVoxelShape(shape, Direction.SOUTH); diff --git a/src/main/java/com/fureniku/metropolis/blocks/decorative/helpers/ToggleHelper.java b/src/main/java/com/fureniku/metropolis/blocks/decorative/helpers/ToggleHelper.java index 97b862a..a6d3635 100644 --- a/src/main/java/com/fureniku/metropolis/blocks/decorative/helpers/ToggleHelper.java +++ b/src/main/java/com/fureniku/metropolis/blocks/decorative/helpers/ToggleHelper.java @@ -1,6 +1,6 @@ package com.fureniku.metropolis.blocks.decorative.helpers; -import com.fureniku.metropolis.blocks.decorative.MetroBlockDecorative; +import com.fureniku.metropolis.blocks.decorative.MetroBlockDecorativeBase; import com.fureniku.metropolis.datagen.MetroBlockStateProvider; import com.fureniku.metropolis.datagen.TextureSet; import com.fureniku.metropolis.enums.HelperType; @@ -74,13 +74,13 @@ public void setRotatable() { BLOCK_SHAPE_TOGGLED_WEST = ShapeUtils.rotateVoxelShape(BLOCK_SHAPE_TOGGLED, Direction.WEST); } - public void neighbourChanged(BlockState state, Level level, BlockPos pos, MetroBlockDecorative block) { + public void neighbourChanged(BlockState state, Level level, BlockPos pos, MetroBlockDecorativeBase block) { if (!level.isClientSide && (_type == ToggleType.REDSTONE || _type == ToggleType.REDSTONE_INTERACT)) { block.setToggledState(level, pos, state, level.hasNeighborSignal(pos)); } } - public void rightClick(BlockState state, BlockPos pos, Player player, MetroBlockDecorative block) { + public void rightClick(BlockState state, BlockPos pos, Player player, MetroBlockDecorativeBase block) { switch (_type) { case REDSTONE_INTERACT: case INTERACT: diff --git a/src/main/java/com/fureniku/metropolis/test/BlockEntityTest.java b/src/main/java/com/fureniku/metropolis/test/BlockEntityTest.java index 338cdd8..edc14a1 100644 --- a/src/main/java/com/fureniku/metropolis/test/BlockEntityTest.java +++ b/src/main/java/com/fureniku/metropolis/test/BlockEntityTest.java @@ -7,7 +7,7 @@ public class BlockEntityTest extends MetroBlockEntity { - public BlockEntityTest(BlockEntityType type, BlockPos pos, BlockState state) { - super(type, pos, state); + public BlockEntityTest(BlockPos pos, BlockState state) { + super(pos, state); } } diff --git a/src/main/java/com/fureniku/metropolis/test/MetroEntityBlockChildTest.java b/src/main/java/com/fureniku/metropolis/test/MetroEntityBlockChildTest.java new file mode 100644 index 0000000..5bd917f --- /dev/null +++ b/src/main/java/com/fureniku/metropolis/test/MetroEntityBlockChildTest.java @@ -0,0 +1,12 @@ +package com.fureniku.metropolis.test; + +import com.fureniku.metropolis.blocks.decorative.MetroEntityBlockDecorative; +import com.fureniku.metropolis.datagen.TextureSet; +import net.minecraft.world.phys.shapes.VoxelShape; + +public abstract class MetroEntityBlockChildTest extends MetroEntityBlockDecorative { + + public MetroEntityBlockChildTest(Properties props, VoxelShape shape, String modelDir, String modelName, String tag, boolean dynamicShape, TextureSet... textures) { + super(props, shape, modelDir, modelName, tag, dynamicShape, textures); + } +} diff --git a/src/main/java/com/fureniku/metropolis/test/RegistrationTest.java b/src/main/java/com/fureniku/metropolis/test/RegistrationTest.java index 38a0240..0bd71f4 100644 --- a/src/main/java/com/fureniku/metropolis/test/RegistrationTest.java +++ b/src/main/java/com/fureniku/metropolis/test/RegistrationTest.java @@ -3,26 +3,18 @@ import com.fureniku.metropolis.Metropolis; import com.fureniku.metropolis.RegistrationBase; import com.fureniku.metropolis.blockentity.MetroBlockEntity; -import com.fureniku.metropolis.blocks.MetroBlockBase; -import com.fureniku.metropolis.blocks.decorative.MetroBlockDecorative; +import com.fureniku.metropolis.blocks.decorative.MetroEntityBlockDecorative; import com.fureniku.metropolis.blocks.decorative.builders.MetroBlockDecorativeBuilder; import com.fureniku.metropolis.blocks.decorative.helpers.ConnectHorizontalHelper; -import com.fureniku.metropolis.blocks.decorative.helpers.HelperBase; -import com.fureniku.metropolis.blocks.decorative.helpers.OffsetHelper; import com.fureniku.metropolis.datagen.MetroBlockStateProvider; -import com.fureniku.metropolis.datagen.TextureSet; import com.fureniku.metropolis.enums.BlockConnectionType; import com.fureniku.metropolis.enums.DecorativeBuilderType; import com.fureniku.metropolis.utils.CreativeTabSet; import com.fureniku.metropolis.utils.ShapeUtils; -import com.fureniku.metropolis.utils.SimpleUtils; import net.minecraft.data.DataGenerator; import net.minecraft.data.PackOutput; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.SoundType; -import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.phys.shapes.VoxelShape; @@ -53,6 +45,8 @@ public RegistrationTest(String modid, IEventBus modEventBus) { ResourceLocation TEST_TEXTURE_1 = new ResourceLocation(Metropolis.MODID, "block/test_texture_1"); ResourceLocation TEST_TEXTURE_2 = new ResourceLocation(Metropolis.MODID, "block/test_texture_2"); + public RegistryObject> TEST_BLOCK_ENTITY_DECORATIVE_ENTITY; + @Override public void init(IEventBus modEventBus) { VoxelShape[] shapeA = ShapeUtils.makeShapes(4f, 4f); @@ -165,33 +159,31 @@ public void init(IEventBus modEventBus) { .setHelpers(new ConnectHorizontalHelper.Builder(BlockConnectionType.METRO, shapes).setDontConnectSolid().build()) .build())); blockNames.add(registerBlockSet("test_connecting_enum_all", () -> - new MetroBlockDecorativeBuilder(_props, DecorativeBuilderType.DECORATIVE_CONNECT_HORIZONTAL) + new MetroBlockDecorativeBuilder(_props, DecorativeBuilderType.DECORATIVE_CONNECT_HORIZONTAL) .setModelDirectory("blocks/decorative/") .setModelName("barrier_concrete_middle") .setTextures(TEST_TEXTURE_1) .setConnectHorizontalHelper(BlockConnectionType.ALL, shapes) .build())); - blockNames.add(registerBlockSet("test_block_entity_decorative", () -> + + blockNames.add("test_block_entity_decorative"); + /*RegistryObject blockEntity = retrieveRegisterBlockSet("test_block_entity_decorative", () -> new MetroBlockDecorativeBuilder(_props, DecorativeBuilderType.DECORATIVE) .setModelDirectory("blocks/decorative/") .setModelName("barrier_concrete_middle") .setTextures(TEST_TEXTURE_1) - .setBlockEntity() - .buildEntity())); - - _testTab = new CreativeTabSet(getCreativeTabDeferredRegister(), "tab_test", getItem(blockNames.get(0))); - - //other code... - registerBlockEntity("test_block_entity_decorative", MetroBlockEntity::new, getBlock("test_block_entity_decorative").get()); - } - - public static final RegistryObject> NEXUS_BLOCK_ENTITY = registerBlockEntity2("nexus", MetroBlockEntity::new, Blocks.STONE); - + .buildEntity());*/ + TEST_BLOCK_ENTITY_DECORATIVE_ENTITY = registerBlockEntityWithBlock("test_block_entity_decorative", () -> + new MetroBlockDecorativeBuilder(_props, DecorativeBuilderType.DECORATIVE) + .setModelDirectory("blocks/decorative/") + .setModelName("barrier_concrete_middle") + .setTextures(TEST_TEXTURE_1) + .setConnectHorizontalHelper(BlockConnectionType.ALL, shapes) + .build(), MetroBlockEntity::new);//Metropolis.registrationTest.getBlock("test_block_entity_decorative").get()) - public static RegistryObject> registerBlockEntity2(String name, BlockEntityType.BlockEntitySupplier factory, Block block) { - return BETYPES.register(name, () -> BlockEntityType.Builder.of(factory, block.get()).build(null)); + _testTab = new CreativeTabSet(getCreativeTabDeferredRegister(), "tab_test", getItem(blockNames.get(0))); } @Override