Skip to content

Commit

Permalink
Change version, fix sending world properties, fix deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
Moulberry committed Sep 23, 2023
1 parent 1cead96 commit 48e1062
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 91 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "com.moulberry.axiom"
version = "1.2.1"
version = "1.4.0"
description = "Serverside component for Axiom on Paper"

java {
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/com/moulberry/axiom/AxiomPaper.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,6 @@ public void onChangedWorld(PlayerChangedWorldEvent event) {
}
}

@EventHandler
public void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {
World world = player.getWorld();

ServerWorldPropertiesRegistry properties = getWorldProperties(world);

if (properties == null) {
player.sendPluginMessage(this, "axiom:register_world_properties", new byte[]{0});
} else {
properties.registerFor(this, player);
}
}, 20); // Why does this need to be delayed?
}

@EventHandler
public void onGameRuleChanged(WorldGameRuleChangeEvent event) {
if (event.getGameRule() == GameRule.DO_WEATHER_CYCLE) {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/moulberry/axiom/packet/HelloPacketListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import com.moulberry.axiom.event.AxiomHandshakeEvent;
import com.moulberry.axiom.persistence.ItemStackDataType;
import com.moulberry.axiom.persistence.UUIDDataType;
import com.moulberry.axiom.world_properties.server.ServerWorldPropertiesRegistry;
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.minecraft.network.FriendlyByteBuf;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -101,6 +103,16 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player pla

player.sendPluginMessage(this.plugin, "axiom:set_editor_views", buf.accessByteBufWithCorrectSize());
}

// Register world properties
World world = player.getWorld();
ServerWorldPropertiesRegistry properties = plugin.getWorldProperties(world);

if (properties == null) {
player.sendPluginMessage(plugin, "axiom:register_world_properties", new byte[]{0});
} else {
properties.registerFor(plugin, player);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -169,99 +169,94 @@ private void applyBlockBuffer(ServerPlayer player, MinecraftServer server, Block

Short2ObjectMap<CompressedBlockEntity> blockEntityChunkMap = buffer.getBlockEntityChunkMap(entry.getLongKey());

sectionStates.acquire();
try {
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
BlockState blockState = container.get(x, y, z);
if (blockState == emptyState) continue;

switch (sectionProtection.getSectionState()) {
case ALLOW -> {}
case DENY -> blockState = Blocks.REDSTONE_BLOCK.defaultBlockState();
case CHECK -> blockState = Blocks.DIAMOND_BLOCK.defaultBlockState();
}
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
BlockState blockState = container.get(x, y, z);
if (blockState == emptyState) continue;

switch (sectionProtection.getSectionState()) {
case ALLOW -> {}
case DENY -> blockState = Blocks.REDSTONE_BLOCK.defaultBlockState();
case CHECK -> blockState = Blocks.DIAMOND_BLOCK.defaultBlockState();
}

int bx = cx*16 + x;
int by = cy*16 + y;
int bz = cz*16 + z;
int bx = cx*16 + x;
int by = cy*16 + y;
int bz = cz*16 + z;

// if (!regionProtection.canBuild(bx, by, bz)) {
// continue;
// }
// if (!regionProtection.canBuild(bx, by, bz)) {
// continue;
// }

blockPos.set(bx, by, bz);
blockPos.set(bx, by, bz);

if (hasOnlyAir && blockState.isAir()) {
continue;
}
if (hasOnlyAir && blockState.isAir()) {
continue;
}

BlockState old = section.setBlockState(x, y, z, blockState, false);
if (blockState != old) {
Block block = blockState.getBlock();
motionBlocking.update(x, by, z, blockState);
motionBlockingNoLeaves.update(x, by, z, blockState);
oceanFloor.update(x, by, z, blockState);
worldSurface.update(x, by, z, blockState);
BlockState old = section.setBlockState(x, y, z, blockState, true);
if (blockState != old) {
Block block = blockState.getBlock();
motionBlocking.update(x, by, z, blockState);
motionBlockingNoLeaves.update(x, by, z, blockState);
oceanFloor.update(x, by, z, blockState);
worldSurface.update(x, by, z, blockState);

if (false) { // Full update
old.onRemove(world, blockPos, blockState, false);
if (false) { // Full update
old.onRemove(world, blockPos, blockState, false);

if (sectionStates.get(x, y, z).is(block)) {
blockState.onPlace(world, blockPos, old, false);
}
if (sectionStates.get(x, y, z).is(block)) {
blockState.onPlace(world, blockPos, old, false);
}
}

if (blockState.hasBlockEntity()) {
BlockEntity blockEntity = chunk.getBlockEntity(blockPos, LevelChunk.EntityCreationType.CHECK);

if (blockState.hasBlockEntity()) {
BlockEntity blockEntity = chunk.getBlockEntity(blockPos, LevelChunk.EntityCreationType.CHECK);

if (blockEntity == null) {
// There isn't a block entity here, create it!
blockEntity = ((EntityBlock)block).newBlockEntity(blockPos, blockState);
if (blockEntity != null) {
chunk.addAndRegisterBlockEntity(blockEntity);
}
} else if (blockEntity.getType().isValid(blockState)) {
// Block entity is here and the type is correct
blockEntity.setBlockState(blockState);

try {
this.updateBlockEntityTicker.invoke(chunk, blockEntity);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
} else {
// Block entity type isn't correct, we need to recreate it
chunk.removeBlockEntity(blockPos);

blockEntity = ((EntityBlock)block).newBlockEntity(blockPos, blockState);
if (blockEntity != null) {
chunk.addAndRegisterBlockEntity(blockEntity);
}
if (blockEntity == null) {
// There isn't a block entity here, create it!
blockEntity = ((EntityBlock)block).newBlockEntity(blockPos, blockState);
if (blockEntity != null) {
chunk.addAndRegisterBlockEntity(blockEntity);
}
if (blockEntity != null && blockEntityChunkMap != null) {
int key = x | (y << 4) | (z << 8);
CompressedBlockEntity savedBlockEntity = blockEntityChunkMap.get((short) key);
if (savedBlockEntity != null) {
blockEntity.load(savedBlockEntity.decompress());
}
} else if (blockEntity.getType().isValid(blockState)) {
// Block entity is here and the type is correct
blockEntity.setBlockState(blockState);

try {
this.updateBlockEntityTicker.invoke(chunk, blockEntity);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
} else if (old.hasBlockEntity()) {
} else {
// Block entity type isn't correct, we need to recreate it
chunk.removeBlockEntity(blockPos);

blockEntity = ((EntityBlock)block).newBlockEntity(blockPos, blockState);
if (blockEntity != null) {
chunk.addAndRegisterBlockEntity(blockEntity);
}
}
if (blockEntity != null && blockEntityChunkMap != null) {
int key = x | (y << 4) | (z << 8);
CompressedBlockEntity savedBlockEntity = blockEntityChunkMap.get((short) key);
if (savedBlockEntity != null) {
blockEntity.load(savedBlockEntity.decompress());
}
}
} else if (old.hasBlockEntity()) {
chunk.removeBlockEntity(blockPos);
}

world.getChunkSource().blockChanged(blockPos); // todo: maybe simply resend chunk instead of this?
world.getChunkSource().blockChanged(blockPos); // todo: maybe simply resend chunk instead of this?

if (LightEngine.hasDifferentLightProperties(chunk, blockPos, old, blockState)) {
lightEngine.checkBlock(blockPos);
}
if (LightEngine.hasDifferentLightProperties(chunk, blockPos, old, blockState)) {
lightEngine.checkBlock(blockPos);
}
}
}
}
} finally {
sectionStates.release();
}

boolean nowHasOnlyAir = section.hasOnlyAir();
Expand Down

0 comments on commit 48e1062

Please sign in to comment.