mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-29 03:59:06 +00:00
add tabcomplete for vanilla loottables and fix some multi version compat
This commit is contained in:
@@ -236,7 +236,8 @@ public class ChunkUpdater {
|
||||
try {
|
||||
c = PaperLib.getChunkAtAsync(world, xx, zz, false, true)
|
||||
.thenApply(chunk -> {
|
||||
chunk.addPluginChunkTicket(Iris.instance);
|
||||
if (chunk != null)
|
||||
chunk.addPluginChunkTicket(Iris.instance);
|
||||
return chunk;
|
||||
}).get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
@@ -244,12 +245,17 @@ public class ChunkUpdater {
|
||||
return;
|
||||
}
|
||||
|
||||
if (c == null) {
|
||||
generated.set(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!c.isLoaded()) {
|
||||
var future = J.sfut(() -> c.load(false));
|
||||
if (future != null) future.join();
|
||||
}
|
||||
|
||||
if (!c.isGenerated())
|
||||
if (!PaperLib.isChunkGenerated(c.getWorld(), xx, zz))
|
||||
generated.set(false);
|
||||
|
||||
var pair = lastUse.computeIfAbsent(Cache.key(c), k -> new Pair<>(0L, new AtomicInteger(-1)));
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.volmit.iris.engine.framework;
|
||||
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public interface ListFunction<T, R> extends Function<T, R> {
|
||||
public interface ListFunction<R> extends Function<IrisData, R> {
|
||||
String key();
|
||||
String fancyName();
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.loader.IrisRegistrant;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.object.annotations.*;
|
||||
import com.volmit.iris.engine.object.annotations.functions.StructureKeyFunction;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.json.JSONObject;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
@@ -141,7 +142,7 @@ public class IrisJigsawStructure extends IrisRegistrant {
|
||||
avg += getLoader().getJigsawPieceLoader().load(i).getMax2dDimension();
|
||||
}
|
||||
|
||||
return (avg / (pieces.size() > 0 ? pieces.size() : 1)) * (((getMaxDepth() + 1) * 2) + 1);
|
||||
return (avg / (!pieces.isEmpty() ? pieces.size() : 1)) * (((getMaxDepth() + 1) * 2) + 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.volmit.iris.engine.object;
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.object.annotations.*;
|
||||
import com.volmit.iris.engine.object.annotations.functions.LootTableKeyFunction;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@@ -25,6 +26,7 @@ public class IrisObjectVanillaLoot {
|
||||
private boolean exact = false;
|
||||
@Desc("The vanilla loot table key")
|
||||
@Required
|
||||
@RegistryListFunction(LootTableKeyFunction.class)
|
||||
private String name;
|
||||
@Desc("The weight of this loot table being chosen")
|
||||
private int weight = 1;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.volmit.iris.engine.object;
|
||||
|
||||
import com.volmit.iris.core.nms.container.Pair;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
@@ -9,20 +10,22 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
import org.apache.commons.io.function.IOFunction;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.*;
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
import org.bukkit.block.banner.PatternType;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
@ToString
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@@ -31,6 +34,7 @@ public class LegacyTileData extends TileData {
|
||||
0, new Pair<>(SignHandler::fromBukkit, SignHandler::new),
|
||||
1, new Pair<>(SpawnerHandler::fromBukkit, SpawnerHandler::new),
|
||||
2, new Pair<>(BannerHandler::fromBukkit, BannerHandler::new));
|
||||
private static final AtomicCache<Tag<Material>> SIGNS = new AtomicCache<>();
|
||||
private final int id;
|
||||
private final Handler handler;
|
||||
|
||||
@@ -122,7 +126,7 @@ public class LegacyTileData extends TileData {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static SignHandler fromBukkit(BlockState blockState, Material type) {
|
||||
if (!Tag.ALL_SIGNS.isTagged(type) || !(blockState instanceof Sign sign))
|
||||
if (!signsTag().isTagged(type) || !(blockState instanceof Sign sign))
|
||||
return null;
|
||||
return new SignHandler(sign.getLine(0), sign.getLine(1), sign.getLine(2), sign.getLine(3), sign.getColor());
|
||||
}
|
||||
@@ -134,7 +138,7 @@ public class LegacyTileData extends TileData {
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(BlockData data) {
|
||||
return Tag.ALL_SIGNS.isTagged(data.getMaterial());
|
||||
return signsTag().isTagged(data.getMaterial());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -247,4 +251,32 @@ public class LegacyTileData extends TileData {
|
||||
banner.update();
|
||||
}
|
||||
}
|
||||
|
||||
private static Tag<Material> signsTag() {
|
||||
return SIGNS.aquire(() -> {
|
||||
var signs = Bukkit.getTag("blocks", NamespacedKey.minecraft("all_signs"), Material.class);
|
||||
if (signs != null)
|
||||
return signs;
|
||||
return new Tag<>() {
|
||||
@Override
|
||||
public boolean isTagged(@NotNull Material item) {
|
||||
return item.getKey().getKey().endsWith("_sign");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<Material> getValues() {
|
||||
return StreamSupport.stream(Registry.MATERIAL.spliterator(), false)
|
||||
.filter(this::isTagged)
|
||||
.collect(Collectors.toUnmodifiableSet());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public NamespacedKey getKey() {
|
||||
return NamespacedKey.minecraft("all_signs");
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.volmit.iris.engine.object.annotations;
|
||||
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.engine.framework.ListFunction;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
|
||||
@@ -13,5 +12,5 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
@Retention(RUNTIME)
|
||||
@Target({PARAMETER, TYPE, FIELD})
|
||||
public @interface RegistryListFunction {
|
||||
Class<? extends ListFunction<IrisData, KList<String>>> value();
|
||||
Class<? extends ListFunction<KList<String>>> value();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.volmit.iris.engine.object.annotations.functions;
|
||||
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.engine.framework.ListFunction;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.loot.LootTable;
|
||||
import org.bukkit.loot.LootTables;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
public class LootTableKeyFunction implements ListFunction<KList<String>> {
|
||||
@Override
|
||||
public String key() {
|
||||
return "loot-table-key";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String fancyName() {
|
||||
return "LootTable Key";
|
||||
}
|
||||
|
||||
@Override
|
||||
public KList<String> apply(IrisData data) {
|
||||
return StreamSupport.stream(Registry.LOOT_TABLES.spliterator(), false)
|
||||
.map(LootTables::getLootTable)
|
||||
.map(LootTable::getKey)
|
||||
.map(NamespacedKey::toString)
|
||||
.collect(Collectors.toCollection(KList::new));
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.volmit.iris.engine.object.annotations;
|
||||
package com.volmit.iris.engine.object.annotations.functions;
|
||||
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.engine.framework.ListFunction;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
|
||||
public class StructureKeyFunction implements ListFunction<IrisData, KList<String>> {
|
||||
public class StructureKeyFunction implements ListFunction<KList<String>> {
|
||||
@Override
|
||||
public String key() {
|
||||
return "structure-key";
|
||||
Reference in New Issue
Block a user