-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
load nosundamage biomes and dimensions from data packs
- Loading branch information
1 parent
051cae4
commit ff2c0df
Showing
17 changed files
with
567 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/generated/resources/data/vampirism/vampirism/sun_damage.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"biomes": [ | ||
"#vampirism:has_faction/vampire" | ||
], | ||
"dimensions": [ | ||
"minecraft:the_nether", | ||
"minecraft:the_end" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/main/java/de/teamlapen/vampirism/data/provider/SundamageProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package de.teamlapen.vampirism.data.provider; | ||
|
||
import com.google.common.collect.Sets; | ||
import com.mojang.serialization.JsonOps; | ||
import de.teamlapen.vampirism.core.ModTags; | ||
import de.teamlapen.vampirism.data.reloadlistener.SundamageReloadListener; | ||
import net.minecraft.data.CachedOutput; | ||
import net.minecraft.data.DataProvider; | ||
import net.minecraft.data.PackOutput; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.tags.TagKey; | ||
import net.minecraft.util.ExtraCodecs; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.biome.Biome; | ||
import net.minecraft.world.level.dimension.BuiltinDimensionTypes; | ||
import net.minecraft.world.level.dimension.DimensionType; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Set; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class SundamageProvider implements DataProvider { | ||
|
||
private static final Logger LOGGER = LogManager.getLogger(); | ||
|
||
protected final PackOutput.PathProvider pathProvider; | ||
private final String modId; | ||
|
||
public SundamageProvider(PackOutput packOutput, String modId) { | ||
this.pathProvider = packOutput.createPathProvider(PackOutput.Target.DATA_PACK, "vampirism"); | ||
this.modId = modId; | ||
} | ||
|
||
@Override | ||
public @NotNull CompletableFuture<?> run(@NotNull CachedOutput pOutput) { | ||
Consumer consumer = new Consumer(); | ||
this.registerNoSundamageBiomes(consumer); | ||
|
||
return DataProvider.saveStable(pOutput, SundamageReloadListener.RawFile.CODEC.encodeStart(JsonOps.INSTANCE, consumer.build()).getOrThrow(false, LOGGER::error), pathProvider.json(new ResourceLocation(modId, "no_sun_damage"))); | ||
} | ||
|
||
@Override | ||
public @NotNull String getName() { | ||
return "No Sundamage"; | ||
} | ||
|
||
protected void registerNoSundamageBiomes(Consumer consumer) { | ||
consumer.addBiome(ModTags.Biomes.IS_VAMPIRE_BIOME); | ||
consumer.addDimension(BuiltinDimensionTypes.NETHER); | ||
consumer.addDimension(BuiltinDimensionTypes.END); | ||
} | ||
|
||
public static class Consumer { | ||
|
||
private final Set<ExtraCodecs.TagOrElementLocation> biomes = Sets.newHashSet(); | ||
private final Set<ExtraCodecs.TagOrElementLocation> dimensions = Sets.newHashSet(); | ||
private final Set<ResourceKey<Level>> levels = Sets.newHashSet(); | ||
private final Set<ResourceKey<Level>> sunDamageLevels = Sets.newHashSet(); | ||
|
||
public void addBiome(ResourceLocation biome) { | ||
this.biomes.add(new ExtraCodecs.TagOrElementLocation(biome, false)); | ||
} | ||
|
||
public void addBiome(ResourceKey<Biome> biome) { | ||
this.biomes.add(new ExtraCodecs.TagOrElementLocation(biome.location(), false)); | ||
} | ||
|
||
public void addBiome(TagKey<Biome> biome) { | ||
this.biomes.add(new ExtraCodecs.TagOrElementLocation(biome.location(), true)); | ||
} | ||
|
||
public void addDimension(ResourceLocation dimension) { | ||
this.dimensions.add(new ExtraCodecs.TagOrElementLocation(dimension, false)); | ||
} | ||
|
||
public void addDimension(ResourceKey<DimensionType> dimension) { | ||
this.dimensions.add(new ExtraCodecs.TagOrElementLocation(dimension.location(), false)); | ||
} | ||
|
||
public void addDimension(TagKey<DimensionType> dimension) { | ||
this.dimensions.add(new ExtraCodecs.TagOrElementLocation(dimension.location(), true)); | ||
} | ||
|
||
public void noSunDamageLevel(ResourceKey<Level> level) { | ||
this.levels.add(level); | ||
} | ||
|
||
public void sunDamageLevel(ResourceKey<Level> level) { | ||
this.sunDamageLevels.add(level); | ||
} | ||
|
||
private SundamageReloadListener.RawFile build() { | ||
return new SundamageReloadListener.RawFile(false, new ArrayList<>(this.biomes), new ArrayList<>(this.dimensions), new ArrayList<>(this.levels), new ArrayList<>(this.sunDamageLevels)); | ||
} | ||
} | ||
} |
Oops, something went wrong.