Skip to content

Commit

Permalink
Fix pitcher pod replant (#29)
Browse files Browse the repository at this point in the history
* Fix sniffer twins

* Update Craftbukkit version

* Refactor AnimalTwins

* Fix Bisected crops replant

* Fix NatureTouch on Pitcher Pod
  • Loading branch information
PainOchoco authored Apr 24, 2024
1 parent db6bf85 commit 757f31b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 31 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ repositories {
}

dependencies {
paperDevBundle("1.20.2-R0.1-SNAPSHOT")
paperDevBundle("1.20.4-R0.1-SNAPSHOT")
implementation("com.github.luben:zstd-jni:1.5.0-4")
implementation("net.kyori:adventure-api:4.14.0")
implementation("redis.clients:jedis:4.3.1")
paperweight.paperDevBundle("1.20.2-R0.1-SNAPSHOT")
paperweight.paperDevBundle("1.20.4-R0.1-SNAPSHOT")
compileOnly("com.comphenix.protocol:ProtocolLib:5.1.0")
compileOnly("com.github.MilkBowl:VaultAPI:1.7.1")
compileOnly("me.clip:placeholderapi:2.11.4")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package net.laboulangerie.laboulangeriemmo.core.abilities.farmer;

import java.util.Random;

import org.bukkit.entity.Animals;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
Expand All @@ -12,6 +10,10 @@

public class AnimalTwins extends AbilityExecutor {

private final static float TIER_3_CHANCE = 1f;
private final static float TIER_2_CHANCE = 0.4f;
private final static float TIER_1_CHANCE = 0.1f;

public AnimalTwins(AbilityArchetype archetype) {
super(archetype);
}
Expand All @@ -26,24 +28,13 @@ public void trigger(Event baseEvent, int level) {
EntityBreedEvent event = (EntityBreedEvent) baseEvent;
Entity entity = event.getEntity();

int max_number = 100;
int min_number = 1;
Random random_chance = new Random();
int find_nearest_int = min_number + random_chance.nextInt(max_number);
float random = (float) Math.random();

if (level >= getTier(2)) {
Animals animal =
(Animals) entity.getWorld().spawnEntity(entity.getLocation(), entity.getType());
animal.setBaby();
} else if (level >= getTier(1) && find_nearest_int <= 40) {
Animals animal =
(Animals) entity.getWorld().spawnEntity(entity.getLocation(), entity.getType());
animal.setBaby();
} else if (find_nearest_int <= 10) {
Animals animal =
(Animals) entity.getWorld().spawnEntity(entity.getLocation(), entity.getType());
if (level >= getTier(2) && random <= TIER_3_CHANCE
|| (level >= getTier(1) && random <= TIER_2_CHANCE)
|| (random <= TIER_1_CHANCE)) {
Animals animal = (Animals) entity.getWorld().spawnEntity(entity.getLocation(), entity.getType());
animal.setBaby();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.data.Ageable;
import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.BlockData;
import org.bukkit.event.Event;
import org.bukkit.event.block.BlockBreakEvent;

Expand Down Expand Up @@ -36,24 +38,39 @@ public void trigger(Event baseEvent, int level) {
BlockBreakEvent event = (BlockBreakEvent) baseEvent;
final Block block = event.getBlock();
Material cropMaterial = block.getType();
Ageable ageable = (Ageable) block.getBlockData();
BlockData blockData = block.getBlockData();
Ageable ageable = (Ageable) blockData;

// Crop didnt finish to grow
if (ageable.getAge() != ageable.getMaximumAge()) return;
if (ageable.getAge() != ageable.getMaximumAge())
return;

float random = (float) Math.random();
boolean shouldReplant = false;

if (level >= getTier(2) && random <= TIER_3_CHANCE) shouldReplant = true;
else if (level >= getTier(1) && random <= TIER_2_CHANCE) shouldReplant = true;
else if (random <= TIER_1_CHANCE) shouldReplant = true;
if (level >= getTier(2) && random <= TIER_3_CHANCE)
shouldReplant = true;
else if (level >= getTier(1) && random <= TIER_2_CHANCE)
shouldReplant = true;
else if (random <= TIER_1_CHANCE)
shouldReplant = true;

if (shouldReplant) {
Bukkit.getScheduler().runTaskLater(LaBoulangerieMmo.PLUGIN, new Runnable() {
public void run() {
block.setType(cropMaterial);
block.getWorld().spawnParticle(Particle.VILLAGER_HAPPY,
block.getLocation().toCenterLocation().add(0, -0.2, 0), 5, 0.1, 0.1, 0.1);
Block updatedBlock = block;
if (blockData instanceof Bisected) {
Bisected bisected = (Bisected) blockData;
if (bisected.getHalf() == Bisected.Half.TOP) {
updatedBlock = block.getRelative(0, -1, 0);
}
}

updatedBlock.setType(cropMaterial);
updatedBlock.getWorld().spawnParticle(
Particle.VILLAGER_HAPPY,
updatedBlock.getLocation().toCenterLocation().add(0, -0.2, 0),
5, 0.1, 0.1, 0.1);
}
}, 1L);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.laboulangerie.laboulangeriemmo.core.abilities.thehunter;

import org.bukkit.Sound;
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.List;

import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.laboulangerie.laboulangeriemmo.utils;

import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
Expand Down

0 comments on commit 757f31b

Please sign in to comment.