Skip to content

Commit

Permalink
fixed tiletick not working after /manipulate chunk erase
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallen-Breath committed Jan 6, 2025
1 parent f1dae3a commit 66363dc
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import net.minecraft.world.chunk.ChunkSection;
import net.minecraft.world.chunk.PalettedContainer;
import net.minecraft.world.chunk.WorldChunk;
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.concurrent.CompletableFuture;
Expand All @@ -57,6 +58,7 @@
//#endif

//#if MC >= 11800
//$$ import carpettisaddition.mixins.command.manipulate.chunk.ChunkTickSchedulerAccessor;
//$$ import carpettisaddition.mixins.command.manipulate.chunk.WorldTickSchedulerAccessor;
//$$ import net.minecraft.block.Blocks;
//$$ import net.minecraft.world.tick.ChunkTickScheduler;
Expand Down Expand Up @@ -140,6 +142,14 @@ private void eraseMatter()
this.eraseDataStructures();
}

private static void clearCollection(@Nullable Collection<?> collection)
{
if (collection != null)
{
collection.clear();
}
}

//#if MC >= 11700
//$$ @SuppressWarnings("unchecked")
//#endif
Expand Down Expand Up @@ -173,8 +183,14 @@ private void eraseOneChunk(ChunkPos chunkPos)
//#if MC >= 11800
//$$ Consumer<WorldTickScheduler<?>> eraseTileTicks = scheduler -> {
//$$ ChunkTickScheduler<?> chunkTickScheduler = ((WorldTickSchedulerAccessor<?>)scheduler).getChunkTickSchedulers().get(chunk.getPos().toLong());
//$$ this.stats.tileTick += chunkTickScheduler != null ? chunkTickScheduler.getTickCount() : 0;
//$$ scheduler.removeChunkTickScheduler(chunk.getPos());
//$$ if (chunkTickScheduler != null)
//$$ {
//$$ ChunkTickSchedulerAccessor<?> ctsAccess = (ChunkTickSchedulerAccessor<?>)chunkTickScheduler;
//$$ this.stats.tileTick += chunkTickScheduler.getTickCount();
//$$ clearCollection(ctsAccess.getQueuedTicks());
//$$ clearCollection(ctsAccess.getTicks());
//$$ clearCollection(ctsAccess.getTickQueue());
//$$ }
//$$ };
//$$ eraseTileTicks.accept(this.world.getBlockTickScheduler());
//$$ eraseTileTicks.accept(this.world.getFluidTickScheduler());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* This file is part of the Carpet TIS Addition project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 Fallen_Breath and contributors
*
* Carpet TIS Addition is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Carpet TIS Addition is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Carpet TIS Addition. If not, see <https://www.gnu.org/licenses/>.
*/

package carpettisaddition.mixins.command.manipulate.chunk;

import carpettisaddition.utils.compat.DummyClass;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(DummyClass.class)
public interface ChunkTickSchedulerAccessor
{
// impl in mc1.18.2+
}
1 change: 1 addition & 0 deletions src/main/resources/carpet-tis-addition.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"command.lifetime.spawning.vehicledismounting.LivingEntityMixin",
"command.lifetime.spawning.zombiereinforce.ZombieEntityMixin",
"command.manipulate.block.FillCommandAccessor",
"command.manipulate.chunk.ChunkTickSchedulerAccessor",
"command.manipulate.chunk.HeightmapAccessor",
"command.manipulate.chunk.PalettedContainerAccessor",
"command.manipulate.chunk.ServerEntityManagerAccessor",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* This file is part of the Carpet TIS Addition project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 Fallen_Breath and contributors
*
* Carpet TIS Addition is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Carpet TIS Addition is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Carpet TIS Addition. If not, see <https://www.gnu.org/licenses/>.
*/

package carpettisaddition.mixins.command.manipulate.chunk;

import net.minecraft.world.tick.ChunkTickScheduler;
import net.minecraft.world.tick.OrderedTick;
import net.minecraft.world.tick.Tick;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.List;
import java.util.Queue;
import java.util.Set;

@Mixin(ChunkTickScheduler.class)
public interface ChunkTickSchedulerAccessor<T>
{
@Accessor
Queue<OrderedTick<T>> getTickQueue();

@Accessor
List<Tick<T>> getTicks();

@Accessor
Set<OrderedTick<?>> getQueuedTicks();
}

0 comments on commit 66363dc

Please sign in to comment.