mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-28 22:47:41 +02:00
Cleanup
This commit is contained in:
parent
11b2426629
commit
d146aacd36
@ -9,6 +9,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -41,10 +42,7 @@ final class BlockImpl implements Block {
|
|||||||
public @NotNull Block withProperty(@NotNull String property, @NotNull String value) {
|
public @NotNull Block withProperty(@NotNull String property, @NotNull String value) {
|
||||||
var properties = new HashMap<>(this.properties);
|
var properties = new HashMap<>(this.properties);
|
||||||
properties.replace(property, value);
|
properties.replace(property, value);
|
||||||
Block block = propertyEntry.getProperties(properties);
|
return compute(properties);
|
||||||
if (block == null)
|
|
||||||
throw new IllegalArgumentException("Invalid property: " + property + ":" + value);
|
|
||||||
return compute(block);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -52,18 +50,12 @@ final class BlockImpl implements Block {
|
|||||||
if (properties.isEmpty()) {
|
if (properties.isEmpty()) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
Block block;
|
|
||||||
if (this.properties.size() == properties.size()) {
|
if (this.properties.size() == properties.size()) {
|
||||||
// Map should be complete
|
return compute(properties); // Map should be complete
|
||||||
block = propertyEntry.getProperties(properties);
|
|
||||||
} else {
|
|
||||||
var newProperties = new HashMap<>(this.properties);
|
|
||||||
newProperties.replaceAll((key, value) -> Objects.requireNonNullElse(properties.get(key), value));
|
|
||||||
block = propertyEntry.getProperties(newProperties);
|
|
||||||
}
|
}
|
||||||
if (block == null)
|
var newProperties = new HashMap<>(this.properties);
|
||||||
throw new IllegalArgumentException("Invalid properties: " + properties);
|
newProperties.replaceAll((key, value) -> Objects.requireNonNullElse(properties.get(key), value));
|
||||||
return compute(block);
|
return compute(newProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -91,7 +83,7 @@ final class BlockImpl implements Block {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Map<String, String> properties() {
|
public @NotNull Map<String, String> properties() {
|
||||||
return properties;
|
return Collections.unmodifiableMap(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -104,8 +96,11 @@ final class BlockImpl implements Block {
|
|||||||
return nbt != null ? tag.read(nbt) : null;
|
return nbt != null ? tag.read(nbt) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Block compute(Block original) {
|
private Block compute(Map<String, String> properties) {
|
||||||
return nbt == null && handler == null ? original :
|
Block block = propertyEntry.getProperties(properties);
|
||||||
new BlockImpl(original.registry(), propertyEntry, original.properties(), nbt, handler);
|
if (block == null)
|
||||||
|
throw new IllegalArgumentException("Invalid properties: " + properties);
|
||||||
|
return nbt == null && handler == null ? block :
|
||||||
|
new BlockImpl(block.registry(), propertyEntry, block.properties(), nbt, handler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user