-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(patch): Prevent iteration tile entity invalidation during chunk …
…loading
- Loading branch information
Showing
4 changed files
with
50 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/tv/darkosto/sevpatches/core/mixins/ChunkTEMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package tv.darkosto.sevpatches.core.mixins; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.block.state.IBlockState; | ||
import net.minecraft.tileentity.TileEntity; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.chunk.Chunk; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
import tv.darkosto.sevpatches.SevPatches; | ||
|
||
@Mixin(value = Chunk.class, priority = 1500) | ||
public abstract class ChunkTEMixin { | ||
private boolean loadingTileEntities = false; | ||
|
||
@Shadow | ||
public abstract IBlockState getBlockState(BlockPos pos); | ||
|
||
@Inject(method = "createNewTileEntity", at = @At(value = "HEAD"), cancellable = true, require = 1) | ||
private void skipTileEntityIfLoading(BlockPos blockPos, CallbackInfoReturnable<TileEntity> cir) { | ||
IBlockState blockState = this.getBlockState(blockPos); | ||
Block block = blockState.getBlock(); | ||
if (this.loadingTileEntities && block.hasTileEntity(blockState)) { | ||
SevPatches.LOGGER.warn("#########################################################################"); | ||
SevPatches.LOGGER.warn("A mod has attempted to add a TileEntity to a chunk during chunk loading; this may result in iterator invalidation"); | ||
SevPatches.LOGGER.warn("This attempt has been blocked, which may lead to some weirdness, e.g. pipes not connecting"); | ||
SevPatches.LOGGER.warn("TE at: {} for block {}", blockPos, block.getRegistryName()); | ||
SevPatches.LOGGER.warn("Stack trace:", new Throwable()); | ||
SevPatches.LOGGER.warn("#########################################################################"); | ||
cir.setReturnValue(null); | ||
} | ||
} | ||
|
||
@Inject(method = "onLoad", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addTileEntities(Ljava/util/Collection;)V"), require = 1) | ||
private void setLoadingTileEntitiesOn(CallbackInfo ci) { | ||
this.loadingTileEntities = true; | ||
} | ||
|
||
@Inject(method = "onLoad", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addTileEntities(Ljava/util/Collection;)V", shift = At.Shift.AFTER), require = 1) | ||
private void setLoadingTileEntitiesOff(CallbackInfo ci) { | ||
this.loadingTileEntities = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters