Skip to content

Commit

Permalink
Added seedy Behavior from indev5
Browse files Browse the repository at this point in the history
  • Loading branch information
CDAGaming committed Feb 8, 2022
1 parent f569f02 commit ba3010d
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ max_errors=400
loader_version=0.12.12

# Mod Properties
mod_version = 1.6.3+1.18.1
mod_version = 1.6.5+1.18.1
maven_group = azzy.fabric
archives_base_name = incubus-core

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.id.incubus_core.mixin;
package net.id.incubus_core.mixin.entity;

import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.id.incubus_core.mixin;
package net.id.incubus_core.mixin.entity;

import net.id.incubus_core.misc.WorthinessChecker;
import com.mojang.authlib.GameProfile;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.id.incubus_core.mixin;
package net.id.incubus_core.mixin.world;

import net.minecraft.server.world.ServerWorld;
import org.spongepowered.asm.mixin.Mixin;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package net.id.incubus_core.mixin.world.biome.source;

import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.PrimitiveCodec;
import net.id.incubus_core.util.SeedSupplier;
import net.minecraft.world.biome.source.MultiNoiseBiomeSource;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(MultiNoiseBiomeSource.class)
public abstract class MultiNoiseBiomeSourceMixin {
/*This doesn't seem to exist in 1.18...
@Unique private static long LAST_SEED = SeedSupplier.MARKER;
@Redirect(
method = "method_38172(Lcom/mojang/serialization/codecs/RecordCodecBuilder$Instance;)Lcom/mojang/datafixers/kinds/App;",
at = @At(
value = "INVOKE",
target = "Lcom/mojang/serialization/codecs/PrimitiveCodec;fieldOf(Ljava/lang/String;)Lcom/mojang/serialization/MapCodec;",
ordinal = 0
)
)
private static MapCodec<Long> giveUsRandomSeeds(PrimitiveCodec<Long> codec, final String name) {
return codec.fieldOf(name).orElseGet(SeedSupplier::getSeed);
}
@ModifyVariable(
method = "<init>(JLnet/minecraft/class_6452$class_6455;Lnet/minecraft/world/biome/source/MultiNoiseBiomeSource$NoiseParameters;Lnet/minecraft/world/biome/source/MultiNoiseBiomeSource$NoiseParameters;Lnet/minecraft/world/biome/source/MultiNoiseBiomeSource$NoiseParameters;Lnet/minecraft/world/biome/source/MultiNoiseBiomeSource$NoiseParameters;Lnet/minecraft/world/biome/source/MultiNoiseBiomeSource$NoiseParameters;IIZLjava/util/Optional;)V",
at = @At(
value = "FIELD",
target = "Lnet/minecraft/world/biome/source/MultiNoiseBiomeSource;field_34194:Lnet/minecraft/class_6466;",
opcode = Opcodes.PUTFIELD,
shift = At.Shift.AFTER
),
ordinal = 0
)
private long replaceSeed(long seed) {
if (seed == SeedSupplier.MARKER) {
return LAST_SEED;
} else {
LAST_SEED = seed;
}
return seed;
}
*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.id.incubus_core.mixin.world.gen;

import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.PrimitiveCodec;
import dev.hephaestus.seedy.SeedSupplier;
import net.minecraft.util.registry.SimpleRegistry;
import net.minecraft.world.dimension.DimensionOptions;
import net.minecraft.world.gen.GeneratorOptions;
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Optional;

@Mixin(GeneratorOptions.class)
public abstract class GeneratorOptionsMixin {
// private static synthetic method_28606(Lcom/mojang/serialization/codecs/RecordCodecBuilder$Instance;)Lcom/mojang/datafixers/kinds/App;
@Redirect(
method = "method_28606(Lcom/mojang/serialization/codecs/RecordCodecBuilder$Instance;)Lcom/mojang/datafixers/kinds/App;",
at = @At(
value = "INVOKE",
target = "Lcom/mojang/serialization/codecs/PrimitiveCodec;fieldOf(Ljava/lang/String;)Lcom/mojang/serialization/MapCodec;",
ordinal = 0
)
)
private static MapCodec<Long> giveUsRandomSeeds(PrimitiveCodec<Long> codec, final String name) {
return codec.fieldOf(name).orElseGet(SeedSupplier::getSeed);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package net.id.incubus_core.mixin.world.gen.chunk;

import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.PrimitiveCodec;
import dev.hephaestus.seedy.SeedSupplier;
import net.minecraft.world.biome.source.BiomeSource;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.chunk.NoiseChunkGenerator;
import net.minecraft.world.gen.chunk.StructuresConfig;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(NoiseChunkGenerator.class)
public abstract class NoiseChunkGeneratorMixin extends ChunkGenerator {
@Unique private static long LAST_SEED = SeedSupplier.MARKER;

public NoiseChunkGeneratorMixin(BiomeSource biomeSource, StructuresConfig structuresConfig) {
super(biomeSource, structuresConfig);
}

@Redirect(
method = "method_28550(Lcom/mojang/serialization/codecs/RecordCodecBuilder$Instance;)Lcom/mojang/datafixers/kinds/App;",
at = @At(
value = "INVOKE",
target = "Lcom/mojang/serialization/codecs/PrimitiveCodec;fieldOf(Ljava/lang/String;)Lcom/mojang/serialization/MapCodec;",
ordinal = 0
)
)
private static MapCodec<Long> giveUsRandomSeeds(PrimitiveCodec<Long> codec, final String name) {
return codec.fieldOf(name).orElseGet(SeedSupplier::getSeed);
}

@ModifyVariable(
method = "<init>(Lnet/minecraft/util/registry/Registry;Lnet/minecraft/world/biome/source/BiomeSource;Lnet/minecraft/world/biome/source/BiomeSource;JLjava/util/function/Supplier;)V",
at = @At(
value = "FIELD",
target = "Lnet/minecraft/world/gen/chunk/NoiseChunkGenerator;seed:J",
opcode = Opcodes.PUTFIELD,
shift = At.Shift.AFTER
),
ordinal = 0,
argsOnly = true
)
private long replaceSeed(long seed) {
if (seed == SeedSupplier.MARKER) {
return LAST_SEED;
} else {
LAST_SEED = seed;
}

return seed;
}
}
9 changes: 9 additions & 0 deletions src/main/java/net/id/incubus_core/util/SeedSupplier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.id.incubus_core.util;

public class SeedSupplier {
public static final long MARKER = -1;

public static long getSeed() {
return MARKER;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
],

"depends": {
"fabricloader": ">=0.7.4",
"fabricloader": ">=0.12.12",
"fabric": "*",
"minecraft": "*"
},
Expand Down
9 changes: 6 additions & 3 deletions src/main/resources/incubus_core.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
"package": "net.id.incubus_core.mixin",
"compatibilityLevel": "JAVA_16",
"mixins": [
"BlockEntityMixin",
"entity.BlockEntityMixin",
"IngredientMixin",
"NameDisplayMixin",
"ServerTickMixin"
"entity.NameDisplayMixin",
"world.ServerTickMixin",
"world.biome.source.MultiNoiseBiomeSourceMixin",
"world.gen.GeneratorOptionsMixin",
"world.gen.chunk.NoiseChunkGeneratorMixin"
],
"client": [
"CapeMixin"
Expand Down

0 comments on commit ba3010d

Please sign in to comment.