Ver código fonte

logger format changed, fixed magic armor tooltip (+translation), ore
generation, some drops / recipes

Kajetan Johannes Hammerle 6 anos atrás
pai
commit
b8a2826593

+ 5 - 3
src/main/java/me/km/Client.java

@@ -27,6 +27,7 @@ import net.minecraft.nbt.CompoundNBT;
 import net.minecraft.util.text.ITextComponent;
 import net.minecraft.util.text.StringTextComponent;
 import net.minecraft.util.text.TextFormatting;
+import net.minecraft.util.text.translation.LanguageMap;
 import net.minecraft.world.GrassColors;
 import net.minecraft.world.biome.BiomeColors;
 import net.minecraftforge.api.distmarker.Dist;
@@ -144,12 +145,13 @@ public class Client
                 if(magic != 0)
                 {
                     List<ITextComponent> list = e.getToolTip();
-                    String s = TextFormatting.BLUE + " +";
                     for(int i = 0; i < list.size(); i++)
                     {
-                        if(list.get(i).getString().startsWith(s))
+                        if(list.get(i).getString().contains("+"))
                         {
-                            list.add(i, new StringTextComponent(String.format("%s +%d Magic Armor", TextFormatting.BLUE, magic)));
+                            list.add(i, new StringTextComponent(
+                                    String.format("%s+%d %s", TextFormatting.BLUE, magic, 
+                                            LanguageMap.getInstance().translateKey("magicarmor"))));
                             break;
                         }
                     }

+ 2 - 1
src/main/java/me/km/KajetansMod.java

@@ -1,6 +1,7 @@
 package me.km;
 
 import me.km.networking.ModPacketHandler;
+import me.km.world.ModWorldGeneration;
 import net.minecraftforge.fluids.FluidRegistry;
 import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
 import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
@@ -34,7 +35,7 @@ public class KajetansMod
     private void init(FMLCommonSetupEvent e) 
     {
         DeferredWorkQueue.runLater(() -> ModPacketHandler.init());
-        //GameRegistry.registerWorldGenerator(new ModWorldGeneration(), 3);
+        ModWorldGeneration.register();
         
         DamageUtils.init();
     }

+ 2 - 2
src/main/java/me/km/blocks/BlockLantern.java

@@ -36,11 +36,11 @@ public class BlockLantern extends DirectionalBlock
 
     public BlockLantern(String name)
     {
-        super(Properties.create(Material.IRON).doesNotBlockMovement().hardnessAndResistance(0.0f).lightValue(14).sound(SoundType.METAL));
+        super(Properties.create(Material.MISCELLANEOUS).doesNotBlockMovement().hardnessAndResistance(0.0f).lightValue(14).sound(SoundType.METAL));
         this.setRegistryName(name);
         this.setDefaultState(this.stateContainer.getBaseState().with(FACING, Direction.UP));
     }
-
+    
     @Override
     public VoxelShape getShape(BlockState state, IBlockReader w, BlockPos pos, ISelectionContext context)
     {

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

@@ -20,7 +20,6 @@ import net.minecraft.potion.Effect;
 import net.minecraft.potion.EffectInstance;
 import net.minecraft.potion.Effects;
 import net.minecraftforge.registries.IForgeRegistry;
-import org.apache.logging.log4j.LogManager;
 
 public class ModItems 
 {

+ 2 - 96
src/main/java/me/km/recipes/ModRecipes.java

@@ -18,104 +18,12 @@ import net.minecraftforge.registries.IForgeRegistry;*/
 
 public class ModRecipes 
 {           
-    // -----------------------------------------------------------------------------------
-    // shaped recipe construction stuff
-    // -----------------------------------------------------------------------------------
-    
-    /*private static ShapedRecipe newShapedRecipe(String group, String[] pattern, ItemStack result, char[] chars, ItemStack[][] stacks)
-    {
-        HashMap<Character, Ingredient> map = getPatternMap(chars, stacks);
-        NonNullList<Ingredient> nonnulllist = getIngredientList(pattern, map);
-        return new ShapedRecipe(group, pattern[0].length(), pattern.length, nonnulllist, result);
-    }
-    
-    private static HashMap<Character, Ingredient> getPatternMap(char[] chars, ItemStack[][] stacks)
-    {
-        HashMap<Character, Ingredient> map = new HashMap<>();
-        for(int i = 0; i < chars.length; i++)
-        {
-            map.put(chars[i], Ingredient.fromStacks(copyItemStack(stacks[i])));
-        }
-        map.put(' ', Ingredient.EMPTY);
-        return map;
-    }
-    
-    private static NonNullList<Ingredient> getIngredientList(String[] pattern, HashMap<Character, Ingredient> map)
-    {
-        int w = pattern[0].length();
-        NonNullList<Ingredient> nonnulllist = NonNullList.<Ingredient>withSize(w * pattern.length, Ingredient.EMPTY);
-        for(int i = 0; i < pattern.length; i++)
-        {
-            for (int j = 0; j < pattern[i].length(); j++)
-            {
-                nonnulllist.set(j + w * i, map.get(pattern[i].charAt(j)));
-            }
-        }
-        return nonnulllist;
-    }
-    
-    private static void registerShaped(IForgeRegistry<IRecipe> r, String group, String[] pattern, ItemStack result, char[] chars, ItemStack[][] stacks)
-    {
-        ShapedRecipes recipe = newShapedRecipe(group, pattern, result, chars, stacks);
-        recipe.setRegistryName(buildRegistryName(result));
-        //System.out.println("Registering " + recipe.getRegistryName());
-        //System.out.println(recipe.getIngredients());
-        //System.out.println(recipe.getRecipeOutput());
-        r.register(recipe);
-    }
-    
-    private static ShapelessRecipes newShapelessRecipe(String group, ItemStack result, ItemStack[][] stacks)
-    {
-        NonNullList<Ingredient> nonnulllist = NonNullList.<Ingredient>withSize(stacks.length, Ingredient.EMPTY);
-        for(int i = 0; i < stacks.length; i++)
-        {
-            nonnulllist.set(i, Ingredient.fromStacks(copyItemStack(stacks[i])));
-        }
-        return new ShapelessRecipes(group, result, nonnulllist);
-    }
-    
-    private static void registerShapeless(IForgeRegistry<IRecipe> r, String group, ItemStack result, ItemStack[][] stacks)
-    {
-        ShapelessRecipes recipe = newShapelessRecipe(group, result, stacks);
-        recipe.setRegistryName(buildRegistryName(result));
-        r.register(recipe);
-    }
-    
-    private static void registerShapeless(IForgeRegistry<IRecipe> r, String group, ItemStack result, Item[] items)
-    {
-        ItemStack[][] stacks = new ItemStack[items.length][1];
-        for(int i = 0; i < items.length; i++)
-        {
-            stacks[i][0] = new ItemStack(items[i]);
-        }
-        registerShapeless(r, group, result, stacks);
-    }
-    
-    private static ItemStack[] copyItemStack(ItemStack[] stacks)
-    {
-        ItemStack[] copyStacks = new ItemStack[stacks.length];
-        for(int i = 0; i < copyStacks.length; i++)
-        {
-            copyStacks[i] = stacks[i].copy();
-        }
-        return copyStacks;
-    }
-    
-    private static String buildRegistryName(ItemStack stack)
-    {
-        id++;
-        if(stack.getMetadata() != 0)
-        {          
-            return stack.getItem().getRegistryName().getResourcePath() + "_" + stack.getMetadata() + "_" + id;
-        }
-        return stack.getItem().getRegistryName().getResourcePath() + "_" + id;
-    }
-    
+
     // -----------------------------------------------------------------------------------
     // init recipes
     // -----------------------------------------------------------------------------------
     
-    private static int id = 0;
+    /*private static int id = 0;
     
     public static void init(IForgeRegistry<IRecipe> r) 
     {
@@ -142,8 +50,6 @@ public class ModRecipes
                 });
         registerShaped(r, "", new String[] {"XXX", "XXX", "XXX"}, new ItemStack(ModItems.hayBundle, 9), 
                 new char[] {'X'}, new ItemStack[][] {{new ItemStack(Blocks.TALLGRASS, 1, 1), new ItemStack(Blocks.TALLGRASS, 1, 2)}});
-        registerShaped(r, "", new String[] {"XXX"}, new ItemStack(ModItems.realHayBed, 3), 
-                new char[] {'X'}, new ItemStack[][] {{new ItemStack(ModBlocks.realHayBlock)}});
         registerShaped(r, "", new String[] {" X ", "XXX"}, new ItemStack(ModItems.strawHat), 
                 new char[] {'X'}, new ItemStack[][] {{new ItemStack(Items.WHEAT)}});
         registerShaped(r, "", new String[] {" S ", "SCS", "WWW"}, new ItemStack(ModItems.campFire), 

+ 1 - 0
src/main/java/me/km/snuviscript/MinecraftFunctions.java

@@ -726,6 +726,7 @@ public class MinecraftFunctions
         { 
             ItemStack stack = (ItemStack) in[0].get(sc);                  
             int value = in[1].getInt(sc);  
+            System.out.println(stack.getItem());
             if(stack.getItem() instanceof ArmorItem)
             {
                 CompoundNBT com = stack.getTag();

+ 23 - 10
src/main/java/me/km/snuviscript/SnuviLogger.java

@@ -29,50 +29,63 @@ public class SnuviLogger implements ISnuviLogger
         StringBuilder sb = new StringBuilder();
         sb.append("[§cLogger§r] ");
         
+        String color;
+        
         if(ex == null)
         {
-            sb.append("§edebug: '");
+            color = "§e";
+            sb.append(color);
+            sb.append("debug: '§r");
             sb.append(message);
+            sb.append(color);
             sb.append("'");
         }
         else
         {
-            sb.append("§eexception: '");
+            color = "§c";
+            sb.append(color);
+            sb.append(ex.getClass().getSimpleName());
+            sb.append("§r: '");
+            sb.append(color);
             sb.append(ex.getMessage());
-            if(message != null)
+            if(message != null && !message.isEmpty())
             {
                 sb.append(" - ");
                 sb.append(message);
             }
-            sb.append("'");
+            sb.append("§r'");
         }
         
-        if(scriptname != null)
+        if(scriptname != null && !scriptname.isEmpty())
         {
             sb.append(" in script '");
+            sb.append(color);
             sb.append(scriptname);
-            sb.append("'");
+            sb.append("§r'");
         }
         
         if(sc != null)
         {
             sb.append(" id '");
+            sb.append(color);
             sb.append(sc.getId());
-            sb.append("'");
+            sb.append("§r'");
         }
         
-        if(function != null)
+        if(function != null && !function.isEmpty())
         {
             sb.append(" in function '");
+            sb.append(color);
             sb.append(function);
-            sb.append("'");
+            sb.append("§r'");
         }
         
         if(line != -1)
         {
             sb.append(" in line '");
+            sb.append(color);
             sb.append(line);
-            sb.append("'");
+            sb.append("§r'");
         }
         
         StringTextComponent text = new StringTextComponent(sb.toString());

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

@@ -1,51 +1,71 @@
 package me.km.world;
 
-import java.util.Random;
 import me.km.blocks.ModBlocks;
-import net.minecraft.block.BlockState;
-import net.minecraft.util.math.BlockPos;
-import net.minecraft.world.World;
-import net.minecraft.world.chunk.AbstractChunkProvider;
-import net.minecraft.world.dimension.DimensionType;
-import net.minecraft.world.gen.ChunkGenerator;
-import net.minecraft.world.gen.feature.OreFeature;
+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.DecoratedFeatureConfig;
+import net.minecraft.world.gen.feature.Feature;
 import net.minecraft.world.gen.feature.OreFeatureConfig;
-import net.minecraftforge.fml.common.IWorldGenerator;
+import net.minecraft.world.gen.placement.CountRangeConfig;
+import net.minecraft.world.gen.placement.Placement;
+import net.minecraftforge.registries.ForgeRegistries;
 
-public class ModWorldGeneration implements IWorldGenerator
+public class ModWorldGeneration
 {
-    @Override
-    public void generate(Random r, int cX, int cZ, World w, ChunkGenerator cg, AbstractChunkProvider cp)
+    public static void register()
     {
-        DimensionType type = w.getDimension().getType();
-        if(type != DimensionType.NETHER && type != DimensionType.THE_END) 
+        // search for all biomes which generate ore
+        for(Biome biome : ForgeRegistries.BIOMES.getValues())
         {
-            generateOverworld(r, cX, cZ, w, cg, cp);
-	}
+            for(ConfiguredFeature f : biome.getFeatures(GenerationStage.Decoration.UNDERGROUND_ORES))
+            {
+                if(!(f.config instanceof DecoratedFeatureConfig))
+                {
+                    continue;
+                }
+                DecoratedFeatureConfig conf = (DecoratedFeatureConfig) f.config;
+                if(!(conf.feature.config instanceof OreFeatureConfig))
+                {
+                    continue;
+                }
+                OreFeatureConfig ore = (OreFeatureConfig) conf.feature.config;
+                if(ore.state == Blocks.IRON_ORE.getDefaultState())
+                {
+                    addFeatures(biome);
+                    break;
+                }
+            }
+        }
     }
-	
-    private void generateOverworld(Random r, int chunkX, int chunkZ, World w, ChunkGenerator cg, AbstractChunkProvider cp) 
-    {
-        generateOre(cg, ModBlocks.copperOre.getDefaultState(), w, r, 
-                chunkX << 4, chunkZ << 4, 0, 128, 9, 25);
-        generateOre(cg, ModBlocks.tinOre.getDefaultState(), w, r, 
-                chunkX << 4, chunkZ << 4, 0, 96, 8, 12);
-        generateOre(cg, ModBlocks.silverOre.getDefaultState(), w, r, 
-                chunkX << 4, chunkZ << 4, 0, 64, 8, 3);
-    } 
     
-    private void generateOre(ChunkGenerator cg, BlockState ore, World w, Random r, int x, int z, 
-            int minY, int maxY, int size, int chances) 
+    private static void addFeatures(Biome biome)
     {
-        int deltaY = maxY - minY;
-        BlockPos pos;
-        OreFeatureConfig config = new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE, ore, size);
-        OreFeature generator = new OreFeature(OreFeatureConfig::deserialize);
-        for(int i = 0; i < chances; i++) 
-        {
-            // generates position in chunk
-            pos = new BlockPos(x + r.nextInt(16), minY + r.nextInt(deltaY), z + r.nextInt(16));
-            generator.place(w, cg, r, pos, config);
-        }
+        //          | 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 |
+        
+        biome.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Biome.createDecoratedFeature(
+                        Feature.ORE, new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE, 
+                                ModBlocks.copperOre.getDefaultState(), 9), Placement.COUNT_RANGE, 
+                        new CountRangeConfig(25, 0, 0, 128)));
+        biome.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Biome.createDecoratedFeature(
+                        Feature.ORE, new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE, 
+                                ModBlocks.tinOre.getDefaultState(), 6), Placement.COUNT_RANGE, 
+                        new CountRangeConfig(12, 0, 0, 96)));
+        biome.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Biome.createDecoratedFeature(
+                        Feature.ORE, new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE, 
+                                ModBlocks.silverOre.getDefaultState(), 9), Placement.COUNT_RANGE, 
+                        new CountRangeConfig(3, 0, 0, 64)));
     }
 }

+ 3 - 1
src/main/resources/assets/km/lang/en_us.json

@@ -194,5 +194,7 @@
     "key.function.6": "Function Key 6", 
     "key.function.7": "Function Key 7", 
     "key.function.8": "Function Key 8", 
-    "key.function.9": "Function Key 9"
+    "key.function.9": "Function Key 9",
+    
+    "magicarmor": "Magic Armor"
 }

+ 20 - 0
src/main/resources/data/km/loot_tables/blocks/lantern.json

@@ -0,0 +1,20 @@
+{
+  "type": "minecraft:block",
+  "pools": [
+    {
+      "name": "main",
+      "rolls": 1,
+      "entries": [
+        {
+          "type": "minecraft:item",
+          "name": "km:lantern"
+        }
+      ],
+      "conditions": [
+        {
+          "condition": "minecraft:survives_explosion"
+        }
+      ]
+    }
+  ]
+}

+ 29 - 0
src/main/resources/data/km/loot_tables/blocks/real_hay_bed.json

@@ -0,0 +1,29 @@
+{
+  "type": "minecraft:block",
+  "pools": [
+    {
+      "name": "main",
+      "rolls": 1,
+      "entries": [
+        {
+          "type": "minecraft:item",
+          "conditions": [
+            {
+              "condition": "minecraft:block_state_property",
+              "block": "km:real_hay_bed",
+              "properties": {
+                "part": "head"
+              }
+            }
+          ],
+          "name": "km:real_hay_bed"
+        }
+      ],
+      "conditions": [
+        {
+          "condition": "minecraft:survives_explosion"
+        }
+      ]
+    }
+  ]
+}

+ 20 - 0
src/main/resources/data/km/loot_tables/blocks/real_hay_block.json

@@ -0,0 +1,20 @@
+{
+  "type": "minecraft:block",
+  "pools": [
+    {
+      "name": "main",
+      "rolls": 1,
+      "entries": [
+        {
+          "type": "minecraft:item",
+          "name": "km:real_hay_block"
+        }
+      ],
+      "conditions": [
+        {
+          "condition": "minecraft:survives_explosion"
+        }
+      ]
+    }
+  ]
+}

+ 22 - 0
src/main/resources/data/km/recipes/lantern.json

@@ -0,0 +1,22 @@
+{
+  "type": "minecraft:crafting_shaped",
+  "pattern": [
+    "XXX",
+    "G#G",
+    "XXX"
+  ],
+  "key": {
+    "#": {
+      "item": "minecraft:torch"
+    },
+    "X": {
+      "item": "minecraft:iron_nugget"
+    },
+    "G": {
+      "item": "minecraft:glass_pane"
+    }
+  },
+  "result": {
+    "item": "km:lantern"
+  }
+}

+ 14 - 0
src/main/resources/data/km/recipes/real_hay_bed.json

@@ -0,0 +1,14 @@
+{
+  "type": "minecraft:crafting_shaped",
+  "pattern": [
+    "###"
+  ],
+  "key": {
+    "#": {
+      "item": "km:real_hay_block"
+    }
+  },
+  "result": {
+    "item": "km:real_hay_bed"
+  }
+}

+ 16 - 0
src/main/resources/data/km/recipes/real_hay_block.json

@@ -0,0 +1,16 @@
+{
+  "type": "minecraft:crafting_shaped",
+  "pattern": [
+    "###",
+    "###",
+    "###"
+  ],
+  "key": {
+    "#": {
+      "item": "km:hay_bundle"
+    }
+  },
+  "result": {
+    "item": "km:real_hay_block"
+  }
+}