more removal and made slabs with vertical slabs into the same block

This commit is contained in:
Adrien1106 2024-02-09 19:51:48 +01:00
parent 5063be5765
commit 2402e86ea7
19 changed files with 88 additions and 537 deletions

View File

@ -33,7 +33,7 @@ public class Templates implements ModInitializer {
//addon devs: *Don't* add your blocks to this collection, it's just for my registration convenience since Templates adds a lot of blocks...
@ApiStatus.Internal static final ArrayList<Block> INTERNAL_TEMPLATES = new ArrayList<>();
@ApiStatus.Internal static Block CUBE, STAIRS, SLAB, VERTICAL_SLAB, POST, FENCE, FENCE_GATE, DOOR, TRAPDOOR, IRON_DOOR, IRON_TRAPDOOR, PRESSURE_PLATE, BUTTON, LEVER, WALL, CARPET, PANE, CANDLE;
@ApiStatus.Internal static Block CUBE, STAIRS, SLAB, POST, FENCE, FENCE_GATE, DOOR, TRAPDOOR, IRON_DOOR, IRON_TRAPDOOR, PRESSURE_PLATE, BUTTON, LEVER, WALL, CARPET, PANE, CANDLE;
//For addon devs: Please don't stuff more blocks into this BlockEntityType, and register your own.
//You can even re-register the same TemplateEntity class under your own ID if you like. (It's an extensible block entity.)
@ -52,7 +52,6 @@ public class Templates implements ModInitializer {
CUBE = registerTemplate("cube" , new TemplateBlock(TemplateInteractionUtil.makeSettings()));
STAIRS = registerTemplate("stairs" , new TemplateStairsBlock(cp(Blocks.OAK_STAIRS)));
SLAB = registerTemplate("slab" , new TemplateSlabBlock(cp(Blocks.OAK_SLAB)));
VERTICAL_SLAB = registerTemplate("vertical_slab" , new TemplateVerticalSlabBlock(cp(Blocks.OAK_SLAB)));
POST = registerTemplate("post" , new TemplatePostBlock(cp(Blocks.OAK_FENCE)));
FENCE = registerTemplate("fence" , new TemplateFenceBlock(cp(Blocks.OAK_FENCE)));
FENCE_GATE = registerTemplate("fence_gate" , new TemplateFenceGateBlock(cp(Blocks.OAK_FENCE_GATE)));

View File

@ -65,7 +65,6 @@ public class TemplatesClient implements ClientModInitializer {
api.addTemplateModel(Templates.id("outer_stairs_special") , api.auto(new Identifier("block/outer_stairs")));
api.addTemplateModel(Templates.id("trapdoor_bottom_special") , api.auto(new Identifier("block/template_trapdoor_bottom")));
api.addTemplateModel(Templates.id("trapdoor_top_special") , api.auto(new Identifier("block/template_trapdoor_top")));
api.addTemplateModel(Templates.id("vertical_slab_special") , api.auto(Templates.id("block/vertical_slab"))); //my model not vanilla
api.addTemplateModel(Templates.id("wall_post_special") , api.auto(new Identifier("block/template_wall_post")));
//vanilla style models (using "special-sprite replacement" method)
@ -97,7 +96,6 @@ public class TemplatesClient implements ClientModInitializer {
api.assignItemModel(Templates.id("slab_bottom_special") , Templates.SLAB);
api.assignItemModel(Templates.id("stairs_special") , Templates.STAIRS);
api.assignItemModel(Templates.id("trapdoor_bottom_special") , Templates.TRAPDOOR);
api.assignItemModel(Templates.id("vertical_slab_special") , Templates.VERTICAL_SLAB);
api.assignItemModel(Templates.id("wall_inventory_special") , Templates.WALL);
}

View File

@ -3,85 +3,59 @@ package fr.adrien1106.reframedtemplates.block;
import com.google.common.base.MoreObjects;
import fr.adrien1106.reframedtemplates.Templates;
import fr.adrien1106.reframedtemplates.api.TemplateInteractionUtil;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.SlabBlock;
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.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.Properties;
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.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
public class TemplateSlabBlock extends SlabBlock implements BlockEntityProvider {
public class TemplateSlabBlock extends WaterloggableTemplateBlock implements BlockEntityProvider, Waterloggable {
private static final VoxelShape DOWN = VoxelShapes.cuboid(0f, 0f, 0f, 1f, 0.5f, 1f);
private static final VoxelShape UP = VoxelShapes.cuboid(0f, 0.5f, 0f, 1f, 1f, 1f);
private static final VoxelShape NORTH = VoxelShapes.cuboid(0f, 0f, 0f, 1f, 1f, 0.5f);
private static final VoxelShape SOUTH = VoxelShapes.cuboid(0f, 0f, 0.5f, 1f, 1f, 1f);
private static final VoxelShape EAST = VoxelShapes.cuboid(0.5f, 0f, 0f, 1f, 1f, 1f);
private static final VoxelShape WEST = VoxelShapes.cuboid(0f, 0f, 0f, 0.5f, 1f, 1f);
public TemplateSlabBlock(Settings settings) {
super(settings);
setDefaultState(TemplateInteractionUtil.setDefaultStates(getDefaultState()));
}
@Nullable
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return Templates.TEMPLATE_BLOCK_ENTITY.instantiate(pos, state);
setDefaultState(getDefaultState().with(Properties.FACING, Direction.DOWN));
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(TemplateInteractionUtil.appendProperties(builder));
super.appendProperties(builder.add(Properties.FACING));
}
@Nullable
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return TemplateInteractionUtil.modifyPlacementState(super.getPlacementState(ctx), ctx);
return super.getPlacementState(ctx).with(Properties.FACING, ctx.getSide().getOpposite());
}
@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);
}
@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);
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return switch (state.get(Properties.FACING)) {
case DOWN -> DOWN;
case UP -> UP;
case NORTH -> NORTH;
case SOUTH -> SOUTH;
case EAST -> EAST;
case WEST -> WEST;
};
}
}

