use of net.modificationstation.stationapi.api.block.BlockState in project StationAPI by ModificationStation.
the class BlockStateHelper method toBlockState.
public static BlockState toBlockState(CompoundTag tag) {
if (tag.containsKey("Name")) {
@NotNull Optional<BlockBase> block = BlockRegistry.INSTANCE.get(Identifier.of(tag.getString("Name")));
if (block.isPresent()) {
BlockStateHolder stateHolder = (BlockStateHolder) block.get();
BlockState blockState = stateHolder.getDefaultState();
if (tag.containsKey("Properties")) {
CompoundTag compoundTag = tag.getCompoundTag("Properties");
StateManager<BlockBase, BlockState> stateManager = stateHolder.getStateManager();
for (String string : ((CompoundTagAccessor) compoundTag).stationapi$getData().keySet()) {
Property<?> property = stateManager.getProperty(string);
if (property != null) {
blockState = withProperty(blockState, property, string, compoundTag, tag);
}
}
}
return blockState;
}
}
return States.AIR.get();
}
use of net.modificationstation.stationapi.api.block.BlockState in project StationAPI by ModificationStation.
the class MixinChunk method setTileWithMetadata.
/**
* @reason early version
* @author mine_diver
*/
@Overwrite
public boolean setTileWithMetadata(int x, int y, int z, int blockId, int meta) {
BlockState state = ((BlockStateHolder) BlockBase.BY_ID[blockId]).getDefaultState();
int yOffset = y >> 4;
ChunkSection section = sections[yOffset];
boolean sameMeta = this.field_957.method_1703(x, y, z) == meta;
if (section == ChunkSection.EMPTY_SECTION) {
if (state.isAir() && sameMeta)
return false;
section = new ChunkSection(yOffset << 4);
this.sections[yOffset] = section;
}
int var6 = this.heightmap[(z << 4) | x] & 255;
BlockState oldState = section.getBlockState(x, y & 15, z);
if (oldState == state && sameMeta)
return false;
else {
int levelX = this.x * 16 + x;
int levelZ = this.z * 16 + z;
section.setBlockState(x, y & 15, z, state);
oldState.getBlock().onBlockRemoved(this.level, levelX, y, levelZ);
this.field_957.method_1704(x, y, z, meta);
if (!this.level.dimension.halvesMapping) {
if (BlockBase.LIGHT_OPACITY[state.getBlock().id] != 0) {
if (y >= var6)
this.method_889(x, y + 1, z);
} else if (y == var6 - 1)
this.method_889(x, y, z);
this.level.method_166(LightType.SKY, levelX, y, levelZ, levelX, y, levelZ);
}
this.level.method_166(LightType.BLOCK, levelX, y, levelZ, levelX, y, levelZ);
this.method_887(x, z);
this.field_957.method_1704(x, y, z, meta);
state.getBlock().onBlockPlaced(this.level, levelX, y, levelZ);
this.field_967 = true;
return true;
}
}
use of net.modificationstation.stationapi.api.block.BlockState in project StationAPI by ModificationStation.
the class MixinChunk method setBlockState.
@Override
@Unique
public BlockState setBlockState(int x, int y, int z, BlockState state) {
int yOffset = y >> 4;
ChunkSection section = sections[yOffset];
if (section == ChunkSection.EMPTY_SECTION) {
if (state.isAir())
return null;
section = new ChunkSection(yOffset << 4);
this.sections[yOffset] = section;
}
int topY = this.heightmap[(z << 4) | x] & 255;
BlockState oldState = section.getBlockState(x, y & 15, z);
if (oldState == state)
return null;
else {
int levelX = this.x * 16 + x;
int levelZ = this.z * 16 + z;
oldState.getBlock().onBlockRemoved(this.level, levelX, y, levelZ);
// moving this to after onBlockRemoved because some blocks may want to get their blockstate before being removed
section.setBlockState(x, y & 15, z, state);
this.field_957.method_1704(x, y, z, 0);
if (!this.level.dimension.halvesMapping) {
if (BlockBase.LIGHT_OPACITY[state.getBlock().id] != 0) {
if (y >= topY)
this.method_889(x, y + 1, z);
} else if (y == topY - 1)
this.method_889(x, y, z);
this.level.method_166(LightType.SKY, levelX, y, levelZ, levelX, y, levelZ);
}
this.level.method_166(LightType.BLOCK, levelX, y, levelZ, levelX, y, levelZ);
this.method_887(x, z);
if (!this.level.isClient) {
state.getBlock().onBlockPlaced(this.level, levelX, y, levelZ);
}
this.field_967 = true;
return oldState;
}
}
use of net.modificationstation.stationapi.api.block.BlockState in project StationAPI by ModificationStation.
the class ItemColours method create.
public static ItemColours create(BlockColours blockColors) {
ItemColours itemColors = new ItemColours();
itemColors.register((stack, tintIndex) -> {
BlockState blockState = ((BlockStateHolder) BlockBase.BY_ID[stack.itemId]).getDefaultState();
return blockColors.getColour(blockState, null, null, tintIndex);
}, (ItemConvertible) BlockBase.GRASS, (ItemConvertible) BlockBase.TALLGRASS, (ItemConvertible) BlockBase.LEAVES);
return itemColors;
}
Aggregations