Move class, rename blockentity, cube template
This commit is contained in:
parent
084861080b
commit
b2b18e294c
@ -1,18 +1,23 @@
|
|||||||
package io.github.cottonmc.templates;
|
package io.github.cottonmc.templates;
|
||||||
|
|
||||||
import io.github.cottonmc.templates.api.TemplateInteractionUtil;
|
import io.github.cottonmc.templates.api.TemplateInteractionUtil;
|
||||||
|
import io.github.cottonmc.templates.block.TemplateBlock;
|
||||||
import io.github.cottonmc.templates.block.TemplateSlabBlock;
|
import io.github.cottonmc.templates.block.TemplateSlabBlock;
|
||||||
import io.github.cottonmc.templates.block.TemplateSlopeBlock;
|
import io.github.cottonmc.templates.block.TemplateSlopeBlock;
|
||||||
import io.github.cottonmc.templates.block.entity.TemplateEntity;
|
import io.github.cottonmc.templates.block.TemplateEntity;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
|
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.entity.BlockEntityType;
|
import net.minecraft.block.entity.BlockEntityType;
|
||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemGroup;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.registry.Registries;
|
import net.minecraft.registry.Registries;
|
||||||
import net.minecraft.registry.Registry;
|
import net.minecraft.registry.Registry;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
@ -22,16 +27,24 @@ import java.util.function.BiConsumer;
|
|||||||
public class Templates implements ModInitializer {
|
public class Templates implements ModInitializer {
|
||||||
public static final String MODID = "templates";
|
public static final String MODID = "templates";
|
||||||
|
|
||||||
|
public static final Block CUBE = Registry.register(Registries.BLOCK, id("cube"), new TemplateBlock(TemplateInteractionUtil.makeSettings()));
|
||||||
public static final Block SLOPE = Registry.register(Registries.BLOCK, id("slope"), new TemplateSlopeBlock(TemplateInteractionUtil.makeSettings()));
|
public static final Block SLOPE = Registry.register(Registries.BLOCK, id("slope"), new TemplateSlopeBlock(TemplateInteractionUtil.makeSettings()));
|
||||||
public static final BlockEntityType<TemplateEntity> SLOPE_ENTITY = Registry.register(
|
public static final Block SLAB = Registry.register(Registries.BLOCK, id("slab"), new TemplateSlabBlock(TemplateInteractionUtil.makeSettings()));
|
||||||
|
|
||||||
|
//N.B. it's fine to make your own block entity type instead of gluing additional blocks to this one
|
||||||
|
public static final BlockEntityType<TemplateEntity> TEMPLATE_BLOCK_ENTITY = Registry.register(
|
||||||
Registries.BLOCK_ENTITY_TYPE, id("slope"),
|
Registries.BLOCK_ENTITY_TYPE, id("slope"),
|
||||||
FabricBlockEntityTypeBuilder.create(Templates::makeSlopeEntity, SLOPE).build(null)
|
FabricBlockEntityTypeBuilder.create(Templates::makeTemplateBlockEntity, CUBE, SLOPE, SLAB).build(null)
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final Block SLAB = Registry.register(Registries.BLOCK, id("slab"), new TemplateSlabBlock(TemplateInteractionUtil.makeSettings()));
|
@SuppressWarnings("unused")
|
||||||
public static final BlockEntityType<TemplateEntity> SLAB_ENTITY = Registry.register(
|
public static final ItemGroup TAB = Registry.register(
|
||||||
Registries.BLOCK_ENTITY_TYPE, id("slab"),
|
Registries.ITEM_GROUP, id("tab"),
|
||||||
FabricBlockEntityTypeBuilder.create(Templates::makeSlabEntity, SLAB).build(null)
|
FabricItemGroup.builder()
|
||||||
|
.displayName(Text.translatable("itemGroup.templates.tab"))
|
||||||
|
.icon(() -> new ItemStack(SLOPE))
|
||||||
|
.entries(Templates::fillItemGroup)
|
||||||
|
.build()
|
||||||
);
|
);
|
||||||
|
|
||||||
//Overridden in TemplatesClient
|
//Overridden in TemplatesClient
|
||||||
@ -39,6 +52,7 @@ public class Templates implements ModInitializer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
|
Registry.register(Registries.ITEM, id("cube"), new BlockItem(CUBE, new Item.Settings()));
|
||||||
Registry.register(Registries.ITEM, id("slope"), new BlockItem(SLOPE, new Item.Settings()));
|
Registry.register(Registries.ITEM, id("slope"), new BlockItem(SLOPE, new Item.Settings()));
|
||||||
Registry.register(Registries.ITEM, id("slab"), new BlockItem(SLAB, new Item.Settings()));
|
Registry.register(Registries.ITEM, id("slab"), new BlockItem(SLAB, new Item.Settings()));
|
||||||
}
|
}
|
||||||
@ -47,12 +61,14 @@ public class Templates implements ModInitializer {
|
|||||||
return new Identifier(MODID, path);
|
return new Identifier(MODID, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
//simply for breaking circular references in the registration calls
|
//simply for breaking circular reference in the registration call
|
||||||
private static TemplateEntity makeSlopeEntity(BlockPos pos, BlockState state) {
|
private static TemplateEntity makeTemplateBlockEntity(BlockPos pos, BlockState state) {
|
||||||
return new TemplateEntity(SLOPE_ENTITY, pos, state);
|
return new TemplateEntity(TEMPLATE_BLOCK_ENTITY, pos, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TemplateEntity makeSlabEntity(BlockPos pos, BlockState state) {
|
private static void fillItemGroup(ItemGroup.DisplayContext ctx, ItemGroup.Entries ent) {
|
||||||
return new TemplateEntity(SLAB_ENTITY, pos, state);
|
ent.add(CUBE);
|
||||||
|
ent.add(SLOPE);
|
||||||
|
ent.add(SLAB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,14 +54,15 @@ public class TemplatesClient implements ClientModInitializer {
|
|||||||
ModelLoadingRegistry.INSTANCE.registerResourceProvider(rm -> provider); //block models
|
ModelLoadingRegistry.INSTANCE.registerResourceProvider(rm -> provider); //block models
|
||||||
ModelLoadingRegistry.INSTANCE.registerVariantProvider(rm -> provider); //item models
|
ModelLoadingRegistry.INSTANCE.registerVariantProvider(rm -> provider); //item models
|
||||||
|
|
||||||
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(), Templates.SLOPE, Templates.SLAB);
|
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutout(), Templates.CUBE, Templates.SLOPE, Templates.SLAB);
|
||||||
|
|
||||||
provider.addTemplateModel(Templates.id("slope_special"), new RetexturedMeshUnbakedModel(Templates.id("block/slope_base"), SlopeBaseMesh::make));
|
|
||||||
provider.assignItemModel(Templates.id("slope_special"), Templates.SLOPE);
|
|
||||||
|
|
||||||
provider.addTemplateModel(Templates.id("cube_special"), new RetexturedJsonModelUnbakedModel(Templates.id("block/cube")));
|
provider.addTemplateModel(Templates.id("cube_special"), new RetexturedJsonModelUnbakedModel(Templates.id("block/cube")));
|
||||||
provider.addTemplateModel(Templates.id("slab_bottom_special"), new RetexturedJsonModelUnbakedModel(Templates.id("block/slab_bottom")));
|
provider.addTemplateModel(Templates.id("slab_bottom_special"), new RetexturedJsonModelUnbakedModel(Templates.id("block/slab_bottom")));
|
||||||
provider.addTemplateModel(Templates.id("slab_top_special"), new RetexturedJsonModelUnbakedModel(Templates.id("block/slab_top")));
|
provider.addTemplateModel(Templates.id("slab_top_special"), new RetexturedJsonModelUnbakedModel(Templates.id("block/slab_top")));
|
||||||
|
provider.addTemplateModel(Templates.id("slope_special"), new RetexturedMeshUnbakedModel(Templates.id("block/slope_base"), SlopeBaseMesh::make));
|
||||||
|
|
||||||
|
provider.assignItemModel(Templates.id("cube_special"), Templates.CUBE);
|
||||||
|
provider.assignItemModel(Templates.id("slope_special"), Templates.SLOPE);
|
||||||
provider.assignItemModel(Templates.id("slab_bottom_special"), Templates.SLAB);
|
provider.assignItemModel(Templates.id("slab_bottom_special"), Templates.SLAB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package io.github.cottonmc.templates.api;
|
package io.github.cottonmc.templates.api;
|
||||||
|
|
||||||
import io.github.cottonmc.templates.block.entity.TemplateEntity;
|
import io.github.cottonmc.templates.block.TemplateEntity;
|
||||||
import net.minecraft.block.AbstractBlock;
|
import net.minecraft.block.AbstractBlock;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockEntityProvider;
|
import net.minecraft.block.BlockEntityProvider;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package io.github.cottonmc.templates.block;
|
package io.github.cottonmc.templates.block;
|
||||||
|
|
||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
|
import io.github.cottonmc.templates.Templates;
|
||||||
import io.github.cottonmc.templates.api.TemplateInteractionUtil;
|
import io.github.cottonmc.templates.api.TemplateInteractionUtil;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockEntityProvider;
|
import net.minecraft.block.BlockEntityProvider;
|
||||||
@ -21,14 +22,16 @@ import net.minecraft.world.BlockView;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public abstract class TemplateBlock extends Block implements BlockEntityProvider {
|
public class TemplateBlock extends Block implements BlockEntityProvider {
|
||||||
public TemplateBlock(Settings settings) {
|
public TemplateBlock(Settings settings) {
|
||||||
super(settings);
|
super(settings);
|
||||||
setDefaultState(TemplateInteractionUtil.setDefaultStates(getDefaultState()));
|
setDefaultState(TemplateInteractionUtil.setDefaultStates(getDefaultState()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract @Nullable BlockEntity createBlockEntity(BlockPos blockPos, BlockState blockState);
|
public @Nullable BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
|
||||||
|
return Templates.TEMPLATE_BLOCK_ENTITY.instantiate(pos, state);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package io.github.cottonmc.templates.block.entity;
|
package io.github.cottonmc.templates.block;
|
||||||
|
|
||||||
import io.github.cottonmc.templates.Templates;
|
import io.github.cottonmc.templates.Templates;
|
||||||
import io.github.cottonmc.templates.api.ThemeableBlockEntity;
|
import io.github.cottonmc.templates.api.ThemeableBlockEntity;
|
@ -32,7 +32,7 @@ public class TemplateSlabBlock extends SlabBlock implements BlockEntityProvider
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
|
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
|
||||||
return Templates.SLAB_ENTITY.instantiate(pos, state);
|
return Templates.TEMPLATE_BLOCK_ENTITY.instantiate(pos, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -48,11 +48,6 @@ public class TemplateSlopeBlock extends TemplateBlock {
|
|||||||
super.appendProperties(builder.add(FACING, HALF));
|
super.appendProperties(builder.add(FACING, HALF));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
|
|
||||||
return Templates.SLOPE_ENTITY.instantiate(pos, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"variants": {
|
||||||
|
"": {
|
||||||
|
"model": "templates:cube_special"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,7 @@
|
|||||||
{
|
{
|
||||||
|
"itemGroup.templates.tab": "Templates",
|
||||||
|
|
||||||
|
"block.templates.cube": "Cube Template",
|
||||||
"block.templates.slope": "Slope Template",
|
"block.templates.slope": "Slope Template",
|
||||||
"block.templates.slab": "Slab Template"
|
"block.templates.slab": "Slab Template"
|
||||||
}
|
}
|
@ -2,8 +2,9 @@
|
|||||||
"parent": "minecraft:recipes/root",
|
"parent": "minecraft:recipes/root",
|
||||||
"rewards": {
|
"rewards": {
|
||||||
"recipes": [
|
"recipes": [
|
||||||
"templates:slope",
|
"templates:cube",
|
||||||
"templates:slab"
|
"templates:slab",
|
||||||
|
"templates:slope"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"criteria": {
|
"criteria": {
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"type": "minecraft:block",
|
||||||
|
"pools": [
|
||||||
|
{
|
||||||
|
"rolls": 1,
|
||||||
|
"entries": [
|
||||||
|
{
|
||||||
|
"type": "minecraft:item",
|
||||||
|
"name": "templates:cube"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"conditions": [
|
||||||
|
{
|
||||||
|
"condition": "minecraft:survives_explosion"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
21
src/main/resources/data/templates/recipes/cube.json
Normal file
21
src/main/resources/data/templates/recipes/cube.json
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"type": "minecraft:crafting_shaped",
|
||||||
|
"pattern": [
|
||||||
|
"III",
|
||||||
|
"I~I",
|
||||||
|
"III"
|
||||||
|
],
|
||||||
|
"key": {
|
||||||
|
"I": {
|
||||||
|
"item": "minecraft:bamboo"
|
||||||
|
},
|
||||||
|
"~": {
|
||||||
|
"item": "minecraft:string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"result": {
|
||||||
|
"item": "templates:cube",
|
||||||
|
"count": 4
|
||||||
|
},
|
||||||
|
"group": "templates"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user