-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port fluid tooltip logic from tinkers
- Loading branch information
1 parent
0edb280
commit 9a52c23
Showing
12 changed files
with
545 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
bd5291d8d6b5177e4c7eda679255cea77848f851 assets/mantle/mantle/fluid_tooltips/buckets.json | ||
3da0739a22aeaf0c3134fa33730756170afae1d9 assets/mantle/mantle/fluid_tooltips/fallback.json | ||
6d86d02a3f9975defeaf27b7d67dcb5a5d06348f data/mantle/tags/fluids/lava.json | ||
5e80abba332ce1f1d5c6f46f0cd536ba6afdf7f3 data/mantle/tags/fluids/water.json |
12 changes: 12 additions & 0 deletions
12
src/generated/resources/assets/mantle/mantle/fluid_tooltips/buckets.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,12 @@ | ||
{ | ||
"units": [ | ||
{ | ||
"key": "gui.mantle.fluid.kilobucket", | ||
"needed": 1000000 | ||
}, | ||
{ | ||
"key": "gui.mantle.fluid.bucket", | ||
"needed": 1000 | ||
} | ||
] | ||
} |
3 changes: 3 additions & 0 deletions
3
src/generated/resources/assets/mantle/mantle/fluid_tooltips/fallback.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,3 @@ | ||
{ | ||
"redirect": "mantle:buckets" | ||
} |
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
27 changes: 27 additions & 0 deletions
27
src/main/java/slimeknights/mantle/datagen/MantleFluidTooltipProvider.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,27 @@ | ||
package slimeknights.mantle.datagen; | ||
|
||
import net.minecraft.data.DataGenerator; | ||
import net.minecraftforge.fluids.FluidAttributes; | ||
import slimeknights.mantle.Mantle; | ||
import slimeknights.mantle.fluid.tooltip.AbstractFluidTooltipProvider; | ||
import slimeknights.mantle.fluid.tooltip.FluidTooltipHandler; | ||
|
||
/** Mantle datagen for fluid tooltips. For mods, don't use this, use {@link AbstractFluidTooltipProvider} */ | ||
public class MantleFluidTooltipProvider extends AbstractFluidTooltipProvider { | ||
public MantleFluidTooltipProvider(DataGenerator generator) { | ||
super(generator, Mantle.modId); | ||
} | ||
|
||
@Override | ||
protected void addFluids() { | ||
add("buckets") | ||
.addUnit("kilobucket", FluidAttributes.BUCKET_VOLUME * 1000) | ||
.addUnit("bucket", FluidAttributes.BUCKET_VOLUME); | ||
addRedirect(FluidTooltipHandler.DEFAULT_ID, id("buckets")); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "Mantle Fluid Tooltip Provider"; | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
src/main/java/slimeknights/mantle/fluid/tooltip/AbstractFluidTooltipProvider.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,128 @@ | ||
package slimeknights.mantle.fluid.tooltip; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.gson.JsonObject; | ||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
import net.minecraft.Util; | ||
import net.minecraft.data.DataGenerator; | ||
import net.minecraft.data.HashCache; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.packs.PackType; | ||
import net.minecraft.tags.TagKey; | ||
import net.minecraft.world.level.material.Fluid; | ||
import slimeknights.mantle.data.GenericDataProvider; | ||
|
||
import javax.annotation.Nullable; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** Provider for fluid tooltip information */ | ||
@SuppressWarnings("unused") | ||
public abstract class AbstractFluidTooltipProvider extends GenericDataProvider { | ||
private final Map<ResourceLocation,ResourceLocation> redirects = new HashMap<>();; | ||
private final Map<ResourceLocation,FluidUnitListBuilder> builders = new HashMap<>(); | ||
private final String modId; | ||
|
||
public AbstractFluidTooltipProvider(DataGenerator generator, String modId) { | ||
super(generator, PackType.CLIENT_RESOURCES, FluidTooltipHandler.FOLDER, FluidTooltipHandler.GSON); | ||
this.modId = modId; | ||
} | ||
|
||
/** Adds all relevant fluids to the maps */ | ||
protected abstract void addFluids(); | ||
|
||
@Override | ||
public final void run(HashCache cache) throws IOException { | ||
addFluids(); | ||
builders.forEach((key, builder) -> saveThing(cache, key, builder.build())); | ||
redirects.forEach((key, target) -> { | ||
JsonObject json = new JsonObject(); | ||
json.addProperty("redirect", target.toString()); | ||
saveThing(cache, key, json); | ||
}); | ||
} | ||
|
||
|
||
/* Helpers */ | ||
|
||
/** Creates a ResourceLocation for the local mod */ | ||
protected ResourceLocation id(String name) { | ||
return new ResourceLocation(modId, name); | ||
} | ||
|
||
/** Adds a fluid to the builder */ | ||
protected FluidUnitListBuilder add(ResourceLocation id, @Nullable TagKey<Fluid> tag) { | ||
if (redirects.containsKey(id)) { | ||
throw new IllegalArgumentException(id + " is already registered as a redirect"); | ||
} | ||
FluidUnitListBuilder newBuilder = new FluidUnitListBuilder(tag); | ||
FluidUnitListBuilder original = builders.put(id, newBuilder); | ||
if (original != null) { | ||
throw new IllegalArgumentException(id + " is already registered"); | ||
} | ||
return newBuilder; | ||
} | ||
|
||
/** Adds a fluid to the builder */ | ||
protected FluidUnitListBuilder add(String id, TagKey<Fluid> tag) { | ||
return add(id(id), tag); | ||
} | ||
|
||
/** Adds a fluid to the builder using the tag name as the ID */ | ||
protected FluidUnitListBuilder add(TagKey<Fluid> tag) { | ||
return add(id(tag.location().getPath()), tag); | ||
} | ||
|
||
/** Adds a fluid to the builder with no tag */ | ||
protected FluidUnitListBuilder add(ResourceLocation id) { | ||
return add(id, null); | ||
} | ||
|
||
/** Adds a fluid to the builder with no tag */ | ||
protected FluidUnitListBuilder add(String id) { | ||
return add(id(id), null); | ||
} | ||
|
||
/** Adds a redirect from a named builder to a target */ | ||
protected void addRedirect(ResourceLocation id, ResourceLocation target) { | ||
if (builders.containsKey(id)) { | ||
throw new IllegalArgumentException(id + " is already registered as a unit list"); | ||
} | ||
ResourceLocation original = redirects.put(id, target); | ||
if (original != null) { | ||
throw new IllegalArgumentException(id + " is already redirecting to " + original); | ||
} | ||
} | ||
|
||
/** Builder for a unit list */ | ||
@SuppressWarnings("unused") | ||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
protected class FluidUnitListBuilder { | ||
@Nullable | ||
private final TagKey<Fluid> tag; | ||
private final ImmutableList.Builder<FluidUnit> units = ImmutableList.builder(); | ||
|
||
/** Adds a unit with a full translation key */ | ||
public FluidUnitListBuilder addUnitRaw(String key, int amount) { | ||
units.add(new FluidUnit(key, amount)); | ||
return this; | ||
} | ||
|
||
/** Adds a unit local to the current mod */ | ||
public FluidUnitListBuilder addUnit(String key, int amount) { | ||
return addUnitRaw(Util.makeDescriptionId("gui", id("fluid." + key)), amount); | ||
} | ||
|
||
/** Adds a unit local to the given mod */ | ||
public FluidUnitListBuilder addUnit(String key, String domain, int amount) { | ||
return addUnitRaw(Util.makeDescriptionId("gui", new ResourceLocation(domain, "fluid." + key)), amount); | ||
} | ||
|
||
/** Builds the final instance */ | ||
private FluidUnitList build() { | ||
return new FluidUnitList(tag, units.build()); | ||
} | ||
} | ||
} |
Oops, something went wrong.