Skip to content

Commit

Permalink
Backport 0.3.3 features 1.19.2
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdElAziz333 committed Feb 8, 2024
1 parent 9a1cba1 commit 9a6c889
Show file tree
Hide file tree
Showing 9 changed files with 270 additions and 25 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mapping_version=1.19.2
mod_id=canary
mod_name=Canary
mod_license=LGPL-3.0
mod_version=0.3.2
mod_version=0.3.3
mod_group_id=com.abdelaziz.canary
mod_credits=AbdlElAziz, Jellysquid, 2No2Name
mod_authors=AbdElAziz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ private CanaryConfig() {
// You must manually add a rule for any new mixins not covered by an existing package rule.

this.addMixinRule("ai", true);
this.addMixinRule("ai.nearby_entity_tracking", true);
this.addMixinRule("ai.nearby_entity_tracking", false);
this.addMixinRule("ai.nearby_entity_tracking.goals", true);
this.addMixinRule("ai.pathing", true);
this.addMixinRule("ai.poi", true);
this.addMixinRule("ai.poi.fast_portals", true);
this.addMixinRule("ai.poi.tasks", true);
this.addMixinRule("ai.raid", true);
this.addMixinRule("ai.replace_streams", true);
this.addMixinRule("ai.replace_streams.storage", true);
this.addMixinRule("ai.sensor", true);
this.addMixinRule("ai.sensor.secondary_poi", true);
this.addMixinRule("ai.task", true);
Expand All @@ -55,7 +57,7 @@ private CanaryConfig() {
this.addMixinRule("alloc.blockstate", true);
this.addMixinRule("alloc.chunk_random", true);
this.addMixinRule("alloc.chunk_ticking", true);
this.addMixinRule("alloc.composter", true);
this.addMixinRule("alloc.composter", false); //duplicated in Saturn
this.addMixinRule("alloc.deep_passengers", true);
this.addMixinRule("alloc.entity_tracker", true);
this.addMixinRule("alloc.enum_values", true);
Expand All @@ -77,7 +79,7 @@ private CanaryConfig() {

this.addMixinRule("chunk", true);
this.addMixinRule("chunk.entity_class_groups", true);
this.addMixinRule("chunk.no_locking", true);
this.addMixinRule("chunk.no_locking", false); //duplicated in Saturn
this.addMixinRule("chunk.no_validation", true);
this.addMixinRule("chunk.palette", true);
this.addMixinRule("chunk.serialization", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return false;
}

if (mixinClassName.startsWith(MIXIN_PACKAGE_ROOT + "entity.hopper_minecart") && (FMLLoader.getLoadingModList().getModFileById("hplus")) != null) {
return false;
}

if ((mixinClassName.startsWith(MIXIN_PACKAGE_ROOT + "shapes") || (mixinClassName.startsWith(MIXIN_PACKAGE_ROOT + "math.sine_lut")) || (mixinClassName.startsWith(MIXIN_PACKAGE_ROOT + "alloc.block_state"))) && !LoadingModList.get().getErrors().isEmpty()) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
package com.abdelaziz.canary.mixin.ai.replace_streams.storage;

import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.LongSet;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.entity.*;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

import java.util.List;
import java.util.Queue;
import java.util.function.Consumer;
import java.util.stream.Stream;

@Mixin(PersistentEntitySectionManager.class)
public abstract class PersistentEntitySectionManagerMixin<T extends EntityAccess> {
@Shadow @Final
private Long2ObjectMap<Visibility> chunkVisibility;

@Shadow @Final
private LongSet chunksToUnload;

@Shadow @Final
EntitySectionStorage<T> sectionStorage;

@Shadow @Final
private Long2ObjectMap<PersistentEntitySectionManager.ChunkLoadStatus> chunkLoadStatuses;

@Shadow @Final
private Queue<ChunkEntities<T>> loadingInbox;

@Shadow
abstract void stopTicking(T entity);

@Shadow
abstract void stopTracking(T entity);

@Shadow
abstract void startTracking(T entity);

@Shadow
abstract void startTicking(T entity);

@Shadow
protected abstract boolean storeChunkSections(long chunkPos, Consumer<T> consumer);

@Shadow
protected abstract void unloadEntity(EntityAccess entityAccess);

@Shadow
protected abstract boolean addEntity(T entityType, boolean callback);

@Shadow
protected abstract void ensureChunkQueuedForLoad(long chunkPos);

/**
* @reason Avoid streams.
* @author AbdElAziz
* */
@Overwrite
public void addLegacyChunkEntities(Stream<T> stream) {
for (T entity : stream.toList()) {
this.addEntity(entity, true);

if (entity instanceof Entity entity1) {
entity1.onAddedToWorld();
}
}
}

/**
* @reason Avoid streams.
* @author AbdElAziz
* */
@Overwrite
public void addWorldGenChunkEntities(Stream<T> stream) {
for (T entity : stream.toList()) {
this.addEntity(entity, false);

if (entity instanceof Entity entity1) {
entity1.onAddedToWorld();
}
}
}

/**
* @reason Avoid streams.
* @author AbdElAziz
* */
@Overwrite
public void updateChunkStatus(ChunkPos chunkPos, Visibility defaultVisibility) {
long i = chunkPos.toLong();

if (defaultVisibility == Visibility.HIDDEN) {
this.chunkVisibility.remove(i);
this.chunksToUnload.add(i);
} else {
this.chunkVisibility.put(i, defaultVisibility);
this.chunksToUnload.remove(i);
this.ensureChunkQueuedForLoad(i);
}

List<EntitySection<T>> list = this.sectionStorage.getExistingSectionsInChunk(i).toList();

for (EntitySection<T> section : list) {
Visibility visibility = section.updateChunkStatus(defaultVisibility);
boolean flag = visibility.isAccessible();
boolean flag1 = defaultVisibility.isAccessible();
boolean flag2 = visibility.isTicking();
boolean flag3 = defaultVisibility.isTicking();

if (flag2 && !flag3) {
for (T entity : section.getEntities().toList()) {
if (!entity.isAlwaysTicking()) {
this.stopTicking(entity);
}
}
}

if (flag && !flag1) {
for (T entity : section.getEntities().toList()) {
if (!entity.isAlwaysTicking()) {
this.stopTracking(entity);
}
}
} else if (!flag && flag1) {
for (T entity : section.getEntities().toList()) {
if (!entity.isAlwaysTicking()) {
this.startTracking(entity);
}
}
}

if (!flag2 && flag3) {
for (T entity : section.getEntities().toList()) {
if (!entity.isAlwaysTicking()) {
this.startTicking(entity);
}
}
}
}
}

/**
* @reason Avoid streams.
* @author AbdElAziz
* */
@Overwrite
private boolean processChunkUnload(long chunkPos) {
boolean flag = this.storeChunkSections(chunkPos, (type) -> {
for (EntityAccess entity : type.getPassengersAndSelf().toList()) {
this.unloadEntity(entity);
}
});
if (!flag) {
return false;
} else {
this.chunkLoadStatuses.remove(chunkPos);
return true;
}
}

/**
* @reason Avoid streams.
* @author AbdElAziz
* */
@Overwrite
private void processPendingLoads() {
ChunkEntities<T> chunkEntities;
while((chunkEntities = this.loadingInbox.poll()) != null) {
for (T entity : chunkEntities.getEntities().toList()) {
this.addEntity(entity, true);

if (entity instanceof Entity entity1) {
entity1.onAddedToWorld();
}
}

this.chunkLoadStatuses.put(chunkEntities.getPos().toLong(), PersistentEntitySectionManager.ChunkLoadStatus.LOADED);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.abdelaziz.canary.mixin.ai.replace_streams.storage;

import it.unimi.dsi.fastutil.longs.LongSet;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.entity.*;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(TransientEntitySectionManager.class)
public class TransientEntitySectionManagerMixin<T extends EntityAccess> {
@Shadow @Final
private LongSet tickingChunks;

@Shadow @Final
EntitySectionStorage<T> sectionStorage;

@Shadow @Final
LevelCallback<T> callbacks;

/**
* @reason Avoid streams.
* @author AbdElAziz
* */
@Overwrite
public void startTicking(ChunkPos chunkPos) {
long i = chunkPos.toLong();
this.tickingChunks.add(i);

for (EntitySection<T> section : this.sectionStorage.getExistingSectionsInChunk(i).toList()) {
Visibility visibility = section.updateChunkStatus(Visibility.TICKING);

if (!visibility.isTicking()) {
for (T entity : section.getEntities().toList()) {
if (!entity.isAlwaysTicking()) {
this.callbacks.onTickingStart(entity);
}
}
}
}
}

/**
* @reason Avoid streams.
* @author AbdElAziz
* */
@Overwrite
public void stopTicking(ChunkPos chunkPos) {
long i = chunkPos.toLong();
this.tickingChunks.remove(i);

for (EntitySection<T> section : this.sectionStorage.getExistingSectionsInChunk(i).toList()) {
Visibility visibility = section.updateChunkStatus(Visibility.TRACKED);

if (visibility.isTicking()) {
for (T entity : section.getEntities().toList()) {
if (!entity.isAlwaysTicking()) {
this.callbacks.onTickingEnd(entity);
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,13 @@ public class GameRulesMixin {
private Map<GameRules.Key<?>, GameRules.Value<?>> rules;

@Inject(
method = "<init>()V",
method = {
"<init>()V",
"<init>(Ljava/util/Map;)V"
},
at = @At("RETURN")
)
private void reinitializeMap(CallbackInfo ci) {
this.rules = new Object2ObjectOpenHashMap<>(this.rules);
}

@Inject(
method = "<init>(Ljava/util/Map;)V",
at = @At("RETURN")
)
private void reinitializeMap(Map<?, ?> rules, CallbackInfo ci) {
this.rules = new Object2ObjectOpenHashMap<>(this.rules);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,4 @@ public BlockState getBlockState(BlockPos pos) {
return section.getBlockState(x & 15, y & 15, z & 15);
//This code path is slower than with the extra world height limit check. Tradeoff in favor of the default path.
}

@Redirect(
method = "getFluidState",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/level/Level;isOutsideBuildHeight(Lnet/minecraft/core/BlockPos;)Z"
)
)
private boolean skipFluidHeightLimitTest(Level world, BlockPos pos) {
return world.isOutsideBuildHeight(pos);
}
}
4 changes: 3 additions & 1 deletion src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ public net.minecraft.world.entity.ai.village.poi.PoiSection m_27272_()Z # isVali
public net.minecraft.util.SortedArraySet <init>(ILjava/util/Comparator;)V
public net.minecraft.server.level.Ticket f_9423_ # createdTick
public net.minecraft.server.level.ServerChunkCache$ChunkAndHolder
public net.minecraft.server.level.ChunkHolder m_143003_(Lnet/minecraft/server/level/ChunkMap;Ljava/util/concurrent/Executor;)V
public net.minecraft.server.level.ChunkHolder m_143003_(Lnet/minecraft/server/level/ChunkMap;Ljava/util/concurrent/Executor;)V

public net.minecraft.world.level.entity.PersistentEntitySectionManager$ChunkLoadStatus
2 changes: 2 additions & 0 deletions src/main/resources/canary.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"ai.raid.ObtainRaidLeaderBannerGoalMixin",
"ai.raid.RaiderMixin",
"ai.raid.RaidMixin",
"ai.replace_streams.storage.PersistentEntitySectionManagerMixin",
"ai.replace_streams.storage.TransientEntitySectionManagerMixin",
"ai.sensor.secondary_poi.SecondaryPoiSensorMixin",
"ai.task.launch.BrainMixin",
"ai.task.memory_change_counting.BehaviorMixin",
Expand Down

0 comments on commit 9a6c889

Please sign in to comment.