mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Made the Tree Growth Accelerator 200% better
This commit is contained in:
parent
f0730237e2
commit
6da39afab7
2
.github/workflows/merge-conflicts.yml
vendored
2
.github/workflows/merge-conflicts.yml
vendored
@ -7,7 +7,7 @@ on:
|
|||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
issues: write
|
pull-requests: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
validate:
|
validate:
|
||||||
|
2
.github/workflows/pr-labels.yml
vendored
2
.github/workflows/pr-labels.yml
vendored
@ -7,7 +7,7 @@ on:
|
|||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
issues: write
|
pull-requests: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
pr-labeler:
|
pr-labeler:
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
* Added a new option to Eletric Gold Pans: "override-output-limit"
|
* Added a new option to Eletric Gold Pans: "override-output-limit"
|
||||||
|
|
||||||
#### Changes
|
#### Changes
|
||||||
|
* Tree Growth Accelerators can now actually cause the Tree to fully grow (1.17+ only)
|
||||||
|
|
||||||
#### Fixes
|
#### Fixes
|
||||||
* Fixed #3597
|
* Fixed #3597
|
||||||
|
@ -1,14 +1,21 @@
|
|||||||
package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.accelerators;
|
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.Particle;
|
||||||
import org.bukkit.Tag;
|
import org.bukkit.Tag;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.data.type.Sapling;
|
import org.bukkit.block.data.type.Sapling;
|
||||||
import org.bukkit.inventory.ItemStack;
|
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.ItemGroup;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
|
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
|
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.implementation.SlimefunItems;
|
||||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||||
import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper;
|
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
|
// We wanna strip the Slimefun Item id here
|
||||||
private static final ItemStack organicFertilizer = ItemStackWrapper.wrap(SlimefunItems.FERTILIZER);
|
private static final ItemStack organicFertilizer = ItemStackWrapper.wrap(SlimefunItems.FERTILIZER);
|
||||||
|
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
public TreeGrowthAccelerator(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
public TreeGrowthAccelerator(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||||
super(itemGroup, item, recipeType, recipe);
|
super(itemGroup, item, recipeType, recipe);
|
||||||
}
|
}
|
||||||
@ -44,7 +52,7 @@ public class TreeGrowthAccelerator extends AbstractGrowthAccelerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tick(Block b) {
|
protected void tick(@Nonnull Block b) {
|
||||||
BlockMenu inv = BlockStorage.getInventory(b);
|
BlockMenu inv = BlockStorage.getInventory(b);
|
||||||
|
|
||||||
if (getCharge(b.getLocation()) >= ENERGY_CONSUMPTION) {
|
if (getCharge(b.getLocation()) >= ENERGY_CONSUMPTION) {
|
||||||
@ -53,9 +61,10 @@ public class TreeGrowthAccelerator extends AbstractGrowthAccelerator {
|
|||||||
Block block = b.getRelative(x, 0, z);
|
Block block = b.getRelative(x, 0, z);
|
||||||
|
|
||||||
if (Tag.SAPLINGS.isTagged(block.getType())) {
|
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;
|
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()) {
|
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);
|
removeCharge(machine.getLocation(), ENERGY_CONSUMPTION);
|
||||||
|
|
||||||
sapling.setStage(sapling.getStage() + 1);
|
sapling.setStage(sapling.getStage() + 1);
|
||||||
@ -81,4 +119,8 @@ public class TreeGrowthAccelerator extends AbstractGrowthAccelerator {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isFertilizer(@Nullable ItemStack item) {
|
||||||
|
return SlimefunUtils.isItemSimilar(item, organicFertilizer, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user