Skip to content

Commit

Permalink
make it compile
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiyou06 committed Aug 4, 2024
1 parent 610c5fb commit 2971510
Show file tree
Hide file tree
Showing 9 changed files with 285 additions and 293 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import net.gensokyoreimagined.nitori.common.entity.EntityClassGroup;
import net.gensokyoreimagined.nitori.common.entity.pushable.EntityPushablePredicate;
import net.gensokyoreimagined.nitori.mixin.util.accessors.ClientEntityManagerAccessor;
import net.gensokyoreimagined.nitori.mixin.util.accessors.EntityTrackingSectionAccessor;
import net.gensokyoreimagined.nitori.mixin.util.accessors.ServerEntityManagerAccessor;
import net.gensokyoreimagined.nitori.common.world.chunk.ClassGroupFilterableList;
import net.gensokyoreimagined.nitori.mixin.util.accessors.ServerWorldAccessor;
import net.minecraft.core.BlockPos;
import net.minecraft.util.ClassInstanceMultiMap;
import net.minecraft.util.AbortableIterationConsumer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
package net.gensokyoreimagined.nitori.mixin.alloc.chunk_random;

import net.gensokyoreimagined.nitori.common.world.ChunkRandomSource;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.core.BlockPos;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(ServerLevel.class)
public abstract class ServerWorldMixin {
private final BlockPos.MutableBlockPos nitori$randomPosInChunkCachedPos = new BlockPos.MutableBlockPos();

/**
* @reason Avoid allocating BlockPos every invocation through using our allocation-free variant
*/
@Redirect(
method = "tickChunk",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/level/ServerLevel;getBlockRandomPos(IIII)Lnet/minecraft/core/BlockPos;"
)
)
private BlockPos redirectTickGetRandomPosInChunk(ServerLevel serverWorld, int x, int y, int z, int mask) {
((ChunkRandomSource) serverWorld).nitori$getRandomPosInChunk(x, y, z, mask, this.nitori$randomPosInChunkCachedPos);

return this.nitori$randomPosInChunkCachedPos;
}

/**
* @reason Ensure an immutable block position is passed on block tick
*/
@Redirect(
method = "tickChunk",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/level/block/state/BlockState;randomTick(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;Lnet/minecraft/util/RandomSource;)V"
)
)
private void redirectBlockStateTick(BlockState blockState, ServerLevel world, BlockPos pos, net.minecraft.util.RandomSource rand) {
blockState.randomTick(world, pos.immutable(), rand);
}
//import net.gensokyoreimagined.nitori.common.world.ChunkRandomSource;
//import net.minecraft.world.level.block.state.BlockState;
//import net.minecraft.server.level.ServerLevel;
//import net.minecraft.core.BlockPos;
//import org.spongepowered.asm.mixin.Mixin;
//import org.spongepowered.asm.mixin.injection.At;
//import org.spongepowered.asm.mixin.injection.Redirect;
//
//@Mixin(ServerLevel.class)
//public abstract class ServerWorldMixin {
// private final BlockPos.MutableBlockPos nitori$randomPosInChunkCachedPos = new BlockPos.MutableBlockPos();
//
// /**
// * @reason Avoid allocating BlockPos every invocation through using our allocation-free variant
// */
// @Redirect(
// method = "tickChunk",
// at = @At(
// value = "INVOKE",
// target = "Lnet/minecraft/server/level/ServerLevel;getBlockRandomPos(IIII)Lnet/minecraft/core/BlockPos;"
// )
// )
// private BlockPos redirectTickGetRandomPosInChunk(ServerLevel serverWorld, int x, int y, int z, int mask) {
// ((ChunkRandomSource) serverWorld).nitori$getRandomPosInChunk(x, y, z, mask, this.nitori$randomPosInChunkCachedPos);
//
// return this.nitori$randomPosInChunkCachedPos;
// }
//
// /**
// * @reason Ensure an immutable block position is passed on block tick
// */
// @Redirect(
// method = "tickChunk",
// at = @At(
// value = "INVOKE",
// target = "Lnet/minecraft/world/level/block/state/BlockState;randomTick(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;Lnet/minecraft/util/RandomSource;)V"
// )
// )
// private void redirectBlockStateTick(BlockState blockState, ServerLevel world, BlockPos pos, net.minecraft.util.RandomSource rand) {
// blockState.randomTick(world, pos.immutable(), rand);
// }

// /**
// * @reason Ensure an immutable block position is passed on fluid tick
Expand All @@ -55,6 +55,6 @@ private void redirectBlockStateTick(BlockState blockState, ServerLevel world, Bl
// private void redirectFluidStateTick(FluidState fluidState, ServerLevel world, BlockPos pos, net.minecraft.util.RandomSource rand) {
// fluidState.randomTick(world, pos.immutable(), rand);
// }
}
//}

// couldn't figure it out....
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package net.gensokyoreimagined.nitori.mixin.logic.recipe_manager;

