Blockstates StringProperty
This commit is contained in:
parent
cbff862594
commit
8fca5aab41
2 changed files with 64 additions and 9 deletions
52
src/main/java/ru/bclib/blocks/properties/StringProperty.java
Normal file
52
src/main/java/ru/bclib/blocks/properties/StringProperty.java
Normal file
|
@ -0,0 +1,52 @@
|
|||
package ru.bclib.blocks.properties;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class StringProperty extends Property<String> {
|
||||
|
||||
private final Set<String> values;
|
||||
|
||||
public static StringProperty create(String name, String... values) {
|
||||
return new StringProperty(name, values);
|
||||
}
|
||||
|
||||
protected StringProperty(String string, String... values) {
|
||||
super(string, String.class);
|
||||
this.values = Sets.newHashSet(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getPossibleValues() {
|
||||
return Collections.unmodifiableSet(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(String comparable) {
|
||||
return comparable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getValue(String string) {
|
||||
if (values.contains(string)) {
|
||||
return Optional.of(string);
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int generateHashCode() {
|
||||
return super.generateHashCode() + Objects.hashCode(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof StringProperty that)) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
return values.equals(that.values);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue