Search in sources :

Example 56 with BlockType

use of org.spongepowered.api.block.BlockType in project SpongeCommon by SpongePowered.

the class SpongeBlockSnapshot method createArchetype.

@Override
public Optional<TileEntityArchetype> createArchetype() {
    final BlockType type = this.blockState.getType();
    if (!(type instanceof ITileEntityProvider)) {
        return Optional.empty();
    }
    if (this.compound == null) {
        // We can't retrieve the TileEntityType
        return Optional.empty();
    }
    final String tileId = this.compound.getString(NbtDataUtil.BLOCK_ENTITY_ID);
    final Class<? extends TileEntity> tileClass = TileEntity.REGISTRY.getObject(new ResourceLocation(tileId));
    if (tileClass == null) {
        return Optional.empty();
    }
    final TileEntityType tileType = TileEntityTypeRegistryModule.getInstance().getForClass(tileClass);
    final TileEntityArchetype archetype = TileEntityArchetype.builder().tile(tileType).state(this.blockState).tileData(NbtTranslator.getInstance().translate(this.compound)).build();
    return Optional.of(archetype);
}
Also used : ITileEntityProvider(net.minecraft.block.ITileEntityProvider) BlockType(org.spongepowered.api.block.BlockType) TileEntityType(org.spongepowered.api.block.tileentity.TileEntityType) ResourceLocation(net.minecraft.util.ResourceLocation) TileEntityArchetype(org.spongepowered.api.block.tileentity.TileEntityArchetype)

Example 57 with BlockType

use of org.spongepowered.api.block.BlockType in project SpongeCommon by SpongePowered.

the class BreakablePlaceableUtils method set.

public static boolean set(ItemStack stack, String nbtKey, Set<BlockType> value) {
    NBTTagCompound stackTag = stack.getTagCompound();
    if (value.isEmpty()) {
        if (stackTag != null) {
            stackTag.removeTag(nbtKey);
            if (stackTag.hasNoTags()) {
                stack.setTagCompound(null);
            }
        }
    } else {
        NBTTagList breakableIds = new NBTTagList();
        for (BlockType breakable : value) {
            String id = breakable.getId();
            if (id.startsWith("minecraft:")) {
                id = id.substring("minecraft:".length());
            }
            breakableIds.appendTag(new NBTTagString(id));
        }
        if (stackTag == null) {
            stackTag = new NBTTagCompound();
            stack.setTagCompound(stackTag);
        }
        stackTag.setTag(nbtKey, breakableIds);
    }
    return true;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) BlockType(org.spongepowered.api.block.BlockType) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 58 with BlockType

use of org.spongepowered.api.block.BlockType in project SpongeCommon by SpongePowered.

the class TimingsExport method reportTimings.

/**
 * Builds an XML report of the timings to be uploaded for parsing.
 *
 * @param sender Who to report to
 */
