From a793bad0ed9c605db530475ad1762a45357a55b7 Mon Sep 17 00:00:00 2001 From: quat1024 Date: Sun, 9 Jul 2023 00:46:59 -0400 Subject: [PATCH] Make TemplateBlock more copy-pasteable --- .../cottonmc/templates/api/TemplateInteractionUtil.java | 1 + .../io/github/cottonmc/templates/block/TemplateBlock.java | 4 +++- .../github/cottonmc/templates/block/TemplateCarpetBlock.java | 4 +++- .../github/cottonmc/templates/block/TemplateFenceBlock.java | 4 +++- .../cottonmc/templates/block/TemplatePressurePlateBlock.java | 4 +++- .../io/github/cottonmc/templates/block/TemplateSlabBlock.java | 4 +++- .../io/github/cottonmc/templates/block/TemplateWallBlock.java | 4 +++- 7 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/github/cottonmc/templates/api/TemplateInteractionUtil.java b/src/main/java/io/github/cottonmc/templates/api/TemplateInteractionUtil.java index ba49ed6..4058cb0 100644 --- a/src/main/java/io/github/cottonmc/templates/api/TemplateInteractionUtil.java +++ b/src/main/java/io/github/cottonmc/templates/api/TemplateInteractionUtil.java @@ -135,6 +135,7 @@ public class TemplateInteractionUtil { } } + //Returns "null" to signal "no opinion". Imagine it like an InteractionResult.PASS. public static @Nullable VoxelShape getCollisionShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ctx) { return view.getBlockEntity(pos) instanceof TemplateEntity be && !be.isSolid() ? VoxelShapes.empty() : null; } diff --git a/src/main/java/io/github/cottonmc/templates/block/TemplateBlock.java b/src/main/java/io/github/cottonmc/templates/block/TemplateBlock.java index a5045c1..754ee16 100644 --- a/src/main/java/io/github/cottonmc/templates/block/TemplateBlock.java +++ b/src/main/java/io/github/cottonmc/templates/block/TemplateBlock.java @@ -40,7 +40,9 @@ public class TemplateBlock extends Block implements BlockEntityProvider { @Override public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { - return TemplateInteractionUtil.onUse(state, world, pos, player, hand, 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 diff --git a/src/main/java/io/github/cottonmc/templates/block/TemplateCarpetBlock.java b/src/main/java/io/github/cottonmc/templates/block/TemplateCarpetBlock.java index 60e2054..2ffa42f 100644 --- a/src/main/java/io/github/cottonmc/templates/block/TemplateCarpetBlock.java +++ b/src/main/java/io/github/cottonmc/templates/block/TemplateCarpetBlock.java @@ -42,7 +42,9 @@ public class TemplateCarpetBlock extends CarpetBlock implements BlockEntityProvi @Override public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { - return TemplateInteractionUtil.onUse(state, world, pos, player, hand, 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 diff --git a/src/main/java/io/github/cottonmc/templates/block/TemplateFenceBlock.java b/src/main/java/io/github/cottonmc/templates/block/TemplateFenceBlock.java index 607b2fc..1715ea8 100644 --- a/src/main/java/io/github/cottonmc/templates/block/TemplateFenceBlock.java +++ b/src/main/java/io/github/cottonmc/templates/block/TemplateFenceBlock.java @@ -42,7 +42,9 @@ public class TemplateFenceBlock extends FenceBlock implements BlockEntityProvide @Override public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { - return TemplateInteractionUtil.onUse(state, world, pos, player, hand, 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 diff --git a/src/main/java/io/github/cottonmc/templates/block/TemplatePressurePlateBlock.java b/src/main/java/io/github/cottonmc/templates/block/TemplatePressurePlateBlock.java index 5de148c..8fef171 100644 --- a/src/main/java/io/github/cottonmc/templates/block/TemplatePressurePlateBlock.java +++ b/src/main/java/io/github/cottonmc/templates/block/TemplatePressurePlateBlock.java @@ -46,7 +46,9 @@ public class TemplatePressurePlateBlock extends PressurePlateBlock implements Bl @Override public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { - return TemplateInteractionUtil.onUse(state, world, pos, player, hand, 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 diff --git a/src/main/java/io/github/cottonmc/templates/block/TemplateSlabBlock.java b/src/main/java/io/github/cottonmc/templates/block/TemplateSlabBlock.java index a85df87..186fd43 100644 --- a/src/main/java/io/github/cottonmc/templates/block/TemplateSlabBlock.java +++ b/src/main/java/io/github/cottonmc/templates/block/TemplateSlabBlock.java @@ -42,7 +42,9 @@ public class TemplateSlabBlock extends SlabBlock implements BlockEntityProvider @Override public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { - return TemplateInteractionUtil.onUse(state, world, pos, player, hand, 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 diff --git a/src/main/java/io/github/cottonmc/templates/block/TemplateWallBlock.java b/src/main/java/io/github/cottonmc/templates/block/TemplateWallBlock.java index 9abfd8c..0f45583 100644 --- a/src/main/java/io/github/cottonmc/templates/block/TemplateWallBlock.java +++ b/src/main/java/io/github/cottonmc/templates/block/TemplateWallBlock.java @@ -50,7 +50,9 @@ public class TemplateWallBlock extends WallBlock implements BlockEntityProvider @Override public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { - return TemplateInteractionUtil.onUse(state, world, pos, player, hand, 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