diff --git a/build.gradle b/build.gradle index bfc6222..bfa8e04 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id "com.modrinth.minotaur" version "2.+" - id 'fabric-loom' version '1.2-SNAPSHOT' + id 'fabric-loom' version '1.7-SNAPSHOT' id 'maven-publish' } @@ -45,7 +45,7 @@ processResources { } tasks.withType(JavaCompile).configureEach { - it.options.release = 17 + it.options.release = 21 } java { @@ -54,8 +54,8 @@ java { // If you remove this line, sources will not be generated. withSourcesJar() - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 } jar { diff --git a/gradle.properties b/gradle.properties index d9504af..5ab2e23 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,15 +1,15 @@ org.gradle.jvmargs = -Xmx1G #Fabric properties -minecraft_version=1.20.1 -yarn_mappings=1.20.1+build.9 -loader_version=0.14.21 +minecraft_version=1.21 +yarn_mappings=1.21+build.7 +loader_version=0.15.11 -#Fabric -fabric_version=0.84.0+1.20.1 +# Fabric API +fabric_version=0.100.4+1.21 #Mod properties -mod_version = 0.9.4 +mod_version = 0.9.5 maven_group = quimufu.structure_item archives_base_name = structure_item diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 15de902..129d130 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Sun Jun 16 00:12:45 CEST 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/quimufu/structure_item/MyItem.java b/src/main/java/quimufu/structure_item/MyItem.java index fb66fd0..5feb17d 100644 --- a/src/main/java/quimufu/structure_item/MyItem.java +++ b/src/main/java/quimufu/structure_item/MyItem.java @@ -1,12 +1,13 @@ package quimufu.structure_item; import com.google.common.collect.Lists; -import net.fabricmc.fabric.api.item.v1.FabricItemSettings; import net.minecraft.block.Block; -import net.minecraft.client.item.TooltipContext; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.NbtComponent; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUsageContext; +import net.minecraft.item.tooltip.TooltipType; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtHelper; @@ -25,6 +26,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3i; import net.minecraft.world.World; +import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.Optional; @@ -32,18 +34,19 @@ import java.util.Optional; import static quimufu.structure_item.StructureItemMod.LOGGER; public class MyItem extends Item { - static Item.Settings p = new FabricItemSettings().fireproof().rarity(Rarity.RARE).maxCount(1); + static Item.Settings p = new Item.Settings().fireproof().rarity(Rarity.RARE).maxCount(1); public MyItem() { super(p); } @Override - public void appendTooltip(ItemStack itemStack, World world, List texts, TooltipContext tooltipFlag) { - if (!itemStack.hasNbt() || !itemStack.getNbt().contains("structure", 8)) { + public void appendTooltip(ItemStack itemStack, Item.TooltipContext context, List texts, TooltipType tooltipFlag) { + NbtComponent nbtComponent = itemStack.get(DataComponentTypes.CUSTOM_DATA); + if (nbtComponent == null || nbtComponent.isEmpty() || !nbtComponent.getNbt().contains("structure", 8)) { texts.add((Text.translatable("item.structure_item.item.tooltip.tag.invalid")).formatted(Formatting.RED)); } else { - NbtCompound tag = itemStack.getNbt(); + NbtCompound tag = nbtComponent.getNbt(); if (tooltipFlag.isAdvanced()) { texts.add(Text.translatable("item.structure_item.item.tooltip.structure")); texts.add(Text.literal(" " + tag.getString("structure"))); @@ -52,7 +55,8 @@ public class MyItem extends Item { texts.add(Text.literal(" " + tag.getString("allowedOn"))); } if (tag.contains("offset", 10)) { - BlockPos offset = NbtHelper.toBlockPos(tag.getCompound("offset")); + + BlockPos offset = toBlockPosNewOrOld(tag, "offset"); texts.add(Text.translatable("item.structure_item.item.tooltip.fixed.offset")); Text c = Text.translatable("item.structure_item.item.tooltip.xyz", Text.literal(String.valueOf(offset.getX())), @@ -111,6 +115,14 @@ public class MyItem extends Item { } + private static @NotNull BlockPos toBlockPosNewOrOld(NbtCompound tag, String key) { + return NbtHelper.toBlockPos(tag, key).orElseGet(() -> toBlockPosOld(tag.getCompound(key))); + } + + public static BlockPos toBlockPosOld(NbtCompound nbt) { + return new BlockPos(nbt.getInt("X"), nbt.getInt("Y"), nbt.getInt("Z")); + } + @Override public ActionResult useOnBlock(ItemUsageContext c) { if (!c.getWorld().isClient) { @@ -120,8 +132,9 @@ public class MyItem extends Item { } else { player = null; } - NbtCompound tag = c.getStack().getNbt(); - if (tag == null) { + NbtCompound tag; + NbtComponent nbtComponent = c.getStack().get(DataComponentTypes.CUSTOM_DATA); + if (nbtComponent == null || (tag = nbtComponent.getNbt()) == null) { Text message = Text.translatable("items.structure.spawner.no.tag"); sendPlayerChat(player, message); @@ -165,15 +178,15 @@ public class MyItem extends Item { sendPlayerChat(player, message); return ActionResult.FAIL; } - Optional xOpt = ((ServerWorld) c.getWorld()).getStructureTemplateManager().getTemplate(structureResourceID); - if (xOpt.isEmpty()) { + Optional optionalStructureTemplate = ((ServerWorld) c.getWorld()).getStructureTemplateManager().getTemplate(structureResourceID); + if (optionalStructureTemplate.isEmpty()) { Text message = Text.translatable("items.structure.spawner.structure.nonexistent", Text.literal(structureResourceID.toString())); sendPlayerChat(player, message); return ActionResult.FAIL; } - StructureTemplate x = xOpt.get(); + StructureTemplate structureTemplate = optionalStructureTemplate.get(); BlockRotation rotation = BlockRotation.NONE; if (tag.contains("rotate", NbtElement.STRING_TYPE)) { @@ -195,10 +208,10 @@ public class MyItem extends Item { BlockPos loc = c.getBlockPos().offset(c.getSide()); if (tag.contains("offset", 10)) { - BlockPos offset = NbtHelper.toBlockPos(tag.getCompound("offset")); + BlockPos offset = toBlockPosNewOrOld(tag, "offset"); loc = loc.add(offset); - Vec3i size = x.getSize(); + Vec3i size = structureTemplate.getSize(); switch (rotation) { case CLOCKWISE_90 -> loc = loc.add(new Vec3i(size.getX() - 1, 0, 0)); case CLOCKWISE_180 -> loc = loc.add(new Vec3i(size.getX() - 1, 0, size.getZ() - 1)); @@ -209,7 +222,7 @@ public class MyItem extends Item { try { StructureOffsetSettings offset = StructureOffsetSettings.ofTag(tag.getCompound("offsetV2")); offset.setRotation(rotation); - Vec3i size = x.getSize(); + Vec3i size = structureTemplate.getSize(); loc = loc.add(offset.getEffective(direction, size)); } catch (Exception e) { Text message = @@ -221,7 +234,7 @@ public class MyItem extends Item { Direction direction = c.getSide().getOpposite(); StructureOffsetSettings offset = StructureOffsetSettings.dynamic(); offset.setRotation(rotation); - Vec3i size = x.getSize(); + Vec3i size = structureTemplate.getSize(); loc = loc.add(offset.getEffective(direction, size)); } @@ -252,11 +265,11 @@ public class MyItem extends Item { ps.setWorld(c.getWorld()) - .setSize(x.getSize()) + .setSize(structureTemplate.getSize()) .setMirror(BlockMirror.NONE) .setRotation(rotation); try { - if (x.place((ServerWorld) c.getWorld(), loc, BlockPos.ORIGIN, ps, c.getWorld().getRandom(), 2)) { + if (structureTemplate.place((ServerWorld) c.getWorld(), loc, BlockPos.ORIGIN, ps, c.getWorld().getRandom(), 2)) { c.getStack().decrement(1); return ActionResult.SUCCESS; } @@ -307,7 +320,6 @@ public class MyItem extends Item { private static void sendPlayerChat(ServerPlayerEntity player, Text message) { if (player != null) player.sendMessage(message, false); - LOGGER.info(message.getContent()); } private Block getBlock(String loc) { diff --git a/src/main/java/quimufu/structure_item/MyPlacementSettings.java b/src/main/java/quimufu/structure_item/MyPlacementSettings.java index 96f1355..bb5e714 100644 --- a/src/main/java/quimufu/structure_item/MyPlacementSettings.java +++ b/src/main/java/quimufu/structure_item/MyPlacementSettings.java @@ -10,6 +10,7 @@ import net.minecraft.structure.StructureTemplate; import net.minecraft.structure.processor.BlockIgnoreStructureProcessor; import net.minecraft.structure.processor.StructureProcessor; import net.minecraft.structure.processor.StructureProcessorType; +import net.minecraft.util.math.BlockBox; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; import net.minecraft.util.math.Vec3i; @@ -31,7 +32,7 @@ public class MyPlacementSettings extends StructurePlacementData { } public void forbidOverwrite(List blocks) { - if (blocks.size() == 0) { + if (blocks.isEmpty()) { blacklist = null; return; } @@ -65,9 +66,9 @@ public class MyPlacementSettings extends StructurePlacementData { public StructureTemplate.StructureBlockInfo process(WorldView world, BlockPos pos, BlockPos pivot, StructureTemplate.StructureBlockInfo originalBlockInfo, StructureTemplate.StructureBlockInfo currentBlockInfo, StructurePlacementData data) { if (entitiesWithinAABB == null) { if (shouldReplaceEntities()) { - entitiesWithinAABB = ((ServerWorld) world).getNonSpectatingEntities(PlayerEntity.class, new Box(pos.subtract(size), pos.add(size))); + entitiesWithinAABB = ((ServerWorld) world).getNonSpectatingEntities(PlayerEntity.class, Box.enclosing(pos.subtract(size), pos.add(size))); } else { - entitiesWithinAABB = ((ServerWorld) world).getNonSpectatingEntities(Entity.class, new Box(pos.subtract(size), pos.add(size))); + entitiesWithinAABB = ((ServerWorld) world).getNonSpectatingEntities(Entity.class, Box.enclosing(pos.subtract(size), pos.add(size))); } } BlockPos posToCheck;