Skip to content

Commit

Permalink
Optimize Secondary POI and remove spotless fr
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiyou06 committed Jul 7, 2024
1 parent ce6219c commit 7e79505
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Original file line number Diff line number Diff line change
@@ -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};
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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???
3 changes: 2 additions & 1 deletion src/main/resources/mixins.core.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
}

0 comments on commit 7e79505

Please sign in to comment.