Skip to content

Commit

Permalink
Add thread safety for block patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
2No2Name committed Feb 1, 2025
1 parent 0a3bc94 commit bcda45d
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 28 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Worldthreader 2.0.3 for Minecraft 1.21.4 fixes a mod compatibility issue.
Worldthreader 2.0.4 for Minecraft 1.21.4 fixes a minor thread safety issue.
Please report any issues you encounter to the [issue tracker of worldthreader](https://github.com/2No2Name/worldthreader/issues). As worldthreader likely comes with massive mod compatibility issues, please do not report crashes and issues to other mods' issue trackers before confirming the issue without worldthreader.

## Fixes:

- Fix incompatibility with Lithium's getChunk overwrite
- Add thread-safety to iron golem, snow golem, end portal and wither block patterns used in spawning

## Known issues

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ loader_version=0.16.10
# Fabric API
fabric_version=0.114.3+1.21.4
# Mod Properties
mod_version=2.0.3
mod_version=2.0.4
maven_group=_2no2name
archives_base_name=Worldthreader
mod_name=Worldthreader
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/no2/worldthreader/WorldThreaderMod.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package no2.worldthreader;

import no2.worldthreader.init.ModGameRules;
import net.fabricmc.api.ModInitializer;
import net.minecraft.world.level.block.Blocks;
import no2.worldthreader.common.mixin_support.interfaces.BeforeThreadingInitialization;
import no2.worldthreader.init.ModGameRules;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -14,4 +16,10 @@ public class WorldThreaderMod implements ModInitializer {
public void onInitialize() {
ModGameRules.registerGameRules();
}

public static void initializeBeforeThreading() {
((BeforeThreadingInitialization) Blocks.CARVED_PUMPKIN).worldthreader$initBeforeThreading();
((BeforeThreadingInitialization) Blocks.END_PORTAL_FRAME).worldthreader$initBeforeThreading();
((BeforeThreadingInitialization) Blocks.WITHER_SKELETON_SKULL).worldthreader$initBeforeThreading();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package no2.worldthreader.common.mixin_support.interfaces;

public interface BeforeThreadingInitialization {
void worldthreader$initBeforeThreading();
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class WorldThreadingManager {


public WorldThreadingManager(MinecraftServer server) {
WorldThreaderMod.initializeBeforeThreading();

this.server = server;
this.tickBarrier = new Phaser();
this.withinTickBarrier = new Phaser();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no2.worldthreader.mixin.threading_compatibility;
package no2.worldthreader.mixin.threading_compatibility.block_behavior;

import net.minecraft.core.dispenser.OptionalDispenseItemBehavior;
import org.spongepowered.asm.mixin.Mixin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
package no2.worldthreader.mixin.threading_compatibility;
package no2.worldthreader.mixin.threading_compatibility.block_behavior;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import org.spongepowered.asm.mixin.Final;
import net.minecraft.world.level.block.RedStoneWireBlock;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Map;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.RedStoneWireBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.block.state.properties.RedstoneSide;

@Mixin(RedStoneWireBlock.class)
public abstract class RedstoneWireBlockMixin {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package no2.worldthreader.mixin.threading_compatibility.block_behavior.patterns;

import net.minecraft.world.level.block.CarvedPumpkinBlock;
import net.minecraft.world.level.block.state.pattern.BlockPattern;
import no2.worldthreader.common.mixin_support.interfaces.BeforeThreadingInitialization;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(CarvedPumpkinBlock.class)
public abstract class CarvedPumpkinBlockMixin implements BeforeThreadingInitialization {

@Shadow
public abstract BlockPattern getOrCreateSnowGolemBase();

@Shadow
public abstract BlockPattern getOrCreateIronGolemBase();

@Shadow
public abstract BlockPattern getOrCreateSnowGolemFull();

@Shadow
public abstract BlockPattern getOrCreateIronGolemFull();


@Override
public void worldthreader$initBeforeThreading() {
this.getOrCreateSnowGolemBase();
this.getOrCreateSnowGolemFull();

this.getOrCreateIronGolemBase();
this.getOrCreateIronGolemFull();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package no2.worldthreader.mixin.threading_compatibility.block_behavior.patterns;

import net.minecraft.world.level.block.EndPortalFrameBlock;
import net.minecraft.world.level.block.state.pattern.BlockPattern;
import no2.worldthreader.common.mixin_support.interfaces.BeforeThreadingInitialization;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(EndPortalFrameBlock.class)
public abstract class EndPortalFrameBlockMixin implements BeforeThreadingInitialization {

@Shadow
public static native BlockPattern getOrCreatePortalShape();


@Override
public void worldthreader$initBeforeThreading() {
getOrCreatePortalShape();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package no2.worldthreader.mixin.threading_compatibility.block_behavior.patterns;

import net.minecraft.world.level.block.WitherSkullBlock;
import net.minecraft.world.level.block.state.pattern.BlockPattern;
import no2.worldthreader.common.mixin_support.interfaces.BeforeThreadingInitialization;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(WitherSkullBlock.class)
public abstract class WitherSkullBlockMixin implements BeforeThreadingInitialization {

@Shadow
public static native BlockPattern getOrCreateWitherBase();

@Shadow
public static native BlockPattern getOrCreateWitherFull();


@Override
public void worldthreader$initBeforeThreading() {
getOrCreateWitherBase();
getOrCreateWitherFull();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no2.worldthreader.mixin.threading_compatibility;
package no2.worldthreader.mixin.threading_compatibility.commands;

import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.commands.WeatherCommand;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no2.worldthreader.mixin.threading_compatibility;
package no2.worldthreader.mixin.threading_compatibility.commands;

import com.mojang.authlib.GameProfile;
import net.minecraft.commands.CommandSourceStack;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no2.worldthreader.mixin.threading_compatibility;
package no2.worldthreader.mixin.threading_compatibility.commands;

import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.MinecraftServer;
Expand Down
13 changes: 8 additions & 5 deletions src/main/resources/worldthreader.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,19 @@
"threading_compatibility.EntitySelectorMixin",
"threading_compatibility.GameruleCommandMixin",
"threading_compatibility.MinecraftServerMixin",
"threading_compatibility.OptionalDispenseItemBehaviorMixin",
"threading_compatibility.PlayerListMixin",
"threading_compatibility.PrimaryLevelDataMixin",
"threading_compatibility.RedstoneWireBlockMixin",
"threading_compatibility.ServerLevelMixin",
"threading_compatibility.ServerPlayerMixin",
"threading_compatibility.ServerTickRateManagerMixin",
"threading_compatibility.WeatherCommandMixin",
"threading_compatibility.WhitelistCommandMixin",
"threading_compatibility.WorldBorderCommandMixin",
"threading_compatibility.block_behavior.OptionalDispenseItemBehaviorMixin",
"threading_compatibility.block_behavior.RedstoneWireBlockMixin",
"threading_compatibility.block_behavior.patterns.CarvedPumpkinBlockMixin",
"threading_compatibility.block_behavior.patterns.EndPortalFrameBlockMixin",
"threading_compatibility.block_behavior.patterns.WitherSkullBlockMixin",
"threading_compatibility.commands.WeatherCommandMixin",
"threading_compatibility.commands.WhitelistCommandMixin",
"threading_compatibility.commands.WorldBorderCommandMixin",
"threading_compatibility.entity_owners.ItemEntityMixin",
"threading_compatibility.entity_owners.PrimedTntMixin",
"threading_compatibility.entity_owners.ProjectileMixin",
Expand Down

0 comments on commit bcda45d

Please sign in to comment.