first pass on doors

This commit is contained in:
quat1024 2023-07-21 03:49:49 -04:00
parent 17d71fec37
commit 20ed304c0d
6 changed files with 218 additions and 19 deletions

View File

@ -1,22 +1,7 @@
package io.github.cottonmc.templates;
import io.github.cottonmc.templates.api.TemplateInteractionUtil;
import io.github.cottonmc.templates.block.TemplateBlock;
import io.github.cottonmc.templates.block.TemplateButtonBlock;
import io.github.cottonmc.templates.block.TemplateCandleBlock;
import io.github.cottonmc.templates.block.TemplateCarpetBlock;
import io.github.cottonmc.templates.block.TemplateFenceBlock;
import io.github.cottonmc.templates.block.TemplateFenceGateBlock;
import io.github.cottonmc.templates.block.TemplateLeverBlock;
import io.github.cottonmc.templates.block.TemplatePaneBlock;
import io.github.cottonmc.templates.block.TemplatePostBlock;
import io.github.cottonmc.templates.block.TemplatePressurePlateBlock;
import io.github.cottonmc.templates.block.TemplateSlabBlock;
import io.github.cottonmc.templates.block.TemplateSlopeBlock;
import io.github.cottonmc.templates.block.TemplateEntity;
import io.github.cottonmc.templates.block.TemplateStairsBlock;
import io.github.cottonmc.templates.block.TemplateTrapdoorBlock;
import io.github.cottonmc.templates.block.TemplateWallBlock;
import io.github.cottonmc.templates.block.*;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
@ -46,7 +31,7 @@ public class Templates implements ModInitializer {
public static final Block CANDLE = Registry.register(Registries.BLOCK, id("candle") , new TemplateCandleBlock(TemplateCandleBlock.configureSettings(cp(Blocks.CANDLE))));
public static final Block CARPET = Registry.register(Registries.BLOCK, id("carpet") , new TemplateCarpetBlock(cp(Blocks.WHITE_CARPET)));
public static final Block CUBE = Registry.register(Registries.BLOCK, id("cube") , new TemplateBlock(TemplateInteractionUtil.makeSettings()));
//door? (hard cause its a multiblock)
public static final Block DOOR = Registry.register(Registries.BLOCK, id("door") , new TemplateDoorBlock(cp(Blocks.OAK_DOOR), BlockSetType.OAK));
public static final Block FENCE = Registry.register(Registries.BLOCK, id("fence") , new TemplateFenceBlock(cp(Blocks.OAK_FENCE)));
public static final Block FENCE_GATE = Registry.register(Registries.BLOCK, id("fence_gate") , new TemplateFenceGateBlock(cp(Blocks.OAK_FENCE_GATE)));
public static final Block IRON_TRAPDOOR = Registry.register(Registries.BLOCK, id("iron_trapdoor") , new TemplateTrapdoorBlock(cp(Blocks.IRON_TRAPDOOR), BlockSetType.IRON));
@ -71,6 +56,7 @@ public class Templates implements ModInitializer {
CANDLE,
CARPET,
CUBE,
DOOR,
FENCE,
FENCE_GATE,
IRON_TRAPDOOR,
@ -104,6 +90,7 @@ public class Templates implements ModInitializer {
Registry.register(Registries.ITEM, id("candle") , new BlockItem(CANDLE, new Item.Settings()));
Registry.register(Registries.ITEM, id("carpet") , new BlockItem(CARPET, new Item.Settings()));
Registry.register(Registries.ITEM, id("cube") , new BlockItem(CUBE, new Item.Settings()));
Registry.register(Registries.ITEM, id("door") , new BlockItem(DOOR, new Item.Settings()));
Registry.register(Registries.ITEM, id("fence") , new BlockItem(FENCE, new Item.Settings()));
Registry.register(Registries.ITEM, id("fence_gate") , new BlockItem(FENCE_GATE, new Item.Settings()));
Registry.register(Registries.ITEM, id("iron_trapdoor") , new BlockItem(IRON_TRAPDOOR, new Item.Settings()));
@ -137,7 +124,7 @@ public class Templates implements ModInitializer {
e.add(POST);
e.add(FENCE);
e.add(FENCE_GATE);
// <-- insert door here
e.add(DOOR);
e.add(TRAPDOOR);
e.add(IRON_TRAPDOOR);
e.add(PRESSURE_PLATE);

View File

@ -60,6 +60,7 @@ public class TemplatesClient implements ClientModInitializer {
Templates.CANDLE,
Templates.CARPET,
Templates.CUBE,
Templates.DOOR,
Templates.FENCE,
Templates.FENCE_GATE,
Templates.IRON_TRAPDOOR,
@ -83,6 +84,14 @@ public class TemplatesClient implements ClientModInitializer {
provider.addTemplateModel(Templates.id("four_candles_special") , new UnbakedAutoRetexturedModel(new Identifier("block/template_four_candles")));
provider.addTemplateModel(Templates.id("carpet_special") , new UnbakedAutoRetexturedModel(new Identifier("block/carpet")));
provider.addTemplateModel(Templates.id("cube_special") , new UnbakedAutoRetexturedModel(new Identifier("block/cube")));
provider.addTemplateModel(Templates.id("door_bottom_left_special") , new UnbakedAutoRetexturedModel(new Identifier("block/door_bottom_left")));
provider.addTemplateModel(Templates.id("door_bottom_right_special") , new UnbakedAutoRetexturedModel(new Identifier("block/door_bottom_right")));
provider.addTemplateModel(Templates.id("door_top_left_special") , new UnbakedAutoRetexturedModel(new Identifier("block/door_top_left")));
provider.addTemplateModel(Templates.id("door_top_right_special") , new UnbakedAutoRetexturedModel(new Identifier("block/door_top_right")));
provider.addTemplateModel(Templates.id("door_bottom_left_open_special"), new UnbakedAutoRetexturedModel(new Identifier("block/door_bottom_left_open")));
provider.addTemplateModel(Templates.id("door_bottom_right_open_special"), new UnbakedAutoRetexturedModel(new Identifier("block/door_bottom_right_open"))); //This is why we dont format code as tables kids
provider.addTemplateModel(Templates.id("door_top_left_open_special") , new UnbakedAutoRetexturedModel(new Identifier("block/door_top_left_open")));
provider.addTemplateModel(Templates.id("door_top_right_open_special") , new UnbakedAutoRetexturedModel(new Identifier("block/door_top_right_open")));
provider.addTemplateModel(Templates.id("fence_post_special") , new UnbakedAutoRetexturedModel(new Identifier("block/fence_post")));
provider.addTemplateModel(Templates.id("fence_gate_special") , new UnbakedAutoRetexturedModel(new Identifier("block/template_fence_gate")));
provider.addTemplateModel(Templates.id("fence_gate_open_special") , new UnbakedAutoRetexturedModel(new Identifier("block/template_fence_gate_open")));

View File

@ -0,0 +1,77 @@
package io.github.cottonmc.templates.block;
import com.google.common.base.MoreObjects;
import io.github.cottonmc.templates.Templates;
import io.github.cottonmc.templates.api.TemplateInteractionUtil;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.state.StateManager;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
public class TemplateDoorBlock extends DoorBlock implements BlockEntityProvider {
public TemplateDoorBlock(Settings settings, BlockSetType blockSetType) {
super(settings, blockSetType);
setDefaultState(TemplateInteractionUtil.setDefaultStates(getDefaultState()));
}
@Nullable
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return Templates.TEMPLATE_BLOCK_ENTITY.instantiate(pos, state);
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(TemplateInteractionUtil.appendProperties(builder));
}
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
ActionResult r = TemplateInteractionUtil.onUse(state, world, pos, player, hand, hit);
if(!r.isAccepted()) r = super.onUse(state, world, pos, player, hand, hit);
return r;
}
@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
TemplateInteractionUtil.onStateReplaced(state, world, pos, newState, moved);
super.onStateReplaced(state, world, pos, newState, moved);
}
@Override
public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) {
TemplateInteractionUtil.onPlaced(world, pos, state, placer, stack);
super.onPlaced(world, pos, state, placer, stack);
}
@Override
public VoxelShape getCollisionShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ctx) {
return MoreObjects.firstNonNull(TemplateInteractionUtil.getCollisionShape(state, view, pos, ctx), super.getCollisionShape(state, view, pos, ctx));
}
@Override
public boolean emitsRedstonePower(BlockState state) {
return TemplateInteractionUtil.emitsRedstonePower(state);
}
@Override
public int getWeakRedstonePower(BlockState state, BlockView view, BlockPos pos, Direction dir) {
return TemplateInteractionUtil.getWeakRedstonePower(state, view, pos, dir);
}
@Override
public int getStrongRedstonePower(BlockState state, BlockView view, BlockPos pos, Direction dir) {
return TemplateInteractionUtil.getStrongRedstonePower(state, view, pos, dir);
}
}

View File

@ -52,6 +52,7 @@ public class TemplateEntity extends BlockEntity implements ThemeableBlockEntity
isSolid = !tag.contains("solid") || tag.getBoolean("solid"); //default to "true" if it's nonexistent
//Force a chunk remesh on the client if the displayed blockstate has changed
//TODO: doors? (need remeshing when the *other* party changes)
if(world != null && world.isClient && !Objects.equals(lastRenderedState, renderedState)) {
Templates.chunkRerenderProxy.accept(world, pos);
}
@ -87,7 +88,7 @@ public class TemplateEntity extends BlockEntity implements ThemeableBlockEntity
return renderedState;
}
private void dispatch() {
protected void dispatch() {
if(world instanceof ServerWorld sworld) sworld.getChunkManager().markForUpdate(pos);
}

View File

@ -0,0 +1,124 @@
{
"variants": {
"facing=east,half=lower,hinge=left,open=false": {
"model": "templates:door_bottom_left_special"
},
"facing=east,half=lower,hinge=left,open=true": {
"model": "templates:door_bottom_left_open_special",
"y": 90
},
"facing=east,half=lower,hinge=right,open=false": {
"model": "templates:door_bottom_right_special"
},
"facing=east,half=lower,hinge=right,open=true": {
"model": "templates:door_bottom_right_open_special",
"y": 270
},
"facing=east,half=upper,hinge=left,open=false": {
"model": "templates:door_top_left_special"
},
"facing=east,half=upper,hinge=left,open=true": {
"model": "templates:door_top_left_open_special",
"y": 90
},
"facing=east,half=upper,hinge=right,open=false": {
"model": "templates:door_top_right_special"
},
"facing=east,half=upper,hinge=right,open=true": {
"model": "templates:door_top_right_open_special",
"y": 270
},
"facing=north,half=lower,hinge=left,open=false": {
"model": "templates:door_bottom_left_special",
"y": 270
},
"facing=north,half=lower,hinge=left,open=true": {
"model": "templates:door_bottom_left_open_special"
},
"facing=north,half=lower,hinge=right,open=false": {
"model": "templates:door_bottom_right_special",
"y": 270
},
"facing=north,half=lower,hinge=right,open=true": {
"model": "templates:door_bottom_right_open_special",
"y": 180
},
"facing=north,half=upper,hinge=left,open=false": {
"model": "templates:door_top_left_special",
"y": 270
},
"facing=north,half=upper,hinge=left,open=true": {
"model": "templates:door_top_left_open_special"
},
"facing=north,half=upper,hinge=right,open=false": {
"model": "templates:door_top_right_special",
"y": 270
},
"facing=north,half=upper,hinge=right,open=true": {
"model": "templates:door_top_right_open_special",
"y": 180
},
"facing=south,half=lower,hinge=left,open=false": {
"model": "templates:door_bottom_left_special",
"y": 90
},
"facing=south,half=lower,hinge=left,open=true": {
"model": "templates:door_bottom_left_open_special",
"y": 180
},
"facing=south,half=lower,hinge=right,open=false": {
"model": "templates:door_bottom_right_special",
"y": 90
},
"facing=south,half=lower,hinge=right,open=true": {
"model": "templates:door_bottom_right_open_special"
},
"facing=south,half=upper,hinge=left,open=false": {
"model": "templates:door_top_left_special",
"y": 90
},
"facing=south,half=upper,hinge=left,open=true": {
"model": "templates:door_top_left_open_special",
"y": 180
},
"facing=south,half=upper,hinge=right,open=false": {
"model": "templates:door_top_right_special",
"y": 90
},
"facing=south,half=upper,hinge=right,open=true": {
"model": "templates:door_top_right_open_special"
},
"facing=west,half=lower,hinge=left,open=false": {
"model": "templates:door_bottom_left_special",
"y": 180
},
"facing=west,half=lower,hinge=left,open=true": {
"model": "templates:door_bottom_left_open_special",
"y": 270
},
"facing=west,half=lower,hinge=right,open=false": {
"model": "templates:door_bottom_right_special",
"y": 180
},
"facing=west,half=lower,hinge=right,open=true": {
"model": "templates:door_bottom_right_open_special",
"y": 90
},
"facing=west,half=upper,hinge=left,open=false": {
"model": "templates:door_top_left_special",
"y": 180
},
"facing=west,half=upper,hinge=left,open=true": {
"model": "templates:door_top_left_open_special",
"y": 270
},
"facing=west,half=upper,hinge=right,open=false": {
"model": "templates:door_top_right_special",
"y": 180
},
"facing=west,half=upper,hinge=right,open=true": {
"model": "templates:door_top_right_open_special",
"y": 90
}
}
}

View File

@ -5,6 +5,7 @@
"block.templates.candle": "Candle Template",
"block.templates.carpet": "Carpet Template",
"block.templates.cube": "Cube Template",
"block.templates.door": "Door Template",
"block.templates.fence": "Fence Template",
"block.templates.fence_gate": "Fence Gate Template",
"block.templates.iron_trapdoor": "Iron Trapdoor Template",