Fix Block#withProperty

This commit is contained in:
TheMode 2021-06-23 14:13:28 +02:00
parent 77ef11ef30
commit 408e80799e
2 changed files with 6 additions and 7 deletions

View File

@ -41,10 +41,6 @@ class BlockRegistry {
return entry.propertyMap.get(properties);
}
static @Nullable Block getProperties(Block block, Map<String, String> properties) {
return getProperties(block.namespace().asString(), properties);
}
static {
// Load data from file
JsonObject blocks = Registry.load(Registry.Resource.BLOCK);

View File

@ -11,7 +11,6 @@ import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
class BlockTest implements Block {
@ -45,8 +44,12 @@ class BlockTest implements Block {
public @NotNull Block withProperty(@NotNull String property, @NotNull String value) {
var properties = new HashMap<>(this.properties);
properties.put(property, value);
final Block block = BlockRegistry.getProperties(this, properties);
return Objects.requireNonNull(block);
Block block = BlockRegistry.getProperties(name(), properties);
if (block == null)
throw new IllegalArgumentException("Invalid property: " + property + ":" + value);
if (nbt != null || handler != null)
return new BlockTest(block.registry(), block.properties(), nbt, handler);
return block;
}
@Override