update to 1.21
This commit is contained in:
parent
e1eef02be4
commit
3d74cf7a7b
|
@ -1,6 +1,6 @@
|
||||||
plugins {
|
plugins {
|
||||||
id "com.modrinth.minotaur" version "2.+"
|
id "com.modrinth.minotaur" version "2.+"
|
||||||
id 'fabric-loom' version '1.2-SNAPSHOT'
|
id 'fabric-loom' version '1.7-SNAPSHOT'
|
||||||
id 'maven-publish'
|
id 'maven-publish'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ processResources {
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType(JavaCompile).configureEach {
|
tasks.withType(JavaCompile).configureEach {
|
||||||
it.options.release = 17
|
it.options.release = 21
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
|
@ -54,8 +54,8 @@ java {
|
||||||
// If you remove this line, sources will not be generated.
|
// If you remove this line, sources will not be generated.
|
||||||
withSourcesJar()
|
withSourcesJar()
|
||||||
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = JavaVersion.VERSION_21
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
targetCompatibility = JavaVersion.VERSION_21
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
org.gradle.jvmargs = -Xmx1G
|
org.gradle.jvmargs = -Xmx1G
|
||||||
|
|
||||||
#Fabric properties
|
#Fabric properties
|
||||||
minecraft_version=1.20.1
|
minecraft_version=1.21
|
||||||
yarn_mappings=1.20.1+build.9
|
yarn_mappings=1.21+build.7
|
||||||
loader_version=0.14.21
|
loader_version=0.15.11
|
||||||
|
|
||||||
#Fabric
|
# Fabric API
|
||||||
fabric_version=0.84.0+1.20.1
|
fabric_version=0.100.4+1.21
|
||||||
|
|
||||||
#Mod properties
|
#Mod properties
|
||||||
mod_version = 0.9.4
|
mod_version = 0.9.5
|
||||||
maven_group = quimufu.structure_item
|
maven_group = quimufu.structure_item
|
||||||
archives_base_name = structure_item
|
archives_base_name = structure_item
|
||||||
|
|
||||||
|
|
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,5 +1,6 @@
|
||||||
|
#Sun Jun 16 00:12:45 CEST 2024
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
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
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package quimufu.structure_item;
|
package quimufu.structure_item;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
|
||||||
import net.minecraft.block.Block;
|
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.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.ItemUsageContext;
|
import net.minecraft.item.ItemUsageContext;
|
||||||
|
import net.minecraft.item.tooltip.TooltipType;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.nbt.NbtElement;
|
import net.minecraft.nbt.NbtElement;
|
||||||
import net.minecraft.nbt.NbtHelper;
|
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.Direction;
|
||||||
import net.minecraft.util.math.Vec3i;
|
import net.minecraft.util.math.Vec3i;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -32,18 +34,19 @@ import java.util.Optional;
|
||||||
import static quimufu.structure_item.StructureItemMod.LOGGER;
|
import static quimufu.structure_item.StructureItemMod.LOGGER;
|
||||||
|
|
||||||
public class MyItem extends Item {
|
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() {
|
public MyItem() {
|
||||||
super(p);
|
super(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appendTooltip(ItemStack itemStack, World world, List<Text> texts, TooltipContext tooltipFlag) {
|
public void appendTooltip(ItemStack itemStack, Item.TooltipContext context, List<Text> texts, TooltipType tooltipFlag) {
|
||||||
if (!itemStack.hasNbt() || !itemStack.getNbt().contains("structure", 8)) {
|
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));
|
texts.add((Text.translatable("item.structure_item.item.tooltip.tag.invalid")).formatted(Formatting.RED));
|
||||||
} else {
|
} else {
|
||||||
NbtCompound tag = itemStack.getNbt();
|
NbtCompound tag = nbtComponent.getNbt();
|
||||||
if (tooltipFlag.isAdvanced()) {
|
if (tooltipFlag.isAdvanced()) {
|
||||||
texts.add(Text.translatable("item.structure_item.item.tooltip.structure"));
|
texts.add(Text.translatable("item.structure_item.item.tooltip.structure"));
|
||||||
texts.add(Text.literal(" " + tag.getString("structure")));
|
texts.add(Text.literal(" " + tag.getString("structure")));
|
||||||
|
@ -52,7 +55,8 @@ public class MyItem extends Item {
|
||||||
texts.add(Text.literal(" " + tag.getString("allowedOn")));
|
texts.add(Text.literal(" " + tag.getString("allowedOn")));
|
||||||
}
|
}
|
||||||
if (tag.contains("offset", 10)) {
|
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"));
|
texts.add(Text.translatable("item.structure_item.item.tooltip.fixed.offset"));
|
||||||
Text c = Text.translatable("item.structure_item.item.tooltip.xyz",
|
Text c = Text.translatable("item.structure_item.item.tooltip.xyz",
|
||||||
Text.literal(String.valueOf(offset.getX())),
|
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
|
@Override
|
||||||
public ActionResult useOnBlock(ItemUsageContext c) {
|
public ActionResult useOnBlock(ItemUsageContext c) {
|
||||||
if (!c.getWorld().isClient) {
|
if (!c.getWorld().isClient) {
|
||||||
|
@ -120,8 +132,9 @@ public class MyItem extends Item {
|
||||||
} else {
|
} else {
|
||||||
player = null;
|
player = null;
|
||||||
}
|
}
|
||||||
NbtCompound tag = c.getStack().getNbt();
|
NbtCompound tag;
|
||||||
if (tag == null) {
|
NbtComponent nbtComponent = c.getStack().get(DataComponentTypes.CUSTOM_DATA);
|
||||||
|
if (nbtComponent == null || (tag = nbtComponent.getNbt()) == null) {
|
||||||
Text message =
|
Text message =
|
||||||
Text.translatable("items.structure.spawner.no.tag");
|
Text.translatable("items.structure.spawner.no.tag");
|
||||||
sendPlayerChat(player, message);
|
sendPlayerChat(player, message);
|
||||||
|
@ -165,15 +178,15 @@ public class MyItem extends Item {
|
||||||
sendPlayerChat(player, message);
|
sendPlayerChat(player, message);
|
||||||
return ActionResult.FAIL;
|
return ActionResult.FAIL;
|
||||||
}
|
}
|
||||||
Optional<StructureTemplate> xOpt = ((ServerWorld) c.getWorld()).getStructureTemplateManager().getTemplate(structureResourceID);
|
Optional<StructureTemplate> optionalStructureTemplate = ((ServerWorld) c.getWorld()).getStructureTemplateManager().getTemplate(structureResourceID);
|
||||||
if (xOpt.isEmpty()) {
|
if (optionalStructureTemplate.isEmpty()) {
|
||||||
Text message =
|
Text message =
|
||||||
Text.translatable("items.structure.spawner.structure.nonexistent",
|
Text.translatable("items.structure.spawner.structure.nonexistent",
|
||||||
Text.literal(structureResourceID.toString()));
|
Text.literal(structureResourceID.toString()));
|
||||||
sendPlayerChat(player, message);
|
sendPlayerChat(player, message);
|
||||||
return ActionResult.FAIL;
|
return ActionResult.FAIL;
|
||||||
}
|
}
|
||||||
StructureTemplate x = xOpt.get();
|
StructureTemplate structureTemplate = optionalStructureTemplate.get();
|
||||||
|
|
||||||
BlockRotation rotation = BlockRotation.NONE;
|
BlockRotation rotation = BlockRotation.NONE;
|
||||||
if (tag.contains("rotate", NbtElement.STRING_TYPE)) {
|
if (tag.contains("rotate", NbtElement.STRING_TYPE)) {
|
||||||
|
@ -195,10 +208,10 @@ public class MyItem extends Item {
|
||||||
|
|
||||||
BlockPos loc = c.getBlockPos().offset(c.getSide());
|
BlockPos loc = c.getBlockPos().offset(c.getSide());
|
||||||
if (tag.contains("offset", 10)) {
|
if (tag.contains("offset", 10)) {
|
||||||
BlockPos offset = NbtHelper.toBlockPos(tag.getCompound("offset"));
|
BlockPos offset = toBlockPosNewOrOld(tag, "offset");
|
||||||
loc = loc.add(offset);
|
loc = loc.add(offset);
|
||||||
|
|
||||||
Vec3i size = x.getSize();
|
Vec3i size = structureTemplate.getSize();
|
||||||
switch (rotation) {
|
switch (rotation) {
|
||||||
case CLOCKWISE_90 -> loc = loc.add(new Vec3i(size.getX() - 1, 0, 0));
|
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));
|
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 {
|
try {
|
||||||
StructureOffsetSettings offset = StructureOffsetSettings.ofTag(tag.getCompound("offsetV2"));
|
StructureOffsetSettings offset = StructureOffsetSettings.ofTag(tag.getCompound("offsetV2"));
|
||||||
offset.setRotation(rotation);
|
offset.setRotation(rotation);
|
||||||
Vec3i size = x.getSize();
|
Vec3i size = structureTemplate.getSize();
|
||||||
loc = loc.add(offset.getEffective(direction, size));
|
loc = loc.add(offset.getEffective(direction, size));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Text message =
|
Text message =
|
||||||
|
@ -221,7 +234,7 @@ public class MyItem extends Item {
|
||||||
Direction direction = c.getSide().getOpposite();
|
Direction direction = c.getSide().getOpposite();
|
||||||
StructureOffsetSettings offset = StructureOffsetSettings.dynamic();
|
StructureOffsetSettings offset = StructureOffsetSettings.dynamic();
|
||||||
offset.setRotation(rotation);
|
offset.setRotation(rotation);
|
||||||
Vec3i size = x.getSize();
|
Vec3i size = structureTemplate.getSize();
|
||||||
loc = loc.add(offset.getEffective(direction, size));
|
loc = loc.add(offset.getEffective(direction, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,11 +265,11 @@ public class MyItem extends Item {
|
||||||
|
|
||||||
|
|
||||||
ps.setWorld(c.getWorld())
|
ps.setWorld(c.getWorld())
|
||||||
.setSize(x.getSize())
|
.setSize(structureTemplate.getSize())
|
||||||
.setMirror(BlockMirror.NONE)
|
.setMirror(BlockMirror.NONE)
|
||||||
.setRotation(rotation);
|
.setRotation(rotation);
|
||||||
try {
|
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);
|
c.getStack().decrement(1);
|
||||||
return ActionResult.SUCCESS;
|
return ActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -307,7 +320,6 @@ public class MyItem extends Item {
|
||||||
private static void sendPlayerChat(ServerPlayerEntity player, Text message) {
|
private static void sendPlayerChat(ServerPlayerEntity player, Text message) {
|
||||||
if (player != null)
|
if (player != null)
|
||||||
player.sendMessage(message, false);
|
player.sendMessage(message, false);
|
||||||
LOGGER.info(message.getContent());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Block getBlock(String loc) {
|
private Block getBlock(String loc) {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import net.minecraft.structure.StructureTemplate;
|
||||||
import net.minecraft.structure.processor.BlockIgnoreStructureProcessor;
|
import net.minecraft.structure.processor.BlockIgnoreStructureProcessor;
|
||||||
import net.minecraft.structure.processor.StructureProcessor;
|
import net.minecraft.structure.processor.StructureProcessor;
|
||||||
import net.minecraft.structure.processor.StructureProcessorType;
|
import net.minecraft.structure.processor.StructureProcessorType;
|
||||||
|
import net.minecraft.util.math.BlockBox;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Box;
|
import net.minecraft.util.math.Box;
|
||||||
import net.minecraft.util.math.Vec3i;
|
import net.minecraft.util.math.Vec3i;
|
||||||
|
@ -31,7 +32,7 @@ public class MyPlacementSettings extends StructurePlacementData {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void forbidOverwrite(List<Block> blocks) {
|
public void forbidOverwrite(List<Block> blocks) {
|
||||||
if (blocks.size() == 0) {
|
if (blocks.isEmpty()) {
|
||||||
blacklist = null;
|
blacklist = null;
|
||||||
return;
|
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) {
|
public StructureTemplate.StructureBlockInfo process(WorldView world, BlockPos pos, BlockPos pivot, StructureTemplate.StructureBlockInfo originalBlockInfo, StructureTemplate.StructureBlockInfo currentBlockInfo, StructurePlacementData data) {
|
||||||
if (entitiesWithinAABB == null) {
|
if (entitiesWithinAABB == null) {
|
||||||
if (shouldReplaceEntities()) {
|
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 {
|
} 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;
|
BlockPos posToCheck;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user