View File

@ -1,117 +0,0 @@
package fr.adrien1106.reframedtemplates.block;
import fr.adrien1106.reframedtemplates.api.TemplateInteractionUtil;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.enums.SlabType;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.util.StringIdentifiable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import org.jetbrains.annotations.Nullable;
//Extending SlabBlock from this is a little bit bold - let's see how this goes
public class TemplateVerticalSlabBlock extends TemplateSlabBlock {
public TemplateVerticalSlabBlock(Settings settings) {
super(settings);
setDefaultState(getDefaultState().with(AFFINITY, Affinity.X));
}
protected static final EnumProperty<Affinity> AFFINITY = EnumProperty.of("affinity", Affinity.class);
protected static final VoxelShape NORTH_SHAPE = createCuboidShape(0, 0, 0, 16, 16, 8);
protected static final VoxelShape EAST_SHAPE = createCuboidShape(8, 0, 0, 16, 16, 16);
protected static final VoxelShape SOUTH_SHAPE = createCuboidShape(0, 0, 8, 16, 16, 16);
protected static final VoxelShape WEST_SHAPE = createCuboidShape(0, 0, 0, 8, 16, 16);
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder.add(AFFINITY));
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext ctx) {
Direction d = stateToDirection(state);
if(d == null) return VoxelShapes.fullCube(); //double slab
else return switch(d) {
case NORTH -> NORTH_SHAPE;
case EAST -> EAST_SHAPE;
case SOUTH -> SOUTH_SHAPE;
case WEST -> WEST_SHAPE;
default -> VoxelShapes.fullCube(); //unreachable
};
}
@Override
public @Nullable BlockState getPlacementState(ItemPlacementContext ctx) {
BlockPos pos = ctx.getBlockPos();
BlockState existingState = ctx.getWorld().getBlockState(pos);
BlockState state;
if(existingState.isOf(this)) {
//Player clicked inside of an existing vertical slab. Complete the double slab.
state = existingState.with(TYPE, SlabType.DOUBLE).with(WATERLOGGED, false);
} else {
state = getDefaultState().with(WATERLOGGED, ctx.getWorld().getFluidState(pos).getFluid() == Fluids.WATER);
//chosen by fair dice roll, guaranteed to be intuitive
if(ctx.getPlayer() != null && ctx.getPlayer().isSneaky() && ctx.getSide().getAxis().isHorizontal()) {
state = directionToState(state, ctx.getSide().getOpposite());
} else {
state = directionToState(state, ctx.getHorizontalPlayerFacing());
}
}
return TemplateInteractionUtil.modifyPlacementState(state, ctx);
}
@Override
public boolean canReplace(BlockState state, ItemPlacementContext ctx) {
SlabType type = state.get(TYPE);
if(type == SlabType.DOUBLE) return false;
ItemStack stack = ctx.getStack();
if(!stack.isOf(asItem())) return false;
//This looks wrong, right? if !ctx.canReplaceExisting, return "true"?
//canReplaceExisting seems to return false when the placement was "bumped"
//into this blockspace, like when you click the side of an end rod that's facing my block.
//If that happens I dont care what orientation you're facing, let's just complete the slab.
if(!ctx.canReplaceExisting()) return true;
Direction d = stateToDirection(state);
return d != null && d == ctx.getSide().getOpposite();
}
protected enum Affinity implements StringIdentifiable {
X, Z;
@Override
public String asString() {
return this == X ? "x" : "z";
}
}
//This only exists because I'm being dumb and extending SlabBlock.
//Really I should fold out into a six-way N/S/E/W/double_x/double_z enum.
protected @Nullable Direction stateToDirection(BlockState state) {
SlabType type = state.get(TYPE);
if(type == SlabType.DOUBLE) return null;
return state.get(AFFINITY) == Affinity.X ?
(type == SlabType.BOTTOM ? Direction.WEST : Direction.EAST) :
(type == SlabType.BOTTOM ? Direction.NORTH : Direction.SOUTH);
}
protected BlockState directionToState(BlockState state, Direction dir) {
return state.with(AFFINITY, (dir == Direction.EAST || dir == Direction.WEST) ? Affinity.X : Affinity.Z)
.with(TYPE, (dir == Direction.NORTH || dir == Direction.WEST) ? SlabType.BOTTOM : SlabType.TOP);
}
}

