use of org.spongepowered.api.block.BlockType in project SpongeCommon by SpongePowered.
the class MixinChunk_Tracker method addTrackedBlockPosition.
@Override
public void addTrackedBlockPosition(Block block, BlockPos pos, User user, PlayerTracker.Type trackerType) {
if (this.world.isRemote) {
return;
}
if (PhaseTracker.getInstance().getCurrentState().ignoresBlockTracking()) {
// Don't track chunk gen
return;
}
// Don't track fake players
if (user instanceof EntityPlayerMP && SpongeImplHooks.isFakePlayer((EntityPlayerMP) user)) {
return;
}
if (!SpongeHooks.getActiveConfig((WorldServer) this.world).getConfig().getBlockTracking().getBlockBlacklist().contains(((BlockType) block).getId())) {
SpongeHooks.logBlockTrack(this.world, block, pos, user, true);
} else {
SpongeHooks.logBlockTrack(this.world, block, pos, user, false);
}
final IMixinWorldInfo worldInfo = (IMixinWorldInfo) this.world.getWorldInfo();
final int indexForUniqueId = worldInfo.getIndexForUniqueId(user.getUniqueId());
if (pos.getY() <= 255) {
short blockPos = blockPosToShort(pos);
final PlayerTracker playerTracker = this.trackedShortBlockPositions.get(blockPos);
if (playerTracker != null) {
if (trackerType == PlayerTracker.Type.OWNER) {
playerTracker.ownerIndex = indexForUniqueId;
playerTracker.notifierIndex = indexForUniqueId;
} else {
playerTracker.notifierIndex = indexForUniqueId;
}
} else {
this.trackedShortBlockPositions.put(blockPos, new PlayerTracker(indexForUniqueId, trackerType));
}
} else {
int blockPos = blockPosToInt(pos);
final PlayerTracker playerTracker = this.trackedIntBlockPositions.get(blockPos);
if (playerTracker != null) {
if (trackerType == PlayerTracker.Type.OWNER) {
playerTracker.ownerIndex = indexForUniqueId;
} else {
playerTracker.notifierIndex = indexForUniqueId;
}
} else {
this.trackedIntBlockPositions.put(blockPos, new PlayerTracker(indexForUniqueId, trackerType));
}
}
}
use of org.spongepowered.api.block.BlockType in project SpongeCommon by SpongePowered.
the class SpongeItemStackBuilder method fromBlockSnapshot.
@Override
public ItemStack.Builder fromBlockSnapshot(BlockSnapshot blockSnapshot) {
checkNotNull(blockSnapshot, "The snapshot was null!");
reset();
final BlockType blockType = blockSnapshot.getState().getType();
final Optional<ItemType> itemType = blockType.getItem();
itemType(itemType.orElseThrow(() -> new IllegalArgumentException("ItemType not found for block type: " + blockType.getId())));
quantity(1);
if (blockSnapshot instanceof SpongeBlockSnapshot) {
final Block block = (Block) blockType;
this.damageValue = block.damageDropped((IBlockState) blockSnapshot.getState());
final Optional<NBTTagCompound> compound = ((SpongeBlockSnapshot) blockSnapshot).getCompound();
if (compound.isPresent()) {
this.compound = new NBTTagCompound();
this.compound.setTag(NbtDataUtil.BLOCK_ENTITY_TAG, compound.get());
}
// todo probably needs more testing, but this'll do donkey...
} else {
// TODO handle through the API specifically handling the rest of the data stuff
blockSnapshot.getContainers().forEach(this::itemData);
}
return this;
}
use of org.spongepowered.api.block.BlockType in project SpongeCommon by SpongePowered.
the class SpongeBlockStateMetaContentUpdater method update.
@SuppressWarnings("deprecation")
@Override
public DataView update(DataView content) {
// Right, so we have to get the block type id
final String blockTypeId = content.getString(DataQueries.BLOCK_TYPE).get();
// Check if it's there....
final Optional<BlockType> blockType = Sponge.getRegistry().getType(BlockType.class, blockTypeId);
if (!blockType.isPresent()) {
// sure, throw an exception to throw down the chain
throw new InvalidDataException("Could not find a block type for the given id: " + blockTypeId);
}
// Get the meta, if it wasn't available, just default to the default block state.
final int meta = content.getInt(DataQueries.BLOCK_STATE_UNSAFE_META).orElse(0);
// Get the block type
final BlockType type = blockType.get();
// Cast to internal and get the block state from damage value, this is purely
// implementation of minecraft, mods may change this in the future, not really known how
// they will handle it?
final IBlockState blockState = ((Block) type).getStateFromMeta(meta);
// Now that we have the actual block state, delete the old data
content.remove(DataQueries.BLOCK_TYPE);
content.remove(DataQueries.BLOCK_STATE_UNSAFE_META);
// Cast to the API state to get the id
final BlockState apiState = (BlockState) blockState;
// set the id
content.set(DataQueries.BLOCK_STATE, apiState.getId());
// set the version!!
content.set(Queries.CONTENT_VERSION, 2);
// Presto!
return content;
}
use of org.spongepowered.api.block.BlockType in project SpongeCommon by SpongePowered.
the class AbstractTileBuilder method buildContent.
@SuppressWarnings("unchecked")
@Override
protected Optional<T> buildContent(DataView container) throws InvalidDataException {
checkNotNull(container);
if (!container.contains(DataQueries.TILE_TYPE, DataQueries.WORLD, Queries.POSITION_X, Queries.POSITION_Y, Queries.POSITION_Z)) {
return Optional.empty();
}
String worldName = container.getString(DataQueries.WORLD).get();
Optional<World> worldOptional = Sponge.getGame().getServer().getWorld(worldName);
if (!worldOptional.isPresent()) {
throw new InvalidDataException("The provided container references a world that does not exist!");
}
Class<? extends TileEntity> clazz = TileEntity.REGISTRY.getObject(new ResourceLocation(container.getString(DataQueries.TILE_TYPE).get()));
if (clazz == null) {
// basically we didn't manage to find the class and the class isn't even registered with MC
return Optional.empty();
}
BlockType type = classToTypeMap.get(clazz);
if (type == null) {
// TODO throw exception maybe?
return Optional.empty();
}
// Now we should be ready to actually translate the TileEntity with the right block.
final int x = container.getInt(DataQueries.X_POS).get();
final int y = container.getInt(DataQueries.Y_POS).get();
final int z = container.getInt(DataQueries.Z_POS).get();
worldOptional.get().getLocation(x, y, z).setBlockType(type);
BlockPos pos = new BlockPos(x, y, z);
TileEntity tileEntity = ((net.minecraft.world.World) worldOptional.get()).getTileEntity(pos);
if (tileEntity == null) {
// TODO throw exception maybe?
return Optional.empty();
}
// We really need to validate only after the implementing class deems it ready...
tileEntity.invalidate();
return Optional.of((T) tileEntity);
}
use of org.spongepowered.api.block.BlockType in project Skree by Skelril.
the class AntiRailDupeListener method onPistonMove.
@Listener
public void onPistonMove(ChangeBlockEvent event, @Named(NamedCause.SOURCE) Piston piston) {
event.getTransactions().stream().map(Transaction::getFinal).forEach(block -> {
BlockType finalType = block.getState().getType();
if (RAIL_BLOCKS.contains(finalType)) {
Location<World> location = block.getLocation().get();
Task.builder().execute(() -> {
location.setBlockType(BlockTypes.AIR, Cause.source(SkreePlugin.container()).build());
}).delayTicks(1).submit(SkreePlugin.inst());
}
});
}
Aggregations