Skip to content

Commit

Permalink
Update slime islands to new structure system
Browse files Browse the repository at this point in the history
Also make them more generic, so there is potential to put them in datapacks fully later
  • Loading branch information
KnightMiner committed Mar 16, 2024
1 parent 988da5d commit f5f8669
Show file tree
Hide file tree
Showing 95 changed files with 915 additions and 737 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ forge_range=[43.3.0,)
parchment_version=2022.11.27

# Build Dependencies
mantle_version=1.10.6
mantle_range=[1.10.6,)
mantle_version=1.10.8
mantle_range=[1.10.8,)

# Optional compat
jei_version=11.6.+
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"parent": "tconstruct:world/tinkers_gadgetry",
"criteria": {
"found_island": {
"conditions": {
"player": [
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"location": {
"structure": "tconstruct:blood_island"
}
}
}
]
},
"trigger": "minecraft:location"
}
},
"display": {
"announce_to_chat": true,
"description": {
"translate": "advancements.tconstruct.world.blood_island.description"
},
"frame": "goal",
"hidden": false,
"icon": {
"item": "tconstruct:blood_slime_sapling"
},
"show_toast": true,
"title": {
"translate": "advancements.tconstruct.world.blood_island.title"
}
},
"requirements": [
[
"found_island"
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"parent": "tconstruct:world/tinkers_gadgetry",
"criteria": {
"found_island": {
"conditions": {
"player": [
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"location": {
"structure": "tconstruct:clay_island"
}
}
}
]
},
"trigger": "minecraft:location"
}
},
"display": {
"announce_to_chat": true,
"description": {
"translate": "advancements.tconstruct.world.clay_island.description"
},
"frame": "goal",
"hidden": false,
"icon": {
"item": "minecraft:clay_ball"
},
"show_toast": true,
"title": {
"translate": "advancements.tconstruct.world.clay_island.title"
}
},
"requirements": [
[
"found_island"
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"parent": "tconstruct:world/tinkers_gadgetry",
"criteria": {
"found_island": {
"conditions": {
"player": [
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"location": {
"structure": "tconstruct:earth_slime_island"
}
}
}
]
},
"trigger": "minecraft:location"
}
},
"display": {
"announce_to_chat": true,
"description": {
"translate": "advancements.tconstruct.world.earth_island.description"
},
"frame": "goal",
"hidden": false,
"icon": {
"item": "tconstruct:earth_slime_sapling"
},
"show_toast": true,
"title": {
"translate": "advancements.tconstruct.world.earth_island.title"
}
},
"requirements": [
[
"found_island"
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"parent": "tconstruct:world/tinkers_gadgetry",
"criteria": {
"found_island": {
"conditions": {
"player": [
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"location": {
"structure": "tconstruct:end_slime_island"
}
}
}
]
},
"trigger": "minecraft:location"
}
},
"display": {
"announce_to_chat": true,
"description": {
"translate": "advancements.tconstruct.world.ender_island.description"
},
"frame": "goal",
"hidden": false,
"icon": {
"item": "tconstruct:ender_slime_sapling"
},
"show_toast": true,
"title": {
"translate": "advancements.tconstruct.world.ender_island.title"
}
},
"requirements": [
[
"found_island"
]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"parent": "tconstruct:world/tinkers_gadgetry",
"criteria": {
"found_island": {
"conditions": {
"player": [
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"location": {
"structure": "tconstruct:sky_slime_island"
}
}
}
]
},
"trigger": "minecraft:location"
}
},
"display": {
"announce_to_chat": true,
"description": {
"translate": "advancements.tconstruct.world.sky_island.description"
},
"frame": "goal",
"hidden": false,
"icon": {
"item": "tconstruct:sky_slime_sapling"
},
"show_toast": true,
"title": {
"translate": "advancements.tconstruct.world.sky_island.title"
}
},
"requirements": [
[
"found_island"
]
]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"parent": "tconstruct:world/tinkers_gadgetry",
"parent": "tconstruct:world/ender_island",
"criteria": {
"crafted_boots": {
"conditions": {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.advancements.critereon.InventoryChangeTrigger;
import net.minecraft.advancements.critereon.ItemDurabilityTrigger;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.advancements.critereon.LocationPredicate;
import net.minecraft.advancements.critereon.MinMaxBounds;
import net.minecraft.advancements.critereon.NbtPredicate;
import net.minecraft.advancements.critereon.PlacedBlockTrigger;
Expand Down Expand Up @@ -77,9 +78,12 @@
import slimeknights.tconstruct.tools.data.ModifierIds;
import slimeknights.tconstruct.tools.data.material.MaterialIds;
import slimeknights.tconstruct.tools.item.ArmorSlotType;
import slimeknights.tconstruct.world.TinkerStructures;
import slimeknights.tconstruct.world.TinkerWorld;

import javax.annotation.Nullable;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
Expand Down Expand Up @@ -360,16 +364,16 @@ protected void generate() {
// exploration path
Advancement tinkersGadgetry = builder(TinkerCommons.tinkersGadgetry, resource("world/tinkers_gadgetry"), materialsAndYou, FrameType.TASK, builder ->
builder.addCriterion("crafted_book", hasItem(TinkerCommons.tinkersGadgetry)));
// builder(TinkerWorld.slimeSapling.get(SlimeType.EARTH), resource("world/earth_island"), tinkersGadgetry, FrameType.GOAL, builder ->
// builder.addCriterion("found_island", PlayerTrigger.TriggerInstance.located(LocationPredicate.inStructure(Objects.requireNonNull(TinkerStructures.configuredEarthSlimeIsland.getKey())))));
// builder(TinkerWorld.slimeSapling.get(SlimeType.SKY), resource("world/sky_island"), tinkersGadgetry, FrameType.GOAL, builder ->
// builder.addCriterion("found_island", PlayerTrigger.TriggerInstance.located(LocationPredicate.inStructure(Objects.requireNonNull(TinkerStructures.configuredSkySlimeIsland.getKey())))));
// builder(TinkerWorld.slimeSapling.get(SlimeType.BLOOD), resource("world/blood_island"), tinkersGadgetry, FrameType.GOAL, builder ->
// builder.addCriterion("found_island", PlayerTrigger.TriggerInstance.located(LocationPredicate.inStructure(Objects.requireNonNull(TinkerStructures.configuredBloodIsland.getKey())))));
// Advancement enderslimeIsland = builder(TinkerWorld.slimeSapling.get(SlimeType.ENDER), resource("world/ender_island"), tinkersGadgetry, FrameType.GOAL, builder ->
// builder.addCriterion("found_island", PlayerTrigger.TriggerInstance.located(LocationPredicate.inStructure(Objects.requireNonNull(TinkerStructures.configuredEndSlimeIsland.getKey())))));
// builder(Items.CLAY_BALL, resource("world/clay_island"), tinkersGadgetry, FrameType.GOAL, builder ->
// builder.addCriterion("found_island", PlayerTrigger.TriggerInstance.located(LocationPredicate.inStructure(Objects.requireNonNull(TinkerStructures.configuredClayIsland.getKey())))));
builder(TinkerWorld.slimeSapling.get(SlimeType.EARTH), resource("world/earth_island"), tinkersGadgetry, FrameType.GOAL, builder ->
builder.addCriterion("found_island", PlayerTrigger.TriggerInstance.located(LocationPredicate.inStructure(Objects.requireNonNull(TinkerStructures.earthSlimeIsland.getKey())))));
builder(TinkerWorld.slimeSapling.get(SlimeType.SKY), resource("world/sky_island"), tinkersGadgetry, FrameType.GOAL, builder ->
builder.addCriterion("found_island", PlayerTrigger.TriggerInstance.located(LocationPredicate.inStructure(Objects.requireNonNull(TinkerStructures.skySlimeIsland.getKey())))));
builder(TinkerWorld.slimeSapling.get(SlimeType.BLOOD), resource("world/blood_island"), tinkersGadgetry, FrameType.GOAL, builder ->
builder.addCriterion("found_island", PlayerTrigger.TriggerInstance.located(LocationPredicate.inStructure(Objects.requireNonNull(TinkerStructures.bloodIsland.getKey())))));
Advancement enderslimeIsland = builder(TinkerWorld.slimeSapling.get(SlimeType.ENDER), resource("world/ender_island"), tinkersGadgetry, FrameType.GOAL, builder ->
builder.addCriterion("found_island", PlayerTrigger.TriggerInstance.located(LocationPredicate.inStructure(Objects.requireNonNull(TinkerStructures.endSlimeIsland.getKey())))));
builder(Items.CLAY_BALL, resource("world/clay_island"), tinkersGadgetry, FrameType.GOAL, builder ->
builder.addCriterion("found_island", PlayerTrigger.TriggerInstance.located(LocationPredicate.inStructure(Objects.requireNonNull(TinkerStructures.clayIsland.getKey())))));
Advancement slimes = builder(TinkerCommons.slimeball.get(SlimeType.ICHOR), resource("world/slime_collector"), tinkersGadgetry, FrameType.TASK, builder -> {
for (SlimeType type : SlimeType.values()) {
builder.addCriterion(type.getSerializedName(), hasTag(type.getSlimeballTag()));
Expand All @@ -384,7 +388,7 @@ protected void generate() {
});
builder(TinkerGadgets.piggyBackpack, resource("world/piggybackpack"), tinkersGadgetry, FrameType.GOAL, builder ->
builder.addCriterion("used_pack", PlayerInteractTrigger.TriggerInstance.itemUsedOnEntity(EntityPredicate.Composite.ANY, ItemPredicate.Builder.item().of(TinkerGadgets.piggyBackpack), EntityPredicate.Composite.wrap(EntityPredicate.Builder.entity().of(EntityType.PIG).build()))));
Advancement slimesuit = builder(TinkerTools.slimesuit.get(ArmorSlotType.CHESTPLATE).getRenderTool(), resource("world/slimesuit"), tinkersGadgetry/*enderslimeIsland*/, FrameType.GOAL, builder ->
Advancement slimesuit = builder(TinkerTools.slimesuit.get(ArmorSlotType.CHESTPLATE).getRenderTool(), resource("world/slimesuit"), enderslimeIsland, FrameType.GOAL, builder ->
TinkerTools.slimesuit.forEach((type, armor) -> builder.addCriterion("crafted_" + type.getSerializedName(), hasItem(armor))));
builder(new MaterialIdNBT(Collections.singletonList(MaterialIds.glass)).updateStack(new ItemStack(TinkerTools.slimesuit.get(ArmorSlotType.HELMET))),
resource("world/slimeskull"), slimesuit, FrameType.CHALLENGE, builder -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package slimeknights.tconstruct.common.data;

import com.google.common.hash.Hashing;
import com.mojang.datafixers.DataFixer;
import com.mojang.datafixers.DataFixerUpper;
import net.minecraft.data.CachedOutput;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.DataProvider;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
import net.minecraft.nbt.NbtUtils;
Expand All @@ -17,25 +15,24 @@
import net.minecraft.util.datafix.DataFixers;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import net.minecraftforge.common.data.ExistingFileHelper;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.library.data.GenericNBTProvider;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.file.Path;
import java.util.Map.Entry;

/**
* Data provider to update structures to a newer data fixer upper version
* Based on https://github.com/BluSunrize/ImmersiveEngineering/blob/1.19.2/src/datagen/java/blusunrize/immersiveengineering/data/StructureUpdater.java
*/
public class StructureUpdater implements DataProvider {
public class StructureUpdater extends GenericNBTProvider {
private final String basePath;
private final String modId;
private final DataGenerator gen;
private final MultiPackResourceManager resources;

public StructureUpdater(DataGenerator gen, ExistingFileHelper helper, String modId, PackType packType, String basePath) {
this.gen = gen;
public StructureUpdater(DataGenerator generator, ExistingFileHelper helper, String modId, PackType packType, String basePath) {
super(generator, packType, basePath);
this.modId = modId;
this.basePath = basePath;
try {
Expand All @@ -48,32 +45,29 @@ public StructureUpdater(DataGenerator gen, ExistingFileHelper helper, String mod
}

@Override
public void run(CachedOutput cache) throws IOException {
public void run(CachedOutput cache) {
for(Entry<ResourceLocation,Resource> entry : resources.listResources(basePath, file -> file.getNamespace().equals(modId) && file.getPath().endsWith(".nbt")).entrySet()) {
process(entry.getKey(), entry.getValue(), cache);
process(localize(entry.getKey()), entry.getValue(), cache);
}
}

private void process(ResourceLocation location, Resource resource, CachedOutput cache) throws IOException {
CompoundTag inputNBT = NbtIo.readCompressed(resource.open());
CompoundTag converted = updateNBT(inputNBT);
if (!converted.equals(inputNBT)) {
Class<? extends DataFixer> fixerClass = DataFixers.getDataFixer().getClass();
if (!fixerClass.equals(DataFixerUpper.class)) {
throw new RuntimeException("Structures are not up to date, but unknown data fixer is in use: " + fixerClass.getName());
/** Updates the given structure */
private void process(ResourceLocation location, Resource resource, CachedOutput cache) {
try {
CompoundTag inputNBT = NbtIo.readCompressed(resource.open());
CompoundTag converted = updateNBT(inputNBT);
if (!converted.equals(inputNBT)) {
Class<? extends DataFixer> fixerClass = DataFixers.getDataFixer().getClass();
if (!fixerClass.equals(DataFixerUpper.class)) {
throw new RuntimeException("Structures are not up to date, but unknown data fixer is in use: " + fixerClass.getName());
}
saveNBT(cache, location, converted);
}
writeNBTTo(location, converted, cache);
} catch (IOException e) {
TConstruct.LOG.error("Couldn't read NBT for {}", location, e);
}
}

private void writeNBTTo(ResourceLocation loc, CompoundTag data, CachedOutput cache) throws IOException {
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
NbtIo.writeCompressed(data, bytearrayoutputstream);
byte[] bytes = bytearrayoutputstream.toByteArray();
Path outputPath = gen.getOutputFolder().resolve("data/"+loc.getNamespace()+"/"+loc.getPath());
cache.writeIfNeeded(outputPath, bytes, Hashing.sha1().hashBytes(bytes));
}

private static CompoundTag updateNBT(CompoundTag nbt) {
final CompoundTag updatedNBT = NbtUtils.update(DataFixers.getDataFixer(), DataFixTypes.STRUCTURE, nbt, nbt.getInt("DataVersion"));
StructureTemplate template = new StructureTemplate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ public void onReloadSafe(ResourceManager manager) {
for(Entry<ResourceLocation, Resource> entry : manager.listResources(FOLDER, (loc) -> loc.getPath().endsWith(".json")).entrySet()) {
// clean up ID by trimming off the extension and folder
ResourceLocation location = entry.getKey();
String path = location.getPath();
String localPath = path.substring(trim, path.length() - 5);
String localPath = JsonHelper.localize(location.getPath(), FOLDER, ".json");

// locate variant as a subfolder, and create final ID
String variant = "";
Expand Down

0 comments on commit f5f8669

Please sign in to comment.