View File

@ -1,13 +1,65 @@
{
"variants": {
"type=bottom": {
"model": "reframedtemplates:slab_bottom_special"
"multipart": [
{
"apply": {
"model": "reframedtemplates:slab_bottom_special",
"uvlock": true
},
"when": {
"facing": "down"
}
},
"type=double": {
"model": "reframedtemplates:cube_special"
{
"apply": {
"model": "reframedtemplates:slab_bottom_special",
"uvlock": true,
"x": 180
},
"when": {
"facing": "up"
}
},
"type=top": {
"model": "reframedtemplates:slab_top_special"
{
"apply": {
"model": "reframedtemplates:slab_bottom_special",
"uvlock": true,
"x": 270
},
"when": {
"facing": "north"
}
},
{
"apply": {
"model": "reframedtemplates:slab_bottom_special",
"uvlock": true,
"x": 90
},
"when": {
"facing": "south"
}
},
{
"apply": {
"model": "reframedtemplates:slab_bottom_special",
"uvlock": true,
"x": 90,
"y": 90
},
"when": {
"facing": "west"
}
},
{
"apply": {
"model": "reframedtemplates:slab_bottom_special",
"uvlock": true,
"x": 90,
"y": 270
},
"when": {
"facing": "east"
}
}
}
]
}

View File

@ -1,64 +0,0 @@
{
"variants": {
"edge=down_east": {
"model": "reframedtemplates:slope_special",
"uvlock": true,
"y": 270
},
"edge=down_north": {
"model": "reframedtemplates:slope_special",
"uvlock": true,
"y": 180
},
"edge=down_south": {
"model": "reframedtemplates:slope_special"
},
"edge=down_west": {
"model": "reframedtemplates:slope_special",
"uvlock": true,
"y": 90
},
"edge=up_east": {
"model": "reframedtemplates:slope_special",
"uvlock": true,
"x": 180,
"y": 90
},
"edge=up_north": {
"model": "reframedtemplates:slope_special",
"uvlock": true,
"x": 180
},
"edge=up_south": {
"model": "reframedtemplates:slope_special",
"uvlock": true,
"x": 180,
"y": 180
},
"edge=up_west": {
"model": "reframedtemplates:slope_special",
"uvlock": true,
"x": 180,
"y": 270
},
"edge=north_east": {
"model": "reframedtemplates:slope_side_special",
"uvlock": true,
"y": 270
},
"edge=north_west": {
"model": "reframedtemplates:slope_side_special",
"uvlock": true,
"y": 180
},
"edge=south_east": {
"model": "reframedtemplates:slope_side_special",
"uvlock": true
},
"edge=south_west": {
"model": "reframedtemplates:slope_side_special",
"uvlock": true,
"y": 90
}
}
}

View File

@ -1,64 +0,0 @@
{
"variants": {
"edge=down_east": {
"model": "reframedtemplates:tiny_slope_special",
"uvlock": true,
"y": 270
},
"edge=down_north": {
"model": "reframedtemplates:tiny_slope_special",
"uvlock": true,
"y": 180
},
"edge=down_south": {
"model": "reframedtemplates:tiny_slope_special"
},
"edge=down_west": {
"model": "reframedtemplates:tiny_slope_special",
"uvlock": true,
"y": 90
},
"edge=up_east": {
"model": "reframedtemplates:tiny_slope_special",
"uvlock": true,
"x": 180,
"y": 90
},
"edge=up_north": {
"model": "reframedtemplates:tiny_slope_special",
"uvlock": true,
"x": 180
},
"edge=up_south": {
"model": "reframedtemplates:tiny_slope_special",
"uvlock": true,
"x": 180,
"y": 180
},
"edge=up_west": {
"model": "reframedtemplates:tiny_slope_special",
"uvlock": true,
"x": 180,
"y": 270
},
"edge=north_east": {
"model": "reframedtemplates:tiny_slope_side_special",
"uvlock": true,
"y": 270
},
"edge=north_west": {
"model": "reframedtemplates:tiny_slope_side_special",
"uvlock": true,
"y": 180
},
"edge=south_east": {
"model": "reframedtemplates:tiny_slope_side_special",
"uvlock": true
},
"edge=south_west": {
"model": "reframedtemplates:tiny_slope_side_special",
"uvlock": true,
"y": 90
}
}
}

View File

@ -1,25 +0,0 @@
{
"variants": {
"type=bottom,affinity=x": {
"model": "reframedtemplates:vertical_slab_special",
"y": 270
},
"type=double,affinity=x": {
"model": "reframedtemplates:cube_special"
},
"type=top,affinity=x": {
"model": "reframedtemplates:vertical_slab_special",
"y": 90
},
"type=bottom,affinity=z": {
"model": "reframedtemplates:vertical_slab_special"
},
"type=double,affinity=z": {
"model": "reframedtemplates:cube_special"
},
"type=top,affinity=z": {
"model": "reframedtemplates:vertical_slab_special",
"y": 180
}
}
}

View File

@ -14,12 +14,9 @@
"block.reframedtemplates.pane": "Pane Frame",
"block.reframedtemplates.post": "Post Frame",
"block.reframedtemplates.pressure_plate": "Pressure Plate Frame",
"block.reframedtemplates.slope": "Slope Frame",
"block.reframedtemplates.tiny_slope": "Tiny Slope Frame",
"block.reframedtemplates.slab": "Slab Frame",
"block.reframedtemplates.stairs": "Stairs Frame",
"block.reframedtemplates.trapdoor": "Trapdoor Frame",
"block.reframedtemplates.vertical_slab": "Vertical Slab Frame",
"block.reframedtemplates.wall": "Wall Frame"
}

View File

@ -1,31 +0,0 @@
{
"parent": "minecraft:block/block",
"gui_light": "front",
"display": {
"firstperson_righthand": {
"rotation": [ 0, 135, 0 ],
"translation": [ 0, 0, 0 ],
"scale": [ 0.40, 0.40, 0.40 ]
},
"firstperson_lefthand": {
"rotation": [ 0, 135, 0 ],
"translation": [ 0, 0, 0 ],
"scale": [ 0.40, 0.40, 0.40 ]
},
"thirdperson_righthand": {
"rotation": [ 75, -225, 0 ],
"translation": [ 0, 2.5, 0],
"scale": [ 0.375, 0.375, 0.375 ]
},
"thirdperson_lefthand": {
"rotation": [ 75, -225, 0 ],
"translation": [ 0, 2.5, 0],
"scale": [ 0.375, 0.375, 0.375 ]
},
"fixed": {
"rotation": [ 0, 90, 0 ],
"translation": [ 0, 0, 0],
"scale":[ 0.5, 0.5, 0.5 ]
}
}
}

View File

@ -1,11 +0,0 @@
{
"parent": "reframedtemplates:block/slope_base",
"gui_light": "front",
"display": {
"gui": {
"rotation": [ 30, 225, 0 ],
"translation": [ 2, 0.5, 0],
"scale":[ 0.625, 0.625, 0.625 ]
}
}
}

View File

@ -1,75 +0,0 @@
{
"parent": "minecraft:block/block",
"textures": {
"down": "reframedtemplates:templates_special/down",
"up": "reframedtemplates:templates_special/up",
"north": "reframedtemplates:templates_special/north",
"south": "reframedtemplates:templates_special/south",
"west": "reframedtemplates:templates_special/west",
"east": "reframedtemplates:templates_special/east"
},
"elements": [
{
"from": [0, 0, 0],
"to": [16, 16, 8],
"faces": {
"down": {
"texture": "#down",
"cullface": "down"
},
"up": {
"texture": "#up",
"cullface": "up"
},
"north": {
"texture": "#north",
"cullface": "north"
},
"south": {
"texture": "#south"
},
"west": {
"texture": "#west",
"cullface": "west"
},
"east": {
"texture": "#east",
"cullface": "east"
}
}
}
],
"display": {
"thirdperson_righthand": {
"rotation": [75, -135, 0],
"translation": [0, 2.5, 0],
"scale": [0.375, 0.375, 0.375]
},
"thirdperson_lefthand": {
"rotation": [75, -135, 0],
"translation": [0, 2.5, 0],
"scale": [0.375, 0.375, 0.375]
},
"firstperson_righthand": {
"rotation": [0, -145, 0],
"scale": [0.4, 0.4, 0.4]
},
"firstperson_lefthand": {
"rotation": [0, 225, 0],
"scale": [0.4, 0.4, 0.4]
},
"ground": {
"translation": [0, 3, 0],
"scale": [0.25, 0.25, 0.25]
},
"gui": {
"rotation": [30, 45, 0],
"translation": [1.75, -1, 0],
"scale": [0.625, 0.625, 0.625]
},
"fixed": {
"rotation": [0, -90, 0],
"scale": [0.5, 0.5, 0.5]
}
}
}

View File

@ -15,7 +15,6 @@
"reframedtemplates:slab",
"reframedtemplates:stairs",
"reframedtemplates:trapdoor",
"reframedtemplates:vertical_slab",
"reframedtemplates:wall"
]
}

