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 {
|
||||
id 'fabric-loom' version '0.6-SNAPSHOT'
|
||||
id "com.modrinth.minotaur" version "2.+"
|
||||
id 'fabric-loom' version '1.2-SNAPSHOT'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
archivesBaseName = project.archives_base_name
|
||||
version = project.mod_version
|
||||
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 {
|
||||
//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}"
|
||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||
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}"
|
||||
|
||||
// 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 {
|
||||
inputs.property "version", project.version
|
||||
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include "fabric.mod.json"
|
||||
filesMatching("fabric.mod.json") {
|
||||
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
|
||||
// this fixes some edge cases with special characters not displaying correctly
|
||||
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = "UTF-8"
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
it.options.release = 17
|
||||
}
|
||||
|
||||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
||||
// if it is present.
|
||||
// If you remove this task, sources will not be generated.
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
classifier = "sources"
|
||||
from sourceSets.main.allSource
|
||||
java {
|
||||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
||||
// if it is present.
|
||||
// If you remove this line, sources will not be generated.
|
||||
withSourcesJar()
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
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
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
// add all the jars that should be included when publishing to maven
|
||||
artifact(jar) {
|
||||
builtBy remapJar
|
||||
}
|
||||
artifact("${project.buildDir.absolutePath}/libs/${archivesBaseName}-${project.version}.jar"){
|
||||
builtBy remapJar
|
||||
}
|
||||
artifact(sourcesJar) {
|
||||
builtBy remapSourcesJar
|
||||
}
|
||||
from components.java
|
||||
}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
// uncomment to publish to the local maven
|
||||
// mavenLocal()
|
||||
// Add repositories to publish to here.
|
||||
// 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
|
||||
|
||||
#Fabric properties
|
||||
minecraft_version=1.16.5
|
||||
yarn_mappings=1.16.5+build.6
|
||||
loader_version=0.11.3
|
||||
minecraft_version=1.20.1
|
||||
yarn_mappings=1.20.1+build.9
|
||||
loader_version=0.14.21
|
||||
|
||||
#Fabric api
|
||||
fabric_version=0.32.5+1.16
|
||||
#Fabric
|
||||
fabric_version=0.84.0+1.20.1
|
||||
|
||||
#Mod properties
|
||||
mod_version = 0.8.1
|
||||
mod_version = 0.9.1
|
||||
maven_group = quimufu.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
|
||||
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
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
|
@ -1,89 +1,93 @@
|
|||
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.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
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.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.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.structure.Structure;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.structure.StructureTemplate;
|
||||
import net.minecraft.text.LiteralTextContent;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.registry.DefaultedRegistry;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static quimufu.structure_item.StructureItemMod.LOGGER;
|
||||
|
||||
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() {
|
||||
super(p);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendTooltip(ItemStack itemStack, World world, List<Text> texts, TooltipContext tooltipFlag) {
|
||||
if (!itemStack.hasTag() || !itemStack.getTag().contains("structure", 8)) {
|
||||
texts.add((new TranslatableText("item.structure_item.item.tooltip.tag.invalid")).formatted(Formatting.RED));
|
||||
if (!itemStack.hasNbt() || !itemStack.getNbt().contains("structure", 8)) {
|
||||
texts.add((Text.translatable("item.structure_item.item.tooltip.tag.invalid")).formatted(Formatting.RED));
|
||||
} else {
|
||||
CompoundTag tag = itemStack.getTag();
|
||||
NbtCompound tag = itemStack.getNbt();
|
||||
if (tooltipFlag.isAdvanced()) {
|
||||
texts.add(new TranslatableText("item.structure_item.item.tooltip.structure"));
|
||||
texts.add(new LiteralText(" " + tag.getString("structure")));
|
||||
texts.add(Text.translatable("item.structure_item.item.tooltip.structure"));
|
||||
texts.add(Text.literal(" " + tag.getString("structure")));
|
||||
if (tag.contains("allowedOn", 8)) {
|
||||
texts.add(new TranslatableText("item.structure_item.item.tooltip.allowed.on"));
|
||||
texts.add(new LiteralText(" " + tag.getString("allowedOn")));
|
||||
texts.add(Text.translatable("item.structure_item.item.tooltip.allowed.on"));
|
||||
texts.add(Text.literal(" " + tag.getString("allowedOn")));
|
||||
}
|
||||
if (tag.contains("offset", 10)) {
|
||||
BlockPos offset = NbtHelper.toBlockPos(tag.getCompound("offset"));
|
||||
texts.add(new TranslatableText("item.structure_item.item.tooltip.fixed.offset"));
|
||||
Text c = new TranslatableText("item.structure_item.item.tooltip.xyz",
|
||||
new LiteralText(String.valueOf(offset.getX())),
|
||||
new LiteralText(String.valueOf(offset.getY())),
|
||||
new LiteralText(String.valueOf(offset.getZ())));
|
||||
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())),
|
||||
Text.literal(String.valueOf(offset.getY())),
|
||||
Text.literal(String.valueOf(offset.getZ())));
|
||||
texts.add(c);
|
||||
} 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)) {
|
||||
texts.add(new TranslatableText("item.structure_item.item.tooltip.blacklist"));
|
||||
ListTag bl = tag.getList("blacklist", 8);
|
||||
texts.add(Text.translatable("item.structure_item.item.tooltip.blacklist"));
|
||||
NbtList bl = tag.getList("blacklist", 8);
|
||||
int i = 0;
|
||||
for ( Tag entry : bl) {
|
||||
texts.add(new LiteralText(" " + entry.asString()));
|
||||
for ( NbtElement entry : bl) {
|
||||
texts.add(Text.literal(" " + entry.asString()));
|
||||
i++;
|
||||
if (i == 4) {
|
||||
texts.add(new TranslatableText("item.structure_item.item.tooltip.blacklist.more",
|
||||
new LiteralText(String.valueOf(bl.size() - i))));
|
||||
texts.add(Text.translatable("item.structure_item.item.tooltip.blacklist.more",
|
||||
Text.literal(String.valueOf(bl.size() - i))));
|
||||
}
|
||||
}
|
||||
}
|
||||
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 {
|
||||
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")) {
|
||||
texts.add(new TranslatableText("item.structure_item.item.tooltip.placeEntities"));
|
||||
texts.add(Text.translatable("item.structure_item.item.tooltip.placeEntities"));
|
||||
} 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 {
|
||||
player = null;
|
||||
}
|
||||
CompoundTag tag = c.getStack().getTag();
|
||||
NbtCompound tag = c.getStack().getNbt();
|
||||
if (tag == null) {
|
||||
TranslatableText message =
|
||||
new TranslatableText("items.structure.spawner.no.tag");
|
||||
Text message =
|
||||
Text.translatable("items.structure.spawner.no.tag");
|
||||
sendPlayerChat(player, message);
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
|
@ -110,9 +114,9 @@ public class MyItem extends Item {
|
|||
String allowedOn = tag.getString("allowedOn");
|
||||
allowed = getBlock(allowedOn);
|
||||
if (allowed == null) {
|
||||
TranslatableText message =
|
||||
new TranslatableText("items.structure.spawner.invalid.block",
|
||||
new LiteralText(allowedOn));
|
||||
Text message =
|
||||
Text.translatable("items.structure.spawner.invalid.block",
|
||||
Text.literal(allowedOn));
|
||||
sendPlayerChat(player, message);
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
|
@ -120,37 +124,39 @@ public class MyItem extends Item {
|
|||
Block current = c.getWorld().getBlockState(c.getBlockPos()).getBlock();
|
||||
|
||||
if (allowed != null && !current.equals(allowed)) {
|
||||
Text currentName = new TranslatableText(current.getTranslationKey());
|
||||
Text allowedName = new TranslatableText(allowed.getTranslationKey());
|
||||
TranslatableText message =
|
||||
new TranslatableText("items.structure.spawner.invalid.block.clicked",
|
||||
Text currentName = Text.translatable(current.getTranslationKey());
|
||||
Text allowedName = Text.translatable(allowed.getTranslationKey());
|
||||
Text message =
|
||||
Text.translatable("items.structure.spawner.invalid.block.clicked",
|
||||
currentName, allowedName);
|
||||
sendPlayer(player, message);
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
if (!tag.contains("structure", 8)) {
|
||||
LOGGER.info("No structure name set");
|
||||
TranslatableText message =
|
||||
new TranslatableText("items.structure.spawner.no.structure");
|
||||
Text message =
|
||||
Text.translatable("items.structure.spawner.no.structure");
|
||||
sendPlayerChat(player, message);
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
String structureName = tag.getString("structure");
|
||||
Identifier structureResourceID = Identifier.tryParse(structureName);
|
||||
if (structureResourceID == null) {
|
||||
TranslatableText message =
|
||||
new TranslatableText("items.structure.spawner.invalid.structure.name");
|
||||
Text message =
|
||||
Text.translatable("items.structure.spawner.invalid.structure.name");
|
||||
sendPlayerChat(player, message);
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
Structure x = ((ServerWorld) c.getWorld()).getStructureManager().getStructure(structureResourceID);
|
||||
if (x == null) {
|
||||
TranslatableText message =
|
||||
new TranslatableText("items.structure.spawner.structure.nonexistent",
|
||||
new LiteralText(structureResourceID.toString()));
|
||||
Optional<StructureTemplate> xOpt = ((ServerWorld) c.getWorld()).getStructureTemplateManager().getTemplate(structureResourceID);
|
||||
if (xOpt.isEmpty()) {
|
||||
Text message =
|
||||
Text.translatable("items.structure.spawner.structure.nonexistent",
|
||||
Text.literal(structureResourceID.toString()));
|
||||
sendPlayerChat(player, message);
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
StructureTemplate x = xOpt.get();
|
||||
|
||||
|
||||
BlockPos loc = c.getBlockPos().offset(c.getSide());
|
||||
if (tag.contains("offset", 10)) {
|
||||
|
@ -158,7 +164,7 @@ public class MyItem extends Item {
|
|||
loc = loc.add(offset);
|
||||
} else if (c.getPlayer() != null) {
|
||||
Direction direction = Direction.getEntityFacingOrder(c.getPlayer())[0];
|
||||
BlockPos size = x.getSize();
|
||||
Vec3i size = x.getSize();
|
||||
loc = loc.add(getDirectionalOffset(direction, size));
|
||||
} else {
|
||||
LOGGER.info("No player & no offset");
|
||||
|
@ -172,16 +178,16 @@ public class MyItem extends Item {
|
|||
ps.setIgnoreEntities(!tag.getBoolean("placeEntities"));
|
||||
}
|
||||
if (tag.contains("blacklist", 9)) {
|
||||
ListTag bl = tag.getList("blacklist", 8);
|
||||
NbtList bl = tag.getList("blacklist", 8);
|
||||
List<Block> blacklist = Lists.newArrayList();
|
||||
for (Tag b : bl) {
|
||||
for (NbtElement b : bl) {
|
||||
Block block = getBlock(b.asString());
|
||||
if (block != null) {
|
||||
blacklist.add(block);
|
||||
} else {
|
||||
TranslatableText message =
|
||||
new TranslatableText("items.structure.spawner.invalid.block",
|
||||
new LiteralText(b.asString()));
|
||||
Text message =
|
||||
Text.translatable("items.structure.spawner.invalid.block",
|
||||
Text.literal(b.asString()));
|
||||
sendPlayerChat(player, message);
|
||||
}
|
||||
|
||||
|
@ -191,8 +197,7 @@ public class MyItem extends Item {
|
|||
ps.setWorld(c.getWorld())
|
||||
.setSize(x.getSize())
|
||||
.setMirror(BlockMirror.NONE)
|
||||
.setRotation(BlockRotation.NONE)
|
||||
.setChunkPosition(null);
|
||||
.setRotation(BlockRotation.NONE);
|
||||
boolean success = false;
|
||||
try {
|
||||
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);
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
TranslatableText message =
|
||||
new TranslatableText("items.structure.spawner.invalid.location");
|
||||
Text message =
|
||||
Text.translatable("items.structure.spawner.invalid.location");
|
||||
sendPlayer(player, message);
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
|
@ -215,52 +220,50 @@ public class MyItem extends Item {
|
|||
if (player == null)
|
||||
return;
|
||||
ServerPlayNetworkHandler connection = player.networkHandler;
|
||||
TitleS2CPacket packet = new TitleS2CPacket(TitleS2CPacket.Action.SUBTITLE, message);
|
||||
connection.sendPacket(packet);
|
||||
packet = new TitleS2CPacket(TitleS2CPacket.Action.TITLE, new LiteralText(""));
|
||||
SubtitleS2CPacket packet = new SubtitleS2CPacket(message);
|
||||
connection.sendPacket(packet);
|
||||
TitleS2CPacket titleS2CPacket = new TitleS2CPacket(Text.literal(""));
|
||||
connection.sendPacket(titleS2CPacket);
|
||||
}
|
||||
|
||||
private static void sendPlayerChat(ServerPlayerEntity player, Text message) {
|
||||
if (player != null)
|
||||
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);
|
||||
switch (direction) {
|
||||
case WEST:
|
||||
case WEST -> {
|
||||
loc = loc.offset(Direction.NORTH, size.getZ() / 2);
|
||||
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);
|
||||
break;
|
||||
case NORTH:
|
||||
case NORTH -> {
|
||||
loc = loc.offset(Direction.NORTH, size.getZ() - 1);
|
||||
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);
|
||||
break;
|
||||
case UP: //positive y
|
||||
case UP -> { //positive y
|
||||
loc = loc.offset(Direction.NORTH, size.getZ() / 2);
|
||||
loc = loc.offset(Direction.WEST, size.getX() / 2);
|
||||
loc = loc.offset(Direction.UP);
|
||||
break;
|
||||
case DOWN:
|
||||
}
|
||||
case DOWN -> {
|
||||
loc = loc.offset(Direction.NORTH, size.getZ() / 2);
|
||||
loc = loc.offset(Direction.WEST, size.getX() / 2);
|
||||
loc = loc.offset(Direction.DOWN, size.getY());
|
||||
break;
|
||||
}
|
||||
}
|
||||
return loc;
|
||||
}
|
||||
|
||||
private Block getBlock(String loc) {
|
||||
Identifier location = Identifier.tryParse(loc);
|
||||
DefaultedRegistry<Block> blocks = Registry.BLOCK;
|
||||
DefaultedRegistry<Block> blocks = Registries.BLOCK;
|
||||
if (location == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -4,10 +4,11 @@ import com.google.common.collect.Lists;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.structure.Structure;
|
||||
import net.minecraft.structure.StructurePlacementData;
|
||||
import net.minecraft.structure.StructureTemplate;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -16,7 +17,7 @@ import java.util.List;
|
|||
public class MyPlacementSettings extends StructurePlacementData {
|
||||
private List<Block> blacklist;
|
||||
private World world;
|
||||
private BlockPos size;
|
||||
private Vec3i size;
|
||||
private boolean replaceEntities = true;
|
||||
|
||||
public void forbidOverwrite(List<Block> blocks) {
|
||||
|
@ -32,30 +33,30 @@ public class MyPlacementSettings extends StructurePlacementData {
|
|||
return this;
|
||||
}
|
||||
|
||||
public MyPlacementSettings setSize(BlockPos p) {
|
||||
public MyPlacementSettings setSize(Vec3i p) {
|
||||
size = p;
|
||||
return this;
|
||||
}
|
||||
|
||||
@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) {
|
||||
return super.getRandomBlockInfos(blocks, pos);
|
||||
}
|
||||
|
||||
List<Structure.PalettedBlockInfoList> eligibleStructures;
|
||||
List<StructureTemplate.PalettedBlockInfoList> eligibleStructures;
|
||||
eligibleStructures = getEligibleStructures(blocks, pos);
|
||||
if (eligibleStructures.size() == 0)
|
||||
return null;
|
||||
Structure.PalettedBlockInfoList randomBlockInfos = super.getRandomBlockInfos(eligibleStructures, pos);
|
||||
List<Structure.StructureBlockInfo> locs = randomBlockInfos.getAll();
|
||||
StructureTemplate.PalettedBlockInfoList randomBlockInfos = super.getRandomBlockInfos(eligibleStructures, pos);
|
||||
List<StructureTemplate.StructureBlockInfo> locs = randomBlockInfos.getAll();
|
||||
if (!locs.isEmpty()) {
|
||||
List<Entity> entitiesWithinAABB = world.getNonSpectatingEntities(Entity.class, new Box(pos,pos.add(size)));
|
||||
for (Structure.StructureBlockInfo blockInfo : locs) {
|
||||
BlockPos posToClean = blockInfo.pos.add(pos);
|
||||
for (StructureTemplate.StructureBlockInfo blockInfo : locs) {
|
||||
BlockPos posToClean = blockInfo.pos().add(pos);
|
||||
for (Entity e : entitiesWithinAABB) {
|
||||
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;
|
||||
}
|
||||
|
||||
private List<Structure.PalettedBlockInfoList> getEligibleStructures(List<Structure.PalettedBlockInfoList> blocks, BlockPos pos) {
|
||||
List<Structure.PalettedBlockInfoList> eligibleStructures = new ArrayList<>();
|
||||
private List<StructureTemplate.PalettedBlockInfoList> getEligibleStructures(List<StructureTemplate.PalettedBlockInfoList> blocks, BlockPos pos) {
|
||||
List<StructureTemplate.PalettedBlockInfoList> eligibleStructures = new ArrayList<>();
|
||||
if (blacklist == null && shouldReplaceEntities()) {
|
||||
eligibleStructures = blocks;
|
||||
} else {
|
||||
for (Structure.PalettedBlockInfoList struct : blocks) {
|
||||
for (StructureTemplate.PalettedBlockInfoList struct : blocks) {
|
||||
if (isValid(struct, pos)) {
|
||||
eligibleStructures.add(struct);
|
||||
}
|
||||
|
@ -77,10 +78,15 @@ public class MyPlacementSettings extends StructurePlacementData {
|
|||
return eligibleStructures;
|
||||
}
|
||||
|
||||
private boolean isValid(Structure.PalettedBlockInfoList struct, BlockPos pos) {
|
||||
List<Entity> entitiesWithinAABB = world.getNonSpectatingEntities(shouldReplaceEntities()?PlayerEntity.class:Entity.class, new Box(pos,pos.add(size)));
|
||||
for (Structure.StructureBlockInfo bi : struct.getAll()) {
|
||||
BlockPos posToCheck = bi.pos.add(pos);
|
||||
private boolean isValid(StructureTemplate.PalettedBlockInfoList struct, BlockPos pos) {
|
||||
List<? extends Entity> entitiesWithinAABB;
|
||||
if (shouldReplaceEntities()) {
|
||||
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)) {
|
||||
for (Entity e : entitiesWithinAABB) {
|
||||
if (e.getBoundingBox().intersects(new Box(posToCheck))) {
|
||||
|
|
|
@ -2,7 +2,8 @@ package quimufu.structure_item;
|
|||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
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.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
@ -19,7 +20,7 @@ public class StructureItemMod implements ModInitializer {
|
|||
@Override
|
||||
public void onInitialize() {
|
||||
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) {
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
},
|
||||
"mixins": [],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.4.0",
|
||||
"fabricloader": ">=0.14",
|
||||
"fabric": "*"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user