From 4e326247d8999e72c5ed14c51f08e9555da426b1 Mon Sep 17 00:00:00 2001 From: Guillaume Mercier Date: Tue, 2 Apr 2024 05:04:33 -0400 Subject: [PATCH] Crop cleanup and automation streamlining. (#30) * Add idea layout file to gitignore * Add get for crop block to redlon Should help with some EIG stuff I'm working on. * Separate rainbow cacti dye drop logic from world. Should help with some EIG stuff I'm working on. * Make sweed cluster sugar drops together and some mild clean-up to help with readability * Update rainbow cacti entry if GregTech is installed - Updates all localisations to remove the mention that it doesn't drop specific dyes if GregTech is installed. - Adds a note that about the fact that the equal dye drop rate when GregTech is installed is an intended feature. * Optimise random drop calls, and burn my brain Should resolve point 1 of https://github.com/GTNewHorizons/ThaumicBases/pull/30#pullrequestreview-1971014677 You can approximate the rates it used to generate by using the LODA calculator here: https://loda-lang.org/edit/?source=mov%20%241%2C%20%240%0Aseq%20%240%2C169%0Amov%20%242%2C%20%240%0Amov%20%240%2C%20%241%0Aseq%20%240%2C%20435%0Amul%20%240%2C%20100000%0Adiv%20%240%2C%20%242%0Amul%20%240%2C%202 - x is the value provided to the nextInt function. - y is the average number of bonus rounds (the values used in this commit from from there) The calculator makes integers, so divide numbers by 100000 to get the actual values. --- .gitignore | 1 + .../java/tb/common/block/BlockAshroom.java | 15 ++++---- .../tb/common/block/BlockRainbowCactus.java | 21 +++++++++-- .../java/tb/common/block/BlockRedlonStem.java | 4 +++ src/main/java/tb/common/block/BlockSweed.java | 10 +++--- .../java/tb/common/block/BlockTBPlant.java | 35 ++++++++++++++++--- src/main/java/tb/init/TBThaumonomicon.java | 5 ++- .../assets/thaumicbases/lang/en_US.lang | 1 + .../assets/thaumicbases/lang/ru_RU.lang | 1 + .../assets/thaumicbases/lang/zh_CN.lang | 1 + 10 files changed, 73 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 40fb5e4..47f4704 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ whitelist.json *.iws src/main/resources/mixins.*.json *.bat +/layout.json diff --git a/src/main/java/tb/common/block/BlockAshroom.java b/src/main/java/tb/common/block/BlockAshroom.java index 1d93ff4..816e050 100644 --- a/src/main/java/tb/common/block/BlockAshroom.java +++ b/src/main/java/tb/common/block/BlockAshroom.java @@ -1,5 +1,6 @@ package tb.common.block; +import java.util.ArrayList; import java.util.Random; import net.minecraft.entity.player.EntityPlayer; @@ -42,14 +43,14 @@ protected boolean func_150109_e(World p_150109_1_, int p_150109_2_, int p_150109 @Override public void onBlockHarvested(World world, int x, int y, int z, int metadata, EntityPlayer player) { if (metadata >= this.growthStages - 1) { - for (int i = 0; i < 8 + world.rand.nextInt(32); ++i) // Nerf for the shrooms + // should be close enough to the rate of the old logic. + int dropCount = 8 + (int) Math.round(world.rand.nextDouble() * 11.76742); + ArrayList primals = Aspect.getPrimalAspects(); + for (int i = 0; i < dropCount; ++i) // Nerf for the shrooms { - Aspect primal = Aspect.getPrimalAspects() - .get( - world.rand.nextInt( - Aspect.getPrimalAspects() - .size())); - EntityAspectOrb orb = new EntityAspectOrb(world, x, y, z, primal, 1); + // We should probably cluster orbs of the same aspect instead of spawning them individually. + Aspect aspect = primals.get(world.rand.nextInt(primals.size())); + EntityAspectOrb orb = new EntityAspectOrb(world, x, y, z, aspect, 1); if (!world.isRemote) world.spawnEntityInWorld(orb); } } diff --git a/src/main/java/tb/common/block/BlockRainbowCactus.java b/src/main/java/tb/common/block/BlockRainbowCactus.java index 0e4f470..aa7bc98 100644 --- a/src/main/java/tb/common/block/BlockRainbowCactus.java +++ b/src/main/java/tb/common/block/BlockRainbowCactus.java @@ -1,6 +1,7 @@ package tb.common.block; import java.util.ArrayList; +import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.BlockCactus; @@ -43,22 +44,36 @@ public ArrayList getDrops(World world, int x, int y, int z, int metad return ret; } - for (int i = 0; i < 3 + world.rand.nextInt(8); ++i) { - ret.add(allowedDyes[world.rand.nextInt(allowedDyes.length)].copy()); - } + addDyeDropsToOutput(world.rand, ret); return ret; } + /** + * Separates the dye drop logic from the world for automation purposes. + * + * @param rand The random source used to generate the dyes. + * @param ret The output list to append to, 1 new stack per dye drop, merge them on your own time. + */ + public void addDyeDropsToOutput(Random rand, ArrayList ret) { + // Should be roughly equivalent to the old bonus rates + int dropCount = 3 + (int) Math.round(rand.nextDouble() * 4.91662); + for (int i = 0; i < dropCount; ++i) { + ret.add(allowedDyes[rand.nextInt(allowedDyes.length)].copy()); + } + } + public static ItemStack[] allowedDyes; public static void loadColors() { if (Loader.isModLoaded("gregtech")) { + // The fact all dyes have the same probability of dropping when gregtech is installed is intended. allowedDyes = new ItemStack[] { ItemList.Color_00.get(1), ItemList.Color_01.get(1), ItemList.Color_02.get(1), ItemList.Color_03.get(1), ItemList.Color_04.get(1), ItemList.Color_05.get(1), ItemList.Color_06.get(1), ItemList.Color_07.get(1), ItemList.Color_08.get(1), ItemList.Color_09.get(1), ItemList.Color_10.get(1), ItemList.Color_11.get(1), ItemList.Color_12.get(1), ItemList.Color_13.get(1), ItemList.Color_14.get(1), ItemList.Color_15.get(1), }; } else { + // Normally it drops more green dyes. allowedDyes = new ItemStack[] { new ItemStack(Items.dye, 1, 1), new ItemStack(Items.dye, 1, 2), new ItemStack(Items.dye, 1, 5), new ItemStack(Items.dye, 1, 2), new ItemStack(Items.dye, 1, 6), new ItemStack(Items.dye, 1, 7), new ItemStack(Items.dye, 1, 2), new ItemStack(Items.dye, 1, 8), diff --git a/src/main/java/tb/common/block/BlockRedlonStem.java b/src/main/java/tb/common/block/BlockRedlonStem.java index 4b28f0c..e9e119f 100644 --- a/src/main/java/tb/common/block/BlockRedlonStem.java +++ b/src/main/java/tb/common/block/BlockRedlonStem.java @@ -207,4 +207,8 @@ public int colorMultiplier(IBlockAccess p_149720_1_, int p_149720_2_, int p_1497 public int getRenderColor(int p_149741_1_) { return 0xffffff; } + + public Block getCropBlock() { + return field_149877_a; + } } diff --git a/src/main/java/tb/common/block/BlockSweed.java b/src/main/java/tb/common/block/BlockSweed.java index 3289d69..b41d0f6 100644 --- a/src/main/java/tb/common/block/BlockSweed.java +++ b/src/main/java/tb/common/block/BlockSweed.java @@ -30,10 +30,8 @@ public void updateTick(World w, int x, int y, int z, Random rnd) { int newX = x + dir.offsetX; int newZ = z + dir.offsetZ; int newY = findSutableY(w, newX, y, newZ); - if (canPlaceBlockOn(w.getBlock(newX, newY - 1, newZ)) && w.isAirBlock(newX, newY, newZ)) // fix for the - // Sweeds - // destroying - // blocks + // fix for the Sweeds destroying blocks + if (canPlaceBlockOn(w.getBlock(newX, newY - 1, newZ)) && w.isAirBlock(newX, newY, newZ)) w.setBlock(newX, newY, newZ, this, 0, 3); } } @@ -53,7 +51,9 @@ public ArrayList getDrops(World world, int x, int y, int z, int metad if (metadata >= growthStages - 1) { if (world.rand.nextInt(growthStages) <= metadata) if (dropSeed != null) ret.add(dropSeed.copy()); - for (int i = 0; i < 3 + fortune; ++i) if (world.rand.nextBoolean()) ret.add(new ItemStack(Items.sugar)); + // should preserve drop rates + int sugarDropCount = world.rand.nextInt(4 + fortune); + if (sugarDropCount > 0) ret.add(new ItemStack(Items.sugar, sugarDropCount)); if (world.rand.nextBoolean()) ret.add(new ItemStack(Items.reeds)); diff --git a/src/main/java/tb/common/block/BlockTBPlant.java b/src/main/java/tb/common/block/BlockTBPlant.java index 4911d9d..7e9ae0b 100644 --- a/src/main/java/tb/common/block/BlockTBPlant.java +++ b/src/main/java/tb/common/block/BlockTBPlant.java @@ -159,13 +159,38 @@ public int getRenderType() { public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { ArrayList ret = new ArrayList(); - if (metadata >= growthStages - 1) { - for (int i = 0; i < 1 + world.rand.nextInt(fortune + 1); ++i) // Change for the resource drop - { - if (world.rand.nextInt(growthStages) <= metadata) { - if (dropItem != null) ret.add(dropItem.copy()); + if (this.dropItem != null && metadata >= growthStages - 1) { + // You can approximate the fortune bonus by diving https://oeis.org/A000169 with https://oeis.org/A000435 + // I can't figure out a good efficient way to compute those without melting my brain so if you feel + // like you can approximate it well enough, feel free to do so. For now, I'm just capping it at 3 drops + // with a linear function since fortune levels above 3 aren't very common, and I don't want some poor lad + // crashing their pc with max int fortune int. + // + // Average bonuses for each fortune level: + // F1 = 0.5 -> 0.5 (stayed the same) + // F2 = 0.88888 -> 0.9 (slight buff) + // F3 = 1.21875 -> 1.3 (slight buff) + // The EIG doesn't use fortune levels, so it shouldn't be affected anyway. + int roundCount = 1; + if (fortune > 0) { + roundCount += (int) Math.min(3, Math.round(world.rand.nextDouble() * (1 + 0.8d * (fortune - 1)))); + } + int dropCount = 0; + if (growthStages <= metadata) { + // we can just skip the random calls if we are at max growth. + dropCount = roundCount; + } else { + for (int i = 0; i < roundCount; ++i) { + if (world.rand.nextInt(growthStages) <= metadata) { + dropCount++; + } } } + if (dropCount > 0) { + ItemStack drop = dropItem.copy(); + drop.stackSize = dropCount; + ret.add(drop); + } } if (dropSeed != null) ret.add(dropSeed.copy()); diff --git a/src/main/java/tb/init/TBThaumonomicon.java b/src/main/java/tb/init/TBThaumonomicon.java index d44ebb4..1692c42 100644 --- a/src/main/java/tb/init/TBThaumonomicon.java +++ b/src/main/java/tb/init/TBThaumonomicon.java @@ -2804,7 +2804,10 @@ public static void setup() { 2, new ItemStack(TBBlocks.rainbowCactus, 1, 0)).setParents("TB.Metalleat") .setConcealed() - .setPages(new ResearchPage("tb.rec.rainCacti.page.0"), new ResearchPage(rainbowCactiRec)) + .setPages( + new ResearchPage( + Loader.isModLoaded("gregtech") ? "tb.rec.rainCacti.page.0.gt" : "tb.rec.rainCacti.page.0"), + new ResearchPage(rainbowCactiRec)) .registerResearchItem(); new ResearchItem( diff --git a/src/main/resources/assets/thaumicbases/lang/en_US.lang b/src/main/resources/assets/thaumicbases/lang/en_US.lang index c4e0914..8b48c2a 100644 --- a/src/main/resources/assets/thaumicbases/lang/en_US.lang +++ b/src/main/resources/assets/thaumicbases/lang/en_US.lang @@ -282,6 +282,7 @@ tb.rec.lazullia.page.0=Sometimes a thaumaturge needs some lapis for his... thaum tc.research_name.TB.RainbowCacti=Rainbow Cacti tc.research_text.TB.RainbowCacti=Grow the rainbow, taste the rainbow! tb.rec.rainCacti.page.0=Magic is not always strict and logical - it is magic, after all. The same goes to life - it can take various shapes, sometimes shocking, sometimes funny. Well, you have managed to create a plant, that, pretty much, is a definition of the word 'funny'. This plant functions just like the regular cacti - must be placed on sand and grows up to 3 blocks. However, once broken it will only drop itself it it is the last cacti block left. Otherwise it will drop all kinds of dyes. however, cacti can't create certain dye types, like bonemeal and Lapis. It is also more likely to drop green dye than other dyes. +tb.rec.rainCacti.page.0.gt=Magic is not always strict and logical - it is magic, after all. The same goes to life - it can take various shapes, sometimes shocking, sometimes funny. Well, you have managed to create a plant, that, pretty much, is a definition of the word 'funny'. This plant functions just like the regular cacti - must be placed on sand and grows up to 3 blocks. However, once broken it will only drop itself it it is the last cacti block left. Otherwise it will drop all kinds of dyes. tc.research_name.TB.Metalleat=Metalleat tc.research_text.TB.Metalleat=Iron is good for your health diff --git a/src/main/resources/assets/thaumicbases/lang/ru_RU.lang b/src/main/resources/assets/thaumicbases/lang/ru_RU.lang index 35fd906..aa54c0e 100644 --- a/src/main/resources/assets/thaumicbases/lang/ru_RU.lang +++ b/src/main/resources/assets/thaumicbases/lang/ru_RU.lang @@ -284,6 +284,7 @@ tb.rec.lazullia.page.0_ec3=Иногда, Тауматургу нужно нем tc.research_name.TB.RainbowCacti=Радужный Кактус tc.research_text.TB.RainbowCacti=Вырасти Радугу, попробуй Радугу! tb.rec.rainCacti.page.0=Магия не всегда действует в рамках логики - все таки это магия. То же самое относится и к Природе - её творения разнообразны, временами жутковатые, временами веселые. Ну, вас посетила идея создать растение, которое является воплощением слова "Веселье". Полученный вид похож на обычный кактус, так же растет на песке 3 блока в высоту. Однако, если его собрать, вы не получите кактус. Вместо этого он взорвётся радужным фонтаном из различных типов красителей, правда, кактус не может создавать белый и синий цвета . Также вами было замечено, что с большей вероятностью выпадает Зеленый. +tb.rec.rainCacti.page.0.gt=Магия не всегда действует в рамках логики - все таки это магия. То же самое относится и к Природе - её творения разнообразны, временами жутковатые, временами веселые. Ну, вас посетила идея создать растение, которое является воплощением слова "Веселье". Полученный вид похож на обычный кактус, так же растет на песке 3 блока в высоту. Однако, если его собрать, вы не получите кактус. Вместо этого он взорвётся радужным фонтаном из различных типов красителей. tc.research_name.TB.Metalleat=Стальная Рожь tc.research_text.TB.Metalleat=Обогащена железом diff --git a/src/main/resources/assets/thaumicbases/lang/zh_CN.lang b/src/main/resources/assets/thaumicbases/lang/zh_CN.lang index 7ccbfb0..ef34217 100644 --- a/src/main/resources/assets/thaumicbases/lang/zh_CN.lang +++ b/src/main/resources/assets/thaumicbases/lang/zh_CN.lang @@ -284,6 +284,7 @@ tb.rec.lazullia.page.0=有时候神秘使会需要一点青金石来进行魔法 tc.research_name.TB.RainbowCacti=彩虹仙人掌 tc.research_text.TB.RainbowCacti=抓住彩虹,品尝彩虹! tb.rec.rainCacti.page.0=魔法不总是严格而且富有逻辑性的,毕竟它是魔法.生命也遵循同样的法则——它也有很多种形态,有时候令人震惊,有时候十分滑稽.你创造出了一种植物,如图'滑稽'这个词的意思一样.它就像普通仙人掌那样生长,也就是必须种植在沙地上,它会生长到3格高.然而如果被破坏时只剩最后一格的时候,它会掉落一个彩虹仙人掌,否则会掉落一些染料.彩虹仙人掌并不能掉落一些特殊的染料比如骨粉和青金石.它掉落绿色染料比其他种类的染料概率要高得多. +tb.rec.rainCacti.page.0.gt=魔法不总是严格而且富有逻辑性的,毕竟它是魔法.生命也遵循同样的法则——它也有很多种形态,有时候令人震惊,有时候十分滑稽.你创造出了一种植物,如图'滑稽'这个词的意思一样.它就像普通仙人掌那样生长,也就是必须种植在沙地上,它会生长到3格高.然而如果被破坏时只剩最后一格的时候,它会掉落一个彩虹仙人掌,否则会掉落一些染料. tc.research_name.TB.Metalleat=金属草 tc.research_text.TB.Metalleat=铁有利于你的健康