mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-10 07:48:29 -04:00
save blockEntities in ChunkSection and not in World
This commit is contained in:
parent
afb39712c8
commit
28e62f0f86
@ -199,7 +199,7 @@ public class EntityMetaData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean getBitMask(EntityMetaDataFields field, int bitMask) {
|
public boolean getBitMask(EntityMetaDataFields field, int bitMask) {
|
||||||
return BitByte.isBitMask(getInt(field), bitMask);
|
return BitByte.isBitMask(getByte(field), bitMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object get(EntityMetaDataFields field) {
|
public Object get(EntityMetaDataFields field) {
|
||||||
@ -231,14 +231,7 @@ public class EntityMetaData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getInt(EntityMetaDataFields field) {
|
public int getInt(EntityMetaDataFields field) {
|
||||||
Object object = get(field);
|
return (int) get(field);
|
||||||
if (object instanceof Integer i) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
if (object instanceof Byte b) {
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Short getShort(EntityMetaDataFields field) {
|
public Short getShort(EntityMetaDataFields field) {
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.data.world;
|
package de.bixilon.minosoft.data.world;
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.entities.block.BlockEntityMetaData;
|
||||||
import de.bixilon.minosoft.data.mappings.blocks.Block;
|
import de.bixilon.minosoft.data.mappings.blocks.Block;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -61,4 +62,25 @@ public class Chunk {
|
|||||||
createSection(section);
|
createSection(section);
|
||||||
sections.get(section).setBlock(location.getInChunkSectionLocation(), block);
|
sections.get(section).setBlock(location.getInChunkSectionLocation(), block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setBlockEntityData(InChunkLocation position, BlockEntityMetaData data) {
|
||||||
|
ChunkSection section = sections.get((byte) (position.getY() / 16));
|
||||||
|
if (section == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
section.setBlockEntityData(position.getInChunkSectionLocation(), data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockEntityMetaData getBlockEntityData(InChunkLocation position) {
|
||||||
|
ChunkSection section = sections.get((byte) (position.getY() / 16));
|
||||||
|
if (section == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return section.getBlockEntityData(position.getInChunkSectionLocation());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBlockEntityData(HashMap<InChunkLocation, BlockEntityMetaData> blockEntities) {
|
||||||
|
blockEntities.forEach(this::setBlockEntityData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.data.world;
|
package de.bixilon.minosoft.data.world;
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.entities.block.BlockEntityMetaData;
|
||||||
import de.bixilon.minosoft.data.mappings.blocks.Block;
|
import de.bixilon.minosoft.data.mappings.blocks.Block;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -21,7 +22,8 @@ import java.util.HashMap;
|
|||||||
* Collection of 16x16x16 blocks
|
* Collection of 16x16x16 blocks
|
||||||
*/
|
*/
|
||||||
public class ChunkSection {
|
public class ChunkSection {
|
||||||
final HashMap<InChunkSectionLocation, Block> blocks;
|
private final HashMap<InChunkSectionLocation, Block> blocks;
|
||||||
|
private final HashMap<InChunkSectionLocation, BlockEntityMetaData> blockEntityMeta = new HashMap<>();
|
||||||
|
|
||||||
public ChunkSection(HashMap<InChunkSectionLocation, Block> blocks) {
|
public ChunkSection(HashMap<InChunkSectionLocation, Block> blocks) {
|
||||||
this.blocks = blocks;
|
this.blocks = blocks;
|
||||||
@ -40,10 +42,27 @@ public class ChunkSection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setBlock(int x, int y, int z, Block block) {
|
public void setBlock(int x, int y, int z, Block block) {
|
||||||
blocks.put(new InChunkSectionLocation(x, y, z), block);
|
setBlock(new InChunkSectionLocation(x, y, z), block);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBlock(InChunkSectionLocation location, Block block) {
|
public void setBlock(InChunkSectionLocation location, Block block) {
|
||||||
|
if (blocks.get(location).equals(block)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
blocks.put(location, block);
|
blocks.put(location, block);
|
||||||
|
blockEntityMeta.remove(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBlockEntityData(InChunkSectionLocation position, BlockEntityMetaData data) {
|
||||||
|
// ToDo check if block is really a block entity (command block, spawner, skull, flower pot)
|
||||||
|
blockEntityMeta.put(position, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockEntityMetaData getBlockEntityData(InChunkSectionLocation position) {
|
||||||
|
return blockEntityMeta.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBlockEntityData(HashMap<InChunkSectionLocation, BlockEntityMetaData> blockEntities) {
|
||||||
|
blockEntities.forEach(blockEntityMeta::put);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@ import java.util.HashMap;
|
|||||||
public class World {
|
public class World {
|
||||||
final HashMap<ChunkLocation, Chunk> chunks = new HashMap<>();
|
final HashMap<ChunkLocation, Chunk> chunks = new HashMap<>();
|
||||||
final HashMap<Integer, Entity> entities = new HashMap<>();
|
final HashMap<Integer, Entity> entities = new HashMap<>();
|
||||||
final HashMap<BlockPosition, BlockEntityMetaData> blockEntityMeta = new HashMap<>();
|
|
||||||
boolean hardcore;
|
boolean hardcore;
|
||||||
boolean raining;
|
boolean raining;
|
||||||
Dimension dimension; // used for sky color, etc
|
Dimension dimension; // used for sky color, etc
|
||||||
@ -108,15 +107,22 @@ public class World {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setBlockEntityData(BlockPosition position, BlockEntityMetaData data) {
|
public void setBlockEntityData(BlockPosition position, BlockEntityMetaData data) {
|
||||||
// ToDo check if block is really a block entity (command block, spawner, skull, flower pot)
|
Chunk chunk = chunks.get(position.getChunkLocation());
|
||||||
blockEntityMeta.put(position, data);
|
if (chunk == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
chunk.setBlockEntityData(position.getInChunkLocation(), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockEntityMetaData getBlockEntityData(BlockPosition position) {
|
public BlockEntityMetaData getBlockEntityData(BlockPosition position) {
|
||||||
return blockEntityMeta.get(position);
|
Chunk chunk = chunks.get(position.getChunkLocation());
|
||||||
|
if (chunk == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return chunk.getBlockEntityData(position.getInChunkLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBlockEntityData(HashMap<BlockPosition, BlockEntityMetaData> blockEntities) {
|
public void setBlockEntityData(HashMap<BlockPosition, BlockEntityMetaData> blockEntities) {
|
||||||
blockEntities.forEach(blockEntityMeta::put);
|
blockEntities.forEach(this::setBlockEntityData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user