Skip to content

Commit

Permalink
move BiomePredicate & LightPredicate packages (should be migrated, too)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaFuqs committed Jan 3, 2025
1 parent 983dca1 commit ecdcca5
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package de.dafuqs.spectrum.api.predicate.entity;

import com.google.gson.*;
import de.dafuqs.spectrum.api.predicate.block.LightPredicate;
import de.dafuqs.spectrum.api.predicate.block.*;
import de.dafuqs.spectrum.api.predicate.world.LightPredicate;
import de.dafuqs.spectrum.api.predicate.world.*;
import net.minecraft.predicate.*;
import net.minecraft.server.world.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.dafuqs.spectrum.api.predicate.block;
package de.dafuqs.spectrum.api.predicate.world;

import com.google.gson.*;
import net.minecraft.registry.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public CommandType(Codec<CommandType.Config> codec) {
public boolean test(Config config, ServerWorld world, BlockPos pos) {
AtomicBoolean passed = new AtomicBoolean(false);
MinecraftServer minecraftServer = world.getServer();
ServerCommandSource serverCommandSource = new ServerCommandSource(this, Vec3d.ofCenter(pos), Vec2f.ZERO, world, 2, "FusionShrine", world.getBlockState(pos).getBlock().getName(), minecraftServer, null)
ServerCommandSource serverCommandSource = new ServerCommandSource(this, Vec3d.ofCenter(pos), Vec2f.ZERO, world, 2, "SpectrumCommandWorldCondition", world.getBlockState(pos).getBlock().getName(), minecraftServer, null)
.withReturnValueConsumer((successful, returnValue) -> {
passed.set(returnValue > 0);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package de.dafuqs.spectrum.api.predicate.block;
package de.dafuqs.spectrum.api.predicate.world;

import org.jetbrains.annotations.Nullable;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import net.minecraft.predicate.NumberRange;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.JsonHelper;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.LightType;
import com.google.gson.*;
import net.minecraft.predicate.*;
import net.minecraft.server.world.*;
import net.minecraft.util.*;
import net.minecraft.util.math.*;
import net.minecraft.world.*;
import org.jetbrains.annotations.*;

public class LightPredicate {
public static final LightPredicate ANY = new LightPredicate(null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ public MoonPhaseType(Codec<Config> codec) {
super(codec);
}

Override

@Override
public boolean test(Config config, ServerWorld world, BlockPos pos) {
return config.moonPhase == world.getMoonPhase();
}


@

public static class Config extends WorldConditionType.Config {

public static final Codec<Config> CODEC = RecordCodecBuilder.create((instance) -> instance.group(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,39 @@ public TimeOfDayType(Codec<Config> codec) {
super(codec);
}

Override

@Override
public boolean test(Config config, ServerWorld world, BlockPos pos) {
TimeHelper.TimeOfDay worldTimeOfDay = TimeHelper.getTimeOfDay(world);
switch (this.timeOfDay) {
switch (config.timeOfDay) {
case DAY -> {
return worldTimeOfDay.isDay();
}
case NIGHT -> {
return worldTimeOfDay.isNight();
}
default -> {
return this.timeOfDay == worldTimeOfDay;
return config.timeOfDay == worldTimeOfDay;
}
}
}

@

public static class Config extends WorldConditionType.Config {

public static TimeOfDayType fromJson(JsonObject json) {
if (json == null || json.isJsonNull()) return ANY;
return new TimeOfDayType(TimeHelper.TimeOfDay.valueOf(json.get("time").getAsString().toUpperCase(Locale.ROOT)));
}

public static final Codec<Config> CODEC = RecordCodecBuilder.create((instance) -> instance.group(

).apply(instance, Config::new));

public final TimeHelper.TimeOfDay timeOfDay;

public Config(TimeHelper.TimeOfDay timeOfDay) {
this.timeOfDay = timeOfDay;
}

public static TimeOfDayType fromJson(JsonObject json) {
if (json == null || json.isJsonNull()) return ANY;
return new TimeOfDayType(TimeHelper.TimeOfDay.valueOf(json.get("time").getAsString().toUpperCase(Locale.ROOT)));
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ public WeatherType(Codec<Config> codec) {
super(codec);
}

Override
public enum WeatherCondition {
CLEAR_SKY,
RAIN, // rain or thunder
STRICT_RAIN, // rain without thunder
THUNDER,
NOT_THUNDER
}

@Override
public boolean test(Config config, ServerWorld world, BlockPos pos) {
switch (config.weatherCondition) {
case CLEAR_SKY -> {
Expand All @@ -37,18 +44,12 @@ public boolean test(Config config, ServerWorld world, BlockPos pos) {
return true;
}


public enum WeatherCondition {
CLEAR_SKY,
RAIN, // rain or thunder
STRICT_RAIN, // rain without thunder
THUNDER,
NOT_THUNDER
}
@

public static class Config extends WorldConditionType.Config {

public static WeatherType fromJson(JsonObject json) {
return new WeatherType(WeatherCondition.valueOf(json.get("weather_condition").getAsString().toUpperCase(Locale.ROOT)));
}

public static final Codec<Config> CODEC = RecordCodecBuilder.create((instance) -> instance.group(

).apply(instance, Config::new));
Expand All @@ -58,10 +59,6 @@ public Config(WeatherCondition weatherCondition) {
this.weatherCondition = weatherCondition;
}

public static WeatherType fromJson(JsonObject json) {
return new WeatherType(WeatherCondition.valueOf(json.get("weather_condition").getAsString().toUpperCase(Locale.ROOT)));
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.minecraft.server.world.*;
import net.minecraft.util.math.*;

public abstract class WorldCondition<S extends WorldConditionType<SC>, SC extends WorldConditionType.Config> {
public class WorldCondition<S extends WorldConditionType<SC>, SC extends WorldConditionType.Config> {

public static final Codec<WorldCondition<?, ?>> CODEC = SpectrumRegistries.WORLD_CONDITION_TYPE.getCodec().dispatch((condition) -> condition.type, WorldConditionType::getCodec);

Expand Down

0 comments on commit ecdcca5

Please sign in to comment.