View File

@ -1,7 +1,6 @@
{
"replace": false,
"values": [
"reframedtemplates:slab",
"reframedtemplates:vertical_slab"
"reframedtemplates:slab"
]
}

View File

@ -1,7 +1,6 @@
{
"replace": false,
"values": [
"reframedtemplates:slab",
"reframedtemplates:vertical_slab"
"reframedtemplates:slab"
]
}

View File

@ -18,7 +18,6 @@
"reframedtemplates:slab",
"reframedtemplates:stairs",
"reframedtemplates:trapdoor",
"reframedtemplates:vertical_slab",
"reframedtemplates:wall"
]
},

View File

@ -6,25 +6,6 @@
"entries": [
{
"type": "minecraft:item",
"functions": [
{
"add": false,
"conditions": [
{
"block": "reframedtemplates:slab",
"condition": "minecraft:block_state_property",
"properties": {
"type": "double"
}
}
],
"count": 2.0,
"function": "minecraft:set_count"
},
{
"function": "minecraft:explosion_decay"
}
],
"name": "reframedtemplates:slab"
}
],

View File

@ -1,38 +0,0 @@
{
"type": "minecraft:block",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:item",
"functions": [
{
"add": false,
"conditions": [
{
"block": "reframedtemplates:vertical_slab",
"condition": "minecraft:block_state_property",
"properties": {
"type": "double"
}
}
],
"count": 2.0,
"function": "minecraft:set_count"
},
{
"function": "minecraft:explosion_decay"
}
],
"name": "reframedtemplates:vertical_slab"
}
],
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
]
}
]
}

View File

@ -1,21 +0,0 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"I ",
"I~",
"I "
],
"key": {
"I": {
"item": "minecraft:bamboo"
},
"~": {
"item": "minecraft:string"
}
},
"result": {
"item": "reframedtemplates:vertical_slab",
"count": 6
},
"group": "reframedtemplates"
}