Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update #85

Merged
merged 1 commit into from
Jan 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//file:noinspection GroovyAssignabilityCheck
buildscript {
repositories {
maven { url = 'https://maven.minecraftforge.net' }
maven { url = 'https://maven.parchmentmc.org' }
maven { url 'https://maven.minecraftforge.net' }
maven { url 'https://maven.parchmentmc.org' }
maven { url 'https://repo.spongepowered.org/repository/maven-public/' }
mavenCentral()
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/xekr/ironstars/IronStars.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.xekr.ironstars;

import com.xekr.ironstars.registry.AllBiomes;
import com.xekr.ironstars.recipe.AnvilRecipeTypes;
import com.xekr.ironstars.recipe.RecipeEventHandler;
import com.xekr.ironstars.registry.AllBlocks;
import com.xekr.ironstars.registry.AllBlockEntities;
import com.xekr.ironstars.registry.AllCapabilities;
import com.xekr.ironstars.registry.AllDimensions;
import com.xekr.ironstars.registry.AllFluids;
import com.xekr.ironstars.registry.AllItems;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -20,7 +21,7 @@ public class IronStars {

public static final String ID = "ironstars";
public static final String NAME = "Iron Stars";
private static final Logger LOGGER = LogManager.getLogger();
public static final Logger LOGGER = LogManager.getLogger();

public IronStars() {
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
Expand All @@ -29,11 +30,12 @@ public IronStars() {
AllBlockEntities.register(bus);
AllItems.register(bus);
AllFluids.register(bus);
AllBiomes.register(bus);
AllDimensions.init();
AnvilRecipeTypes.init();
MinecraftForge.EVENT_BUS.register(RecipeEventHandler.class);
}

public static ResourceLocation asResource(String name) {
public static ResourceLocation id(String name) {
return new ResourceLocation(ID, name);
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/xekr/ironstars/IronStarsUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.xekr.ironstars;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class IronStarsUtil {
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
}
20 changes: 20 additions & 0 deletions src/main/java/com/xekr/ironstars/mixin/AnvilBlockMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.xekr.ironstars.mixin;

import com.xekr.ironstars.recipe.AnvilFlatteningCraftingManager;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.item.FallingBlockEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.AnvilBlock;
import net.minecraft.world.level.block.state.BlockState;
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(AnvilBlock.class)
public class AnvilBlockMixin {
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;levelEvent(ILnet/minecraft/core/BlockPos;I)V"), method = "onLand")
private void onLand(Level level, BlockPos blockPos, BlockState state, BlockState targetState, FallingBlockEntity entity, CallbackInfo ci) {
AnvilFlatteningCraftingManager.craft(level, entity.blockPosition());
}
}
27 changes: 0 additions & 27 deletions src/main/java/com/xekr/ironstars/recipe/RecipeEventHandler.java

This file was deleted.

37 changes: 37 additions & 0 deletions src/main/java/com/xekr/ironstars/registry/AllBiomes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.xekr.ironstars.registry;

import com.xekr.ironstars.IronStars;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeGenerationSettings;
import net.minecraft.world.level.biome.BiomeSpecialEffects;
import net.minecraft.world.level.biome.MobSpawnSettings;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

public class AllBiomes {
private static final DeferredRegister<Biome> BIOMES = DeferredRegister.create(ForgeRegistries.BIOMES, IronStars.ID);

public static final ResourceKey<Biome> MOON = registerBiome("moon");


private static ResourceKey<Biome> registerBiome(String name) {
BIOMES.register(name, () -> new Biome.BiomeBuilder()
.precipitation(Biome.Precipitation.NONE)
.biomeCategory(Biome.BiomeCategory.NONE)
.downfall(0)
.temperature(0)
.specialEffects(new BiomeSpecialEffects.Builder().fogColor(0).waterColor(0).waterFogColor(0).skyColor(0).build())
.generationSettings(new BiomeGenerationSettings.Builder().build())
.mobSpawnSettings(new MobSpawnSettings.Builder().build())
.temperatureAdjustment(Biome.TemperatureModifier.NONE)
.build());
return ResourceKey.create(Registry.BIOME_REGISTRY, IronStars.id(name));
}

public static void register(IEventBus bus) {
BIOMES.register(bus);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;

public class CreativeTab {
public class AllCreativeTab {

public static final CreativeModeTab BASE = new CreativeModeTab(IronStars.ID + ".base") {
@Override
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/xekr/ironstars/registry/AllDimensions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.xekr.ironstars.registry;

import com.xekr.ironstars.IronStars;
import com.xekr.ironstars.world.BiomeProvider;
import com.xekr.ironstars.world.ModChunkGenerator;
import net.minecraft.core.Registry;

public class AllDimensions {
public static long seed;
public static void init() {
Registry.register(Registry.BIOME_SOURCE, IronStars.id("ironstars_biomes"), BiomeProvider.CODEC);

Registry.register(Registry.CHUNK_GENERATOR, IronStars.id("structure_locating_wrapper"), ModChunkGenerator.CODEC);
}

}
17 changes: 10 additions & 7 deletions src/main/java/com/xekr/ironstars/registry/AllEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

import com.mojang.brigadier.CommandDispatcher;
import com.xekr.ironstars.command.TestCommand;
import com.xekr.ironstars.world.WorldGenerator;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.data.DataGenerator;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.forge.event.lifecycle.GatherDataEvent;

public final class AllEvents {
@Mod.EventBusSubscriber
Expand All @@ -22,13 +26,12 @@ public static void onCommandRegister(RegisterCommandsEvent event) {
}
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
static class ModBusGlobal { // mod管线全局事件
// @SubscribeEvent
// public static void gatherData(GatherDataEvent event) {
// DataGenerator generator = event.getGenerator();
// ExistingFileHelper helper = event.getExistingFileHelper();
// generator.addProvider(new WorldGenerator(generator));
//
// }
@SubscribeEvent
public static void gatherData(GatherDataEvent event) { //TODO 不好使
DataGenerator generator = event.getGenerator();
ExistingFileHelper helper = event.getExistingFileHelper();
generator.addProvider(new WorldGenerator(generator));
}
}
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
static class ModBusClient { // mod管线客户端事件
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/xekr/ironstars/registry/AllItemTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import net.minecraft.resources.ResourceLocation;

import static com.xekr.ironstars.IronStars.asResource;
import static com.xekr.ironstars.IronStars.id;

public class AllItemTags {
public static final ResourceLocation TITANIUM = asResource("titanium_alloy");
public static final ResourceLocation TITANIUM = id("titanium_alloy");

}
2 changes: 1 addition & 1 deletion src/main/java/com/xekr/ironstars/registry/AllItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

import static com.xekr.ironstars.registry.CreativeTab.*;
import static com.xekr.ironstars.registry.AllCreativeTab.*;

@SuppressWarnings("unused")
public class AllItems {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/xekr/ironstars/world/Area.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.xekr.ironstars.world;

public interface Area {
int get(int p_76486_, int p_76487_);
}
5 changes: 5 additions & 0 deletions src/main/java/com/xekr/ironstars/world/AreaFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.xekr.ironstars.world;

public interface AreaFactory<A extends Area> {
A make();
}
12 changes: 12 additions & 0 deletions src/main/java/com/xekr/ironstars/world/AreaTransformer0.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.xekr.ironstars.world;

public interface AreaTransformer0 {
default <R extends Area> AreaFactory<R> run(BigContext<R> p_76985_) {
return () -> p_76985_.createResult((p_164642_, p_164643_) -> {
p_76985_.initRandom(p_164642_, p_164643_);
return this.applyPixel(p_76985_, p_164642_, p_164643_);
});
}

int applyPixel(Context p_76990_, int p_76991_, int p_76992_);
}
30 changes: 30 additions & 0 deletions src/main/java/com/xekr/ironstars/world/BigContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.xekr.ironstars.world;

public interface BigContext<R extends Area> extends Context {
void initRandom(long p_76508_, long p_76509_);

R createResult(PixelTransformer p_76510_);

default R createResult(PixelTransformer p_76511_, R p_76512_) {
return this.createResult(p_76511_);
}

default R createResult(PixelTransformer p_76513_, R p_76514_, R p_76515_) {
return this.createResult(p_76513_);
}

default int random(int p_76501_, int p_76502_) {
return this.nextRandom(2) == 0 ? p_76501_ : p_76502_;
}

default int random(int p_76504_, int p_76505_, int p_76506_, int p_76507_) {
int i = this.nextRandom(4);
if (i == 0) {
return p_76504_;
} else if (i == 1) {
return p_76505_;
} else {
return i == 2 ? p_76506_ : p_76507_;
}
}
}
96 changes: 96 additions & 0 deletions src/main/java/com/xekr/ironstars/world/BiomeProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.xekr.ironstars.world;

import com.google.common.collect.ImmutableList;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.xekr.ironstars.registry.AllBiomes;
import com.xekr.ironstars.registry.AllDimensions;
import net.minecraft.core.Registry;
import net.minecraft.resources.RegistryLookupCodec;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.biome.Climate;

import java.util.List;
import java.util.Optional;
import java.util.function.LongFunction;

public class BiomeProvider extends BiomeSource {
public static final Codec<BiomeProvider> CODEC = RecordCodecBuilder.create((instance) -> instance.group(
Codec.LONG.fieldOf("seed").stable().orElseGet(() -> AllDimensions.seed).forGetter((obj) -> obj.seed),
RegistryLookupCodec.create(Registry.BIOME_REGISTRY).forGetter(provider -> provider.registry)
).apply(instance, instance.stable(BiomeProvider::new)));

private static final List<ResourceKey<Biome>> BIOMES = ImmutableList.of(AllBiomes.MOON);

private final Registry<Biome> registry;
private final Layer genBiomes;
private final long seed;

public BiomeProvider(long seed, Registry<Biome> registryIn) {
super(BIOMES.stream().map(ResourceKey::location).map(registryIn::getOptional).filter(Optional::isPresent).map(opt -> opt::get));
this.seed = seed;
registry = registryIn;
genBiomes = makeLayers(seed, registryIn);

}

public static int getBiomeId(ResourceKey<Biome> biome, Registry<Biome> registry) {
return registry.getId(registry.get(biome));
}

private static <T extends Area, C extends BigContext<T>> AreaFactory<T> makeLayers(LongFunction<C> seed, Registry<Biome> registry, long rawSeed) {

AreaFactory<T> biomes = GenLayerTFBiomes.INSTANCE.setup(registry).run(seed.apply(1L));
// biomes = GenLayerTFKeyBiomes.INSTANCE.setup(registry, rawSeed).run(seed.apply(1000L), biomes);
// biomes = GenLayerTFCompanionBiomes.INSTANCE.setup(registry).run(seed.apply(1000L), biomes);
//
// biomes = ZoomLayer.NORMAL.run(seed.apply(1000L), biomes);
// biomes = ZoomLayer.NORMAL.run(seed.apply(1001L), biomes);
//
// biomes = GenLayerTFBiomeStabilize.INSTANCE.run(seed.apply(700L), biomes);
//
// biomes = GenLayerTFThornBorder.INSTANCE.setup(registry).run(seed.apply(500L), biomes);
//
// biomes = ZoomLayer.NORMAL.run(seed.apply(1002), biomes);
// biomes = ZoomLayer.NORMAL.run(seed.apply(1003), biomes);
// biomes = ZoomLayer.NORMAL.run(seed.apply(1004), biomes);
// biomes = ZoomLayer.NORMAL.run(seed.apply(1005), biomes);
//
// AreaFactory<T> riverLayer = GenLayerTFStream.INSTANCE.setup(registry).run(seed.apply(1L), biomes);
// riverLayer = SmoothLayer.INSTANCE.run(seed.apply(7000L), riverLayer);
// biomes = GenLayerTFRiverMix.INSTANCE.setup(registry).run(seed.apply(100L), biomes, riverLayer);

return biomes;
}

public static Layer makeLayers(long seed, Registry<Biome> registry) {
AreaFactory<LazyArea> areaFactory = makeLayers((context) -> new LazyAreaContext(25, seed, context), registry, seed);
return new Layer(areaFactory) {
@Override
public Biome get(Registry<Biome> p_242936_1_, int p_242936_2_, int p_242936_3_) {
int i = this.area.get(p_242936_2_, p_242936_3_);
Biome biome = registry.byId(i);
if (biome == null)
throw new IllegalStateException("Unknown biome id emitted by layers: " + i);
return biome;
}
};
}

@Override
protected Codec<? extends BiomeSource> codec() {
return CODEC;
}

@Override
public BiomeSource withSeed(long pSeed) {
return new BiomeProvider(pSeed, registry);
}

@Override
public Biome getNoiseBiome(int p_186735_, int p_186736_, int p_186737_, Climate.Sampler p_186738_) {
return genBiomes.get(registry, p_186735_, p_186737_);
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/xekr/ironstars/world/Context.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.xekr.ironstars.world;

import net.minecraft.world.level.levelgen.synth.ImprovedNoise;

public interface Context {
int nextRandom(int p_76516_);

ImprovedNoise getBiomeNoise();
}
Loading