mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-17 14:21:08 +00:00
fix MaterialSet issues
This commit is contained in:
@@ -1,12 +1,43 @@
|
|||||||
package com.dfsek.terra.api.util;
|
package com.dfsek.terra.api.util;
|
||||||
|
|
||||||
import com.dfsek.terra.api.block.BlockType;
|
import com.dfsek.terra.api.block.BlockType;
|
||||||
|
import com.dfsek.terra.api.block.state.BlockState;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.util.AbstractSet;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public interface MaterialSet extends Set<BlockType> {
|
public class MaterialSet extends HashSet<BlockType> {
|
||||||
static MaterialSet empty() {
|
@Serial
|
||||||
return (MaterialSet) (Object) Collections.emptySet();
|
private static final long serialVersionUID = 3056512763631017301L;
|
||||||
|
|
||||||
|
public static MaterialSet singleton(BlockType material) {
|
||||||
|
MaterialSet set = new MaterialSet();
|
||||||
|
set.add(material);
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MaterialSet get(BlockType... materials) {
|
||||||
|
MaterialSet set = new MaterialSet();
|
||||||
|
set.addAll(Arrays.asList(materials));
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MaterialSet get(BlockState... materials) {
|
||||||
|
MaterialSet set = new MaterialSet();
|
||||||
|
Arrays.stream(materials).forEach(set::add);
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MaterialSet empty() {
|
||||||
|
return new MaterialSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void add(BlockState data) {
|
||||||
|
add(data.getBlockType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-38
@@ -1,38 +0,0 @@
|
|||||||
package com.dfsek.terra.api.util.collections;
|
|
||||||
|
|
||||||
import com.dfsek.terra.api.block.state.BlockState;
|
|
||||||
import com.dfsek.terra.api.block.BlockType;
|
|
||||||
import com.dfsek.terra.api.util.MaterialSet;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
public class MaterialSetImpl extends HashSet<BlockType> implements MaterialSet {
|
|
||||||
private static final long serialVersionUID = 3056512763631017301L;
|
|
||||||
|
|
||||||
public static MaterialSetImpl singleton(BlockType material) {
|
|
||||||
MaterialSetImpl set = new MaterialSetImpl();
|
|
||||||
set.add(material);
|
|
||||||
return set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MaterialSetImpl get(BlockType... materials) {
|
|
||||||
MaterialSetImpl set = new MaterialSetImpl();
|
|
||||||
set.addAll(Arrays.asList(materials));
|
|
||||||
return set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MaterialSetImpl get(BlockState... materials) {
|
|
||||||
MaterialSetImpl set = new MaterialSetImpl();
|
|
||||||
Arrays.stream(materials).forEach(set::add);
|
|
||||||
return set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MaterialSetImpl empty() {
|
|
||||||
return new MaterialSetImpl();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void add(BlockState data) {
|
|
||||||
add(data.getBlockType());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,9 +5,9 @@ import com.dfsek.terra.api.TerraPlugin;
|
|||||||
import com.dfsek.terra.api.addon.TerraAddon;
|
import com.dfsek.terra.api.addon.TerraAddon;
|
||||||
import com.dfsek.terra.api.block.BlockType;
|
import com.dfsek.terra.api.block.BlockType;
|
||||||
import com.dfsek.terra.api.tectonic.LoaderRegistrar;
|
import com.dfsek.terra.api.tectonic.LoaderRegistrar;
|
||||||
|
import com.dfsek.terra.api.util.MaterialSet;
|
||||||
import com.dfsek.terra.api.util.ProbabilityCollection;
|
import com.dfsek.terra.api.util.ProbabilityCollection;
|
||||||
import com.dfsek.terra.api.util.Range;
|
import com.dfsek.terra.api.util.Range;
|
||||||
import com.dfsek.terra.api.util.collections.MaterialSetImpl;
|
|
||||||
import com.dfsek.terra.api.world.biome.generation.pipeline.BiomeSource;
|
import com.dfsek.terra.api.world.biome.generation.pipeline.BiomeSource;
|
||||||
import com.dfsek.terra.config.loaders.LinkedHashMapLoader;
|
import com.dfsek.terra.config.loaders.LinkedHashMapLoader;
|
||||||
import com.dfsek.terra.config.loaders.MaterialSetLoader;
|
import com.dfsek.terra.config.loaders.MaterialSetLoader;
|
||||||
@@ -27,7 +27,7 @@ public class GenericLoaders implements LoaderRegistrar {
|
|||||||
public void register(TypeRegistry registry) {
|
public void register(TypeRegistry registry) {
|
||||||
registry.registerLoader(ProbabilityCollection.class, new ProbabilityCollectionLoader())
|
registry.registerLoader(ProbabilityCollection.class, new ProbabilityCollectionLoader())
|
||||||
.registerLoader(Range.class, new RangeLoader())
|
.registerLoader(Range.class, new RangeLoader())
|
||||||
.registerLoader(MaterialSetImpl.class, new MaterialSetLoader())
|
.registerLoader(MaterialSet.class, new MaterialSetLoader())
|
||||||
.registerLoader(LinkedHashMap.class, new LinkedHashMapLoader())
|
.registerLoader(LinkedHashMap.class, new LinkedHashMapLoader())
|
||||||
.registerLoader(BiomeSource.Type.class, (t, object, cf) -> BiomeSource.Type.valueOf((String) object));
|
.registerLoader(BiomeSource.Type.class, (t, object, cf) -> BiomeSource.Type.valueOf((String) object));
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -4,17 +4,17 @@ import com.dfsek.tectonic.exception.LoadException;
|
|||||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||||
import com.dfsek.tectonic.loading.TypeLoader;
|
import com.dfsek.tectonic.loading.TypeLoader;
|
||||||
import com.dfsek.terra.api.block.BlockType;
|
import com.dfsek.terra.api.block.BlockType;
|
||||||
import com.dfsek.terra.api.util.collections.MaterialSetImpl;
|
import com.dfsek.terra.api.util.MaterialSet;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class MaterialSetLoader implements TypeLoader<MaterialSetImpl> {
|
public class MaterialSetLoader implements TypeLoader<MaterialSet> {
|
||||||
@Override
|
@Override
|
||||||
public MaterialSetImpl load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
public MaterialSet load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||||
List<String> stringData = (List<String>) o;
|
List<String> stringData = (List<String>) o;
|
||||||
MaterialSetImpl set = new MaterialSetImpl();
|
MaterialSet set = new MaterialSet();
|
||||||
|
|
||||||
for(String string : stringData) {
|
for(String string : stringData) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.dfsek.terra.bukkit.world;
|
|||||||
import com.dfsek.terra.api.TerraPlugin;
|
import com.dfsek.terra.api.TerraPlugin;
|
||||||
import com.dfsek.terra.api.handle.WorldHandle;
|
import com.dfsek.terra.api.handle.WorldHandle;
|
||||||
import com.dfsek.terra.api.profiler.ProfileFrame;
|
import com.dfsek.terra.api.profiler.ProfileFrame;
|
||||||
import com.dfsek.terra.api.util.collections.MaterialSetImpl;
|
import com.dfsek.terra.api.util.MaterialSet;
|
||||||
import com.dfsek.terra.api.vector.Vector3;
|
import com.dfsek.terra.api.vector.Vector3;
|
||||||
import com.dfsek.terra.api.world.Tree;
|
import com.dfsek.terra.api.world.Tree;
|
||||||
import com.dfsek.terra.api.world.World;
|
import com.dfsek.terra.api.world.World;
|
||||||
@@ -14,7 +14,7 @@ import java.util.Random;
|
|||||||
|
|
||||||
public class BukkitTree implements Tree {
|
public class BukkitTree implements Tree {
|
||||||
private final TreeType delegate;
|
private final TreeType delegate;
|
||||||
private final MaterialSetImpl spawnable;
|
private final MaterialSet spawnable;
|
||||||
private final TerraPlugin main;
|
private final TerraPlugin main;
|
||||||
|
|
||||||
public BukkitTree(TreeType delegate, TerraPlugin main) {
|
public BukkitTree(TreeType delegate, TerraPlugin main) {
|
||||||
@@ -23,21 +23,21 @@ public class BukkitTree implements Tree {
|
|||||||
this.spawnable = getSpawnable(delegate);
|
this.spawnable = getSpawnable(delegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MaterialSetImpl getSpawnable(TreeType type) {
|
private MaterialSet getSpawnable(TreeType type) {
|
||||||
WorldHandle handle = main.getWorldHandle();
|
WorldHandle handle = main.getWorldHandle();
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case CRIMSON_FUNGUS:
|
case CRIMSON_FUNGUS:
|
||||||
return MaterialSetImpl.get(handle.createBlockData("minecraft:crimson_nylium"));
|
return MaterialSet.get(handle.createBlockData("minecraft:crimson_nylium"));
|
||||||
case WARPED_FUNGUS:
|
case WARPED_FUNGUS:
|
||||||
return MaterialSetImpl.get(handle.createBlockData("minecraft:warped_nylium"));
|
return MaterialSet.get(handle.createBlockData("minecraft:warped_nylium"));
|
||||||
case BROWN_MUSHROOM:
|
case BROWN_MUSHROOM:
|
||||||
case RED_MUSHROOM:
|
case RED_MUSHROOM:
|
||||||
return MaterialSetImpl.get(handle.createBlockData("minecraft:mycelium"), handle.createBlockData("minecraft:grass_block"),
|
return MaterialSet.get(handle.createBlockData("minecraft:mycelium"), handle.createBlockData("minecraft:grass_block"),
|
||||||
handle.createBlockData("minecraft:podzol"));
|
handle.createBlockData("minecraft:podzol"));
|
||||||
case CHORUS_PLANT:
|
case CHORUS_PLANT:
|
||||||
return MaterialSetImpl.get(handle.createBlockData("minecraft:end_stone"));
|
return MaterialSet.get(handle.createBlockData("minecraft:end_stone"));
|
||||||
default:
|
default:
|
||||||
return MaterialSetImpl.get(handle.createBlockData("minecraft:grass_block"), handle.createBlockData("minecraft:dirt"),
|
return MaterialSet.get(handle.createBlockData("minecraft:grass_block"), handle.createBlockData("minecraft:dirt"),
|
||||||
handle.createBlockData("minecraft:podzol"));
|
handle.createBlockData("minecraft:podzol"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ public class BukkitTree implements Tree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MaterialSetImpl getSpawnable() {
|
public MaterialSet getSpawnable() {
|
||||||
return spawnable;
|
return spawnable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -2,7 +2,7 @@ package com.dfsek.terra.fabric.mixin.implementations;
|
|||||||
|
|
||||||
import com.dfsek.terra.api.block.BlockType;
|
import com.dfsek.terra.api.block.BlockType;
|
||||||
import com.dfsek.terra.api.profiler.ProfileFrame;
|
import com.dfsek.terra.api.profiler.ProfileFrame;
|
||||||
import com.dfsek.terra.api.util.collections.MaterialSetImpl;
|
import com.dfsek.terra.api.util.MaterialSet;
|
||||||
import com.dfsek.terra.api.vector.Vector3;
|
import com.dfsek.terra.api.vector.Vector3;
|
||||||
import com.dfsek.terra.api.world.Tree;
|
import com.dfsek.terra.api.world.Tree;
|
||||||
import com.dfsek.terra.api.world.World;
|
import com.dfsek.terra.api.world.World;
|
||||||
@@ -38,7 +38,7 @@ public abstract class ConfiguredFeatureMixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Set<BlockType> terra$getSpawnable() {
|
public Set<BlockType> terra$getSpawnable() {
|
||||||
return MaterialSetImpl.get(TerraFabricPlugin.getInstance().getWorldHandle().createBlockData("minecraft:grass_block"),
|
return MaterialSet.get(TerraFabricPlugin.getInstance().getWorldHandle().createBlockData("minecraft:grass_block"),
|
||||||
TerraFabricPlugin.getInstance().getWorldHandle().createBlockData("minecraft:podzol"),
|
TerraFabricPlugin.getInstance().getWorldHandle().createBlockData("minecraft:podzol"),
|
||||||
TerraFabricPlugin.getInstance().getWorldHandle().createBlockData("minecraft:mycelium"));
|
TerraFabricPlugin.getInstance().getWorldHandle().createBlockData("minecraft:mycelium"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.dfsek.terra.platform;
|
package com.dfsek.terra.platform;
|
||||||
|
|
||||||
import com.dfsek.terra.api.util.collections.MaterialSetImpl;
|
import com.dfsek.terra.api.util.MaterialSet;
|
||||||
import com.dfsek.terra.api.vector.Vector3;
|
import com.dfsek.terra.api.vector.Vector3;
|
||||||
import com.dfsek.terra.api.world.Tree;
|
import com.dfsek.terra.api.world.Tree;
|
||||||
import com.dfsek.terra.api.world.World;
|
import com.dfsek.terra.api.world.World;
|
||||||
@@ -14,7 +14,7 @@ public class RawTree implements Tree { // TODO: implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MaterialSetImpl getSpawnable() {
|
public MaterialSet getSpawnable() {
|
||||||
return MaterialSetImpl.empty();
|
return MaterialSet.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user