Rename solid to replacable

fixes #1358
This commit is contained in:
IntegratedQuantum 2025-05-12 18:05:45 +02:00
parent 48f67e19c2
commit 4d62da9ae8
17 changed files with 25 additions and 23 deletions

View File

@ -4,7 +4,7 @@
.transparent = true,
.absorbedLight = 0x000000,
.viewThrough = true,
.solid = false,
.replacable = true,
.rotation = .no_rotation,
.degradable = true,
.hasItem = false,

View File

@ -4,7 +4,7 @@
.drops = .{
.{.items = .{.auto}},
},
.solid = false,
.replacable = true,
.viewThrough = true,
.degradable = true,
.absorbedLight = 0x010101,

View File

@ -5,7 +5,7 @@
.degradable = true,
.transparent = true,
.hasBackFace = true,
.solid = false,
.replacable = true,
.collide = false,
.model = "cubyz:cube",

View File

@ -4,7 +4,7 @@
.drops = .{
.{.items = .{.auto}},
},
.solid = false,
.replacable = true,
.degradable = true,
.viewThrough = true,
.absorbedLight = 0x010101,

View File

@ -2,7 +2,7 @@
.tags = .{.fluid},
.drops = .{},
.selectable = false,
.solid = false,
.replacable = true,
.degradable = true,
.transparent = true,
.hasBackFace = true,

View File

@ -4,7 +4,7 @@
.drops = .{
.{.items = .{.auto}},
},
.solid = false,
.replacable = true,
.emittedLight = 0x2b81b2,
.viewThrough = true,
.absorbedLight = 0x010101,

View File

@ -4,7 +4,7 @@
.drops = .{
.{.items = .{.auto}},
},
.solid = false,
.replacable = true,
.degradable = true,
.viewThrough = true,
.absorbedLight = 0x010101,

View File

@ -4,7 +4,7 @@
.drops = .{
.{.items = .{.auto}},
},
.solid = false,
.replacable = true,
.emittedLight = 0xa58d73,
.viewThrough = true,
.absorbedLight = 0x010101,

View File

@ -5,7 +5,6 @@
.absorbedLight = 0x000000,
.viewThrough = true,
.hasBackFace = true,
.solid = true,
.rotation = .no_rotation,
.degradable = false,
.collide = false,

View File

@ -2,7 +2,7 @@
.tags = .{.fluid},
.drops = .{},
.selectable = false,
.solid = false,
.replacable = true,
.degradable = true,
.transparent = true,
.hasBackFace = true,

View File

