Skip to content

Commit 69467ae

Browse files
committed
fix: Keep track of player and pass them when destroying block after gold rush #26
1 parent 7c1ca4b commit 69467ae

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-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
@@ -75,7 +75,7 @@ public static void initialize() {
7575
public static void addActiveGoldRush(BlockPos pos) {
7676
final var level = Minecraft.getInstance().level;
7777
if (level != null) {
78-
activeGoldRushes.put(level.dimension(), pos, new GoldRushInstance(pos, level.getBlockState(pos), BuiltInLootTables.EMPTY, -1, -1));
78+
activeGoldRushes.put(level.dimension(), pos, new GoldRushInstance(pos, level.getBlockState(pos), BuiltInLootTables.EMPTY, -1, -1, null));
7979
}
8080
}
8181

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
@@ -75,7 +75,8 @@ public static void initialize() {
7575
event.getState(),
7676
recipe.lootTable(),
7777
(int) Math.floor(20 * recipe.seconds()),
78-
recipe.maxDropsPerSecond() == -1 ? 0 : (int) Math.floor(20 / recipe.maxDropsPerSecond()));
78+
recipe.maxDropsPerSecond() == -1 ? 0 : (int) Math.floor(20 / recipe.maxDropsPerSecond()),
79+
serverPlayer);
7980
Balm.getNetworking().sendToTracking(((ServerLevel) level), event.getPos(), new ClientboundGoldRushPacket(event.getPos(), true));
8081
event.getPlayer().awardStat(ModStats.goldRushesTriggered);
8182
activeGoldRushes.put(level.dimension(), event.getPos(), activeGoldRush);
@@ -107,7 +108,7 @@ public static void initialize() {
107108
goldRush.setDropCooldownTicks(goldRush.getDropCooldownTicks() - 1);
108109
if (goldRush.getTicksPassed() >= goldRush.getMaxTicks()) {
109110
if (level.getBlockState(goldRush.getPos()).equals(goldRush.getInitialState())) {
110-
level.destroyBlock(goldRush.getPos(), true);
111+
level.destroyBlock(goldRush.getPos(), true, goldRush.getPlayer());
111112
}
112113
Balm.getNetworking().sendToAll(level.getServer(), new ClientboundGoldRushPacket(goldRush.getPos(), false));
113114
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,28 @@
33
import net.minecraft.core.BlockPos;
44
import net.minecraft.resources.ResourceKey;
55
import net.minecraft.resources.ResourceLocation;
6+
import net.minecraft.world.entity.player.Player;
67
import net.minecraft.world.level.block.state.BlockState;
78
import net.minecraft.world.level.storage.loot.LootTable;
9+
import org.jetbrains.annotations.Nullable;
810

911
public final class GoldRushInstance {
1012
private final BlockPos pos;
1113
private final BlockState initialState;
1214
private final ResourceKey<LootTable> lootTable;
1315
private final int maxTicks;
1416
private final int ticksPerDrop;
17+
private final Player player;
1518
private int ticksPassed;
1619
private int dropCooldownTicks;
1720

18-
public GoldRushInstance(BlockPos pos, BlockState initialState, ResourceKey<LootTable> lootTable, int maxTicks, int ticksPerDrop) {
21+
public GoldRushInstance(BlockPos pos, BlockState initialState, ResourceKey<LootTable> lootTable, int maxTicks, int ticksPerDrop, @Nullable Player player) {
1922
this.pos = pos;
2023
this.initialState = initialState;
2124
this.lootTable = lootTable;
2225
this.maxTicks = maxTicks;
2326
this.ticksPerDrop = ticksPerDrop;
27+
this.player = player;
2428
}
2529

2630
public BlockPos getPos() {
@@ -43,6 +47,11 @@ public int getTicksPerDrop() {
4347
return ticksPerDrop;
4448
}
4549

50+
@Nullable
51+
public Player getPlayer() {
52+
return player;
53+
}
54+
4655
public int getTicksPassed() {
4756
return ticksPassed;
4857
}

0 commit comments

Comments
 (0)