Skip to content

Commit e5512aa

Browse files
committed
fix: Keep track of player and pass them when destroying block after gold rush #26
1 parent af348de commit e5512aa

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

common/src/main/java/net/blay09/mods/littlejoys/client/handler/GoldRushClientHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static void initialize() {
7777
public static void addActiveGoldRush(BlockPos pos) {
7878
final var level = Minecraft.getInstance().level;
7979
if (level != null) {
80-
activeGoldRushes.put(level.dimension(), pos, new GoldRushInstance(pos, level.getBlockState(pos), Optional.empty(), -1, -1));
80+
activeGoldRushes.put(level.dimension(), pos, new GoldRushInstance(pos, level.getBlockState(pos), Optional.empty(), -1, -1, null));
8181
}
8282
}
8383

common/src/main/java/net/blay09/mods/littlejoys/handler/GoldRushHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public static void initialize() {
7474
event.getState(),
7575
Optional.of(recipe.lootTable()),
7676
(int) Math.floor(20 * recipe.seconds()),
77-
recipe.maxDropsPerSecond() == -1 ? 0 : (int) Math.floor(20 / recipe.maxDropsPerSecond()));
77+
recipe.maxDropsPerSecond() == -1 ? 0 : (int) Math.floor(20 / recipe.maxDropsPerSecond()),
78+
serverPlayer);
7879
Balm.getNetworking().sendToTracking(((ServerLevel) level), event.getPos(), new ClientboundGoldRushPacket(event.getPos(), true));
7980
event.getPlayer().awardStat(ModStats.goldRushesTriggered);
8081
activeGoldRushes.put(level.dimension(), event.getPos(), activeGoldRush);
@@ -106,7 +107,7 @@ public static void initialize() {
106107
goldRush.setDropCooldownTicks(goldRush.getDropCooldownTicks() - 1);
107108
if (goldRush.getTicksPassed() >= goldRush.getMaxTicks()) {
108109
if (level.getBlockState(goldRush.getPos()).equals(goldRush.getInitialState())) {
109-
level.destroyBlock(goldRush.getPos(), true);
110+
level.destroyBlock(goldRush.getPos(), true, goldRush.getPlayer());
110111
}
111112
Balm.getNetworking().sendToAll(level.getServer(), new ClientboundGoldRushPacket(goldRush.getPos(), false));
112113
}

common/src/main/java/net/blay09/mods/littlejoys/handler/GoldRushInstance.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
import net.minecraft.core.BlockPos;
44
import net.minecraft.resources.ResourceKey;
5+
import net.minecraft.resources.ResourceLocation;
6+
import net.minecraft.world.entity.player.Player;
57
import net.minecraft.world.level.block.state.BlockState;
68
import net.minecraft.world.level.storage.loot.LootTable;
9+
import org.jetbrains.annotations.Nullable;
710

811
import java.util.Optional;
912

@@ -13,15 +16,17 @@ public final class GoldRushInstance {
1316
private final ResourceKey<LootTable> lootTable;
1417
private final int maxTicks;
1518
private final int ticksPerDrop;
19+
private final Player player;
1620
private int ticksPassed;
1721
private int dropCooldownTicks;
1822

19-
public GoldRushInstance(BlockPos pos, BlockState initialState, @SuppressWarnings("OptionalUsedAsFieldOrParameterType") Optional<ResourceKey<LootTable>> lootTable, int maxTicks, int ticksPerDrop) {
23+
public GoldRushInstance(BlockPos pos, BlockState initialState, @SuppressWarnings("OptionalUsedAsFieldOrParameterType") Optional<ResourceKey<LootTable>> lootTable, int maxTicks, int ticksPerDrop, @Nullable Player player) {
2024
this.pos = pos;
2125
this.initialState = initialState;
2226
this.lootTable = lootTable.orElse(null);
2327
this.maxTicks = maxTicks;
2428
this.ticksPerDrop = ticksPerDrop;
29+
this.player = player;
2530
}
2631

2732
public BlockPos getPos() {
@@ -44,6 +49,11 @@ public int getTicksPerDrop() {
4449
return ticksPerDrop;
4550
}
4651

52+
@Nullable
53+
public Player getPlayer() {
54+
return player;
55+
}
56+
4757
public int getTicksPassed() {
4858
return ticksPassed;
4959
}

0 commit comments

Comments
 (0)