Skip to content

Commit

Permalink
feat(patch): Prevent iteration tile entity invalidation during chunk …
Browse files Browse the repository at this point in the history
…loading
  • Loading branch information
sam-kirby committed Dec 20, 2023
1 parent 3ca7406 commit 0af6372
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ buildscript {
repositories {
maven { url = 'https://repo.spongepowered.org/maven' }
maven { url = 'https://files.minecraftforge.net/maven' }
jcenter()
mavenCentral()
}
dependencies {
Expand Down Expand Up @@ -79,7 +78,7 @@ dependencies {
}

compile 'curse.maven:astralsorcery-1.0.23-241721:2920254'
compile fg.deobf('curse.maven:jaff-1.7-235261:2448283')
compile 'curse.maven:jaff-1.7-235261:2448284'
compile 'slimeknights:TConstruct:1.12.2-2.13.0.184'
compile 'curse.maven:realisticitemdrops_deobf_1.2.14-245620:2630385'
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version_base = 1.10.1
version_base = 1.11.0

# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
# This is required to provide enough memory for the Minecraft decompilation process.
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/tv/darkosto/sevpatches/core/mixins/ChunkTEMixin.java
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;
}
}
1 change: 1 addition & 0 deletions src/main/resources/mixins.sevpatches.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"mixins": [
"ChunkTEMixin",
"EnchantmentHelperMixin",
"TileEntityBeaconMixin"
]
Expand Down

0 comments on commit 0af6372

Please sign in to comment.