removed slab mode... and instead added custom class passing

This commit is contained in:
DaniTheSkunk 2022-10-30 02:18:15 +00:00
parent 03af07cb04
commit 3b387e05de
4 changed files with 58 additions and 19 deletions

View File

@ -1,22 +1,26 @@
package com.danitheskunk.skunkstuff; package com.danitheskunk.skunkstuff;
import com.danitheskunk.skunkstuff.Blocks.Blocks;
import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SlabBlock; import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Material;
import org.quiltmc.qsl.block.extensions.api.QuiltBlockSettings; import org.quiltmc.qsl.block.extensions.api.QuiltBlockSettings;
import java.lang.reflect.InvocationTargetException;
public class BlockBuilder extends QuiltBlockSettings { public class BlockBuilder extends QuiltBlockSettings {
public String name; public String name;
public CreativeModeTab creativeModeTab = CreativeModeTab.TAB_MISC; public CreativeModeTab creativeModeTab = CreativeModeTab.TAB_MISC;
public BlockType blockType; public Class<? extends Block> blockClass;
public Block block; public Block block;
public BlockBuilder() { public BlockBuilder() {
super(QuiltBlockSettings.of(Material.WOOD)); super(QuiltBlockSettings.of(Material.WOOD));
strength(2); strength(2);
opaque(false); opaque(false);
blockType = BlockType.Full; blockClass = Block.class;
} }
public BlockBuilder name(String name) { public BlockBuilder name(String name) {
@ -29,19 +33,24 @@ public class BlockBuilder extends QuiltBlockSettings {
return this; return this;
} }
public BlockBuilder slab() { public BlockBuilder type(Class<? extends Block> blockClass) {
blockType = BlockType.Slab; this.blockClass = blockClass;
return this; return this;
} }
public Block build() { public Block build() {
block = switch(blockType) { try {
case Full -> new Block(this); var constructor =
case Slab -> new SlabBlock(this); blockClass.getDeclaredConstructor(BlockBehaviour.Properties.class);
}; block = constructor.newInstance(this);
} catch(NoSuchMethodException | InvocationTargetException |
InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
}
Blocks.addToDeffered(this); Blocks.addToDeffered(this);
return block; return block;
} }
private enum BlockType { private enum BlockType {
Full, Slab Full, Slab
} }

View File

@ -0,0 +1,27 @@
package com.danitheskunk.skunkstuff.Blocks;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
public class BlockGoban extends Block {
private static final VoxelShape AABB = Block.box(0.0,
0.0,
0.0,
16.0,
8.0,
16.0
);
public BlockGoban(Properties properties) {
super(properties);
}
@Override
public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
return AABB;
}
}

View File

@ -1,5 +1,6 @@
package com.danitheskunk.skunkstuff; package com.danitheskunk.skunkstuff.Blocks;
import com.danitheskunk.skunkstuff.BlockBuilder;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.BlockItem;

View File

@ -1,5 +1,7 @@
package com.danitheskunk.skunkstuff; package com.danitheskunk.skunkstuff;
import com.danitheskunk.skunkstuff.Blocks.BlockGoban;
import com.danitheskunk.skunkstuff.Blocks.Blocks;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import org.quiltmc.loader.api.ModContainer; import org.quiltmc.loader.api.ModContainer;
import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; import org.quiltmc.qsl.base.api.entrypoint.ModInitializer;
@ -10,23 +12,23 @@ public class SkunkStuff implements ModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("SkunkStuff"); public static final Logger LOGGER = LoggerFactory.getLogger("SkunkStuff");
public static final Block OAK_GOBAN_BLOCK = Blocks.register().name( public static final Block OAK_GOBAN_BLOCK = Blocks.register().name(
"oak_goban").build(); "oak_goban").type(BlockGoban.class).build();
public static final Block SPRUCE_GOBAN_BLOCK = Blocks.register().name( public static final Block SPRUCE_GOBAN_BLOCK = Blocks.register().name(
"spruce_goban").build(); "spruce_goban").type(BlockGoban.class).build();
public static final Block BIRCH_GOBAN_BLOCK = Blocks.register().name( public static final Block BIRCH_GOBAN_BLOCK = Blocks.register().name(
"birch_goban").build(); "birch_goban").type(BlockGoban.class).build();
public static final Block JUNGLE_GOBAN_BLOCK = Blocks.register().name( public static final Block JUNGLE_GOBAN_BLOCK = Blocks.register().name(
"jungle_goban").build(); "jungle_goban").type(BlockGoban.class).build();
public static final Block ACACIA_GOBAN_BLOCK = Blocks.register().name( public static final Block ACACIA_GOBAN_BLOCK = Blocks.register().name(
"acacia_goban").build(); "acacia_goban").type(BlockGoban.class).build();
public static final Block DARK_OAK_GOBAN_BLOCK = Blocks.register().name( public static final Block DARK_OAK_GOBAN_BLOCK = Blocks.register().name(
"dark_oak_goban").build(); "dark_oak_goban").type(BlockGoban.class).build();
public static final Block WARPED_GOBAN_BLOCK = Blocks.register().name( public static final Block WARPED_GOBAN_BLOCK = Blocks.register().name(
"warped_goban").build(); "warped_goban").type(BlockGoban.class).build();
public static final Block CRIMSON_GOBAN_BLOCK = Blocks.register().name( public static final Block CRIMSON_GOBAN_BLOCK = Blocks.register().name(
"crimson_goban").build(); "crimson_goban").type(BlockGoban.class).build();
public static final Block MANGROVE_GOBAN_BLOCK = Blocks.register().name( public static final Block MANGROVE_GOBAN_BLOCK = Blocks.register().name(
"mangrove_goban").build(); "mangrove_goban").type(BlockGoban.class).build();
@Override @Override
public void onInitialize(ModContainer mod) { public void onInitialize(ModContainer mod) {