Improve shape utility

This commit is contained in:
Andrew-71 2023-09-23 14:42:48 +03:00
parent e997a0a281
commit 2a6898b664
8 changed files with 96 additions and 131 deletions

View file

@ -32,9 +32,9 @@ import static net.minecraft.block.StairsBlock.SHAPE;
// By the way, Blockstate not updating when removing stairs is a "creative decision" apparently
// - Andrew71
public class HandrailBlock extends HorizontalFacingBlock implements BlockEntityProvider, Waterloggable {
protected static final Shapes.HorizontalShape2 SHAPE1;
protected static final Shapes.HorizontalShape2 SHAPE2;
protected static final Shapes.HorizontalShape2 SHAPE3;
protected static final Shapes.HorizontalShape SHAPE1;
protected static final Shapes.HorizontalShape SHAPE2;
protected static final Shapes.HorizontalShape SHAPE3;
public static final BooleanProperty WATERLOGGED;
public static final IntProperty ROTATION;
@ -128,9 +128,9 @@ public class HandrailBlock extends HorizontalFacingBlock implements BlockEntityP
}
static {
SHAPE2 = new Shapes.HorizontalShape2(List.of(List.of(0.0, 0.0, 15.0, 16.0, 17.0, 16.0), List.of(0.0, 17.0, 14.5, 16.0, 19.0, 16.5)));
SHAPE1 = new Shapes.HorizontalShape2(List.of(List.of(0.0, 0.0, 15.0, 8.0, 18.0, 16.0), List.of(8.0, -8.0, 15.0, 16.0, 10.0, 16.0)));
SHAPE3 = new Shapes.HorizontalShape2(List.of(List.of(0.0, -8.0, 15.0, 8.0, 10.0, 16.0), List.of(8.0, 0.0, 15.0, 16.0, 18.0, 16.0)));
SHAPE2 = new Shapes.HorizontalShape(List.of(List.of(0.0, 0.0, 15.0, 16.0, 17.0, 16.0), List.of(0.0, 17.0, 14.5, 16.0, 19.0, 16.5)));
SHAPE1 = new Shapes.HorizontalShape(List.of(List.of(0.0, 0.0, 15.0, 8.0, 18.0, 16.0), List.of(8.0, -8.0, 15.0, 16.0, 10.0, 16.0)));
SHAPE3 = new Shapes.HorizontalShape(List.of(List.of(0.0, -8.0, 15.0, 8.0, 10.0, 16.0), List.of(8.0, 0.0, 15.0, 16.0, 18.0, 16.0)));
ROTATION = IntProperty.of("rotate", 1, 3);;
WATERLOGGED = Properties.WATERLOGGED;
}

View file

@ -19,7 +19,7 @@ import su.a71.new_soviet.util.Shapes;
import java.util.List;
public class TVBlock extends HorizontalFacingBlock implements BlockEntityProvider {
protected static final Shapes.HorizontalShape SHAPE;
protected static final Shapes.HorizontalShapeLegacy SHAPE;
public TVBlock(AbstractBlock.Settings settings) {
super(settings.sounds(BlockSoundGroup.METAL).pistonBehavior(PistonBehavior.BLOCK).strength(1f, 2f));
@ -54,6 +54,6 @@ public class TVBlock extends HorizontalFacingBlock implements BlockEntityProvide
}
static {
SHAPE = new Shapes.HorizontalShape(List.of(List.of(0.0, 1.0, 3.0, 16.0, 13.0, 13.0), List.of(2.0, 0.0, 4.0, 14.0, 1.0, 12.0), List.of(6.0, 13.0, 7.0, 10.0, 14.0, 9.0)));
SHAPE = new Shapes.HorizontalShapeLegacy(List.of(List.of(0.0, 1.0, 3.0, 16.0, 13.0, 13.0), List.of(2.0, 0.0, 4.0, 14.0, 1.0, 12.0), List.of(6.0, 13.0, 7.0, 10.0, 14.0, 9.0)));
}
}

View file