static void reportTimings(CommandSource sender) {
    Platform platform = SpongeImpl.getGame().getPlatform();
    JsonObjectBuilder builder = JSONUtil.objectBuilder().add("version", platform.getContainer(IMPLEMENTATION).getVersion().orElse(platform.getMinecraftVersion().getName() + "-DEV")).add("maxplayers", SpongeImpl.getGame().getServer().getMaxPlayers()).add("start", TimingsManager.timingStart / 1000).add("end", System.currentTimeMillis() / 1000).add("sampletime", (System.currentTimeMillis() - TimingsManager.timingStart) / 1000);
    if (!TimingsManager.privacy) {
        builder.add("server", getServerName()).add("motd", Sponge.getServer().getMotd().toPlain()).add("online-mode", Sponge.getServer().getOnlineMode()).add("icon", SpongeImpl.getServer().getServerStatusResponse().getFavicon());
    }
    final Runtime runtime = Runtime.getRuntime();
    RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
    builder.add("system", JSONUtil.objectBuilder().add("timingcost", getCost()).add("name", System.getProperty("os.name")).add("version", System.getProperty("os.version")).add("jvmversion", System.getProperty("java.version")).add("arch", System.getProperty("os.arch")).add("maxmem", runtime.maxMemory()).add("cpu", runtime.availableProcessors()).add("runtime", ManagementFactory.getRuntimeMXBean().getUptime()).add("flags", RUNTIME_FLAG_JOINER.join(runtimeBean.getInputArguments())).add("gc", JSONUtil.mapArrayToObject(ManagementFactory.getGarbageCollectorMXBeans(), (input) -> {
        return JSONUtil.singleObjectPair(input.getName(), JSONUtil.arrayOf(input.getCollectionCount(), input.getCollectionTime()));
    })));
    Set<BlockType> blockTypeSet = Sets.newHashSet();
    Set<EntityType> entityTypeSet = Sets.newHashSet();
    int size = HISTORY.size();
    TimingHistory[] history = new TimingHistory[size + 1];
    int i = 0;
    for (TimingHistory timingHistory : HISTORY) {
        blockTypeSet.addAll(timingHistory.blockTypeSet);
        entityTypeSet.addAll(timingHistory.entityTypeSet);
        history[i++] = timingHistory;
    }
    // Current snapshot
    history[i] = new TimingHistory();
    blockTypeSet.addAll(history[i].blockTypeSet);
    entityTypeSet.addAll(history[i].entityTypeSet);
    JsonObjectBuilder handlersBuilder = JSONUtil.objectBuilder();
    for (TimingIdentifier.TimingGroup group : TimingIdentifier.GROUP_MAP.values()) {
        for (TimingHandler id : group.handlers) {
            if (!id.timed && !id.isSpecial()) {
                continue;
            }
            handlersBuilder.add(id.id, JSONUtil.arrayOf(group.id, id.name));
        }
    }
    builder.add("idmap", JSONUtil.objectBuilder().add("groups", JSONUtil.mapArrayToObject(TimingIdentifier.GROUP_MAP.values(), (group) -> {
        return JSONUtil.singleObjectPair(group.id, group.name);
    })).add("handlers", handlersBuilder).add("worlds", JSONUtil.mapArrayToObject(TimingHistory.worldMap.entrySet(), (entry) -> {
        return JSONUtil.singleObjectPair(entry.getValue(), entry.getKey());
    })).add("tileentity", JSONUtil.mapArrayToObject(blockTypeSet, (blockType) -> {
        return JSONUtil.singleObjectPair(Block.getIdFromBlock((Block) blockType), blockType.getId());
    })).add("entity", JSONUtil.mapArrayToObject(entityTypeSet, (entityType) -> {
        if (entityType == EntityTypes.UNKNOWN) {
            return null;
        }
        return JSONUtil.singleObjectPair(TimingsPls.getEntityId(entityType), entityType.getId());
    })));
    // Information about loaded plugins
    builder.add("plugins", JSONUtil.mapArrayToObject(SpongeImpl.getGame().getPluginManager().getPlugins(), (plugin) -> {
        return JSONUtil.objectBuilder().add(plugin.getId(), JSONUtil.objectBuilder().add("version", plugin.getVersion().orElse("")).add("description", plugin.getDescription().orElse("")).add("website", plugin.getUrl().orElse("")).add("authors", AUTHOR_LIST_JOINER.join(plugin.getAuthors()))).build();
    }));
    // Information on the users Config
    builder.add("config", JSONUtil.objectBuilder().add("sponge", serializeConfigNode(SpongeImpl.getGlobalConfig().getRootNode())));
    new TimingsExport(sender, builder.build(), history).start();
}
Also used : SpongeImpl(org.spongepowered.common.SpongeImpl) HttpURLConnection(java.net.HttpURLConnection) JsonObject(com.google.gson.JsonObject) ConsoleSource(org.spongepowered.api.command.source.ConsoleSource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HISTORY(co.aikar.timings.TimingsManager.HISTORY) URL(java.net.URL) JsonObjectBuilder(co.aikar.util.JSONUtil.JsonObjectBuilder) IMPLEMENTATION(org.spongepowered.api.Platform.Component.IMPLEMENTATION) Platform(org.spongepowered.api.Platform) JsonElement(com.google.gson.JsonElement) InetAddress(java.net.InetAddress) Block(net.minecraft.block.Block) EntityTypes(org.spongepowered.api.entity.EntityTypes) Text(org.spongepowered.api.text.Text) RconSource(org.spongepowered.api.command.source.RconSource) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) ManagementFactory(java.lang.management.ManagementFactory) TextColors(org.spongepowered.api.text.format.TextColors) OutputStream(java.io.OutputStream) RuntimeMXBean(java.lang.management.RuntimeMXBean) TextActions(org.spongepowered.api.text.action.TextActions) CommandSource(org.spongepowered.api.command.CommandSource) Sponge(org.spongepowered.api.Sponge) Set(java.util.Set) IOException(java.io.IOException) Sets(com.google.common.collect.Sets) JSONUtil(co.aikar.util.JSONUtil) JsonArray(com.google.gson.JsonArray) BlockType(org.spongepowered.api.block.BlockType) Entry(java.util.Map.Entry) EntityType(org.spongepowered.api.entity.EntityType) GZIPOutputStream(java.util.zip.GZIPOutputStream) Joiner(com.google.common.base.Joiner) InputStream(java.io.InputStream) Platform(org.spongepowered.api.Platform) RuntimeMXBean(java.lang.management.RuntimeMXBean) EntityType(org.spongepowered.api.entity.EntityType) BlockType(org.spongepowered.api.block.BlockType) JsonObjectBuilder(co.aikar.util.JSONUtil.JsonObjectBuilder)

