Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added multiple block drop support #329

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
import net.swofty.types.generic.region.RegionType;
import net.swofty.types.generic.region.SkyBlockMiningConfiguration;
import net.swofty.types.generic.region.SkyBlockRegion;
import net.swofty.types.generic.region.mining.MineableBlock;
import net.swofty.types.generic.user.SkyBlockPlayer;
import net.swofty.types.generic.event.SkyBlockEvent;
import net.swofty.types.generic.event.custom.CustomBlockBreakEvent;
import net.swofty.types.generic.utility.MaterialQuantifiableRandom;

public class ActionRegionBlockBreak implements SkyBlockEventClass {

Expand Down Expand Up @@ -67,24 +69,31 @@ public void run(PlayerBlockBreakEvent event) {
player, item.getMaterial(), event.getBlockPosition()
));

MineableBlock mineableBlock = MineableBlock.get(block);
Double fortune = player.getStatistics().allStatistics().getOverall(mineableBlock.getFortuneType());
Double dropMultiplicator = (1 + (fortune*0.01));
Integer drops = mineableBlock.getDrops().getAmount(dropMultiplicator);

/**
* Handle block dropping
*/
DroppedItemEntityImpl droppedItem = new DroppedItemEntityImpl(item, player);
Pos pos = Pos.fromPoint(event.getBlockPosition());
// Move the dropped item to the center of the block
pos = pos.add(0.5, 0.5, 0.5);
// Move block closer to player by 0.5 blocks
Pos playerPos = player.getPosition().add(0, 0.5, 0);
double x = playerPos.x() - pos.x();
double y = playerPos.y() - pos.y();
double z = playerPos.z() - pos.z();
double distance = Math.sqrt(x * x + y * y + z * z);
double multiplier = 1.4 / distance;
pos = pos.add(x * multiplier, y * multiplier * 3, z * multiplier);
for (int i = 0; i < drops; i++) {
DroppedItemEntityImpl droppedItem = new DroppedItemEntityImpl(item, player);
Pos pos = Pos.fromPoint(event.getBlockPosition());
// Move the dropped item to the center of the block
pos = pos.add(0.5, 0.5, 0.5);
// Move block closer to player by 0.5 blocks
Pos playerPos = player.getPosition().add(0, 0.5, 0);
double x = playerPos.x() - pos.x();
double y = playerPos.y() - pos.y();
double z = playerPos.z() - pos.z();
double distance = Math.sqrt(x * x + y * y + z * z);
double multiplier = 1.4 / distance;
pos = pos.add(x * multiplier, y * multiplier * 3, z * multiplier);

droppedItem.setInstance(player.getInstance(), pos);
droppedItem.addViewer(player);
droppedItem.setInstance(player.getInstance(), pos);
droppedItem.addViewer(player);
}
}
shouldItemDrop = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,65 @@
import net.minestom.server.instance.block.Block;
import net.minestom.server.item.Material;
import net.swofty.types.generic.item.SkyBlockItem;
import net.swofty.types.generic.user.statistics.ItemStatistic;
import net.swofty.types.generic.utility.MaterialQuantifiableRandom;

