瀏覽代碼

updated to new core mod, fixed ore generation

Kajetan Johannes Hammerle 3 年之前
父節點
當前提交
79a1244213

+ 52 - 4
src/main/java/me/km/KajetansMod.java

@@ -1,12 +1,21 @@
 package me.km;
 
+import java.util.function.Supplier;
+import me.km.blocks.ModBlocks;
 import me.km.networking.ModPacketHandler;
-import me.km.world.ModWorldGeneration;
+import net.minecraft.block.Block;
+import net.minecraft.block.Blocks;
 import net.minecraft.server.dedicated.DedicatedServer;
+import net.minecraft.world.gen.GenerationStage;
+import net.minecraft.world.gen.feature.ConfiguredFeature;
+import net.minecraft.world.gen.feature.DecoratedFeatureConfig;
+import net.minecraft.world.gen.feature.Feature;
+import net.minecraft.world.gen.feature.OreFeatureConfig;
 import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.common.world.BiomeGenerationSettingsBuilder;
+import net.minecraftforge.event.world.BiomeLoadingEvent;
 import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
 import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
-import net.minecraftforge.fml.event.lifecycle.ModLifecycleEvent;
 import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
 import net.minecraftforge.fml.common.Mod;
 import net.minecraftforge.eventbus.api.IEventBus;
@@ -26,14 +35,12 @@ public class KajetansMod {
         IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
         bus.addListener(this::init);
         bus.addListener(this::clientInit);
-        bus.addListener(this::onServerStop);
 
         MinecraftForge.EVENT_BUS.register(this);
     }
 
     private void init(FMLCommonSetupEvent e) {
         DeferredWorkQueue.runLater(() -> ModPacketHandler.init());
-        ModWorldGeneration.register();
 
         MinecraftForge.EVENT_BUS.register(new CommonEvents());
     }
@@ -55,4 +62,45 @@ public class KajetansMod {
             Server.onStop();
         }
     }
