vectorwing / FarmersDelight

[Forge] A lightweight farming expansion for Minecraft.
MIT License
265 stars 165 forks source link

[1.20.4][Mod Integration][Botania] Make Pies edible for Kekimurus #901

Open RaymondBlaze opened 2 months ago

RaymondBlaze commented 2 months ago

Intro

The Kekimurus in Botania is known for generating mana from eating cakes. Botania's code only checks for CakeBlock and thus only vanilla cake and some modded cakes.

Since FD's pies(including the sweet berry cheesecake) behaves like vanilla cake, it's reasonable for pies to have integration with Kekimurus.

It's possible to make this integration on Botania's side, but that would be requiring Botania to compile against FD. Since I found a way to implement it on FD's side without needing to compile against Botania, I believe making a PR to FD would be better.

Related Discord discussion

Implementation

This PR used a @Pseudo mixin on the KekimurusBlockEntity to avoid adding Botania as a hard dependency on compile time.

Not having Botania on the compile classpath results in not being able to call Botania specific methods in the mixin, however with MixinExtras, a safe and possibly more coremod-compatible implementation could be made. The mixin result will basically be equivalent to the code below:

Click to uncollapse ```java /* * This class is distributed as part of the Botania Mod. * Get the Source Code in github: * https://github.com/Vazkii/Botania * * Botania is Open Source and distributed under the * Botania License: http://botaniamod.net/license.php */ @Override public void tickFlower() { boolean isPie = false; super.tickFlower(); if (getLevel().isClientSide) { return; } int mana = 1800; if (getMaxMana() - this.getMana() >= mana && !getLevel().isClientSide && ticksExisted % 80 == 0) { for (int i = 0; i < RANGE * 2 + 1; i++) { for (int j = 0; j < RANGE * 2 + 1; j++) { for (int k = 0; k < RANGE * 2 + 1; k++) { BlockPos pos = getEffectivePos().offset(i - RANGE, j - RANGE, k - RANGE); BlockState state = getLevel().getBlockState(pos); Block block = state.getBlock(); if ((isPie = block instanceof PieBlock) || (block instanceof CakeBlock)) { int nextSlicesEaten = state.getValue(isPie ? PieBlock.BITES : CakeBlock.BITES) + 1; if (nextSlicesEaten > (isPie ? 3 : 6)) { getLevel().removeBlock(pos, false); } else { getLevel().setBlockAndUpdate(pos, state.setValue(isPie ? PieBlock.BITES : CakeBlock.BITES, nextSlicesEaten)); } getLevel().levelEvent(LevelEvent.PARTICLES_DESTROY_BLOCK, pos, Block.getId(state)); //Usage of vanilla sound event: Subtitle is "Eating", generic sounds are meant to be reused. getLevel().playSound(null, getEffectivePos(), SoundEvents.GENERIC_EAT, SoundSource.BLOCKS, 1F, 0.5F + (float) Math.random() * 0.5F); addMana(mana); sync(); return; } } } } } } ```

Changes

MixinExtras is now embedded in the mod's jar using Forge's jar in jar, so no extra dependency for players is introduced. Since NeoForge 20.2.84+ includes MixinExtras already, removing the embedded dependency when FD updates to NeoForge is possible.

The only change for the building workflow is that now the jarJar task should be used to create the jar used for production instead of the original jar task.

Discussion

The Kekimurus generates 1800 mana per bite for all cakes, currently I let the pie use the same value. However, since pie slices are generally better than cake slices, and pies only have 4 bites comparing to cake's 7 bites, we might should consider a proper value for the mana generated per bite for pies.

My current preferred value is 3200 mana, which is 12800 mana in total, while for cake it's 12600 mana in total.

Of course, this value should be made tweakable through config, but we still need some discussion to determine a default value.

If the discussion results in rejecting this integration PR, I shall port it to Create: Central Kitchen for those who're interested in it :)