@Getter
public enum MineableBlock {
// default minable blocks
STONE(Material.STONE, 15, 1, MiningLoot.defaultLoot()),
SAND(Material.SAND, 5, 1, MiningLoot.defaultLoot()),
NETHERRACK(Material.NETHERRACK, 4, 1, MiningLoot.defaultLoot()),
COBBLESTONE(Material.COBBLESTONE, 20, 1, MiningLoot.defaultLoot()),
ANDESITE(Material.ANDESITE, 15, 1, MiningLoot.defaultLoot()),
GRANITE(Material.GRANITE, 15, 1, MiningLoot.defaultLoot()),
DIORITE(Material.DIORITE, 15, 1, MiningLoot.defaultLoot()),
END_STONE(Material.END_STONE, 30, 1, MiningLoot.defaultLoot()),
OBSIDIAN(Material.END_STONE, 500, 4, MiningLoot.defaultLoot()),
ORE_IRON(Material.IRON_ORE, 30, 2, MiningLoot.defaultLoot()),
ORE_COAL(Material.COAL_ORE, 30, 1, MiningLoot.defaultLoot()),
ORE_GOLD(Material.GOLD_ORE, 30, 3, MiningLoot.defaultLoot()),
ORE_DIAMOND(Material.DIAMOND_ORE, 30, 3, MiningLoot.defaultLoot()),
ORE_REDSTONE(Material.REDSTONE_ORE, 30, 3, MiningLoot.defaultLoot()),
STONE(Material.STONE, 15, 1, MiningLoot.defaultLoot(), ItemStatistic.MINING_FORTUNE),
SAND(Material.SAND, 5, 1, MiningLoot.defaultLoot(), ItemStatistic.MINING_FORTUNE),
NETHERRACK(Material.NETHERRACK, 4, 1, MiningLoot.defaultLoot(), ItemStatistic.MINING_FORTUNE),
COBBLESTONE(Material.COBBLESTONE, 20, 1, MiningLoot.defaultLoot(), ItemStatistic.MINING_FORTUNE),
ANDESITE(Material.ANDESITE, 15, 1, MiningLoot.defaultLoot(), ItemStatistic.MINING_FORTUNE),
GRANITE(Material.GRANITE, 15, 1, MiningLoot.defaultLoot(), ItemStatistic.MINING_FORTUNE),
DIORITE(Material.DIORITE, 15, 1, MiningLoot.defaultLoot(), ItemStatistic.MINING_FORTUNE),
END_STONE(Material.END_STONE, 30, 1, MiningLoot.defaultLoot(), ItemStatistic.MINING_FORTUNE),
OBSIDIAN(Material.END_STONE, 500, 4, MiningLoot.defaultLoot(), ItemStatistic.MINING_FORTUNE),
ORE_IRON(Material.IRON_ORE, 30, 2, MiningLoot.defaultLoot(), ItemStatistic.MINING_FORTUNE),
ORE_COAL(Material.COAL_ORE, 30, 1, MiningLoot.defaultLoot(), ItemStatistic.MINING_FORTUNE),
ORE_GOLD(Material.GOLD_ORE, 30, 3, MiningLoot.defaultLoot(), ItemStatistic.MINING_FORTUNE),
ORE_DIAMOND(Material.DIAMOND_ORE, 30, 3, MiningLoot.defaultLoot(), ItemStatistic.MINING_FORTUNE),
ORE_REDSTONE(Material.REDSTONE_ORE, 30, 3, MiningLoot.defaultLoot(), ItemStatistic.MINING_FORTUNE),

// Forest minable blocks
ACACIA_LOG(Material.ACACIA_LOG, 1, 0, MiningLoot.defaultLoot()),
BIRCH_LOG(Material.BIRCH_LOG, 1, 0, MiningLoot.defaultLoot()),
JUNGLE_LOG(Material.JUNGLE_LOG, 1, 0, MiningLoot.defaultLoot()),
SPRUCE_LOG(Material.SPRUCE_LOG, 1, 0, MiningLoot.defaultLoot()),
DARK_OAK_LOG(Material.DARK_OAK_LOG, 1, 0, MiningLoot.defaultLoot()),
MANGROVE_LOG(Material.MANGROVE_LOG, 1, 0, MiningLoot.defaultLoot()),
OAK_LOG(Material.OAK_LOG, 1, 0, MiningLoot.defaultLoot()),
ACACIA_LOG(Material.ACACIA_LOG, 1, 0, MiningLoot.defaultLoot(), ItemStatistic.FORAGING_FORTUNE),
BIRCH_LOG(Material.BIRCH_LOG, 1, 0, MiningLoot.defaultLoot(), ItemStatistic.FORAGING_FORTUNE),
JUNGLE_LOG(Material.JUNGLE_LOG, 1, 0, MiningLoot.defaultLoot(), ItemStatistic.FORAGING_FORTUNE),
SPRUCE_LOG(Material.SPRUCE_LOG, 1, 0, MiningLoot.defaultLoot(), ItemStatistic.FORAGING_FORTUNE),
DARK_OAK_LOG(Material.DARK_OAK_LOG, 1, 0, MiningLoot.defaultLoot(), ItemStatistic.FORAGING_FORTUNE),
MANGROVE_LOG(Material.MANGROVE_LOG, 1, 0, MiningLoot.defaultLoot(), ItemStatistic.FORAGING_FORTUNE),
OAK_LOG(Material.OAK_LOG, 1, 0, MiningLoot.defaultLoot(), ItemStatistic.FORAGING_FORTUNE),

// Farming minable blocks
PUMPKIN(Material.PUMPKIN, 1, 0, MiningLoot.defaultLoot()),
CARVED_PUMPKIN(Material.CARVED_PUMPKIN, 1, 0, MiningLoot.defaultLoot()),
MELON(Material.MELON, 1, 0, MiningLoot.custom(Material.MELON, 3, 7)),
WHEAT(Material.WHEAT, 0, 0, MiningLoot.defaultLoot(), ItemStatistic.FARMING_FORTUNE),
PUMPKIN(Material.PUMPKIN, 1, 0, MiningLoot.defaultLoot(), ItemStatistic.FARMING_FORTUNE),
CARVED_PUMPKIN(Material.CARVED_PUMPKIN, 1, 0, MiningLoot.defaultLoot(), ItemStatistic.FARMING_FORTUNE),
MELON(Material.MELON, 1, 0, MiningLoot.custom(Material.MELON_SLICE, 3, 7), ItemStatistic.FARMING_FORTUNE),

// Dwarven mines minable blocks
MITHRIL_WEAK(Material.GRAY_WOOL, 500, 4, MiningLoot.none()),
MITHRIL_WEAK2(Material.CYAN_TERRACOTTA, 500, 4, MiningLoot.none()),
MITHRIL_MEDIUM(Material.PRISMARINE, 800, 4, MiningLoot.none()),
MITHRIL_STRONG(Material.LIGHT_BLUE_WOOL, 1500, 4, MiningLoot.none()),
TITANIUM(Material.DIORITE, 2500, 5, MiningLoot.none()),
DWARVEN_GOLD(Material.GOLD_BLOCK, 600, 3, MiningLoot.custom(Material.GOLD_INGOT, 2, 4)),
MITHRIL_WEAK(Material.GRAY_WOOL, 500, 4, MiningLoot.none(), ItemStatistic.MINING_FORTUNE),
MITHRIL_WEAK2(Material.CYAN_TERRACOTTA, 500, 4, MiningLoot.none(), ItemStatistic.MINING_FORTUNE),
MITHRIL_MEDIUM(Material.PRISMARINE, 800, 4, MiningLoot.none(), ItemStatistic.MINING_FORTUNE),
MITHRIL_STRONG(Material.LIGHT_BLUE_WOOL, 1500, 4, MiningLoot.none(), ItemStatistic.MINING_FORTUNE),
TITANIUM(Material.DIORITE, 2500, 5, MiningLoot.none(), ItemStatistic.MINING_FORTUNE),
DWARVEN_GOLD(Material.GOLD_BLOCK, 600, 3, MiningLoot.custom(Material.GOLD_INGOT, 2, 4), ItemStatistic.MINING_FORTUNE),
;

private final Material material;
private final double strength;
private final int miningPowerRequirement;
private final MaterialQuantifiableRandom drops;
private final ItemStatistic fortuneType;

MineableBlock(Material material, double strength, int miningPowerRequirement, MiningLoot drops) {
MineableBlock(Material material, double strength, int miningPowerRequirement, MiningLoot drops, ItemStatistic fortuneType) {
this.material = material;
this.strength = strength;
this.miningPowerRequirement = miningPowerRequirement;
this.drops = drops.identifier().equals("default") ?
new MaterialQuantifiableRandom(new SkyBlockItem(material), 1, 1) :
drops.material();
this.fortuneType = fortuneType;
}

public static MineableBlock get(Block block) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static MiningLoot defaultLoot() {
}

public static MiningLoot custom(Material mat, int bounds1, int bounds2) {
return new MiningLoot("custom", new MaterialQuantifiableRandom(ItemDropChanger.get(mat).getItemSupplier().get(), bounds1, bounds2));
return new MiningLoot("custom", new MaterialQuantifiableRandom(new SkyBlockItem(mat), bounds1, bounds2));
}

public static MiningLoot custom(Material mat, int singleBounds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,18 @@ public MaterialQuantifiableRandom setBound2(int amount) {
return this;
}

public int getAmount() {
return MathUtility.random(bounds1, bounds2);
public int getAmount(Double multiplicator) {
if (bounds1 == bounds2) {
Integer x = (int) Math.floor(bounds1*multiplicator);
Integer y = (int) (((bounds2*multiplicator)-x)*100);

if (MathUtility.random(0, 100) <= y) {
return (int) Math.ceil(bounds2*multiplicator);
} else {
return (int) Math.floor(bounds1*multiplicator);
}
} else {
return MathUtility.random((int) Math.floor(bounds1*multiplicator), (int) Math.ceil(bounds2*multiplicator));
}
}
}
Loading