@ -54,7 +54,8 @@ var _id: [maxBlockCount][]u8 = undefined;
var _blockHealth: [maxBlockCount]f32 = undefined;
var _blockResistance: [maxBlockCount]f32 = undefined;
var _solid: [maxBlockCount]bool = undefined;
/// Whether you can replace it with another block, mainly used for fluids/gases
var _replacable: [maxBlockCount]bool = undefined;
var _selectable: [maxBlockCount]bool = undefined;
var _blockDrops: [maxBlockCount][]BlockDrop = undefined;
/// Meaning undegradable parts of trees or other structures can grow through this block.
@ -114,7 +115,7 @@ pub fn register(_: []const u8, id: []const u8, zon: ZonElement) u16 {
_absorption[size] = zon.get(u32, "absorbedLight", 0xffffff);
_degradable[size] = zon.get(bool, "degradable", false);
_selectable[size] = zon.get(bool, "selectable", true);
_solid[size] = zon.get(bool, "solid", true);
_replacable[size] = zon.get(bool, "replacable", false);
_gui[size] = allocator.dupe(u8, zon.get([]const u8, "gui", ""));
_transparent[size] = zon.get(bool, "transparent", false);
_collide[size] = zon.get(bool, "collide", true);
@ -300,8 +301,9 @@ pub const Block = packed struct { // MARK: Block
return _blockResistance[self.typ];
}
pub inline fn solid(self: Block) bool {
return _solid[self.typ];
/// Whether you can replace it with another block, mainly used for fluids/gases
pub inline fn replacable(self: Block) bool {
return _replacable[self.typ];
}
pub inline fn selectable(self: Block) bool {

View File

@ -990,7 +990,7 @@ pub const MeshSelection = struct { // MARK: MeshSelection
return;
}
} else {
if(block.solid()) return;
if(!block.replacable()) return;
block.typ = itemBlock;
block.data = 0;
if(rotationMode.generateData(main.game.world.?, neighborPos, relPos, lastDir, neighborDir, neighborOfSelection, &block, neighborBlock, true)) {

View File

@ -98,7 +98,7 @@ pub const RotationMode = struct { // MARK: RotationMode
shouldDropSourceBlockOnSuccess.* = true;
if(oldBlock == newBlock) return .no;
if(oldBlock.typ == newBlock.typ) return .yes;
if(oldBlock.solid()) {
if(!oldBlock.replacable()) {
var damage: f32 = 1;
const isTool = item.item != null and item.item.? == .tool;
if(isTool) {

View File

@ -351,13 +351,13 @@ pub fn generateData(
) bool {
const canConnectToNeighbor = currentBlock.mode() == neighborBlock.mode() and currentBlock.modeData() == neighborBlock.modeData();
if(blockPlacing or canConnectToNeighbor or neighborBlock.solid()) {
if(blockPlacing or canConnectToNeighbor or !neighborBlock.replacable()) {
const neighborModel = blocks.meshes.model(neighborBlock).model();
var currentData = BranchData.init(currentBlock.data);
// Branch block upon placement should extend towards a block it was placed
// on if the block is solid or also uses branch model.
const targetVal = ((neighborBlock.solid() and (!neighborBlock.viewThrough() or canConnectToNeighbor)) and (canConnectToNeighbor or neighborModel.isNeighborOccluded[neighbor.?.reverse().toInt()]));
const targetVal = ((!neighborBlock.replacable() and (!neighborBlock.viewThrough() or canConnectToNeighbor)) and (canConnectToNeighbor or neighborModel.isNeighborOccluded[neighbor.?.reverse().toInt()]));
currentData.setConnection(neighbor.?, targetVal);
const result: u16 = currentData.enabledConnections;
@ -379,7 +379,7 @@ pub fn updateData(block: *Block, neighbor: Neighbor, neighborBlock: Block) bool
if(canConnectToNeighbor) {
const neighborData = BranchData.init(neighborBlock.data);
currentData.setConnection(neighbor, neighborData.isConnected(neighbor.reverse()));
} else if(!neighborBlock.solid()) {
} else if(neighborBlock.replacable()) {
currentData.setConnection(neighbor, false);
}

View File

@ -106,7 +106,7 @@ pub fn updateData(block: *Block, neighbor: Neighbor, neighborBlock: Block) bool
const blockBaseModelIndex = blocks.meshes.modelIndexStart(block.*);
const neighborBaseModelIndex = blocks.meshes.modelIndexStart(neighborBlock);
const neighborModel = blocks.meshes.model(neighborBlock).model();
const targetVal = neighborBlock.solid() and (blockBaseModelIndex == neighborBaseModelIndex or neighborModel.isNeighborOccluded[neighbor.reverse().toInt()]);
const targetVal = !neighborBlock.replacable() and (blockBaseModelIndex == neighborBaseModelIndex or neighborModel.isNeighborOccluded[neighbor.reverse().toInt()]);
var currentData: FenceData = @bitCast(@as(u4, @truncate(block.data)));
switch(neighbor) {
.dirNegX => {

View File

@ -122,7 +122,7 @@ pub fn rotateZ(data: u16, angle: Degrees) u16 {
pub fn generateData(_: *main.game.World, _: Vec3i, _: Vec3f, _: Vec3f, relativeDir: Vec3i, neighbor: ?Neighbor, currentData: *Block, neighborBlock: Block, _: bool) bool {
if(neighbor == null) return false;
const neighborModel = blocks.meshes.model(neighborBlock).model();
const neighborSupport = neighborBlock.solid() and neighborModel.neighborFacingQuads[neighbor.?.reverse().toInt()].len != 0;
const neighborSupport = !neighborBlock.replacable() and neighborModel.neighborFacingQuads[neighbor.?.reverse().toInt()].len != 0;
if(!neighborSupport) return false;
var data: TorchData = @bitCast(@as(u5, @truncate(currentData.data)));
if(relativeDir[0] == 1) data.posX = true;
@ -140,7 +140,7 @@ pub fn generateData(_: *main.game.World, _: Vec3i, _: Vec3f, _: Vec3f, relativeD
pub fn updateData(block: *Block, neighbor: Neighbor, neighborBlock: Block) bool {
const neighborModel = blocks.meshes.model(neighborBlock).model();
const neighborSupport = neighborBlock.solid() and neighborModel.neighborFacingQuads[neighbor.reverse().toInt()].len != 0;
const neighborSupport = !neighborBlock.replacable() and neighborModel.neighborFacingQuads[neighbor.reverse().toInt()].len != 0;
var currentData: TorchData = @bitCast(@as(u5, @truncate(block.data)));
switch(neighbor) {
.dirNegX => {

View File

@ -274,7 +274,8 @@ pub const ChunkCompression = struct { // MARK: ChunkCompression
for(0..chunk.chunkVolume) |i| {
uncompressedData[i] = @intCast(ch.data.data.getValue(i));
if(allowLossy) {
if(ch.data.palette[uncompressedData[i]].solid()) {
const model = main.blocks.meshes.model(ch.data.palette[uncompressedData[i]]).model();
if(model.allNeighborsOccluded) {
solidMask[i >> 5] |= @as(u32, 1) << @intCast(i & 31);
} else {
solidMask[i >> 5] &= ~(@as(u32, 1) << @intCast(i & 31));