Optimize Secondary POI and remove spotless fr

This commit is contained in:
Taiyou06
2024-07-07 05:05:32 +03:00
parent ce6219c206
commit 7e795056a8
6 changed files with 88 additions and 3 deletions

View File

@@ -34,7 +34,7 @@ jobs:
- name: Gradle deez
uses: gradle/gradle-build-action@v3
- name: Build artifacts
run: ./gradlew clean :spotlessApply build
run: ./gradlew clean build
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:

View File

@@ -20,4 +20,3 @@ mixinExtras = { group = "io.github.llamalad7", name = "mixinextras-common", vers
build-paperweight = { module = "io.papermc.paperweight.userdev:io.papermc.paperweight.userdev.gradle.plugin", version.ref = "paperweight" }
build-shadow = { module = "io.github.goooler:shadow", version.ref = "shadow" }
build-spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version.ref = "spotless" }

View File

@@ -0,0 +1,11 @@
package net.gensokyoreimagined.nitori.common.util;
/**
* Pre-initialized constants to avoid unnecessary allocations.
*/
public final class ArrayConstants {
private ArrayConstants() {}
public static final int[] EMPTY = new int[0];
public static final int[] ZERO = new int[]{0};
}

View File

@@ -0,0 +1,26 @@
package net.gensokyoreimagined.nitori.mixin.ai.sensor.secondary_poi;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.world.entity.ai.sensing.SecondaryPoiSensor;
import net.minecraft.world.entity.npc.Villager;
import net.minecraft.server.level.ServerLevel;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(SecondaryPoiSensor.class)
public class SecondaryPointsOfInterestSensorMixin {
@Inject(
method = "doTick(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/npc/Villager;)V",
at = @At("HEAD"),
cancellable = true
)
private void skipUselessSense(ServerLevel serverWorld, Villager villagerEntity, CallbackInfo ci) {
if (villagerEntity.getVillagerData().getProfession().secondaryPoi().isEmpty()) {
villagerEntity.getBrain().eraseMemory(MemoryModuleType.SECONDARY_JOB_SITE);
ci.cancel();
}
}
}

View File

@@ -0,0 +1,48 @@
package net.gensokyoreimagined.nitori.mixin.alloc.composter;
//import net.gensokyoreimagined.nitori.common.util.ArrayConstants;
//import net.minecraft.world.WorldlyContainer;
//import net.minecraft.core.Direction;
//import org.spongepowered.asm.mixin.Mixin;
//import org.spongepowered.asm.mixin.Overwrite;
//
//public class ComposterMixin {
//
// @Mixin(targets = "net.minecraft.block.ComposterBlock$ComposterInventory")
// static abstract class ComposterBlockComposterInventoryMixin implements WorldlyContainer {
// /**
// * @author 2No2Name
// * @reason avoid allocation
// */
// @Overwrite
// public int[] getSlotsForFace(Direction side) {
// return side == Direction.UP ? ArrayConstants.ZERO : ArrayConstants.EMPTY;
// }
// }
//
// @Mixin(targets = "net.minecraft.block.ComposterBlock$DummyInventory")
// static abstract class ComposterBlockDummyInventoryMixin implements WorldlyContainer {
// /**
// * @author 2No2Name
// * @reason avoid allocation
// */
// @Overwrite
// public int[] getSlotsForFace(Direction side) {
// return ArrayConstants.EMPTY;
// }
// }
//
// @Mixin(targets = "net.minecraft.block.ComposterBlock$FullComposterInventory")
// static abstract class ComposterBlockFullComposterInventoryMixin implements WorldlyContainer {
// /**
// * @author 2No2Name
// * @reason avoid allocation
// */
// @Overwrite
// public int[] getSlotsForFace(Direction side) {
// return side == Direction.DOWN ? ArrayConstants.ZERO : ArrayConstants.EMPTY;
// }
// }
//}
//TODO: Mixins are not getting dettected for some reason even if they are in the mixins.core???

View File

@@ -36,6 +36,7 @@
"cached_hashcode.BlockNeighborGroupMixin",
"shapes.blockstate_cache.BlockMixin",
"math.fast_blockops.DirectionMixin",
"math.fast_blockops.BlockPosMixin"
"math.fast_blockops.BlockPosMixin",
"ai.sensor.secondary_poi.SecondaryPointsOfInterestSensorMixin",
]
}