update to 1.20.1
This commit is contained in:
parent
8f0c9fdf56
commit
db1d4b2df2
99
build.gradle
99
build.gradle
|
@ -1,79 +1,102 @@
|
||||||
plugins {
|
plugins {
|
||||||
id 'fabric-loom' version '0.6-SNAPSHOT'
|
id "com.modrinth.minotaur" version "2.+"
|
||||||
|
id 'fabric-loom' version '1.2-SNAPSHOT'
|
||||||
id 'maven-publish'
|
id 'maven-publish'
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
|
||||||
targetCompatibility = JavaVersion.VERSION_1_8
|
|
||||||
|
|
||||||
archivesBaseName = project.archives_base_name
|
|
||||||
version = project.mod_version
|
version = project.mod_version
|
||||||
group = project.maven_group
|
group = project.maven_group
|
||||||
|
|
||||||
minecraft {
|
base {
|
||||||
|
archivesName = project.archives_base_name
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
// Add repositories to retrieve artifacts from in here.
|
||||||
|
// You should only use this when depending on other mods because
|
||||||
|
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
|
||||||
|
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
|
||||||
|
// for more information about repositories.
|
||||||
|
}
|
||||||
|
|
||||||
|
loom {
|
||||||
|
splitEnvironmentSourceSets()
|
||||||
|
|
||||||
|
mods {
|
||||||
|
"modid" {
|
||||||
|
sourceSet sourceSets.main
|
||||||
|
sourceSet sourceSets.client
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
//to change the versions see the gradle.properties file
|
// To change the versions see the gradle.properties file
|
||||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||||
|
|
||||||
|
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||||
|
|
||||||
|
// Uncomment the following line to enable the deprecated Fabric API modules.
|
||||||
|
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.
|
||||||
|
|
||||||
|
// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
inputs.property "version", project.version
|
inputs.property "version", project.version
|
||||||
|
|
||||||
from(sourceSets.main.resources.srcDirs) {
|
filesMatching("fabric.mod.json") {
|
||||||
include "fabric.mod.json"
|
|
||||||
expand "version": project.version
|
expand "version": project.version
|
||||||
}
|
}
|
||||||
|
|
||||||
from(sourceSets.main.resources.srcDirs) {
|
|
||||||
exclude "fabric.mod.json"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
tasks.withType(JavaCompile).configureEach {
|
||||||
// this fixes some edge cases with special characters not displaying correctly
|
it.options.release = 17
|
||||||
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
|
||||||
tasks.withType(JavaCompile) {
|
|
||||||
options.encoding = "UTF-8"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
java {
|
||||||
// if it is present.
|
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
||||||
// If you remove this task, sources will not be generated.
|
// if it is present.
|
||||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
// If you remove this line, sources will not be generated.
|
||||||
classifier = "sources"
|
withSourcesJar()
|
||||||
from sourceSets.main.allSource
|
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
from "LICENSE"
|
from("LICENSE") {
|
||||||
|
rename { "${it}_${project.archivesBaseName}"}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import com.modrinth.minotaur.dependencies.ModDependency
|
||||||
|
|
||||||
|
modrinth {
|
||||||
|
projectId = 'lwR0Ovmu' // The ID of your Modrinth project. Slugs will not work.
|
||||||
|
uploadFile = remapJar // Tells Minotaur to use the remapped jar
|
||||||
|
versionType = "beta"
|
||||||
|
dependencies = [
|
||||||
|
new ModDependency('P7dR8mSH', 'required'), //required dependency on Fabric API
|
||||||
|
]
|
||||||
|
}
|
||||||
// configure the maven publication
|
// configure the maven publication
|
||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
mavenJava(MavenPublication) {
|
mavenJava(MavenPublication) {
|
||||||
// add all the jars that should be included when publishing to maven
|
from components.java
|
||||||
artifact(jar) {
|
|
||||||
builtBy remapJar
|
|
||||||
}
|
|
||||||
artifact("${project.buildDir.absolutePath}/libs/${archivesBaseName}-${project.version}.jar"){
|
|
||||||
builtBy remapJar
|
|
||||||
}
|
|
||||||
artifact(sourcesJar) {
|
|
||||||
builtBy remapSourcesJar
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// select the repositories you want to publish to
|
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
|
||||||
repositories {
|
repositories {
|
||||||
// uncomment to publish to the local maven
|
// Add repositories to publish to here.
|
||||||
// mavenLocal()
|
// Notice: This block does NOT have the same function as the block in the top level.
|
||||||
|
// The repositories here will be used for publishing your artifact, not for
|
||||||
|
// retrieving dependencies.
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,15 +1,15 @@
|
||||||
org.gradle.jvmargs = -Xmx1G
|
org.gradle.jvmargs = -Xmx1G
|
||||||
|
|
||||||
#Fabric properties
|
#Fabric properties
|
||||||
minecraft_version=1.16.5
|
minecraft_version=1.20.1
|
||||||
yarn_mappings=1.16.5+build.6
|
yarn_mappings=1.20.1+build.9
|
||||||
loader_version=0.11.3
|
loader_version=0.14.21
|
||||||
|
|
||||||
#Fabric api
|
#Fabric
|
||||||
fabric_version=0.32.5+1.16
|
fabric_version=0.84.0+1.20.1
|
||||||
|
|
||||||
#Mod properties
|
#Mod properties
|
||||||
mod_version = 0.8.1
|
mod_version = 0.9.1
|
||||||
maven_group = quimufu.structure_item
|
maven_group = quimufu.structure_item
|
||||||
archives_base_name = structure_item
|
archives_base_name = structure_item
|
||||||
|
|
||||||
|
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,5 +1,5 @@
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|
|
@ -1,89 +1,93 @@
|
||||||
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.client.item.TooltipContext;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemGroup;
|
import net.minecraft.item.ItemGroup;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.ItemUsageContext;
|
import net.minecraft.item.ItemUsageContext;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.nbt.ListTag;
|
import net.minecraft.nbt.NbtElement;
|
||||||
import net.minecraft.nbt.NbtHelper;
|
import net.minecraft.nbt.NbtHelper;
|
||||||
import net.minecraft.nbt.Tag;
|
import net.minecraft.nbt.NbtList;
|
||||||
|
import net.minecraft.network.packet.s2c.play.SubtitleS2CPacket;
|
||||||
import net.minecraft.network.packet.s2c.play.TitleS2CPacket;
|
import net.minecraft.network.packet.s2c.play.TitleS2CPacket;
|
||||||
|
import net.minecraft.registry.DefaultedRegistry;
|
||||||
|
import net.minecraft.registry.Registries;
|
||||||
|
import net.minecraft.registry.Registry;
|
||||||
|
import net.minecraft.registry.SimpleDefaultedRegistry;
|
||||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.structure.Structure;
|
import net.minecraft.structure.StructureTemplate;
|
||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.text.LiteralTextContent;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.text.TranslatableText;
|
|
||||||
import net.minecraft.util.*;
|
import net.minecraft.util.*;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.registry.DefaultedRegistry;
|
import net.minecraft.util.math.Vec3i;
|
||||||
import net.minecraft.util.registry.Registry;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
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 Item.Settings()).group(ItemGroup.REDSTONE).maxCount(1);
|
static Item.Settings p = new FabricItemSettings().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, World world, List<Text> texts, TooltipContext tooltipFlag) {
|
||||||
if (!itemStack.hasTag() || !itemStack.getTag().contains("structure", 8)) {
|
if (!itemStack.hasNbt() || !itemStack.getNbt().contains("structure", 8)) {
|
||||||
texts.add((new TranslatableText("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 {
|
||||||
CompoundTag tag = itemStack.getTag();
|
NbtCompound tag = itemStack.getNbt();
|
||||||
if (tooltipFlag.isAdvanced()) {
|
if (tooltipFlag.isAdvanced()) {
|
||||||
texts.add(new TranslatableText("item.structure_item.item.tooltip.structure"));
|
texts.add(Text.translatable("item.structure_item.item.tooltip.structure"));
|
||||||
texts.add(new LiteralText(" " + tag.getString("structure")));
|
texts.add(Text.literal(" " + tag.getString("structure")));
|
||||||
if (tag.contains("allowedOn", 8)) {
|
if (tag.contains("allowedOn", 8)) {
|
||||||
texts.add(new TranslatableText("item.structure_item.item.tooltip.allowed.on"));
|
texts.add(Text.translatable("item.structure_item.item.tooltip.allowed.on"));
|
||||||
texts.add(new LiteralText(" " + 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 = NbtHelper.toBlockPos(tag.getCompound("offset"));
|
||||||
texts.add(new TranslatableText("item.structure_item.item.tooltip.fixed.offset"));
|
texts.add(Text.translatable("item.structure_item.item.tooltip.fixed.offset"));
|
||||||
Text c = new TranslatableText("item.structure_item.item.tooltip.xyz",
|
Text c = Text.translatable("item.structure_item.item.tooltip.xyz",
|
||||||
new LiteralText(String.valueOf(offset.getX())),
|
Text.literal(String.valueOf(offset.getX())),
|
||||||
new LiteralText(String.valueOf(offset.getY())),
|
Text.literal(String.valueOf(offset.getY())),
|
||||||
new LiteralText(String.valueOf(offset.getZ())));
|
Text.literal(String.valueOf(offset.getZ())));
|
||||||
texts.add(c);
|
texts.add(c);
|
||||||
} else {
|
} else {
|
||||||
texts.add(new TranslatableText("item.structure_item.item.tooltip.dynamic.offset"));
|
texts.add(Text.translatable("item.structure_item.item.tooltip.dynamic.offset"));
|
||||||
}
|
}
|
||||||
if (tag.contains("blacklist", 9)) {
|
if (tag.contains("blacklist", 9)) {
|
||||||
texts.add(new TranslatableText("item.structure_item.item.tooltip.blacklist"));
|
texts.add(Text.translatable("item.structure_item.item.tooltip.blacklist"));
|
||||||
ListTag bl = tag.getList("blacklist", 8);
|
NbtList bl = tag.getList("blacklist", 8);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for ( Tag entry : bl) {
|
for ( NbtElement entry : bl) {
|
||||||
texts.add(new LiteralText(" " + entry.asString()));
|
texts.add(Text.literal(" " + entry.asString()));
|
||||||
i++;
|
i++;
|
||||||
if (i == 4) {
|
if (i == 4) {
|
||||||
texts.add(new TranslatableText("item.structure_item.item.tooltip.blacklist.more",
|
texts.add(Text.translatable("item.structure_item.item.tooltip.blacklist.more",
|
||||||
new LiteralText(String.valueOf(bl.size() - i))));
|
Text.literal(String.valueOf(bl.size() - i))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!tag.contains("replaceEntities", 99) || tag.getBoolean("replaceEntities")) {
|
if (!tag.contains("replaceEntities", 99) || tag.getBoolean("replaceEntities")) {
|
||||||
texts.add(new TranslatableText("item.structure_item.item.tooltip.replaceEntities"));
|
texts.add(Text.translatable("item.structure_item.item.tooltip.replaceEntities"));
|
||||||
} else {
|
} else {
|
||||||
texts.add(new TranslatableText("item.structure_item.item.tooltip.doNotReplaceEntities"));
|
texts.add(Text.translatable("item.structure_item.item.tooltip.doNotReplaceEntities"));
|
||||||
}
|
}
|
||||||
if (!tag.contains("placeEntities", 99) || tag.getBoolean("placeEntities")) {
|
if (!tag.contains("placeEntities", 99) || tag.getBoolean("placeEntities")) {
|
||||||
texts.add(new TranslatableText("item.structure_item.item.tooltip.placeEntities"));
|
texts.add(Text.translatable("item.structure_item.item.tooltip.placeEntities"));
|
||||||
} else {
|
} else {
|
||||||
texts.add(new TranslatableText("item.structure_item.item.tooltip.doNotPlaceEntities"));
|
texts.add(Text.translatable("item.structure_item.item.tooltip.doNotPlaceEntities"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,10 +102,10 @@ public class MyItem extends Item {
|
||||||
} else {
|
} else {
|
||||||
player = null;
|
player = null;
|
||||||
}
|
}
|
||||||
CompoundTag tag = c.getStack().getTag();
|
NbtCompound tag = c.getStack().getNbt();
|
||||||
if (tag == null) {
|
if (tag == null) {
|
||||||
TranslatableText message =
|
Text message =
|
||||||
new TranslatableText("items.structure.spawner.no.tag");
|
Text.translatable("items.structure.spawner.no.tag");
|
||||||
sendPlayerChat(player, message);
|
sendPlayerChat(player, message);
|
||||||
return ActionResult.FAIL;
|
return ActionResult.FAIL;
|
||||||
}
|
}
|
||||||
|
@ -110,9 +114,9 @@ public class MyItem extends Item {
|
||||||
String allowedOn = tag.getString("allowedOn");
|
String allowedOn = tag.getString("allowedOn");
|
||||||
allowed = getBlock(allowedOn);
|
allowed = getBlock(allowedOn);
|
||||||
if (allowed == null) {
|
if (allowed == null) {
|
||||||
TranslatableText message =
|
Text message =
|
||||||
new TranslatableText("items.structure.spawner.invalid.block",
|
Text.translatable("items.structure.spawner.invalid.block",
|
||||||
new LiteralText(allowedOn));
|
Text.literal(allowedOn));
|
||||||
sendPlayerChat(player, message);
|
sendPlayerChat(player, message);
|
||||||
return ActionResult.FAIL;
|
return ActionResult.FAIL;
|
||||||
}
|
}
|
||||||
|
@ -120,37 +124,39 @@ public class MyItem extends Item {
|
||||||
Block current = c.getWorld().getBlockState(c.getBlockPos()).getBlock();
|
Block current = c.getWorld().getBlockState(c.getBlockPos()).getBlock();
|
||||||
|
|
||||||
if (allowed != null && !current.equals(allowed)) {
|
if (allowed != null && !current.equals(allowed)) {
|
||||||
Text currentName = new TranslatableText(current.getTranslationKey());
|
Text currentName = Text.translatable(current.getTranslationKey());
|
||||||
Text allowedName = new TranslatableText(allowed.getTranslationKey());
|
Text allowedName = Text.translatable(allowed.getTranslationKey());
|
||||||
TranslatableText message =
|
Text message =
|
||||||
new TranslatableText("items.structure.spawner.invalid.block.clicked",
|
Text.translatable("items.structure.spawner.invalid.block.clicked",
|
||||||
currentName, allowedName);
|
currentName, allowedName);
|
||||||
sendPlayer(player, message);
|
sendPlayer(player, message);
|
||||||
return ActionResult.FAIL;
|
return ActionResult.FAIL;
|
||||||
}
|
}
|
||||||
if (!tag.contains("structure", 8)) {
|
if (!tag.contains("structure", 8)) {
|
||||||
LOGGER.info("No structure name set");
|
LOGGER.info("No structure name set");
|
||||||
TranslatableText message =
|
Text message =
|
||||||
new TranslatableText("items.structure.spawner.no.structure");
|
Text.translatable("items.structure.spawner.no.structure");
|
||||||
sendPlayerChat(player, message);
|
sendPlayerChat(player, message);
|
||||||
return ActionResult.FAIL;
|
return ActionResult.FAIL;
|
||||||
}
|
}
|
||||||
String structureName = tag.getString("structure");
|
String structureName = tag.getString("structure");
|
||||||
Identifier structureResourceID = Identifier.tryParse(structureName);
|
Identifier structureResourceID = Identifier.tryParse(structureName);
|
||||||
if (structureResourceID == null) {
|
if (structureResourceID == null) {
|
||||||
TranslatableText message =
|
Text message =
|
||||||
new TranslatableText("items.structure.spawner.invalid.structure.name");
|
Text.translatable("items.structure.spawner.invalid.structure.name");
|
||||||
sendPlayerChat(player, message);
|
sendPlayerChat(player, message);
|
||||||
return ActionResult.FAIL;
|
return ActionResult.FAIL;
|
||||||
}
|
}
|
||||||
Structure x = ((ServerWorld) c.getWorld()).getStructureManager().getStructure(structureResourceID);
|
Optional<StructureTemplate> xOpt = ((ServerWorld) c.getWorld()).getStructureTemplateManager().getTemplate(structureResourceID);
|
||||||
if (x == null) {
|
if (xOpt.isEmpty()) {
|
||||||
TranslatableText message =
|
Text message =
|
||||||
new TranslatableText("items.structure.spawner.structure.nonexistent",
|
Text.translatable("items.structure.spawner.structure.nonexistent",
|
||||||
new LiteralText(structureResourceID.toString()));
|
Text.literal(structureResourceID.toString()));
|
||||||
sendPlayerChat(player, message);
|
sendPlayerChat(player, message);
|
||||||
return ActionResult.FAIL;
|
return ActionResult.FAIL;
|
||||||
}
|
}
|
||||||
|
StructureTemplate x = xOpt.get();
|
||||||
|
|
||||||
|
|
||||||
BlockPos loc = c.getBlockPos().offset(c.getSide());
|
BlockPos loc = c.getBlockPos().offset(c.getSide());
|
||||||
if (tag.contains("offset", 10)) {
|
if (tag.contains("offset", 10)) {
|
||||||
|
@ -158,7 +164,7 @@ public class MyItem extends Item {
|
||||||
loc = loc.add(offset);
|
loc = loc.add(offset);
|
||||||
} else if (c.getPlayer() != null) {
|
} else if (c.getPlayer() != null) {
|
||||||
Direction direction = Direction.getEntityFacingOrder(c.getPlayer())[0];
|
Direction direction = Direction.getEntityFacingOrder(c.getPlayer())[0];
|
||||||
BlockPos size = x.getSize();
|
Vec3i size = x.getSize();
|
||||||
loc = loc.add(getDirectionalOffset(direction, size));
|
loc = loc.add(getDirectionalOffset(direction, size));
|
||||||
} else {
|
} else {
|
||||||
LOGGER.info("No player & no offset");
|
LOGGER.info("No player & no offset");
|
||||||
|
@ -172,16 +178,16 @@ public class MyItem extends Item {
|
||||||
ps.setIgnoreEntities(!tag.getBoolean("placeEntities"));
|
ps.setIgnoreEntities(!tag.getBoolean("placeEntities"));
|
||||||
}
|
}
|
||||||
if (tag.contains("blacklist", 9)) {
|
if (tag.contains("blacklist", 9)) {
|
||||||
ListTag bl = tag.getList("blacklist", 8);
|
NbtList bl = tag.getList("blacklist", 8);
|
||||||
List<Block> blacklist = Lists.newArrayList();
|
List<Block> blacklist = Lists.newArrayList();
|
||||||
for (Tag b : bl) {
|
for (NbtElement b : bl) {
|
||||||
Block block = getBlock(b.asString());
|
Block block = getBlock(b.asString());
|
||||||
if (block != null) {
|
if (block != null) {
|
||||||
blacklist.add(block);
|
blacklist.add(block);
|
||||||
} else {
|
} else {
|
||||||
TranslatableText message =
|
Text message =
|
||||||
new TranslatableText("items.structure.spawner.invalid.block",
|
Text.translatable("items.structure.spawner.invalid.block",
|
||||||
new LiteralText(b.asString()));
|
Text.literal(b.asString()));
|
||||||
sendPlayerChat(player, message);
|
sendPlayerChat(player, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,8 +197,7 @@ public class MyItem extends Item {
|
||||||
ps.setWorld(c.getWorld())
|
ps.setWorld(c.getWorld())
|
||||||
.setSize(x.getSize())
|
.setSize(x.getSize())
|
||||||
.setMirror(BlockMirror.NONE)
|
.setMirror(BlockMirror.NONE)
|
||||||
.setRotation(BlockRotation.NONE)
|
.setRotation(BlockRotation.NONE);
|
||||||
.setChunkPosition(null);
|
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
try {
|
try {
|
||||||
if(x.place((ServerWorld)c.getWorld(), loc, loc, ps, c.getWorld().getRandom(), 2))
|
if(x.place((ServerWorld)c.getWorld(), loc, loc, ps, c.getWorld().getRandom(), 2))
|
||||||
|
@ -203,8 +208,8 @@ public class MyItem extends Item {
|
||||||
c.getStack().decrement(1);
|
c.getStack().decrement(1);
|
||||||
return ActionResult.SUCCESS;
|
return ActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
TranslatableText message =
|
Text message =
|
||||||
new TranslatableText("items.structure.spawner.invalid.location");
|
Text.translatable("items.structure.spawner.invalid.location");
|
||||||
sendPlayer(player, message);
|
sendPlayer(player, message);
|
||||||
return ActionResult.FAIL;
|
return ActionResult.FAIL;
|
||||||
}
|
}
|
||||||
|
@ -215,52 +220,50 @@ public class MyItem extends Item {
|
||||||
if (player == null)
|
if (player == null)
|
||||||
return;
|
return;
|
||||||
ServerPlayNetworkHandler connection = player.networkHandler;
|
ServerPlayNetworkHandler connection = player.networkHandler;
|
||||||
TitleS2CPacket packet = new TitleS2CPacket(TitleS2CPacket.Action.SUBTITLE, message);
|
SubtitleS2CPacket packet = new SubtitleS2CPacket(message);
|
||||||
connection.sendPacket(packet);
|
|
||||||
packet = new TitleS2CPacket(TitleS2CPacket.Action.TITLE, new LiteralText(""));
|
|
||||||
connection.sendPacket(packet);
|
connection.sendPacket(packet);
|
||||||
|
TitleS2CPacket titleS2CPacket = new TitleS2CPacket(Text.literal(""));
|
||||||
|
connection.sendPacket(titleS2CPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
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.asString());
|
LOGGER.info(message.getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
private BlockPos getDirectionalOffset(Direction direction, BlockPos size) {
|
private BlockPos getDirectionalOffset(Direction direction, Vec3i size) {
|
||||||
BlockPos loc = new BlockPos(0, 0, 0);
|
BlockPos loc = new BlockPos(0, 0, 0);
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case WEST:
|
case WEST -> {
|
||||||
loc = loc.offset(Direction.NORTH, size.getZ() / 2);
|
loc = loc.offset(Direction.NORTH, size.getZ() / 2);
|
||||||
loc = loc.offset(Direction.WEST, size.getX() - 1);
|
loc = loc.offset(Direction.WEST, size.getX() - 1);
|
||||||
break;
|
}
|
||||||
case EAST: //positive x
|
case EAST -> //positive x
|
||||||
loc = loc.offset(Direction.NORTH, size.getZ() / 2);
|
loc = loc.offset(Direction.NORTH, size.getZ() / 2);
|
||||||
break;
|
case NORTH -> {
|
||||||
case NORTH:
|
|
||||||
loc = loc.offset(Direction.NORTH, size.getZ() - 1);
|
loc = loc.offset(Direction.NORTH, size.getZ() - 1);
|
||||||
loc = loc.offset(Direction.WEST, size.getX() / 2);
|
loc = loc.offset(Direction.WEST, size.getX() / 2);
|
||||||
break;
|
}
|
||||||
case SOUTH: //positive z
|
case SOUTH -> //positive z
|
||||||
loc = loc.offset(Direction.WEST, size.getX() / 2);
|
loc = loc.offset(Direction.WEST, size.getX() / 2);
|
||||||
break;
|
case UP -> { //positive y
|
||||||
case UP: //positive y
|
|
||||||
loc = loc.offset(Direction.NORTH, size.getZ() / 2);
|
loc = loc.offset(Direction.NORTH, size.getZ() / 2);
|
||||||
loc = loc.offset(Direction.WEST, size.getX() / 2);
|
loc = loc.offset(Direction.WEST, size.getX() / 2);
|
||||||
loc = loc.offset(Direction.UP);
|
loc = loc.offset(Direction.UP);
|
||||||
break;
|
}
|
||||||
case DOWN:
|
case DOWN -> {
|
||||||
loc = loc.offset(Direction.NORTH, size.getZ() / 2);
|
loc = loc.offset(Direction.NORTH, size.getZ() / 2);
|
||||||
loc = loc.offset(Direction.WEST, size.getX() / 2);
|
loc = loc.offset(Direction.WEST, size.getX() / 2);
|
||||||
loc = loc.offset(Direction.DOWN, size.getY());
|
loc = loc.offset(Direction.DOWN, size.getY());
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
return loc;
|
return loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Block getBlock(String loc) {
|
private Block getBlock(String loc) {
|
||||||
Identifier location = Identifier.tryParse(loc);
|
Identifier location = Identifier.tryParse(loc);
|
||||||
DefaultedRegistry<Block> blocks = Registry.BLOCK;
|
DefaultedRegistry<Block> blocks = Registries.BLOCK;
|
||||||
if (location == null) {
|
if (location == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,11 @@ import com.google.common.collect.Lists;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.structure.Structure;
|
|
||||||
import net.minecraft.structure.StructurePlacementData;
|
import net.minecraft.structure.StructurePlacementData;
|
||||||
|
import net.minecraft.structure.StructureTemplate;
|
||||||
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.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -16,7 +17,7 @@ import java.util.List;
|
||||||
public class MyPlacementSettings extends StructurePlacementData {
|
public class MyPlacementSettings extends StructurePlacementData {
|
||||||
private List<Block> blacklist;
|
private List<Block> blacklist;
|
||||||
private World world;
|
private World world;
|
||||||
private BlockPos size;
|
private Vec3i size;
|
||||||
private boolean replaceEntities = true;
|
private boolean replaceEntities = true;
|
||||||
|
|
||||||
public void forbidOverwrite(List<Block> blocks) {
|
public void forbidOverwrite(List<Block> blocks) {
|
||||||
|
@ -32,30 +33,30 @@ public class MyPlacementSettings extends StructurePlacementData {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MyPlacementSettings setSize(BlockPos p) {
|
public MyPlacementSettings setSize(Vec3i p) {
|
||||||
size = p;
|
size = p;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Structure.PalettedBlockInfoList getRandomBlockInfos(List<Structure.PalettedBlockInfoList> blocks, BlockPos pos) {
|
public StructureTemplate.PalettedBlockInfoList getRandomBlockInfos(List<StructureTemplate.PalettedBlockInfoList> blocks, BlockPos pos) {
|
||||||
if (world == null || pos == null || size == null) {
|
if (world == null || pos == null || size == null) {
|
||||||
return super.getRandomBlockInfos(blocks, pos);
|
return super.getRandomBlockInfos(blocks, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Structure.PalettedBlockInfoList> eligibleStructures;
|
List<StructureTemplate.PalettedBlockInfoList> eligibleStructures;
|
||||||
eligibleStructures = getEligibleStructures(blocks, pos);
|
eligibleStructures = getEligibleStructures(blocks, pos);
|
||||||
if (eligibleStructures.size() == 0)
|
if (eligibleStructures.size() == 0)
|
||||||
return null;
|
return null;
|
||||||
Structure.PalettedBlockInfoList randomBlockInfos = super.getRandomBlockInfos(eligibleStructures, pos);
|
StructureTemplate.PalettedBlockInfoList randomBlockInfos = super.getRandomBlockInfos(eligibleStructures, pos);
|
||||||
List<Structure.StructureBlockInfo> locs = randomBlockInfos.getAll();
|
List<StructureTemplate.StructureBlockInfo> locs = randomBlockInfos.getAll();
|
||||||
if (!locs.isEmpty()) {
|
if (!locs.isEmpty()) {
|
||||||
List<Entity> entitiesWithinAABB = world.getNonSpectatingEntities(Entity.class, new Box(pos,pos.add(size)));
|
List<Entity> entitiesWithinAABB = world.getNonSpectatingEntities(Entity.class, new Box(pos,pos.add(size)));
|
||||||
for (Structure.StructureBlockInfo blockInfo : locs) {
|
for (StructureTemplate.StructureBlockInfo blockInfo : locs) {
|
||||||
BlockPos posToClean = blockInfo.pos.add(pos);
|
BlockPos posToClean = blockInfo.pos().add(pos);
|
||||||
for (Entity e : entitiesWithinAABB) {
|
for (Entity e : entitiesWithinAABB) {
|
||||||
if (!(e instanceof PlayerEntity) && e.getBoundingBox().intersects(new Box(posToClean))) {
|
if (!(e instanceof PlayerEntity) && e.getBoundingBox().intersects(new Box(posToClean))) {
|
||||||
e.remove();
|
e.remove(Entity.RemovalReason.DISCARDED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,12 +64,12 @@ public class MyPlacementSettings extends StructurePlacementData {
|
||||||
return randomBlockInfos;
|
return randomBlockInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Structure.PalettedBlockInfoList> getEligibleStructures(List<Structure.PalettedBlockInfoList> blocks, BlockPos pos) {
|
private List<StructureTemplate.PalettedBlockInfoList> getEligibleStructures(List<StructureTemplate.PalettedBlockInfoList> blocks, BlockPos pos) {
|
||||||
List<Structure.PalettedBlockInfoList> eligibleStructures = new ArrayList<>();
|
List<StructureTemplate.PalettedBlockInfoList> eligibleStructures = new ArrayList<>();
|
||||||
if (blacklist == null && shouldReplaceEntities()) {
|
if (blacklist == null && shouldReplaceEntities()) {
|
||||||
eligibleStructures = blocks;
|
eligibleStructures = blocks;
|
||||||
} else {
|
} else {
|
||||||
for (Structure.PalettedBlockInfoList struct : blocks) {
|
for (StructureTemplate.PalettedBlockInfoList struct : blocks) {
|
||||||
if (isValid(struct, pos)) {
|
if (isValid(struct, pos)) {
|
||||||
eligibleStructures.add(struct);
|
eligibleStructures.add(struct);
|
||||||
}
|
}
|
||||||
|
@ -77,10 +78,15 @@ public class MyPlacementSettings extends StructurePlacementData {
|
||||||
return eligibleStructures;
|
return eligibleStructures;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isValid(Structure.PalettedBlockInfoList struct, BlockPos pos) {
|
private boolean isValid(StructureTemplate.PalettedBlockInfoList struct, BlockPos pos) {
|
||||||
List<Entity> entitiesWithinAABB = world.getNonSpectatingEntities(shouldReplaceEntities()?PlayerEntity.class:Entity.class, new Box(pos,pos.add(size)));
|
List<? extends Entity> entitiesWithinAABB;
|
||||||
for (Structure.StructureBlockInfo bi : struct.getAll()) {
|
if (shouldReplaceEntities()) {
|
||||||
BlockPos posToCheck = bi.pos.add(pos);
|
entitiesWithinAABB = world.getNonSpectatingEntities(PlayerEntity.class, new Box(pos, pos.add(size)));
|
||||||
|
} else {
|
||||||
|
entitiesWithinAABB = world.getNonSpectatingEntities(Entity.class, new Box(pos, pos.add(size)));
|
||||||
|
}
|
||||||
|
for (StructureTemplate.StructureBlockInfo bi : struct.getAll()) {
|
||||||
|
BlockPos posToCheck = bi.pos().add(pos);
|
||||||
if (World.isValid(posToCheck)) {
|
if (World.isValid(posToCheck)) {
|
||||||
for (Entity e : entitiesWithinAABB) {
|
for (Entity e : entitiesWithinAABB) {
|
||||||
if (e.getBoundingBox().intersects(new Box(posToCheck))) {
|
if (e.getBoundingBox().intersects(new Box(posToCheck))) {
|
||||||
|
|
|
@ -2,7 +2,8 @@ package quimufu.structure_item;
|
||||||
|
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.registry.Registries;
|
||||||
|
import net.minecraft.registry.Registry;
|
||||||
import org.apache.logging.log4j.Level;
|
import org.apache.logging.log4j.Level;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
@ -19,7 +20,7 @@ public class StructureItemMod implements ModInitializer {
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
log(Level.INFO, "Initializing");
|
log(Level.INFO, "Initializing");
|
||||||
Registry.register(Registry.ITEM, MOD_ID + ":item", item);
|
Registry.register(Registries.ITEM, MOD_ID + ":item", item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void log(Level level, String message) {
|
public static void log(Level level, String message) {
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
},
|
},
|
||||||
"mixins": [],
|
"mixins": [],
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": ">=0.4.0",
|
"fabricloader": ">=0.14",
|
||||||
"fabric": "*"
|
"fabric": "*"
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user