1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Made the Tree Growth Accelerator 200% better

This commit is contained in:
TheBusyBiscuit 2022-07-14 13:09:49 +02:00
parent f0730237e2
commit 6da39afab7
4 changed files with 50 additions and 7 deletions

View File

@ -7,7 +7,7 @@ on:
permissions:
contents: read
issues: write
pull-requests: write
jobs:
validate:

View File

@ -7,7 +7,7 @@ on:
permissions:
contents: read
issues: write
pull-requests: write
jobs:
pr-labeler:

View File

@ -45,6 +45,7 @@
* Added a new option to Eletric Gold Pans: "override-output-limit"
#### Changes
* Tree Growth Accelerators can now actually cause the Tree to fully grow (1.17+ only)
#### Fixes
* Fixed #3597

View File

@ -1,14 +1,21 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.accelerators;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.Particle;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.type.Sapling;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper;
@ -34,6 +41,7 @@ public class TreeGrowthAccelerator extends AbstractGrowthAccelerator {
// We wanna strip the Slimefun Item id here
private static final ItemStack organicFertilizer = ItemStackWrapper.wrap(SlimefunItems.FERTILIZER);
@ParametersAreNonnullByDefault
public TreeGrowthAccelerator(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(itemGroup, item, recipeType, recipe);
}
@ -44,7 +52,7 @@ public class TreeGrowthAccelerator extends AbstractGrowthAccelerator {
}
@Override
protected void tick(Block b) {
protected void tick(@Nonnull Block b) {
BlockMenu inv = BlockStorage.getInventory(b);
if (getCharge(b.getLocation()) >= ENERGY_CONSUMPTION) {
@ -53,9 +61,10 @@ public class TreeGrowthAccelerator extends AbstractGrowthAccelerator {
Block block = b.getRelative(x, 0, z);
if (Tag.SAPLINGS.isTagged(block.getType())) {
Sapling sapling = (Sapling) block.getBlockData();
boolean isGrowthBoosted = tryToBoostGrowth(b, inv, block);
if (sapling.getStage() < sapling.getMaximumStage() && growSapling(b, block, inv, sapling)) {
if (isGrowthBoosted) {
// Finish this tick and wait for the next.
return;
}
}
@ -64,9 +73,38 @@ public class TreeGrowthAccelerator extends AbstractGrowthAccelerator {
}
}
private boolean growSapling(Block machine, Block block, BlockMenu inv, Sapling sapling) {
@ParametersAreNonnullByDefault
private boolean tryToBoostGrowth(Block machine, BlockMenu inv, Block sapling) {
if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_17)) {
// On 1.17+ we can actually simulate bonemeal :O
return applyBoneMeal(machine, sapling, inv);
} else {
Sapling saplingData = (Sapling) sapling.getBlockData();
return saplingData.getStage() < saplingData.getMaximumStage() && updateSaplingData(machine, sapling, inv, saplingData);
}
}
@ParametersAreNonnullByDefault
private boolean applyBoneMeal(Block machine, Block sapling, BlockMenu inv) {
for (int slot : getInputSlots()) {
if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFertilizer, false, false)) {
if (isFertilizer(inv.getItemInSlot(slot))) {
removeCharge(machine.getLocation(), ENERGY_CONSUMPTION);
sapling.applyBoneMeal(BlockFace.UP);
inv.consumeItem(slot);
sapling.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, sapling.getLocation().add(0.5D, 0.5D, 0.5D), 4, 0.1F, 0.1F, 0.1F);
return true;
}
}
return false;
}
@ParametersAreNonnullByDefault
private boolean updateSaplingData(Block machine, Block block, BlockMenu inv, Sapling sapling) {
for (int slot : getInputSlots()) {
if (isFertilizer(inv.getItemInSlot(slot))) {
removeCharge(machine.getLocation(), ENERGY_CONSUMPTION);
sapling.setStage(sapling.getStage() + 1);
@ -81,4 +119,8 @@ public class TreeGrowthAccelerator extends AbstractGrowthAccelerator {
return false;
}
protected boolean isFertilizer(@Nullable ItemStack item) {
return SlimefunUtils.isItemSimilar(item, organicFertilizer, false, false);
}
}