Auto generated shapes for blocks
This commit is contained in:
parent
f04a353ab6
commit
1fd093d07d
49
shapenator.js
Normal file
49
shapenator.js
Normal file
@ -0,0 +1,49 @@
|
||||
|
||||
const models = [
|
||||
'android_station',
|
||||
'battery_bank',
|
||||
'matter_scanner',
|
||||
'pattern_storage',
|
||||
'matter_replicator',
|
||||
// 'matter_panel',
|
||||
'matter_decomposer',
|
||||
];
|
||||
|
||||
const fs = require('fs')
|
||||
const root = './src/main/resources/assets/overdrive_that_matters/models/block/'
|
||||
|
||||
const handle = fs.openSync('./src/main/java/ru/dbotthepony/mc/otm/shapes/BlockShapes.java', 'w')
|
||||
|
||||
fs.writeSync(handle, 'package ru.dbotthepony.mc.otm.shapes;\n\n\n')
|
||||
fs.writeSync(handle, `// Auto generated at ${new Date().toUTCString()}\n`)
|
||||
fs.writeSync(handle, 'public class BlockShapes {\n')
|
||||
|
||||
for (const model of models) {
|
||||
fs.writeSync(handle, '\tpublic static final BlockShape ' + model.toUpperCase() + ' = new BlockShape(\n')
|
||||
|
||||
const obj = JSON.parse(fs.readFileSync(root + model + '.json', {encoding: 'utf-8'}))
|
||||
let first = true
|
||||
|
||||
for (const elementID in obj.elements) {
|
||||
const element = obj.elements[elementID]
|
||||
|
||||
if (element.rotation)
|
||||
continue;
|
||||
|
||||
const from = element.from
|
||||
const to = element.to
|
||||
|
||||
if (first) {
|
||||
first = false
|
||||
} else {
|
||||
fs.writeSync(handle, ',\n')
|
||||
}
|
||||
|
||||
fs.writeSync(handle, `\t\tnew SimpleCuboid(${from[0] / 16}d, ${from[1] / 16}d, ${from[2] / 16}d, ${to[0] / 16}d, ${to[1] / 16}d, ${to[2] / 16}d)`)
|
||||
}
|
||||
|
||||
fs.writeSync(handle, '\n\t);\n\n')
|
||||
}
|
||||
|
||||
fs.writeSync(handle, '}')
|
||||
fs.closeSync(handle)
|
@ -26,6 +26,8 @@ import ru.dbotthepony.mc.otm.client.AndroidGui;
|
||||
import ru.dbotthepony.mc.otm.matter.MatterGrid;
|
||||
import ru.dbotthepony.mc.otm.matter.MatterRegistry;
|
||||
import ru.dbotthepony.mc.otm.network.MatteryNetworking;
|
||||
import ru.dbotthepony.mc.otm.shapes.Point;
|
||||
import ru.dbotthepony.mc.otm.shapes.Rectangle;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ru.dbotthepony.mc.otm.block;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
@ -15,8 +16,10 @@ import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import ru.dbotthepony.mc.otm.Registry;
|
||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityBatteryBank;
|
||||
import ru.dbotthepony.mc.otm.shapes.BlockShapes;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class BlockBatteryBank extends BlockMatteryRotatable implements EntityBlock {
|
||||
@Nullable
|
||||
@ -31,82 +34,28 @@ public class BlockBatteryBank extends BlockMatteryRotatable implements EntityBlo
|
||||
return new BlockEntityBatteryBank(blockPos, blockState);
|
||||
}
|
||||
|
||||
private static final List<VoxelShape> SHAPES;
|
||||
|
||||
static {
|
||||
var def = BlockShapes.BATTERY_BANK.computeShape();
|
||||
|
||||
SHAPES = List.of(
|
||||
def,
|
||||
def,
|
||||
def,
|
||||
BlockShapes.BATTERY_BANK.rotate(Direction.NORTH).computeShape(),
|
||||
BlockShapes.BATTERY_BANK.rotate(Direction.WEST).computeShape(),
|
||||
BlockShapes.BATTERY_BANK.rotate(Direction.EAST).computeShape()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState p_60555_, BlockGetter p_60556_, BlockPos p_60557_, CollisionContext p_60558_) {
|
||||
return SHAPES.get(p_60555_.getValue(FACING).ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean faceToPlayer(BlockPlaceContext context) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static final VoxelShape SHAPE;
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState p_60555_, BlockGetter p_60556_, BlockPos p_60557_, CollisionContext p_60558_) {
|
||||
return SHAPE;
|
||||
}
|
||||
|
||||
static {
|
||||
VoxelShape final_shape = Shapes.box(0.125, 0.125, 0.125, 0.875, 0.875, 0.875);
|
||||
|
||||
// вертикальные балки
|
||||
final_shape = Shapes.joinUnoptimized(final_shape, Shapes.box(
|
||||
0, 0, 0,
|
||||
0.125, 1, 0.125
|
||||
), BooleanOp.OR);
|
||||
|
||||
final_shape = Shapes.joinUnoptimized(final_shape, Shapes.box(
|
||||
0, 0, 0.875,
|
||||
0.125, 1, 1
|
||||
), BooleanOp.OR);
|
||||
|
||||
final_shape = Shapes.joinUnoptimized(final_shape, Shapes.box(
|
||||
0.875, 0, 0,
|
||||
1, 1, 0.125
|
||||
), BooleanOp.OR);
|
||||
|
||||
final_shape = Shapes.joinUnoptimized(final_shape, Shapes.box(
|
||||
0.875, 0, 0.875,
|
||||
1, 1, 1
|
||||
), BooleanOp.OR);
|
||||
|
||||
// горизонтальные балки сверху
|
||||
final_shape = Shapes.joinUnoptimized(final_shape, Shapes.box(
|
||||
0, 0.875, 0,
|
||||
0.125, 1, 1
|
||||
), BooleanOp.OR);
|
||||
|
||||
final_shape = Shapes.joinUnoptimized(final_shape, Shapes.box(
|
||||
0, 0.875, 0,
|
||||
1, 1, 0.125
|
||||
), BooleanOp.OR);
|
||||
|
||||
final_shape = Shapes.joinUnoptimized(final_shape, Shapes.box(
|
||||
0.875, 0.875, 0,
|
||||
1, 1, 1
|
||||
), BooleanOp.OR);
|
||||
|
||||
final_shape = Shapes.joinUnoptimized(final_shape, Shapes.box(
|
||||
0, 0.875, 0.875,
|
||||
1, 1, 1
|
||||
), BooleanOp.OR);
|
||||
|
||||
// горизонтальные балки снизу
|
||||
final_shape = Shapes.joinUnoptimized(final_shape, Shapes.box(
|
||||
0, 0, 0,
|
||||
0.125, 0.125, 1
|
||||
), BooleanOp.OR);
|
||||
|
||||
final_shape = Shapes.joinUnoptimized(final_shape, Shapes.box(
|
||||
0, 0, 0,
|
||||
1, 0.125, 0.125
|
||||
), BooleanOp.OR);
|
||||
|
||||
final_shape = Shapes.joinUnoptimized(final_shape, Shapes.box(
|
||||
0.875, 0, 0,
|
||||
1, 0.125, 1
|
||||
), BooleanOp.OR);
|
||||
|
||||
SHAPE = Shapes.joinUnoptimized(final_shape, Shapes.box(
|
||||
0, 0, 0.875,
|
||||
1, 0.125, 1
|
||||
), BooleanOp.OR);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ru.dbotthepony.mc.otm.block;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
@ -9,8 +10,10 @@ import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterCapacitorBank;
|
||||
import ru.dbotthepony.mc.otm.shapes.BlockShapes;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class BlockMatterCapacitorBank extends BlockMatteryRotatable implements EntityBlock {
|
||||
@Nullable
|
||||
@ -19,8 +22,23 @@ public class BlockMatterCapacitorBank extends BlockMatteryRotatable implements E
|
||||
return new BlockEntityMatterCapacitorBank(blockPos, blockState);
|
||||
}
|
||||
|
||||
private static final List<VoxelShape> SHAPES;
|
||||
|
||||
static {
|
||||
var def = BlockShapes.BATTERY_BANK.computeShape();
|
||||
|
||||
SHAPES = List.of(
|
||||
def,
|
||||
def,
|
||||
def,
|
||||
BlockShapes.BATTERY_BANK.rotate(Direction.NORTH).computeShape(),
|
||||
BlockShapes.BATTERY_BANK.rotate(Direction.WEST).computeShape(),
|
||||
BlockShapes.BATTERY_BANK.rotate(Direction.EAST).computeShape()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState p_60555_, BlockGetter p_60556_, BlockPos p_60557_, CollisionContext p_60558_) {
|
||||
return BlockBatteryBank.SHAPE;
|
||||
return SHAPES.get(p_60555_.getValue(FACING).ordinal());
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,22 @@
|
||||
package ru.dbotthepony.mc.otm.block;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import ru.dbotthepony.mc.otm.Registry;
|
||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterDecomposer;
|
||||
import ru.dbotthepony.mc.otm.shapes.BlockShapes;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class BlockMatterDecomposer extends BlockMatteryRotatable implements EntityBlock {
|
||||
@Nullable
|
||||
@ -24,4 +30,24 @@ public class BlockMatterDecomposer extends BlockMatteryRotatable implements Enti
|
||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level p_153212_, BlockState p_153213_, BlockEntityType<T> p_153214_) {
|
||||
return p_153212_.isClientSide || p_153214_ != Registry.BlockEntities.MATTER_DECOMPOSER ? null : BlockEntityMatterDecomposer::tick;
|
||||
}
|
||||
|
||||
private static final List<VoxelShape> SHAPES;
|
||||
|
||||
static {
|
||||
var def = BlockShapes.MATTER_DECOMPOSER.computeShape();
|
||||
|
||||
SHAPES = List.of(
|
||||
def,
|
||||
def,
|
||||
def,
|
||||
BlockShapes.MATTER_DECOMPOSER.rotate(Direction.NORTH).computeShape(),
|
||||
BlockShapes.MATTER_DECOMPOSER.rotate(Direction.WEST).computeShape(),
|
||||
BlockShapes.MATTER_DECOMPOSER.rotate(Direction.EAST).computeShape()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState p_60555_, BlockGetter p_60556_, BlockPos p_60557_, CollisionContext p_60558_) {
|
||||
return SHAPES.get(p_60555_.getValue(FACING).ordinal());
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,23 @@
|
||||
package ru.dbotthepony.mc.otm.block;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import ru.dbotthepony.mc.otm.Registry;
|
||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterReplicator;
|
||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatteryPoweredWorker;
|
||||
import ru.dbotthepony.mc.otm.shapes.BlockShapes;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class BlockMatterReplicator extends BlockMatteryRotatable implements EntityBlock {
|
||||
@Nullable
|
||||
@ -25,4 +31,24 @@ public class BlockMatterReplicator extends BlockMatteryRotatable implements Enti
|
||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level p_153212_, BlockState p_153213_, BlockEntityType<T> p_153214_) {
|
||||
return p_153212_.isClientSide || p_153214_ != Registry.BlockEntities.MATTER_REPLICATOR ? null : BlockEntityMatteryPoweredWorker::basicTicker;
|
||||
}
|
||||
|
||||
private static final List<VoxelShape> SHAPES;
|
||||
|
||||
static {
|
||||
var def = BlockShapes.MATTER_REPLICATOR.computeShape();
|
||||
|
||||
SHAPES = List.of(
|
||||
def,
|
||||
def,
|
||||
def,
|
||||
BlockShapes.MATTER_REPLICATOR.rotate(Direction.NORTH).computeShape(),
|
||||
BlockShapes.MATTER_REPLICATOR.rotate(Direction.WEST).computeShape(),
|
||||
BlockShapes.MATTER_REPLICATOR.rotate(Direction.EAST).computeShape()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState p_60555_, BlockGetter p_60556_, BlockPos p_60557_, CollisionContext p_60558_) {
|
||||
return SHAPES.get(p_60555_.getValue(FACING).ordinal());
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,23 @@
|
||||
package ru.dbotthepony.mc.otm.block;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import ru.dbotthepony.mc.otm.Registry;
|
||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterScanner;
|
||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatteryPoweredWorker;
|
||||
import ru.dbotthepony.mc.otm.shapes.BlockShapes;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class BlockMatterScanner extends BlockMatteryRotatable implements EntityBlock {
|
||||
@Nullable
|
||||
@ -25,4 +31,24 @@ public class BlockMatterScanner extends BlockMatteryRotatable implements EntityB
|
||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level p_153212_, BlockState p_153213_, BlockEntityType<T> p_153214_) {
|
||||
return p_153212_.isClientSide || p_153214_ != Registry.BlockEntities.MATTER_SCANNER ? null : BlockEntityMatteryPoweredWorker::basicTicker;
|
||||
}
|
||||
|
||||
private static final List<VoxelShape> SHAPES;
|
||||
|
||||
static {
|
||||
var def = BlockShapes.MATTER_SCANNER.computeShape();
|
||||
|
||||
SHAPES = List.of(
|
||||
def,
|
||||
def,
|
||||
def,
|
||||
BlockShapes.MATTER_SCANNER.rotate(Direction.NORTH).computeShape(),
|
||||
BlockShapes.MATTER_SCANNER.rotate(Direction.WEST).computeShape(),
|
||||
BlockShapes.MATTER_SCANNER.rotate(Direction.EAST).computeShape()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState p_60555_, BlockGetter p_60556_, BlockPos p_60557_, CollisionContext p_60558_) {
|
||||
return SHAPES.get(p_60555_.getValue(FACING).ordinal());
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,18 @@
|
||||
package ru.dbotthepony.mc.otm.block;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityPatternStorage;
|
||||
import ru.dbotthepony.mc.otm.shapes.BlockShapes;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class BlockPatternStorage extends BlockMatteryRotatable implements EntityBlock {
|
||||
@Nullable
|
||||
@ -14,4 +20,24 @@ public class BlockPatternStorage extends BlockMatteryRotatable implements Entity
|
||||
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
|
||||
return new BlockEntityPatternStorage(blockPos, blockState);
|
||||
}
|
||||
|
||||
private static final List<VoxelShape> SHAPES;
|
||||
|
||||
static {
|
||||
var def = BlockShapes.PATTERN_STORAGE.computeShape();
|
||||
|
||||
SHAPES = List.of(
|
||||
def,
|
||||
def,
|
||||
def,
|
||||
BlockShapes.PATTERN_STORAGE.rotate(Direction.NORTH).computeShape(),
|
||||
BlockShapes.PATTERN_STORAGE.rotate(Direction.WEST).computeShape(),
|
||||
BlockShapes.PATTERN_STORAGE.rotate(Direction.EAST).computeShape()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState p_60555_, BlockGetter p_60556_, BlockPos p_60557_, CollisionContext p_60558_) {
|
||||
return SHAPES.get(p_60555_.getValue(FACING).ordinal());
|
||||
}
|
||||
}
|
||||
|
42
src/main/java/ru/dbotthepony/mc/otm/shapes/BlockShape.java
Normal file
42
src/main/java/ru/dbotthepony/mc/otm/shapes/BlockShape.java
Normal file
@ -0,0 +1,42 @@
|
||||
package ru.dbotthepony.mc.otm.shapes;
|
||||
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.phys.shapes.BooleanOp;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
public record BlockShape(SimpleCuboid ...shapes) {
|
||||
public BlockShape rotateAroundY(double rad) {
|
||||
var list = new SimpleCuboid[shapes.length];
|
||||
|
||||
for (int i = 0; i < shapes.length; i++)
|
||||
list[i] = shapes[i].rotateAroundY(rad);
|
||||
|
||||
return new BlockShape(list);
|
||||
}
|
||||
|
||||
public BlockShape rotate(Direction dir) {
|
||||
if (dir == Direction.SOUTH)
|
||||
return this;
|
||||
|
||||
if (dir == Direction.NORTH)
|
||||
return rotateAroundY(Math.PI);
|
||||
|
||||
if (dir == Direction.WEST)
|
||||
return rotateAroundY(-Math.PI / 2d);
|
||||
|
||||
if (dir == Direction.EAST)
|
||||
return rotateAroundY(Math.PI / 2d);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public VoxelShape computeShape() {
|
||||
VoxelShape final_shape = shapes[0].getShape();
|
||||
|
||||
for (int i = 1; i < shapes.length; i++)
|
||||
final_shape = Shapes.joinUnoptimized(final_shape, shapes[i].getShape(), BooleanOp.OR);
|
||||
|
||||
return final_shape;
|
||||
}
|
||||
}
|
95
src/main/java/ru/dbotthepony/mc/otm/shapes/BlockShapes.java
Normal file
95
src/main/java/ru/dbotthepony/mc/otm/shapes/BlockShapes.java
Normal file
@ -0,0 +1,95 @@
|
||||
package ru.dbotthepony.mc.otm.shapes;
|
||||
|
||||
|
||||
// Auto generated at Wed, 18 Aug 2021 07:55:20 GMT
|
||||
public class BlockShapes {
|
||||
public static final BlockShape ANDROID_STATION = new BlockShape(
|
||||
new SimpleCuboid(0d, 0.4375d, 0d, 1d, 0.5625d, 1d),
|
||||
new SimpleCuboid(0d, 0d, 0d, 1d, 0.25d, 1d),
|
||||
new SimpleCuboid(0.125d, 0.25d, 0.125d, 0.875d, 0.4375d, 0.875d),
|
||||
new SimpleCuboid(0.0625d, 0.25d, 0.8125d, 0.1875d, 0.4375d, 0.9375d),
|
||||
new SimpleCuboid(0.8125d, 0.25d, 0.8125d, 0.9375d, 0.4375d, 0.9375d),
|
||||
new SimpleCuboid(0.8125d, 0.25d, 0.0625d, 0.9375d, 0.4375d, 0.1875d),
|
||||
new SimpleCuboid(0.0625d, 0.25d, 0.0625d, 0.1875d, 0.4375d, 0.1875d)
|
||||
);
|
||||
|
||||
public static final BlockShape BATTERY_BANK = new BlockShape(
|
||||
new SimpleCuboid(0.875d, 0d, 0d, 1d, 0.125d, 1d),
|
||||
new SimpleCuboid(0d, 0d, 0d, 0.125d, 0.125d, 1d),
|
||||
new SimpleCuboid(0.125d, 0d, 0d, 0.875d, 0.125d, 0.125d),
|
||||
new SimpleCuboid(0.125d, 0d, 0.875d, 0.875d, 0.125d, 1d),
|
||||
new SimpleCuboid(0.125d, 0.875d, 0d, 0.875d, 1d, 0.125d),
|
||||
new SimpleCuboid(0d, 0.875d, 0d, 0.125d, 1d, 1d),
|
||||
new SimpleCuboid(0.125d, 0.875d, 0.875d, 0.875d, 1d, 1d),
|
||||
new SimpleCuboid(0.875d, 0.875d, 0d, 1d, 1d, 1d),
|
||||
new SimpleCuboid(0.875d, 0.125d, 0.875d, 1d, 0.875d, 1d),
|
||||
new SimpleCuboid(0d, 0.125d, 0.875d, 0.125d, 0.875d, 1d),
|
||||
new SimpleCuboid(0.875d, 0.125d, 0d, 1d, 0.875d, 0.125d),
|
||||
new SimpleCuboid(0d, 0.125d, 0d, 0.125d, 0.875d, 0.125d),
|
||||
new SimpleCuboid(0.0625d, 0.0625d, 0.4375d, 0.9375d, 0.9375d, 0.5625d)
|
||||
);
|
||||
|
||||
public static final BlockShape MATTER_SCANNER = new BlockShape(
|
||||
new SimpleCuboid(0d, 0.25d, 0d, 1d, 0.5d, 1d),
|
||||
new SimpleCuboid(0d, 0d, 0d, 1d, 0.125d, 1d),
|
||||
new SimpleCuboid(0.0625d, 0.125d, 0.0625d, 0.9375d, 0.25d, 0.9375d),
|
||||
new SimpleCuboid(0d, 0.875d, 0.0625d, 0.0625d, 0.9375d, 0.9375d),
|
||||
new SimpleCuboid(0.9375d, 0.5d, 0d, 1d, 1d, 0.0625d),
|
||||
new SimpleCuboid(0d, 0.5d, 0d, 0.0625d, 1d, 0.0625d),
|
||||
new SimpleCuboid(0d, 0.5d, 0.9375d, 0.0625d, 1d, 1d),
|
||||
new SimpleCuboid(0.9375d, 0.5d, 0.9375d, 1d, 1d, 1d),
|
||||
new SimpleCuboid(0.9375d, 0.875d, 0.0625d, 1d, 0.9375d, 0.9375d),
|
||||
new SimpleCuboid(0d, 0.8125d, 0.6875d, 0.125d, 0.875d, 0.8125d),
|
||||
new SimpleCuboid(0.0625d, 0.875d, 0.6875d, 0.125d, 0.9375d, 0.8125d),
|
||||
new SimpleCuboid(0.875d, 0.875d, 0.6875d, 0.9375d, 0.9375d, 0.8125d),
|
||||
new SimpleCuboid(0.875d, 0.8125d, 0.6875d, 1d, 0.875d, 0.8125d),
|
||||
new SimpleCuboid(0.125d, 0.875d, 0.6875d, 0.875d, 0.875d, 0.8125d),
|
||||
new SimpleCuboid(0.1875d, 0.8125d, 0.5625d, 0.375d, 0.9375d, 0.875d)
|
||||
);
|
||||
|
||||
public static final BlockShape PATTERN_STORAGE = new BlockShape(
|
||||
new SimpleCuboid(0d, 0d, 0d, 1d, 0.125d, 1d),
|
||||
new SimpleCuboid(0.875d, 0.125d, 0.875d, 1d, 0.875d, 1d),
|
||||
new SimpleCuboid(0.875d, 0.9375d, 0d, 1d, 1d, 0.75d),
|
||||
new SimpleCuboid(0d, 0.9375d, 0d, 0.125d, 1d, 0.75d),
|
||||
new SimpleCuboid(0d, 0.125d, 0.875d, 0.125d, 0.875d, 1d),
|
||||
new SimpleCuboid(0d, 0.125d, 0.625d, 1d, 0.3125d, 0.75d),
|
||||
new SimpleCuboid(0d, 0.125d, 0d, 1d, 0.1875d, 0.0625d),
|
||||
new SimpleCuboid(0d, 0.875d, 0d, 1d, 0.9375d, 0.0625d),
|
||||
new SimpleCuboid(0d, 0.875d, 0.75d, 1d, 1d, 1d)
|
||||
);
|
||||
|
||||
public static final BlockShape MATTER_REPLICATOR = new BlockShape(
|
||||
new SimpleCuboid(0.9375d, 0d, 0d, 1d, 0.6875d, 1d),
|
||||
new SimpleCuboid(0d, 0d, 0d, 0.0625d, 0.6875d, 1d),
|
||||
new SimpleCuboid(0d, 0.6875d, 0.0625d, 0.5d, 1d, 0.375d),
|
||||
new SimpleCuboid(0.5d, 0.6875d, 0d, 1d, 1d, 0.375d),
|
||||
new SimpleCuboid(0.1875d, 0.6875d, 0.6875d, 0.9375d, 0.9375d, 0.9375d),
|
||||
new SimpleCuboid(0.1875d, 0.6875d, 0.375d, 0.9375d, 0.9375d, 0.625d),
|
||||
new SimpleCuboid(0.0625d, 0.6875d, 0.4375d, 0.1875d, 0.875d, 0.5625d),
|
||||
new SimpleCuboid(0.0625d, 0.6875d, 0.75d, 0.1875d, 0.875d, 0.875d),
|
||||
new SimpleCuboid(0d, 0.6875d, 0.9375d, 0d, 1d, 1d),
|
||||
new SimpleCuboid(1d, 0.6875d, 0.9375d, 1d, 1d, 1d),
|
||||
new SimpleCuboid(1d, 0.9375d, 0.375d, 1d, 1d, 0.9375d),
|
||||
new SimpleCuboid(0d, 0.9375d, 0.375d, 0d, 1d, 0.9375d),
|
||||
new SimpleCuboid(0.0625d, 0d, 0d, 0.9375d, 0.0625d, 1d),
|
||||
new SimpleCuboid(0.5d, 0.4375d, 0d, 0.9375d, 0.6875d, 0.0625d),
|
||||
new SimpleCuboid(0.0625d, 0.5625d, 0d, 0.5d, 0.6875d, 0.0625d),
|
||||
new SimpleCuboid(0.0625d, 0.0625d, 0d, 0.125d, 0.5625d, 0.0625d),
|
||||
new SimpleCuboid(0.875d, 0.0625d, 0d, 0.9375d, 0.4375d, 0.0625d),
|
||||
new SimpleCuboid(0.125d, 0.0625d, 0d, 0.875d, 0.125d, 0.0625d),
|
||||
new SimpleCuboid(0.0625d, 0.625d, 0.0625d, 0.9375d, 0.6875d, 0.9375d),
|
||||
new SimpleCuboid(0.0625d, 0.0625d, 0.9375d, 0.9375d, 0.6875d, 1d),
|
||||
new SimpleCuboid(0.1875d, 0.0625d, 0.1875d, 0.8125d, 0.125d, 0.8125d)
|
||||
);
|
||||
|
||||
public static final BlockShape MATTER_DECOMPOSER = new BlockShape(
|
||||
new SimpleCuboid(0d, 0d, 0d, 1d, 0.1875d, 1d),
|
||||
new SimpleCuboid(0.5d, 0.1875d, 0d, 1d, 1d, 1d),
|
||||
new SimpleCuboid(0.0625d, 0.1875d, 0.0625d, 0.4375d, 0.875d, 0.4375d),
|
||||
new SimpleCuboid(0.0625d, 0.1875d, 0.5625d, 0.4375d, 0.875d, 0.9375d),
|
||||
new SimpleCuboid(0.1875d, 0.8125d, 0.6875d, 0.5d, 0.9375d, 0.8125d),
|
||||
new SimpleCuboid(0.1875d, 0.8125d, 0.1875d, 0.5d, 0.9375d, 0.3125d)
|
||||
);
|
||||
|
||||
}
|
25
src/main/java/ru/dbotthepony/mc/otm/shapes/MathHelper.java
Normal file
25
src/main/java/ru/dbotthepony/mc/otm/shapes/MathHelper.java
Normal file
@ -0,0 +1,25 @@
|
||||
package ru.dbotthepony.mc.otm.shapes;
|
||||
|
||||
public class MathHelper {
|
||||
public static double min(double ...values) {
|
||||
double min = values[0];
|
||||
|
||||
for (int i = 1; i < values.length; i++) {
|
||||
if (min > values[i])
|
||||
min = values[i];
|
||||
}
|
||||
|
||||
return min;
|
||||
}
|
||||
|
||||
public static double max(double ...values) {
|
||||
double max = values[0];
|
||||
|
||||
for (int i = 1; i < values.length; i++) {
|
||||
if (max < values[i])
|
||||
max = values[i];
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
}
|
21
src/main/java/ru/dbotthepony/mc/otm/shapes/Point.java
Normal file
21
src/main/java/ru/dbotthepony/mc/otm/shapes/Point.java
Normal file
@ -0,0 +1,21 @@
|
||||
package ru.dbotthepony.mc.otm.shapes;
|
||||
|
||||
public record Point(double x, double y) {
|
||||
public Point rotate(double rad) {
|
||||
double sin = Math.sin(rad);
|
||||
double cos = Math.cos(rad);
|
||||
|
||||
return new Point(x * cos - y * sin, x * sin + y * cos);
|
||||
}
|
||||
|
||||
public Point translate(double x, double y) {
|
||||
return new Point(this.x + x, this.y + y);
|
||||
}
|
||||
|
||||
public int compareTo(Point other) {
|
||||
if (x == other.x && y == other.y)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
11
src/main/java/ru/dbotthepony/mc/otm/shapes/Rectangle.java
Normal file
11
src/main/java/ru/dbotthepony/mc/otm/shapes/Rectangle.java
Normal file
@ -0,0 +1,11 @@
|
||||
package ru.dbotthepony.mc.otm.shapes;
|
||||
|
||||
public record Rectangle(Point a, Point b, Point c, Point d) {
|
||||
public Rectangle rotate(double rad) {
|
||||
return new Rectangle(a.rotate(rad), b.rotate(rad), c.rotate(rad), d.rotate(rad));
|
||||
}
|
||||
|
||||
public Rectangle translate(double x, double y) {
|
||||
return new Rectangle(a.translate(x, y), b.translate(x, y), c.translate(x, y), d.translate(x, y));
|
||||
}
|
||||
}
|
67
src/main/java/ru/dbotthepony/mc/otm/shapes/SimpleCuboid.java
Normal file
67
src/main/java/ru/dbotthepony/mc/otm/shapes/SimpleCuboid.java
Normal file
@ -0,0 +1,67 @@
|
||||
package ru.dbotthepony.mc.otm.shapes;
|
||||
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
public record SimpleCuboid(double min_x, double min_y, double min_z, double max_x, double max_y, double max_z) {
|
||||
public SimpleCuboid normalized() {
|
||||
if (min_x <= max_x && min_y <= max_y && min_z <= max_z)
|
||||
return this;
|
||||
|
||||
double min_x;
|
||||
double min_y;
|
||||
double min_z;
|
||||
double max_x;
|
||||
double max_y;
|
||||
double max_z;
|
||||
|
||||
if (this.min_x <= this.max_x) {
|
||||
min_x = this.min_x;
|
||||
max_x = this.max_x;
|
||||
} else {
|
||||
min_x = this.max_x;
|
||||
max_x = this.min_x;
|
||||
}
|
||||
|
||||
if (this.min_y <= this.max_y) {
|
||||
min_y = this.min_y;
|
||||
max_y = this.max_y;
|
||||
} else {
|
||||
min_y = this.max_y;
|
||||
max_y = this.min_y;
|
||||
}
|
||||
|
||||
if (this.min_z <= this.max_z) {
|
||||
min_z = this.min_z;
|
||||
max_z = this.max_z;
|
||||
} else {
|
||||
min_z = this.max_z;
|
||||
max_z = this.min_z;
|
||||
}
|
||||
|
||||
return new SimpleCuboid(min_x, min_y, min_z, max_x, max_y, max_z);
|
||||
}
|
||||
|
||||
public VoxelShape getShape() {
|
||||
var normalize = normalized();
|
||||
|
||||
return Shapes.box(normalize.min_x, normalize.min_y, normalize.min_z, normalize.max_x, normalize.max_y, normalize.max_z);
|
||||
}
|
||||
|
||||
public SimpleCuboid rotateAroundY(double rad) {
|
||||
var rect = new Rectangle(
|
||||
new Point(min_x, min_z),
|
||||
new Point(max_x, min_z),
|
||||
new Point(max_x, max_z),
|
||||
new Point(min_x, max_z)
|
||||
).translate(-0.5, -0.5).rotate(rad).translate(0.5, 0.5);
|
||||
|
||||
double min_x = MathHelper.min(rect.a().x(), rect.b().x(), rect.c().x(), rect.d().x());
|
||||
double max_x = MathHelper.max(rect.a().x(), rect.b().x(), rect.c().x(), rect.d().x());
|
||||
|
||||
double min_z = MathHelper.min(rect.a().y(), rect.b().y(), rect.c().y(), rect.d().y());
|
||||
double max_z = MathHelper.max(rect.a().y(), rect.b().y(), rect.c().y(), rect.d().y());
|
||||
|
||||
return new SimpleCuboid(min_x, min_y, min_z, max_x, max_y, max_z);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user