@Override public BlockType getBlockType() { return this.blockState.getBlockType(); }
@Override public BaseBlock toBaseBlock(CompoundTag compoundTag) { if (compoundTag == null) { return this.blockState.toBaseBlock(); } else if (compoundTag == this.nbtData) { return this; } else { return new BaseBlock(this.blockState, compoundTag); } }
for (List<Object> valueList : valueLists) { Map<Property<?>, Object> valueMap = Maps.newTreeMap(Comparator.comparing(Property::getName)); BlockState stateMaker = new BlockState(blockType); for (int i = 0; i < valueList.size(); i++) { Property<?> property = properties.get(i); Object value = valueList.get(i); valueMap.put(property, value); stateMaker.setState(property, value); stateMap.put(new LinkedHashMap<>(), new BlockState(blockType)); state.populate(stateMap);
@Override public <V> BaseBlock with(Property<V> property, V value) { return this.blockState.with(property, value).toBaseBlock(getNbtData()); }
@Override public boolean equalsFuzzy(BlockStateHolder<?> o) { if (this == o) { // Added a reference equality check for return true; } if (!getBlockType().equals(o.getBlockType())) { return false; } Set<Property<?>> differingProperties = new HashSet<>(); for (Object state : o.getStates().keySet()) { if (getState((Property<?>) state) == null) { differingProperties.add((Property<?>) state); } } for (Property<?> property : getStates().keySet()) { if (o.getState(property) == null) { differingProperties.add(property); } } for (Property<?> property : getStates().keySet()) { if (differingProperties.contains(property)) { continue; } if (!Objects.equals(getState(property), o.getState(property))) { return false; } } return true; }
blockType = state.getBlockType(); blockType = blockInHand.getBlockType(); blockStates = blockInHand.getStates(); } else { return state.toBaseBlock();
&& !config.allowedDataCycleBlocks.contains(block.getBlockType().getId())) { player.printError("You are not permitted to cycle the data value of that block."); return true; if (block.getStates().keySet().isEmpty()) { player.printError("That block's data cannot be cycled!"); } else { Property<?> currentProperty = selectedProperties.get(player.getUniqueId()); if (currentProperty == null || (forward && block.getState(currentProperty) == null)) { currentProperty = block.getStates().keySet().stream().findFirst().get(); selectedProperties.put(player.getUniqueId(), currentProperty); block.getState(currentProperty); int index = currentProperty.getValues().indexOf(block.getState(currentProperty)); index = (index + 1) % currentProperty.getValues().size(); @SuppressWarnings("unchecked") Property<Object> objProp = (Property<Object>) currentProperty; BlockState newBlock = block.with(objProp, currentProperty.getValues().get(index)); List<Property<?>> properties = Lists.newArrayList(block.getStates().keySet()); int index = properties.indexOf(currentProperty); index = (index + 1) % properties.size();
Property<Object> propertyKey = (Property<Object>) state.getBlockType().getPropertyMap().get(parts[0]); if (propertyKey == null) { throw new NoMatchException("Unknown state " + parts[0] + " for block " + state.getBlockType().getName()); state = state.with(propertyKey, value); } catch (NoMatchException e) { throw e; // Pass-through
String name = c.getID().getBlockType().getName(); String str; if (separateStates) { c.getAmount() / (double) size * 100, name, c.getID().getAsString()); } else { str = String.format("%-7s (%.3f%%) %s #%s", c.getAmount() / (double) size * 100, name, c.getID().getBlockType().getId());
if (paletteEntry.containsKey("Properties")) { CompoundTag properties = NBTUtils.getChildTag(paletteEntry.getValue(), "Properties", CompoundTag.class); for (Property<?> property : blockState.getStates().keySet()) { if (properties.containsKey(property.getName())) { String value = properties.getString(property.getName()); blockState = getBlockStateWith(blockState, property, value); } catch (IllegalArgumentException e) { throw new InvalidFormatException("Invalid block state for " + blockState.getBlockType().getId() + ", " + property.getName() + ": " + value);
/** * Checks if the type is the same, and if the matched states are the same. * * @param o other block * @return true if equal */ @Override public boolean equalsFuzzy(BlockStateHolder<?> o) { return this.blockState.equalsFuzzy(o); }
@Override public String toString() { // if (getNbtData() != null) { // TODO Maybe make some JSON serialiser to make this not awful. // return blockState.getAsString() + " {" + String.valueOf(getNbtData()) + "}"; // } else { return blockState.getAsString(); // } }
/** * Gets the State for this Block. * * @param property The state to get the value for * @return The state value */ @Override public <V> V getState(Property<V> property) { return this.blockState.getState(property); }
/** * Gets a map of state to statevalue * * @return The state map */ @Override public Map<Property<?>, Object> getStates() { return this.blockState.getStates(); }
private Map<Map<Property<?>, Object>, BlockState> getBlockStatesMap() { return updateField(blockStatesMap, () -> BlockState.generateStateMap(this)); }
@Override public int hashCode() { int ret = toImmutableState().hashCode() << 3; if (hasNbtData()) { ret += getNbtData().hashCode(); } return ret; }
@Override public boolean equals(Object obj) { if (!(obj instanceof BlockState)) { return false; } return equalsFuzzy((BlockState) obj); }
@Override public String toString() { return getAsString(); }
/** * The type of the Fuzzy BlockState * * @param state The state * @return The builder, for chaining */ public Builder type(BlockState state) { checkNotNull(state); this.type = state.getBlockType(); return this; }
@Override public BaseBlock apply(BlockVector3 pos) { BaseBlock block = buffer.get(pos); if (block != null) { return block; } else { return BlockTypes.AIR.getDefaultState().toBaseBlock(); } }