Skip to content

Commit

Permalink
Crop cleanup and automation streamlining. (#30)
Browse files Browse the repository at this point in the history
* 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 #30 (review)

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.
  • Loading branch information
C0bra5 authored Apr 2, 2024
1 parent d73d5c7 commit 4e32624
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ whitelist.json
*.iws
src/main/resources/mixins.*.json
*.bat
/layout.json
15 changes: 8 additions & 7 deletions src/main/java/tb/common/block/BlockAshroom.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tb.common.block;

import java.util.ArrayList;
import java.util.Random;

import net.minecraft.entity.player.EntityPlayer;
Expand Down Expand Up @@ -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<Aspect> 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);
}
}
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/tb/common/block/BlockRainbowCactus.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -43,22 +44,36 @@ public ArrayList<ItemStack> 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<ItemStack> 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),
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/tb/common/block/BlockRedlonStem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
10 changes: 5 additions & 5 deletions src/main/java/tb/common/block/BlockSweed.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -53,7 +51,9 @@ public ArrayList<ItemStack> 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));

Expand Down
35 changes: 30 additions & 5 deletions src/main/java/tb/common/block/BlockTBPlant.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,38 @@ public int getRenderType() {
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();

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());

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/tb/init/TBThaumonomicon.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/thaumicbases/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/thaumicbases/lang/ru_RU.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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=Обогащена железом
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/thaumicbases/lang/zh_CN.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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=铁有利于你的健康
Expand Down

0 comments on commit 4e32624

Please sign in to comment.