diff --git a/build.gradle b/build.gradle index bfa8e04..1e4aeb7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id "com.modrinth.minotaur" version "2.+" - id 'fabric-loom' version '1.7-SNAPSHOT' + id 'fabric-loom' version '1.9-SNAPSHOT' id 'maven-publish' } diff --git a/gradle.properties b/gradle.properties index b767522..489352b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,15 +1,15 @@ org.gradle.jvmargs = -Xmx1G #Fabric properties -minecraft_version=1.21.1 -yarn_mappings=1.21.1+build.3 -loader_version=0.16.7 +minecraft_version=1.21.4 +yarn_mappings=1.21.4+build.7 +loader_version=0.16.9 # Fabric API -fabric_version=0.105.0+1.21.1 +fabric_version=0.114.0+1.21.4 #Mod properties -mod_version = 0.9.6 +mod_version = 0.9.7 maven_group = quimufu.structure_item archives_base_name = structure_item diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e644113..a4b76b9 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index df97d72..cea7a79 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index b740cf1..f5feea6 100755 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -84,7 +86,8 @@ done # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum diff --git a/gradlew.bat b/gradlew.bat index 7101f8e..9b42019 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## diff --git a/src/main/java/quimufu/structure_item/MyItem.java b/src/main/java/quimufu/structure_item/MyItem.java index 5feb17d..96a07ed 100644 --- a/src/main/java/quimufu/structure_item/MyItem.java +++ b/src/main/java/quimufu/structure_item/MyItem.java @@ -34,9 +34,8 @@ import java.util.Optional; import static quimufu.structure_item.StructureItemMod.LOGGER; public class MyItem extends Item { - static Item.Settings p = new Item.Settings().fireproof().rarity(Rarity.RARE).maxCount(1); - public MyItem() { + public MyItem(Item.Settings p) { super(p); } @@ -90,6 +89,19 @@ public class MyItem extends Item { break; } } + } else if (tag.contains("whitelist", 9)) { + texts.add(Text.translatable("item.structure_item.item.tooltip.whitelist")); + NbtList bl = tag.getList("whitelist", 8); + int i = 0; + for (NbtElement entry : bl) { + texts.add(Text.literal(" " + entry.asString())); + i++; + if (i == 4) { + texts.add(Text.translatable("item.structure_item.item.tooltip.whitelist.more", + Text.literal(String.valueOf(bl.size() - i)))); + break; + } + } } if (!tag.contains("replaceEntities", 99) || tag.getBoolean("replaceEntities")) { texts.add(Text.translatable("item.structure_item.item.tooltip.replaceEntities")); @@ -261,6 +273,22 @@ public class MyItem extends Item { } ps.forbidOverwrite(blacklist); + } else if (tag.contains("whitelist", 9)) { + NbtList bl = tag.getList("whitelist", 8); + List whitelist = Lists.newArrayList(); + for (NbtElement b : bl) { + Block block = getBlock(b.asString()); + if (block != null) { + whitelist.add(block); + } else { + Text message = + Text.translatable("items.structure.spawner.invalid.block", + Text.literal(b.asString())); + sendPlayerChat(player, message); + } + + } + ps.overwriteOnly(whitelist); } diff --git a/src/main/java/quimufu/structure_item/MyPlacementSettings.java b/src/main/java/quimufu/structure_item/MyPlacementSettings.java index bb5e714..b158eee 100644 --- a/src/main/java/quimufu/structure_item/MyPlacementSettings.java +++ b/src/main/java/quimufu/structure_item/MyPlacementSettings.java @@ -22,6 +22,7 @@ import java.util.List; public class MyPlacementSettings extends StructurePlacementData { private List blacklist; + private List whitelist; private World world; private Vec3i size; private boolean replaceEntities = true; @@ -37,6 +38,7 @@ public class MyPlacementSettings extends StructurePlacementData { return; } blacklist = Lists.newArrayList(blocks); + this.whitelist = null; } public MyPlacementSettings setWorld(World w) { @@ -57,6 +59,15 @@ public class MyPlacementSettings extends StructurePlacementData { this.replaceEntities = replaceEntities; } + public void overwriteOnly(List whitelist) { + if (whitelist.isEmpty()) { + this.whitelist = null; + return; + } + this.whitelist = Lists.newArrayList(whitelist); + this.blacklist = null; + } + public class CheckingStructureProcess extends StructureProcessor { List entitiesWithinAABB; @@ -79,7 +90,10 @@ public class MyPlacementSettings extends StructurePlacementData { } } Block blockToCheck = world.getBlockState(posToCheck).getBlock(); - if (blacklist.contains(blockToCheck)) { + if (blacklist != null && blacklist.contains(blockToCheck)) { + throw new PlacementNotAllowedException(blockToCheck.getName(), posToCheck); + } + if (whitelist != null && !whitelist.contains(blockToCheck)) { throw new PlacementNotAllowedException(blockToCheck.getName(), posToCheck); } } diff --git a/src/main/java/quimufu/structure_item/StructureItemMod.java b/src/main/java/quimufu/structure_item/StructureItemMod.java index 892915c..f6a3e64 100644 --- a/src/main/java/quimufu/structure_item/StructureItemMod.java +++ b/src/main/java/quimufu/structure_item/StructureItemMod.java @@ -2,8 +2,13 @@ package quimufu.structure_item; import net.fabricmc.api.ModInitializer; import net.minecraft.item.Item; +import net.minecraft.item.Items; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.util.Identifier; +import net.minecraft.util.Rarity; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -15,12 +20,18 @@ public class StructureItemMod implements ModInitializer { public static final String MOD_ID = "structure_item"; public static final String MOD_NAME = "Structure Item Mod (Fabric)"; - public static final Item item = new MyItem(); + public static final Item ITEM = Items.register( + RegistryKey.of(RegistryKeys.ITEM, Identifier.of(MOD_ID, "item")), + MyItem::new, + new Item.Settings() + .fireproof() + .rarity(Rarity.RARE) + .maxCount(1) + ); @Override public void onInitialize() { log(Level.INFO, "Initializing"); - Registry.register(Registries.ITEM, MOD_ID + ":item", item); } public static void log(Level level, String message) { diff --git a/src/main/resources/assets/structure_item/items/item.json b/src/main/resources/assets/structure_item/items/item.json new file mode 100644 index 0000000..c97ecbf --- /dev/null +++ b/src/main/resources/assets/structure_item/items/item.json @@ -0,0 +1,6 @@ +{ + "model": { + "type": "minecraft:model", + "model": "structure_item:item/item" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/structure_item/lang/en_us.json b/src/main/resources/assets/structure_item/lang/en_us.json index 840b9b6..9c7cdf0 100644 --- a/src/main/resources/assets/structure_item/lang/en_us.json +++ b/src/main/resources/assets/structure_item/lang/en_us.json @@ -22,6 +22,8 @@ "item.structure_item.item.tooltip.dynamic.offset": "Dynamic offset", "item.structure_item.item.tooltip.blacklist": "Blacklist:", "item.structure_item.item.tooltip.blacklist.more": " And %s more...", + "item.structure_item.item.tooltip.whitelist": "Whitelist:", + "item.structure_item.item.tooltip.whitelist.more": " And %s more...", "item.structure_item.item.tooltip.replaceEntities": "Deletes Entities in the way", "item.structure_item.item.tooltip.doNotReplaceEntities": "Doesn't allow placement with entities in the way", "item.structure_item.item.tooltip.placeEntities": "Places contained Entities", diff --git a/src/main/resources/assets/structure_item/models/item/item.json b/src/main/resources/assets/structure_item/models/item/item.json index f13ea55..a55f302 100644 --- a/src/main/resources/assets/structure_item/models/item/item.json +++ b/src/main/resources/assets/structure_item/models/item/item.json @@ -1,6 +1,6 @@ { - "parent": "item/handheld", + "parent": "minecraft:item/handheld", "textures": { - "layer0": "item/stick" + "layer0": "minecraft:item/stick" } } \ No newline at end of file