@ -1,14 +1,5 @@
package su.a71.new_soviet.blocks.lamps;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
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.WorldView;
import su.a71.new_soviet.util.Shapes;
import java.util.List;
@ -17,7 +8,7 @@ public class DevTableLampBlock extends GoldenTableLampBlock {
public DevTableLampBlock(Settings settings) {
super(settings);
SHAPE = new Shapes.HorizontalShape(List.of(
SHAPE = new Shapes.HorizontalShapeLegacy(List.of(
List.of(5.0, 0.0, 5.0, 11.0, 2.0, 11.0),
List.of(7.0, 2.0, 7.0, 9.0, 4.0, 9.0),
List.of(6.0, 4.0, 6.0, 10.0, 5.0, 10.0),

View file

@ -21,7 +21,7 @@ import java.util.List;
public class GoldenTableLampBlock extends LampBlock {
public static final DirectionProperty FACING;
public Shapes.HorizontalShape SHAPE = new Shapes.HorizontalShape(List.of(
public Shapes.HorizontalShapeLegacy SHAPE = new Shapes.HorizontalShapeLegacy(List.of(
List.of(5.0, 0.0, 5.0, 11.0, 2.0, 11.0),
List.of(7.0, 2.0, 7.0, 9.0, 4.0, 9.0),
List.of(6.0, 4.0, 6.0, 10.0, 5.0, 10.0),

View file

@ -23,14 +23,12 @@ import net.minecraft.world.WorldView;
import org.jetbrains.annotations.Nullable;
import su.a71.new_soviet.util.Shapes;
import java.util.List;
public class LampPostLampBlock extends Block implements Waterloggable {
public static final DirectionProperty FACING;
public static final BooleanProperty WATERLOGGED;
public Shapes.HorizontalShape SHAPE;
public Shapes.HorizontalShapeLegacy SHAPE;
public LampPostLampBlock(AbstractBlock.Settings settings, Shapes.HorizontalShape shape) {
public LampPostLampBlock(AbstractBlock.Settings settings, Shapes.HorizontalShapeLegacy shape) {
super(settings.luminance((state) -> 14));
SHAPE = shape;
this.setDefaultState(this.stateManager.getDefaultState()

View file

@ -20,12 +20,12 @@ import su.a71.new_soviet.registration.NSE_Sounds;
public class DiceItem extends Item {
private final int sides;
private final String loacl_tooltip;
private final String local_tooltip;
public DiceItem(int sides, String localTooltip, Settings settings) {
super(settings);
this.sides = sides;
this.loacl_tooltip = localTooltip;
this.local_tooltip = localTooltip;
}
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
@ -56,7 +56,7 @@ public class DiceItem extends Item {
@Override
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
tooltip.add(Text.translatable(loacl_tooltip));
tooltip.add(Text.translatable(local_tooltip));
super.appendTooltip(stack, world, tooltip, context);
}
}

View file

@ -46,22 +46,22 @@ public class NSE_Custom extends NSE_BaseRegistration {
public static final LampPostBaseBlock LAMP_POST_BASE = new LampPostBaseBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.METAL).strength(1f, 1.5f).mapColor(MapColor.IRON_GRAY));
public static final LampPostLampBlock CAGED_POST_LAMP = new LampPostLampBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.METAL).strength(1f, 1.5f).mapColor(MapColor.IRON_GRAY),
new Shapes.HorizontalShape(List.of(List.of(6.5, 0.0, 6.5, 9.5, 2.0, 9.5),
new Shapes.HorizontalShapeLegacy(List.of(List.of(6.5, 0.0, 6.5, 9.5, 2.0, 9.5),
List.of(7.0, 2.0, 7.0, 9.0, 7.0, 9.0),
List.of(6.5, 7.0, 6.5, 9.5, 9.0, 9.5),
List.of(7.0, 9.0, 7.0, 9.0, 12.0, 9.0))));
public static final LampPostLampBlock MODERN_POST_LAMP = new LampPostLampBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.METAL).strength(1f, 1.5f).mapColor(MapColor.IRON_GRAY),
new Shapes.HorizontalShape(List.of(List.of(6.5, 0.0, 6.5, 9.5, 2.0, 9.5),
new Shapes.HorizontalShapeLegacy(List.of(List.of(6.5, 0.0, 6.5, 9.5, 2.0, 9.5),
List.of(7.0, 2.0, 7.0, 9.0, 7.0, 9.0),
List.of(6.5, 7.0, 6.5, 9.5, 9.0, 9.5),
List.of(7.0, 9.0, 7.0, 9.0, 12.0, 9.0))));
public static final LampPostLampBlock BIG_POST_LAMP = new LampPostLampBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.METAL).strength(1f, 1.5f).mapColor(MapColor.IRON_GRAY),
new Shapes.HorizontalShape(List.of(List.of(6.5, 0.0, 6.5, 9.5, 2.0, 9.5),
new Shapes.HorizontalShapeLegacy(List.of(List.of(6.5, 0.0, 6.5, 9.5, 2.0, 9.5),
List.of(7.0, 2.0, 7.0, 9.0, 7.0, 9.0),
List.of(6.5, 7.0, 6.5, 9.5, 9.0, 9.5),
List.of(7.0, 9.0, 7.0, 9.0, 12.0, 9.0))));
public static final LampPostLampBlock VINTAGE_POST_LAMP = new LampPostLampBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.METAL).strength(1f, 1.5f).mapColor(MapColor.IRON_GRAY),
new Shapes.HorizontalShape(List.of(List.of(6.5, 0.0, 6.5, 9.5, 2.0, 9.5),
new Shapes.HorizontalShapeLegacy(List.of(List.of(6.5, 0.0, 6.5, 9.5, 2.0, 9.5),
List.of(7.0, 2.0, 7.0, 9.0, 7.0, 9.0),
List.of(6.5, 7.0, 6.5, 9.5, 9.0, 9.5),
List.of(7.0, 9.0, 7.0, 9.0, 12.0, 9.0))));

View file

@ -8,25 +8,13 @@ import java.util.ArrayList;
import java.util.List;
public class Shapes {
public static class NHShape{
private VoxelShape NORTH;
private VoxelShape WEST;
private VoxelShape SOUTH;
private VoxelShape EAST;
private double minX;
private double minY;
private double minZ;
private double maxX;
private double maxY;
private double maxZ;
public static class NHShapeLegacy {
private final VoxelShape NORTH;
private final VoxelShape WEST;
private final VoxelShape SOUTH;
private final VoxelShape EAST;
public NHShape(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
this.minX = minX;
this.minY = minY;
this.minZ = minZ;
this.maxX = maxX;
this.maxY = maxY;
this.maxZ = maxZ;
public NHShapeLegacy(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
this.NORTH = Block.createCuboidShape(minX, minY, minZ, maxX, maxY, maxZ);
this.WEST = Block.createCuboidShape(minZ, minY, minX, maxZ, maxY, maxX);
this.SOUTH = Block.createCuboidShape(minX, minY, (16 - maxZ), maxX, maxY, (16 - minZ));
@ -50,25 +38,13 @@ public class Shapes {
}
}
public static class NHShape2{
private VoxelShape NORTH;
private VoxelShape WEST;
private VoxelShape SOUTH;
private VoxelShape EAST;
private double minX;
private double minY;
private double minZ;
private double maxX;
private double maxY;
private double maxZ;
public static class NHShape {
private final VoxelShape NORTH;
private final VoxelShape WEST;
private final VoxelShape SOUTH;
private final VoxelShape EAST;
public NHShape2(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
this.minX = minX;
this.minY = minY;
this.minZ = minZ;
this.maxX = maxX;
this.maxY = maxY;
this.maxZ = maxZ;
public NHShape(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
this.NORTH = Block.createCuboidShape((16 - maxX), minY, minZ, (16 - minX), maxY, maxZ);
this.WEST = Block.createCuboidShape(minZ, minY, minX, maxZ, maxY, maxX);
this.SOUTH = Block.createCuboidShape(minX, minY, (16 - maxZ), maxX, maxY, (16 - minZ));
@ -92,11 +68,63 @@ public class Shapes {
}
}
public static class HorizontalShape{
private List ShapesListN;
private List ShapesListS;
private List ShapesListW;
private List ShapesListE;
public static class HorizontalShapeLegacy {
private final List<VoxelShape> ShapesListN;
private final List<VoxelShape> ShapesListS;
private final List<VoxelShape> ShapesListW;
private final List<VoxelShape> ShapesListE;
public HorizontalShapeLegacy(List<List<Double>> list) {
this.ShapesListN = new ArrayList<>();
this.ShapesListS = new ArrayList<>();
this.ShapesListW = new ArrayList<>();
this.ShapesListE = new ArrayList<>();
for (List<Double> i : list) {
NHShapeLegacy shape = new NHShapeLegacy(i.get(0), i.get(1), i.get(2), i.get(3), i.get(4), i.get(5));
ShapesListN.add(shape.north());
ShapesListS.add(shape.south());
ShapesListW.add(shape.west());
ShapesListE.add(shape.east());
}
}
public VoxelShape north() {
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);
for (VoxelShape o : ShapesListN) {
shape = VoxelShapes.union(shape, o);
}
return shape;
}
public VoxelShape west() {
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);;
for (VoxelShape o : ShapesListW) {
shape = VoxelShapes.union(shape, o);
}
return shape;
}
public VoxelShape south() {
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);;
for (VoxelShape shapesList : ShapesListS) {
shape = VoxelShapes.union(shape, shapesList);
}
return shape;
}
public VoxelShape east() {
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);;
for (VoxelShape o : ShapesListE) {
shape = VoxelShapes.union(shape, o);
}
return shape;
}
}
public static class HorizontalShape {
private final List<VoxelShape> ShapesListN;
private final List<VoxelShape> ShapesListS;
private final List<VoxelShape> ShapesListW;
private final List<VoxelShape> ShapesListE;
public HorizontalShape(List<List<Double>> list) {
this.ShapesListN = new ArrayList<>();
this.ShapesListS = new ArrayList<>();
@ -113,84 +141,32 @@ public class Shapes {
public VoxelShape north() {
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);
for (int i=0;i<ShapesListN.size();i++) {
shape = VoxelShapes.union(shape, (VoxelShape) ShapesListN.get(i));
for (VoxelShape o : ShapesListN) {
shape = VoxelShapes.union(shape, o);
}
return shape;
}
public VoxelShape west() {
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);;
for (int i=0;i<ShapesListW.size();i++) {
shape = VoxelShapes.union(shape, (VoxelShape) ShapesListW.get(i));
for (VoxelShape o : ShapesListW) {
shape = VoxelShapes.union(shape, o);
}
return shape;
}
public VoxelShape south() {
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);;
for (int i=0;i<ShapesListS.size();i++) {
shape = VoxelShapes.union(shape, (VoxelShape) ShapesListS.get(i));
for (VoxelShape shapesList : ShapesListS) {
shape = VoxelShapes.union(shape, shapesList);
}
return shape;
}
public VoxelShape east() {
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);;
for (int i=0;i<ShapesListE.size();i++) {
shape = VoxelShapes.union(shape, (VoxelShape) ShapesListE.get(i));
}
return shape;
}
}
public static class HorizontalShape2{
private List ShapesListN;
private List ShapesListS;
private List ShapesListW;
private List ShapesListE;
public HorizontalShape2(List<List<Double>> list) {
this.ShapesListN = new ArrayList<>();
this.ShapesListS = new ArrayList<>();
this.ShapesListW = new ArrayList<>();
this.ShapesListE = new ArrayList<>();
for (List<Double> i : list) {
NHShape2 shape = new NHShape2(i.get(0), i.get(1), i.get(2), i.get(3), i.get(4), i.get(5));
ShapesListN.add(shape.north());
ShapesListS.add(shape.south());
ShapesListW.add(shape.west());
ShapesListE.add(shape.east());
}
}
public VoxelShape north() {
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);
for (int i=0;i<ShapesListN.size();i++) {
shape = VoxelShapes.union(shape, (VoxelShape) ShapesListN.get(i));
}
return shape;
}
public VoxelShape west() {
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);;
for (int i=0;i<ShapesListW.size();i++) {
shape = VoxelShapes.union(shape, (VoxelShape) ShapesListW.get(i));
}
return shape;
}
public VoxelShape south() {
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);;
for (int i=0;i<ShapesListS.size();i++) {
shape = VoxelShapes.union(shape, (VoxelShape) ShapesListS.get(i));
}
return shape;
}
public VoxelShape east() {
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);;
for (int i=0;i<ShapesListE.size();i++) {
shape = VoxelShapes.union(shape, (VoxelShape) ShapesListE.get(i));
for (VoxelShape o : ShapesListE) {
shape = VoxelShapes.union(shape, o);
}
return shape;
}