Skip to content

Commit

Permalink
Make end duration configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerozgen committed Nov 11, 2023
1 parent 882aa8c commit d8dc3b1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryElementCodec;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.dynamic.Codecs;
import net.minecraft.world.dimension.DimensionOptions;
import xyz.nucleoid.codecs.MoreCodecs;
Expand All @@ -16,12 +12,13 @@
import java.util.List;
import java.util.Optional;

public record ItemHuntConfig(PlayerConfig playerConfig, DimensionOptions dimensionOptions, int duration,
public record ItemHuntConfig(PlayerConfig playerConfig, DimensionOptions dimensionOptions, int duration, int endDuration,
Optional<String> statisticBundleNamespace, boolean crafting, Optional<List<ItemStack>> startItems) {
public static final Codec<ItemHuntConfig> CODEC = RecordCodecBuilder.create(instance -> instance.group(
PlayerConfig.CODEC.fieldOf("players").forGetter(ItemHuntConfig::playerConfig),
DimensionOptions.CODEC.fieldOf("dimension_options").forGetter(ItemHuntConfig::dimensionOptions),
Codecs.POSITIVE_INT.optionalFieldOf("duration", 180).forGetter(ItemHuntConfig::duration),
Codecs.POSITIVE_INT.optionalFieldOf("end_duration", 15).forGetter(ItemHuntConfig::endDuration),
GameStatisticBundle.NAMESPACE_CODEC.optionalFieldOf("statistic_bundle").forGetter(ItemHuntConfig::statisticBundleNamespace),
Codec.BOOL.optionalFieldOf("crafting", false).forGetter(ItemHuntConfig::crafting),
MoreCodecs.ITEM_STACK.listOf().optionalFieldOf("start_items").forGetter(ItemHuntConfig::startItems)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
import java.util.concurrent.TimeUnit;

public class ItemHuntEndingPhase extends ItemHuntPhase {
public static final long ENDING_DURATION = TimeUnit.SECONDS.toMillis(15);

private BossBarWidget bossbar;
private long endTime;
private long endDuration;
private int lastSecondsLeft = -1;

public ItemHuntEndingPhase(ItemHuntGame game) {
Expand All @@ -38,7 +37,8 @@ protected void setupPhase(GameActivity activity) {
}

private void start() {
endTime = Util.getMeasuringTimeMs() + ENDING_DURATION;
endDuration = TimeUnit.SECONDS.toMillis(game.config().endDuration());
endTime = Util.getMeasuringTimeMs() + endDuration;
}

private void tick() {
Expand All @@ -48,7 +48,7 @@ private void tick() {
lastSecondsLeft = secondsLeft;
bossbar.setTitle(ItemHuntTexts.time(secondsLeft));
}
bossbar.setProgress((float) (millisLeft / (double) ENDING_DURATION));
bossbar.setProgress((float) (millisLeft / (double) endDuration));
if (millisLeft <= 0)
game.gameSpace().close(GameCloseReason.FINISHED);
}
Expand Down

0 comments on commit d8dc3b1

Please sign in to comment.