import net.minecraft.world.Container;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.item.crafting.RecipeType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@Mixin(RecipeManager.class)
public abstract class RecipeManagerMixin {

@Shadow protected abstract <C extends Container, T extends Recipe<C>> Collection<RecipeHolder<T>> byType(RecipeType<T> type);

/**
* @author QPCrummer & Leaf Patch #0023
* @reason Optimize RecipeManager List Creation
*/
@Overwrite
public <C extends Container, T extends Recipe<C>> List<RecipeHolder<T>> getAllRecipesFor(RecipeType<T> type) {
return new ArrayList<>(this.byType(type));
}
}
//import net.minecraft.world.Container;
//import net.minecraft.world.item.crafting.Recipe;
//import net.minecraft.world.item.crafting.RecipeHolder;
//import net.minecraft.world.item.crafting.RecipeManager;
//import net.minecraft.world.item.crafting.RecipeType;
//import org.spongepowered.asm.mixin.Mixin;
//import org.spongepowered.asm.mixin.Overwrite;
//import org.spongepowered.asm.mixin.Shadow;
//
//import java.util.ArrayList;
//import java.util.Collection;
//import java.util.List;
//import java.util.Map;
//@Mixin(RecipeManager.class)
//public abstract class RecipeManagerMixin {
//
// @Shadow protected abstract <C extends Container, T extends Recipe<C>> Collection<RecipeHolder<T>> byType(RecipeType<T> type);
//
// /**
// * @author QPCrummer & Leaf Patch #0023
// * @reason Optimize RecipeManager List Creation
// */
// @Overwrite
// public <C extends Container, T extends Recipe<C>> List<RecipeHolder<T>> getAllRecipesFor(RecipeType<T> type) {
// return new ArrayList<>(this.byType(type));
// }
//}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package net.gensokyoreimagined.nitori.mixin.math.random.creation;

import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
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.Redirect;

@Mixin(ServerPlayer.class)
public abstract class ServerPlayerEntityRandomMixin {

@Shadow public abstract ServerLevel serverLevel();

@Redirect(method = "fudgeSpawnLocation", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/RandomSource;create()Lnet/minecraft/util/RandomSource;"))
private RandomSource redirectCreatedRandom() {
return serverLevel().random;
}
}
//import net.minecraft.server.level.ServerPlayer;
//import net.minecraft.server.level.ServerLevel;
//import net.minecraft.util.RandomSource;
//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.Redirect;
//
//@Mixin(ServerPlayer.class)
//public abstract class ServerPlayerEntityRandomMixin {
//
// @Shadow public abstract ServerLevel serverLevel();
//
// @Redirect(method = "fudgeSpawnLocation", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/RandomSource;create()Lnet/minecraft/util/RandomSource;"))
// private RandomSource redirectCreatedRandom() {
// return serverLevel().random;
// }
//}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package net.gensokyoreimagined.nitori.mixin.util.accessors;

import net.minecraft.world.level.entity.EntityAccess;
import net.minecraft.world.level.entity.EntitySectionStorage;
import net.minecraft.world.level.entity.TransientEntitySectionManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(TransientEntitySectionManager.class)
public interface ClientEntityManagerAccessor<T extends EntityAccess> {
@Accessor
EntitySectionStorage<T> getSectionStorage();
}
//import net.minecraft.world.level.entity.EntityAccess;
//import net.minecraft.world.level.entity.EntitySectionStorage;
//import net.minecraft.world.level.entity.TransientEntitySectionManager;
//import org.spongepowered.asm.mixin.Mixin;
//import org.spongepowered.asm.mixin.gen.Accessor;
//
//@Mixin(TransientEntitySectionManager.class)
//public interface ClientEntityManagerAccessor<T extends EntityAccess> {
// @Accessor
// EntitySectionStorage<T> getSectionStorage();
//}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package net.gensokyoreimagined.nitori.mixin.util.accessors;

import net.minecraft.world.level.entity.EntityAccess;
import net.minecraft.world.level.entity.EntitySectionStorage;
import net.minecraft.world.level.entity.PersistentEntitySectionManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(PersistentEntitySectionManager.class)
public interface ServerEntityManagerAccessor<T extends EntityAccess> {
@Accessor
EntitySectionStorage<T> getSectionStorage();
}
//import net.minecraft.world.level.entity.EntityAccess;
//import net.minecraft.world.level.entity.EntitySectionStorage;
//import net.minecraft.world.level.entity.PersistentEntitySectionManager;
//import org.spongepowered.asm.mixin.Mixin;
//import org.spongepowered.asm.mixin.gen.Accessor;
//
//@Mixin(PersistentEntitySectionManager.class)
//public interface ServerEntityManagerAccessor<T extends EntityAccess> {
// @Accessor
// EntitySectionStorage<T> getSectionStorage();
//}
Loading

0 comments on commit 2971510

Please sign in to comment.