Fix up annotations in block classes and slight cleanup

Dieser Commit ist enthalten in:
dordsor21 2021-08-25 12:25:33 +01:00
Ursprung 80d99073ec
Commit ea6b29f145
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B
6 geänderte Dateien mit 81 neuen und 89 gelöschten Zeilen

Datei anzeigen

@ -54,9 +54,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
private final BlockState blockState; private final BlockState blockState;
@Nullable @Nullable
//FAWE start - LR<CBT> instead of CompoundTat
private final LazyReference<CompoundBinaryTag> nbtData; private final LazyReference<CompoundBinaryTag> nbtData;
//FAWE end
//FAWE start //FAWE start
@ -167,16 +165,13 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
@Override @Override
public String getNbtId() { public String getNbtId() {
//FAWE start - LR<CBT> > CompoundTag
LazyReference<CompoundBinaryTag> nbtData = this.nbtData; LazyReference<CompoundBinaryTag> nbtData = this.nbtData;
if (nbtData == null) { if (nbtData == null) {
return ""; return "";
} }
return nbtData.getValue().getString("id"); return nbtData.getValue().getString("id");
//FAWE end
} }
//FAWE start
@Nullable @Nullable
@Override @Override
public LazyReference<CompoundBinaryTag> getNbtReference() { public LazyReference<CompoundBinaryTag> getNbtReference() {
@ -187,7 +182,6 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
public void setNbtReference(@Nullable LazyReference<CompoundBinaryTag> nbtData) { public void setNbtReference(@Nullable LazyReference<CompoundBinaryTag> nbtData) {
throw new UnsupportedOperationException("This class is immutable."); throw new UnsupportedOperationException("This class is immutable.");
} }
//FAWE end
/** /**
* Checks whether the type ID and data value are equal. * Checks whether the type ID and data value are equal.
@ -249,6 +243,17 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
return this; return this;
} }
@Override
public BaseBlock toBaseBlock(LazyReference<CompoundBinaryTag> compoundTag) {
if (compoundTag == null) {
return this.blockState.toBaseBlock();
} else if (compoundTag == this.nbtData) {
return this;
} else {
return new BaseBlock(this.blockState, compoundTag);
}
}
//FAWE start //FAWE start
@Override @Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException { public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
@ -284,22 +289,15 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
return toImmutableState().with(property, value).toBaseBlock(getNbtData()); return toImmutableState().with(property, value).toBaseBlock(getNbtData());
} }
@Override
public BaseBlock toBaseBlock(LazyReference<CompoundBinaryTag> compoundTag) {
if (compoundTag == null) {
return this.blockState.toBaseBlock();
} else if (compoundTag == this.nbtData) {
return this;
} else {
return new BaseBlock(this.blockState, compoundTag);
}
}
@Override @Override
public <V> V getState(PropertyKey property) { public <V> V getState(PropertyKey property) {
return toImmutableState().getState(property); return toImmutableState().getState(property);
} }
public BlockState toBlockState() {
return blockState;
}
@Override @Override
public int hashCode() { public int hashCode() {
return getOrdinal(); return getOrdinal();
@ -309,7 +307,6 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
@Override @Override
public String toString() { public String toString() {
String nbtString = ""; String nbtString = "";
//FAWE start - use CBT
CompoundBinaryTag nbtData = getNbt(); CompoundBinaryTag nbtData = getNbt();
if (nbtData != null) { if (nbtData != null) {
try { try {
@ -321,9 +318,4 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
return blockState.getAsString() + nbtString; return blockState.getAsString() + nbtString;
} }
public BlockState toBlockState() {
return blockState;
}
//FAWE end
} }

Datei anzeigen

@ -250,11 +250,6 @@ public class BlockState implements BlockStateHolder<BlockState>, Pattern {
return getBlockType().withPropertyId(propertyId); return getBlockType().withPropertyId(propertyId);
} }
@Override
public BlockType getBlockType() {
return this.blockType;
}
@Override @Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException { public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
return set.setBlock(extent, this); return set.setBlock(extent, this);
@ -338,15 +333,22 @@ public class BlockState implements BlockStateHolder<BlockState>, Pattern {
} }
return newState; return newState;
} }
//FAWE end
@Override @Override
public Map<Property<?>, Object> getStates() { public Map<Property<?>, Object> getStates() {
//FAWE end
BlockType type = this.getBlockType(); BlockType type = this.getBlockType();
// Lazily initialize the map // Lazily initialize the map
Map<? extends Property, Object> map = Maps.asMap(type.getPropertiesSet(), (Function<Property, Object>) this::getState); Map<? extends Property, Object> map = Maps.asMap(type.getPropertiesSet(), (Function<Property, Object>) this::getState);
return Collections.unmodifiableMap((Map<Property<?>, Object>) map); return Collections.unmodifiableMap(map);
}
//FAWE end //FAWE end
}
@Override
public BlockType getBlockType() {
return this.blockType;
}
@Override @Override
public boolean equalsFuzzy(BlockStateHolder<?> o) { public boolean equalsFuzzy(BlockStateHolder<?> o) {
@ -357,10 +359,12 @@ public class BlockState implements BlockStateHolder<BlockState>, Pattern {
// Added a reference equality check for speediness // Added a reference equality check for speediness
return true; return true;
} }
//FAWE start
if (o.getClass() == BlockState.class) { if (o.getClass() == BlockState.class) {
return o.getOrdinal() == this.getOrdinal(); return o.getOrdinal() == this.getOrdinal();
} }
return o.equalsFuzzy(this); return o.equalsFuzzy(this);
//FAWE end
} }
@Override @Override
@ -431,20 +435,6 @@ public class BlockState implements BlockStateHolder<BlockState>, Pattern {
return this.ordinalChar; return this.ordinalChar;
} }
@Override
public String toString() {
return getAsString();
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof BlockState)) {
return false;
}
return equalsFuzzy((BlockState) obj);
}
@Override @Override
public int hashCode() { public int hashCode() {
return getOrdinal(); return getOrdinal();
@ -459,4 +449,18 @@ public class BlockState implements BlockStateHolder<BlockState>, Pattern {
return compoundInput.get(this, input, x, y, z); return compoundInput.get(this, input, x, y, z);
} }
//FAWE end //FAWE end
@Override
public String toString() {
return getAsString();
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof BlockState)) {
return false;
}
return equalsFuzzy((BlockState) obj);
}
} }

Datei anzeigen

@ -92,6 +92,15 @@ public interface BlockStateHolder<B extends BlockStateHolder<B>> extends TileEnt
*/ */
<V> B with(final Property<V> property, final V value); <V> B with(final Property<V> property, final V value);
/**
* Gets the value for the given state.
*
* @param property The state
* @return The value
*/
<V> V getState(Property<V> property);
//FAWE start
/** /**
* Returns a BlockStateHolder with the given state and value applied. * Returns a BlockStateHolder with the given state and value applied.
* *
@ -101,14 +110,6 @@ public interface BlockStateHolder<B extends BlockStateHolder<B>> extends TileEnt
*/ */
<V> B with(final PropertyKey property, final V value); <V> B with(final PropertyKey property, final V value);
/**
* Gets the value for the given state.
*
* @param property The state
* @return The value
*/
<V> V getState(Property<V> property);
/** /**
* Gets the value for the given state. * Gets the value for the given state.
* *
@ -116,6 +117,7 @@ public interface BlockStateHolder<B extends BlockStateHolder<B>> extends TileEnt
* @return The value * @return The value
*/ */
<V> V getState(final PropertyKey property); <V> V getState(final PropertyKey property);
//FAWE end
/** /**
* Gets an immutable collection of the states. * Gets an immutable collection of the states.
@ -146,8 +148,6 @@ public interface BlockStateHolder<B extends BlockStateHolder<B>> extends TileEnt
*/ */
BaseBlock toBaseBlock(); BaseBlock toBaseBlock();
//FAWE start
/** /**
* Gets a {@link BaseBlock} from this BlockStateHolder. * Gets a {@link BaseBlock} from this BlockStateHolder.
* *
@ -193,6 +193,7 @@ public interface BlockStateHolder<B extends BlockStateHolder<B>> extends TileEnt
return toBaseBlock(); return toBaseBlock();
} }
//FAWE start
void applyTileEntity(OutputExtent output, int x, int y, int z); void applyTileEntity(OutputExtent output, int x, int y, int z);
default BaseBlock toBaseBlock(ITileInput input, int x, int y, int z) { default BaseBlock toBaseBlock(ITileInput input, int x, int y, int z) {

Datei anzeigen

@ -60,17 +60,15 @@ public class BlockType implements Keyed, Pattern {
private static final Logger LOGGER = LogManagerCompat.getLogger(); private static final Logger LOGGER = LogManagerCompat.getLogger();
private final String id; private final String id;
private final BlockTypesCache.Settings settings;
private final LazyReference<FuzzyBlockState> emptyFuzzy private final LazyReference<FuzzyBlockState> emptyFuzzy
= LazyReference.from(() -> new FuzzyBlockState(this)); = LazyReference.from(() -> new FuzzyBlockState(this));
//FAWE start
private final BlockTypesCache.Settings settings;
@Deprecated @Deprecated
private final LazyReference<String> name = LazyReference.from(() -> WorldEdit.getInstance().getPlatformManager() private final LazyReference<String> name = LazyReference.from(() -> WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getName(this)); .queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getName(this));
//FAWE start //FAWE start
private final LazyReference<Integer> legacyId = LazyReference.from(() -> computeLegacy(0));
private final LazyReference<Integer> legacyData = LazyReference.from(() -> computeLegacy(1));
private Integer legacyCombinedId; private Integer legacyCombinedId;
private boolean initItemType; private boolean initItemType;
private ItemType itemType; private ItemType itemType;
@ -382,6 +380,11 @@ public class BlockType implements Keyed, Pattern {
//FAWE end //FAWE end
} }
@Override
public String toString() {
return getId();
}
//FAWE start //FAWE start
/** /**
@ -397,11 +400,6 @@ public class BlockType implements Keyed, Pattern {
return this.settings.internalId; return this.settings.internalId;
} }
@Override
public String toString() {
return getId();
}
@Override @Override
public int hashCode() { public int hashCode() {
return settings.internalId; // stop changing this to WEs bad hashcode return settings.internalId; // stop changing this to WEs bad hashcode

Datei anzeigen

@ -37,16 +37,16 @@ public class BlockTypesCache {
*/ */
protected static final class Settings { protected static final class Settings {
protected final int internalId; final int internalId;
protected final BlockState defaultState; final BlockState defaultState;
protected final AbstractProperty<?>[] propertiesMapArr; final AbstractProperty<?>[] propertiesMapArr;
protected final AbstractProperty<?>[] propertiesArr; final AbstractProperty<?>[] propertiesArr;
protected final List<AbstractProperty<?>> propertiesList; final List<AbstractProperty<?>> propertiesList;
protected final Map<String, AbstractProperty<?>> propertiesMap; final Map<String, AbstractProperty<?>> propertiesMap;
protected final Set<AbstractProperty<?>> propertiesSet; final Set<AbstractProperty<?>> propertiesSet;
protected final BlockMaterial blockMaterial; final BlockMaterial blockMaterial;
protected final int permutations; final int permutations;
protected int[] stateOrdinals; int[] stateOrdinals;
Settings(BlockType type, String id, int internalId, List<BlockState> states) { Settings(BlockType type, String id, int internalId, List<BlockState> states) {
this.internalId = internalId; this.internalId = internalId;

Datei anzeigen

@ -52,8 +52,8 @@ public class FuzzyBlockState extends BlockState {
} }
//FAWE end //FAWE end
//FAWE start - use internal ids
private FuzzyBlockState(BlockState state, Map<Property<?>, Object> values) { private FuzzyBlockState(BlockState state, Map<Property<?>, Object> values) {
//FAWE start - use internal ids
super(state.getBlockType(), state.getInternalId(), state.getOrdinal()); super(state.getBlockType(), state.getInternalId(), state.getOrdinal());
if (values == null || values.isEmpty()) { if (values == null || values.isEmpty()) {
props = Collections.emptyMap(); props = Collections.emptyMap();
@ -65,9 +65,8 @@ public class FuzzyBlockState extends BlockState {
} }
this.values = new HashMap<>(values); this.values = new HashMap<>(values);
} }
}
//FAWE end //FAWE end
}
/** /**
* Gets a full BlockState from this fuzzy one, filling in * Gets a full BlockState from this fuzzy one, filling in
@ -85,6 +84,11 @@ public class FuzzyBlockState extends BlockState {
return state; return state;
} }
@Override
public BlockState toImmutableState() {
return getFullState();
}
//FAWE start //FAWE start
@Override @Override
public boolean equalsFuzzy(BlockStateHolder<?> o) { public boolean equalsFuzzy(BlockStateHolder<?> o) {
@ -113,15 +117,16 @@ public class FuzzyBlockState extends BlockState {
return new BaseBlock(state); return new BaseBlock(state);
} }
@Override
public BlockState toImmutableState() {
return getFullState();
}
@Override @Override
public Map<Property<?>, Object> getStates() { public Map<Property<?>, Object> getStates() {
return values; return values;
} }
@Deprecated
@Override
public CompoundTag getNbtData() {
return getBlockType().getMaterial().isTile() ? getBlockType().getMaterial().getDefaultTile() : null;
}
//FAWE end //FAWE end
/** /**
@ -133,14 +138,6 @@ public class FuzzyBlockState extends BlockState {
return new Builder(); return new Builder();
} }
//FAWE start
@Deprecated
@Override
public CompoundTag getNbtData() {
return getBlockType().getMaterial().isTile() ? getBlockType().getMaterial().getDefaultTile() : null;
}
//FAWE end
/** /**
* Builder for FuzzyBlockState * Builder for FuzzyBlockState
*/ */