Update some things
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
YoyoNow 2024-09-19 19:47:23 +02:00
Ursprung 5721a06c51
Commit b32b300e9b
6 geänderte Dateien mit 107 neuen und 40 gelöschten Zeilen

Datei anzeigen

@ -29,21 +29,60 @@ import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.util.VoxelShape;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.stream.Collectors;
public abstract class BoundingBoxLoader2<T extends BlockData> {
protected final Boolean[] BOOLEANS = {false, true};
protected final BlockFace[] CARDINAL_BLOCKFACES_WITHOUT_UP = {BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST, BlockFace.DOWN};
protected final BlockFace[] CARDINAL_BLOCKFACES = {BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN};
protected static class Value<V> {
private String name;
protected final V value;
public Value(V value) {
this.value = value;
reset();
}
public Value<V> hideLore() {
name = null;
return this;
}
public Value<V> name(String name) {
this.name = name;
return this;
}
public Value<V> reset() {
name = "LAUFBAU_VALUE_" + value;
return this;
}
}
protected final Value<Boolean>[] BOOLEANS = new Value[]{
new Value<>(false).hideLore(),
new Value<>(true)
};
protected final Value<BlockFace>[] CARDINAL_BLOCKFACES_WITHOUT_UP = new Value[] {
new Value<>(BlockFace.NORTH),
new Value<>(BlockFace.EAST),
new Value<>(BlockFace.SOUTH),
new Value<>(BlockFace.WEST),
new Value<>(BlockFace.DOWN),
};
protected final Value<BlockFace>[] CARDINAL_BLOCKFACES = new Value[] {
new Value<>(BlockFace.NORTH),
new Value<>(BlockFace.EAST),
new Value<>(BlockFace.SOUTH),
new Value<>(BlockFace.WEST),
new Value<>(BlockFace.UP),
new Value<>(BlockFace.DOWN),
};
public abstract Material[] getMaterials();
@ -54,7 +93,7 @@ public abstract class BoundingBoxLoader2<T extends BlockData> {
Generator<T> generator = new Generator<>(() -> (T) material.createBlockData());
load(generator);
if (!generator.nodes.isEmpty()) {
generator.nodes.get(0).accept(null);
generator.nodes.get(0).accept(new LinkedList<>(), null);
}
}
} catch (Exception e) {
@ -67,7 +106,7 @@ public abstract class BoundingBoxLoader2<T extends BlockData> {
protected class Generator<T extends BlockData> {
private Supplier<T> blockDataSupplier;
private List<Consumer<T>> nodes = new ArrayList<>();
private List<BiConsumer<Deque<String>, T>> nodes = new ArrayList<>();
private Generator(Supplier<T> blockDataSupplier) {
this.blockDataSupplier = blockDataSupplier;
@ -75,54 +114,75 @@ public abstract class BoundingBoxLoader2<T extends BlockData> {
public final Generator<T> use() {
final int nextNode = nodes.size() + 1;
nodes.add(blockData -> {
nodes.add((lore, blockData) -> {
if (nextNode == 1) blockData = blockDataSupplier.get();
load(blockData.clone());
load(lore, blockData.clone());
if (nodes.size() > nextNode) {
nodes.get(nextNode).accept(blockData);
nodes.get(nextNode).accept(lore, blockData);
}
});
return this;
}
public final <V> Generator<T> generate(Collection<V> values, BiConsumer<T, V> setter) {
public final <V> Generator<T> generate(String loreString, Collection<Value<V>> values, BiConsumer<T, V> setter) {
final int nextNode = nodes.size() + 1;
nodes.add(blockData -> {
for (V value : values) {
if (nextNode == 1) blockData = blockDataSupplier.get();
setter.accept(blockData, value);
nodes.add((lore, blockData) -> {
if (nextNode == 1) blockData = blockDataSupplier.get();
for (Value<V> value : values) {
setter.accept(blockData, value.value);
if (nodes.size() > nextNode) {
nodes.get(nextNode).accept(blockData);
if (value.name != null) {
lore.add(loreString);
lore.add(value.name);
}
nodes.get(nextNode).accept(lore, blockData);
if (value.name != null) {
lore.removeLast();
lore.removeLast();
}
}
}
});
return this;
}
public final <V> Generator<T> generate(V[] values, BiConsumer<T, V> setter) {
return generate(Arrays.asList(values), setter);
public final <V extends Enum<V>> Generator<T> generate(String loreString, Class<V> values, BiConsumer<T, V> setter) {
return generate(loreString, convert(values.getEnumConstants()), setter);
}
public final Generator<T> generate(int minValue, int maxValue, BiConsumer<T, Integer> setter) {
List<Integer> values = new ArrayList<>();
public final <V> Generator<T> generate(String loreString, Value<V>[] values, BiConsumer<T, V> setter) {
return generate(loreString, Arrays.asList(values), setter);
}
public final Generator<T> generate(String loreString, int minValue, int maxValue, BiConsumer<T, Integer> setter) {
List<Value<Integer>> values = new ArrayList<>();
for (int i = minValue; i < maxValue; i++) {
values.add(i);
values.add(new Value<>(i));
}
return generate(values, setter);
return generate(loreString, values, setter);
}
@SafeVarargs
public final <V> Value<V>[] convert(V... values) {
Value<V>[] converted = new Value[values.length];
for (int i = 0; i < values.length; i++) {
converted[i] = new Value<>(values[i]);
}
return converted;
}
}
private static final World WORLD = Bukkit.getWorlds().get(0);
private static final BlockState ORIGIN = WORLD.getBlockState(0, 0, 0);
private void load(BlockData blockData) {
private void load(Deque<String> lore, BlockData blockData) {
WORLD.setBlockData(0, 0, 0, blockData);
VoxelShape voxelShape = WORLD.getBlockAt(0, 0, 0).getCollisionShape();
ORIGIN.update(true, false);
List<Cuboid> cuboids = voxelShape.getBoundingBoxes().stream().map(boundingBox -> {
return new Cuboid(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getWidthX(), boundingBox.getHeight(), boundingBox.getWidthZ());
}).collect(Collectors.toList());
System.out.println(blockData + " " + voxelShape);
System.out.println(blockData + " " + voxelShape + " " + lore);
new BlockBoundingBox(blockData, cuboids, new SWItem(blockData.getMaterial(), "..."));
}
}

Datei anzeigen

@ -40,7 +40,7 @@ public class AmethystBoundingBox extends BoundingBoxLoader2<AmethystCluster> {
@Override
protected void load(BoundingBoxLoader2<AmethystCluster>.Generator<AmethystCluster> generator) {
generator.generate(CARDINAL_BLOCKFACES, AmethystCluster::setFacing)
generator.generate("LAUFBAU_FACING", CARDINAL_BLOCKFACES, AmethystCluster::setFacing)
.use();
}
}

Datei anzeigen

@ -36,7 +36,7 @@ public class HopperBoundingBox extends BoundingBoxLoader2<Hopper> {
@Override
protected void load(BoundingBoxLoader2<Hopper>.Generator<Hopper> generator) {
generator.generate(CARDINAL_BLOCKFACES_WITHOUT_UP, Hopper::setFacing)
generator.generate("LAUFBAU_CONNECTION", CARDINAL_BLOCKFACES_WITHOUT_UP, Hopper::setFacing)
.use();
}
}

Datei anzeigen

@ -20,9 +20,11 @@
package de.steamwar.bausystem.features.slaves.laufbau.boundingboxes2;
import de.steamwar.bausystem.features.slaves.laufbau.BoundingBoxLoader2;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.block.data.type.Snow;
@Linked
public class SnowBoundingBox extends BoundingBoxLoader2<Snow> {
@Override
@ -34,7 +36,7 @@ public class SnowBoundingBox extends BoundingBoxLoader2<Snow> {
@Override
protected void load(BoundingBoxLoader2<Snow>.Generator<Snow> generator) {
generator.generate(2, 8, Snow::setLayers)
generator.generate("LAUFBAU_LAYERS", 2, 8, Snow::setLayers)
.use();
}
}

Datei anzeigen

@ -24,7 +24,6 @@ import de.steamwar.linkage.Linked;
import de.steamwar.linkage.MaxVersion;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Fence;
@MaxVersion(15)
@ -40,10 +39,10 @@ public class WallBoundingBox15 extends BoundingBoxLoader2<Fence> {
@Override
protected void load(BoundingBoxLoader2<Fence>.Generator<Fence> generator) {
generator.generate(BOOLEANS, (wall, has) -> wall.setFace(BlockFace.NORTH, has))
.generate(BOOLEANS, (wall, has) -> wall.setFace(BlockFace.SOUTH, has))
.generate(BOOLEANS, (wall, has) -> wall.setFace(BlockFace.EAST, has))
.generate(BOOLEANS, (wall, has) -> wall.setFace(BlockFace.WEST, has))
generator.generate("", BOOLEANS, (wall, has) -> wall.setFace(BlockFace.NORTH, has))
.generate("", BOOLEANS, (wall, has) -> wall.setFace(BlockFace.SOUTH, has))
.generate("", BOOLEANS, (wall, has) -> wall.setFace(BlockFace.EAST, has))
.generate("", BOOLEANS, (wall, has) -> wall.setFace(BlockFace.WEST, has))
.use();
}
}

Datei anzeigen

@ -37,13 +37,19 @@ public class WallBoundingBox18 extends BoundingBoxLoader2<Wall> {
};
}
private static final Value<Wall.Height>[] HEIGHTS = new Value[] {
new Value<>(Wall.Height.NONE).hideLore(),
new Value<>(Wall.Height.LOW),
new Value<>(Wall.Height.TALL),
};
@Override
protected void load(BoundingBoxLoader2<Wall>.Generator<Wall> generator) {
generator.generate(BOOLEANS, Wall::setUp)
.generate(Wall.Height.values(), (wall, height) -> wall.setHeight(BlockFace.NORTH, height))
.generate(Wall.Height.values(), (wall, height) -> wall.setHeight(BlockFace.SOUTH, height))
.generate(Wall.Height.values(), (wall, height) -> wall.setHeight(BlockFace.EAST, height))
.generate(Wall.Height.values(), (wall, height) -> wall.setHeight(BlockFace.WEST, height))
generator.generate("", BOOLEANS, Wall::setUp)
.generate("", HEIGHTS, (wall, height) -> wall.setHeight(BlockFace.NORTH, height))
.generate("", HEIGHTS, (wall, height) -> wall.setHeight(BlockFace.SOUTH, height))
.generate("", HEIGHTS, (wall, height) -> wall.setHeight(BlockFace.EAST, height))
.generate("", HEIGHTS, (wall, height) -> wall.setHeight(BlockFace.WEST, height))
.use();
}
}