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

This commit is contained in:
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);
}
}