+
+    @SubscribeEvent
+    public void onBiomeLoad(BiomeLoadingEvent e) {
+        if(findOreBiome(e)) {
+            addFeatures(e.getGeneration());
+        }
+    }
+
+    private static boolean findOreBiome(BiomeLoadingEvent e) {
+        for(Supplier<ConfiguredFeature<?, ?>> a : e.getGeneration().getFeatures(GenerationStage.Decoration.UNDERGROUND_ORES)) {
+            ConfiguredFeature<?, ?> cf = a.get();
+            if(unpack(cf)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private static boolean unpack(ConfiguredFeature<?, ?> cf) {
+        if(cf.config instanceof DecoratedFeatureConfig) {
+            return unpack(((DecoratedFeatureConfig) cf.config).feature.get());
+        } else if(cf.config instanceof OreFeatureConfig) {
+            OreFeatureConfig oreConfig = (OreFeatureConfig) cf.config;
+            if(oreConfig.state.getBlock() == Blocks.IRON_ORE) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private static void addOre(BiomeGenerationSettingsBuilder builder, Block ore, int maxCount, int spawnTries, int maxHeight) {
+        builder.withFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Feature.ORE.withConfiguration(
+                new OreFeatureConfig(OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD,
+                        ore.getDefaultState(), maxCount)).range(maxHeight).square().func_242731_b(spawnTries));
+    }
+
+    private static void addFeatures(BiomeGenerationSettingsBuilder builder) {
+        addOre(builder, ModBlocks.copperOre, 9, 25, 128);
+        addOre(builder, ModBlocks.tinOre, 6, 12, 96);
+        addOre(builder, ModBlocks.silverOre, 9, 3, 64);
+    }
 }

+ 4 - 0
src/main/java/me/km/ObjectRegistry.java

@@ -1,5 +1,6 @@
 package me.km;
 
+import java.util.function.Supplier;
 import me.km.blocks.ModBlocks;
 import me.km.blocks.cookingpot.TileEntityCookingPot;
 import me.km.entities.ModEntities;
@@ -10,7 +11,10 @@ import net.minecraft.entity.EntityType;
 import net.minecraft.item.Item;
 import net.minecraft.item.Items;
 import net.minecraft.tileentity.TileEntityType;
+import net.minecraft.world.gen.GenerationStage;
+import net.minecraft.world.gen.feature.ConfiguredFeature;
 import net.minecraftforge.event.RegistryEvent;
+import net.minecraftforge.event.world.BiomeLoadingEvent;
 import net.minecraftforge.eventbus.api.SubscribeEvent;
 import net.minecraftforge.fml.common.Mod;
 

+ 2 - 2
src/main/java/me/km/Server.java

@@ -65,8 +65,8 @@ public class Server {
         scheduler = new SnuviScheduler(logger);
 
         // mod player list hook
-        Hooks.setPlayerListFunction(ds -> {
-            ds.setPlayerList(new ModPlayerList(ds, (DynamicRegistries.Impl) ds.func_244267_aX(), ReflectionUtils.getPlayerDataManager(ds)));
+        Hooks.setPlayerListFunction((ds, impl, pd) -> {
+            ds.setPlayerList(new ModPlayerList(ds, impl, pd));
         });
 
         // scripts

+ 0 - 4
src/main/java/me/km/items/ModItems.java

@@ -127,8 +127,6 @@ public class ModItems {
     public static Item hayBundle;
     public static Item batWing;
     public static Item wolfFur;
-    public static Item bearBrownFur;
-    public static Item bearBlackFur;
     public static Item bearPolarFur;
     public static Item cloth;
     public static Item coarseCloth;
@@ -357,8 +355,6 @@ public class ModItems {
         hayBundle = register(r, newItem(ItemGroup.MATERIALS), "hay_bundle");
         batWing = register(r, newItem(ItemGroup.MATERIALS), "bat_wing");
         wolfFur = register(r, newItem(ItemGroup.MATERIALS), "wolf_fur");
-        bearBrownFur = register(r, newItem(ItemGroup.MATERIALS), "bear_brown_fur");
-        bearBlackFur = register(r, newItem(ItemGroup.MATERIALS), "bear_black_fur");
         bearPolarFur = register(r, newItem(ItemGroup.MATERIALS), "bear_polar_fur");
         cloth = register(r, newItem(ItemGroup.MATERIALS), "cloth");
         coarseCloth = register(r, newItem(ItemGroup.MATERIALS), "coarse_cloth");

+ 1 - 1
src/main/java/me/km/overrides/ModPlayerList.java

@@ -164,7 +164,7 @@ public final class ModPlayerList extends DedicatedPlayerList {
         return p;
     }
 
-    private void setPlayerGameTypeBasedOnOther(ServerPlayerEntity target, ServerPlayerEntity source, IWorld w) {
+    private void setPlayerGameTypeBasedOnOther(ServerPlayerEntity target, ServerPlayerEntity source, ServerWorld w) {
         ReflectionUtils.setPlayerGameTypeBasedOnOther(this, target, source, w);
     }
 

+ 8 - 22
src/main/java/me/km/utils/ReflectionUtils.java

@@ -1,13 +1,10 @@
 package me.km.utils;
 
 import cpw.mods.modlauncher.api.INameMappingService;
-import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import java.util.Map;
 import java.util.Set;
-import java.util.function.Function;
 import net.minecraft.block.Block;
 import net.minecraft.block.Blocks;
 import net.minecraft.block.FireBlock;
@@ -16,21 +13,16 @@ import net.minecraft.entity.ai.goal.GoalSelector;
 import net.minecraft.entity.ai.goal.PrioritizedGoal;
 import net.minecraft.entity.player.PlayerAbilities;
 import net.minecraft.entity.player.ServerPlayerEntity;
+import net.minecraft.resources.DataPackRegistries;
 import net.minecraft.server.MinecraftServer;
 import net.minecraft.server.management.PlayerInteractionManager;
 import net.minecraft.server.management.PlayerList;
 import net.minecraft.util.FoodStats;
-import net.minecraft.util.ResourceLocation;
 import net.minecraft.world.Explosion;
 import net.minecraft.world.GameRules;
 import net.minecraft.world.GameType;
 import net.minecraft.world.IWorld;
-import net.minecraft.world.World;
-import net.minecraft.world.biome.Biome;
-import net.minecraft.world.biome.provider.BiomeProvider;
-import net.minecraft.world.gen.feature.IFeatureConfig;
-import net.minecraft.world.gen.feature.structure.Structure;
-import net.minecraft.world.storage.PlayerData;
+import net.minecraft.world.server.ServerWorld;
 import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
 import static net.minecraftforge.fml.common.ObfuscationReflectionHelper.remapName;
 import org.apache.logging.log4j.LogManager;
@@ -166,11 +158,11 @@ public class ReflectionUtils {
     // PlayerList
     // -----------------------------------------------------------------------------------
     private final static Method SET_GAMETYPE = getMethod(PlayerList.class, "func_72381_a",
-            ServerPlayerEntity.class, ServerPlayerEntity.class, IWorld.class); // setPlayerGameTypeBasedOnOther
+            ServerPlayerEntity.class, ServerPlayerEntity.class, ServerWorld.class); // setPlayerGameTypeBasedOnOther
 
-    public static void setPlayerGameTypeBasedOnOther(PlayerList pl, ServerPlayerEntity target, ServerPlayerEntity source, IWorld worldIn) {
+    public static void setPlayerGameTypeBasedOnOther(PlayerList pl, ServerPlayerEntity target, ServerPlayerEntity source, ServerWorld sw) {
         try {
-            SET_GAMETYPE.invoke(pl, target, source, worldIn);
+            SET_GAMETYPE.invoke(pl, target, source, sw);
         } catch(IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
             LogManager.getLogger().warn("setPlayerGameTypeBasedOnOther - " + ex);
         }
@@ -179,10 +171,10 @@ public class ReflectionUtils {
     // -----------------------------------------------------------------------------------
     // minecraft server 
     // -----------------------------------------------------------------------------------
-    private final static Field COMMAND_MANAGER = getField(MinecraftServer.class, "field_195579_af"); // commandManager
+    private final static Field COMMAND_MANAGER = getField(DataPackRegistries.class, "field_240953_c_"); // commands
 
     public static void setCommandManager(MinecraftServer server, Commands manager) {
-        setFieldValue(server, COMMAND_MANAGER, manager);
+        setFieldValue(server.getDataPackRegistries(), COMMAND_MANAGER, manager);
     }
 
     private final static Field MODE = getField(Explosion.class, "field_222260_b"); // mode
@@ -218,7 +210,7 @@ public class ReflectionUtils {
         return getFieldValue(Set.class, gs, GOALS);
     }
 
-    private final static Method SET_FIRE_INFO = getMethod(FireBlock.class, "func_180686_a");
+    private final static Method SET_FIRE_INFO = getMethod(FireBlock.class, "func_180686_a", Block.class, int.class, int.class);
 
     public static void setFireInfo(Block b, int encouragement, int flammability) {
         FireBlock fireblock = (FireBlock) Blocks.FIRE;
@@ -228,10 +220,4 @@ public class ReflectionUtils {
             LogManager.getLogger().warn("setFireInfo - " + ex);
         }
     }
-    
-    private final static Field PLAYER_DATA = getField(MinecraftServer.class, "field_240766_e_");
-
-    public static PlayerData getPlayerDataManager(MinecraftServer ms) {
-        return getFieldValue(PlayerData.class, ms, PLAYER_DATA);
-    }
 }

+ 0 - 58
src/main/java/me/km/world/ModWorldGeneration.java

@@ -1,58 +0,0 @@
-package me.km.world;
-
-import java.util.function.Supplier;
-import me.km.blocks.ModBlocks;
-import net.minecraft.block.Block;
-import net.minecraft.block.Blocks;
-import net.minecraft.world.biome.Biome;
-import net.minecraft.world.gen.GenerationStage;
-import net.minecraft.world.gen.feature.ConfiguredFeature;
-import net.minecraft.world.gen.feature.Feature;
-import net.minecraft.world.gen.feature.OreFeatureConfig;
-import net.minecraftforge.registries.ForgeRegistries;
-
-public class ModWorldGeneration {
-    public static void register() {
-        // search for all biomes which generate ore
-        for(Biome biome : ForgeRegistries.BIOMES.getValues()) {
-            biome.getGenerationSettings().getFeatures().forEach(list -> {
-                for(Supplier<ConfiguredFeature<?, ?>> entry : list) {
-                    if(entry.get().config instanceof OreFeatureConfig) {
-                        OreFeatureConfig ore = (OreFeatureConfig) entry.get().config;
-                        if(ore.state == Blocks.IRON_ORE.getDefaultState()) {
-                            addFeatures(biome);
-                            break;
-                        }
-                    }
-                }
-            });
-        }
-    }
-
-    private static void addOre(Biome b, Block ore, int maxCount, int spawnTries, int maxHeight) {
-        b.getGenerationSettings().getFeatures().get(GenerationStage.Decoration.UNDERGROUND_ORES.ordinal()).add(() -> {
-            return Feature.ORE.withConfiguration(
-                    new OreFeatureConfig(OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD,
-                            ore.getDefaultState(), maxCount)).range(maxHeight).square().func_242731_b(spawnTries);
-        });
-    }
-
-    private static void addFeatures(Biome biome) {
-        //          | max   | bottom | top    | max  | spawn |
-        // name     | size  | offset | offset | high | tries |
-        // ---------------------------------------------------
-        // coal     |    17 |      0 |      0 |  128 |    20 |
-        // iron     |     9 |      0 |      0 |   64 |    20 |
-        // gold     |     9 |      0 |      0 |   32 |     2 |
-        // redstone |     8 |      0 |      0 |   16 |     8 |
-        // diamond  |     8 |      0 |      0 |   16 |     1 |
-        // lapis    |     7 |      - |      - |    - |     - |
-        // copper   |     9 |      0 |      0 |  128 |    25 |
-        // tin      |     6 |      0 |      0 |   96 |    12 |
-        // silver   |     9 |      0 |      0 |   64 |     3 |
-
-        addOre(biome, ModBlocks.copperOre, 9, 25, 128);
-        addOre(biome, ModBlocks.tinOre, 6, 12, 96);
-        addOre(biome, ModBlocks.silverOre, 9, 3, 64);
-    }
-}

+ 1 - 1
src/main/resources/META-INF/mods.toml

@@ -1,9 +1,9 @@
 modLoader="javafml"
 loaderVersion="[35,)"
+license="All rights reserved"
 [[mods]]
 modId="km"
 version="0.0.47"
-license="All rights reserved"
 displayName="Kajetans Mod"
 credits="kajetanjohannes"
 authors="kajetanjohannes"