Example 59 with BlockType

use of org.spongepowered.api.block.BlockType in project SpongeAPI by SpongePowered.

the class HarvestingProperty method compareTo.

@Override
public int compareTo(Property<?, ?> o) {
    if (o instanceof HarvestingProperty) {
        HarvestingProperty property = (HarvestingProperty) o;
        Set<BlockType> set = Sets.newHashSet(property.getValue());
        for (BlockType harvest : this.getValue()) {
            if (set.contains(harvest)) {
                set.remove(harvest);
            } else {
                return 1;
            }
        }
        return set.size() > 0 ? -set.size() : 0;
    }
    return this.getClass().getName().compareTo(o.getClass().getName());
}
Also used : BlockType(org.spongepowered.api.block.BlockType)

Example 60 with BlockType

use of org.spongepowered.api.block.BlockType in project Skree by Skelril.

the class WildernessWorldWrapper method onBlockBreak.

@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @Named(NamedCause.SOURCE) Entity srcEnt) {
    List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
    for (Transaction<BlockSnapshot> block : transactions) {
        BlockSnapshot original = block.getOriginal();
        Optional<Location<World>> optLoc = original.getLocation();
        if (!optLoc.isPresent()) {
            continue;
        }
        Optional<Integer> optLevel = getLevel(optLoc.get());
        if (!optLevel.isPresent()) {
            continue;
        }
        int level = optLevel.get();
        Location<World> loc = optLoc.get();
        BlockState state = original.getState();
        BlockType type = state.getType();
        // Prevent item dupe glitch by removing the position before subsequent breaks
        markedOrePoints.remove(loc);
        if (config.getDropAmplificationConfig().amplifies(state) && !original.getCreator().isPresent()) {
            markedOrePoints.add(loc);
            if (srcEnt instanceof Player) {
                Optional<HighScoreService> optHighScores = Sponge.getServiceManager().provide(HighScoreService.class);
                optHighScores.ifPresent(highScoreService -> highScoreService.update((Player) srcEnt, ScoreTypes.WILDERNESS_ORES_MINED, 1));
            }
        }
        if (srcEnt instanceof Player && type.equals(BlockTypes.STONE) && Probability.getChance(Math.max(12, 250 - level))) {
            Vector3d max = loc.getPosition().add(1, 1, 1);
            Vector3d min = loc.getPosition().sub(1, 1, 1);
            Extent world = loc.getExtent();
            if (Probability.getChance(3)) {
                Entity entity = world.createEntity(EntityTypes.SILVERFISH, loc.getPosition().add(.5, 0, .5));
                world.spawnEntity(entity, Cause.source(SpawnCause.builder().type(SpawnTypes.BLOCK_SPAWNING).build()).build());
            }
            // Do this one tick later to guarantee no collision with transaction data
            Task.builder().delayTicks(1).execute(() -> {
                for (int x = min.getFloorX(); x <= max.getFloorX(); ++x) {
                    for (int z = min.getFloorZ(); z <= max.getFloorZ(); ++z) {
                        for (int y = min.getFloorY(); y <= max.getFloorY(); ++y) {
                            if (!world.containsBlock(x, y, z)) {
                                continue;
                            }
                            if (world.getBlockType(x, y, z) == BlockTypes.STONE) {
                                world.setBlockType(x, y, z, BlockTypes.MONSTER_EGG, BlockChangeFlag.NONE, Cause.source(SkreePlugin.container()).build());
                            }
                        }
                    }
                }
            }).submit(SkreePlugin.inst());
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Extent(org.spongepowered.api.world.extent.Extent) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) HighScoreService(com.skelril.skree.service.HighScoreService) BlockState(org.spongepowered.api.block.BlockState) Transaction(org.spongepowered.api.data.Transaction) BlockType(org.spongepowered.api.block.BlockType) Vector3d(com.flowpowered.math.vector.Vector3d) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Aggregations

BlockType (org.spongepowered.api.block.BlockType)80 World (org.spongepowered.api.world.World)34 Listener (org.spongepowered.api.event.Listener)21 BlockState (org.spongepowered.api.block.BlockState)18 Location (org.spongepowered.api.world.Location)17 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)16 ItemStack (org.spongepowered.api.item.inventory.ItemStack)14 Vector3i (com.flowpowered.math.vector.Vector3i)12 Player (org.spongepowered.api.entity.living.player.Player)12 Optional (java.util.Optional)11 Direction (org.spongepowered.api.util.Direction)10 Vector3d (com.flowpowered.math.vector.Vector3d)9 Keys (org.spongepowered.api.data.key.Keys)9 ArrayList (java.util.ArrayList)8 List (java.util.List)7 Set (java.util.Set)7 LanternBlockType (org.lanternpowered.server.block.LanternBlockType)7 Text (org.spongepowered.api.text.Text)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6