Search in sources :

Example 11 with PrettyPrinter

use of org.spongepowered.asm.util.PrettyPrinter in project SpongeCommon by SpongePowered.

the class SpongeGameRegistry method preRegistryInit.

public void preRegistryInit() {
    CommonModuleRegistry.getInstance().registerDefaultModules();
    final DirectedGraph<Class<? extends RegistryModule>> graph = new DirectedGraph<>();
    for (RegistryModule module : this.registryModules) {
        this.classMap.put(module.getClass(), module);
        addToGraph(module, graph);
    }
    // Now we need ot do the catalog ones
    for (CatalogRegistryModule<?> module : this.catalogRegistryMap.values()) {
        this.classMap.put(module.getClass(), module);
        addToGraph(module, graph);
    }
    try {
        this.orderedModules.addAll(TopologicalOrder.createOrderedLoad(graph));
    } catch (CyclicGraphException e) {
        StringBuilder msg = new StringBuilder();
        msg.append("Registry module dependencies are cyclical!\n");
        msg.append("Dependency loops are:\n");
        for (DataNode<?>[] cycle : e.getCycles()) {
            msg.append("[");
            for (DataNode<?> node : cycle) {
                msg.append(node.getData().toString()).append(" ");
            }
            msg.append("]\n");
        }
        SpongeImpl.getLogger().fatal(msg.toString());
        throw new RuntimeException("Registry modules dependencies error.");
    }
    registerModulePhase();
    SpongeVillagerRegistry.registerVanillaTrades();
    DataRegistrar.setupSerialization();
    final List<Tuple<Class<? extends CatalogType>, CatalogRegistryModule<?>>> modules = new ArrayList<>();
    for (Map.Entry<Class<? extends CatalogType>, CatalogRegistryModule<?>> entry : this.catalogRegistryMap.entrySet()) {
        modules.add(new Tuple<>(entry.getKey(), entry.getValue()));
    }
    modules.sort(Comparator.comparing(tuple -> tuple.getFirst().getSimpleName()));
    if (PRINT_CATALOG_TYPES) {
        // Lol... this gets spammy really fast.... Probably at some point should be put to file.
        final PrettyPrinter printer = new PrettyPrinter(100).add("Printing all Catalogs and their ID's").centre().hr().addWrapped("This is a test to print out all registered catalogs during initialization for their mapping, id's, and objects themselves.");
        for (Tuple<Class<? extends CatalogType>, CatalogRegistryModule<?>> module : modules) {
            printer.add(" %s : %s", "CatalogType", module.getFirst().getSimpleName());
            final Collection<? extends CatalogType> all = module.getSecond().getAll();
            final List<CatalogType> catalogTypes = new ArrayList<>(all);
            catalogTypes.sort(Comparator.comparing(CatalogType::getId));
            for (CatalogType catalogType : catalogTypes) {
                printer.add("  -%s", catalogType.getId());
            }
            printer.hr();
        }
        printer.trace(System.err, SpongeImpl.getLogger(), Level.DEBUG);
    }
}
Also used : DataNode(org.spongepowered.common.util.graph.DirectedGraph.DataNode) ValueFactory(org.spongepowered.api.data.value.ValueFactory) BlockStatistic(org.spongepowered.api.statistic.BlockStatistic) TextSerializerFactory(org.spongepowered.api.text.serializer.TextSerializerFactory) Level(org.apache.logging.log4j.Level) FurnaceRecipes(net.minecraft.item.crafting.FurnaceRecipes) CyclicGraphException(org.spongepowered.common.util.graph.CyclicGraphException) BookView(org.spongepowered.api.text.BookView) ExtentBufferFactory(org.spongepowered.api.world.extent.ExtentBufferFactory) Block(net.minecraft.block.Block) TextColor(org.spongepowered.api.text.format.TextColor) RegistryModuleAlreadyRegisteredException(org.spongepowered.api.registry.RegistryModuleAlreadyRegisteredException) SpongeSelectorFactory(org.spongepowered.common.text.selector.SpongeSelectorFactory) Map(java.util.Map) Path(java.nio.file.Path) SpongeTextSerializerFactory(org.spongepowered.common.text.serializer.SpongeTextSerializerFactory) ItemStatistic(org.spongepowered.api.statistic.ItemStatistic) EntityList(net.minecraft.entity.EntityList) DisplaySlotRegistryModule(org.spongepowered.common.registry.type.scoreboard.DisplaySlotRegistryModule) AITaskTypeModule(org.spongepowered.common.registry.type.entity.AITaskTypeModule) RegistryModuleLoader(org.spongepowered.common.registry.util.RegistryModuleLoader) Set(java.util.Set) DisplaySlot(org.spongepowered.api.scoreboard.displayslot.DisplaySlot) DirectedGraph(org.spongepowered.common.util.graph.DirectedGraph) AITaskType(org.spongepowered.api.entity.ai.task.AITaskType) Favicon(org.spongepowered.api.network.status.Favicon) Singleton(com.google.inject.Singleton) DataRegistration(org.spongepowered.api.data.DataRegistration) Agent(org.spongepowered.api.entity.living.Agent) PrettyPrinter(org.spongepowered.asm.util.PrettyPrinter) Supplier(java.util.function.Supplier) SpongeDataManager(org.spongepowered.common.data.SpongeDataManager) ArrayList(java.util.ArrayList) AdditionalCatalogRegistryModule(org.spongepowered.api.registry.AdditionalCatalogRegistryModule) Rotation(org.spongepowered.api.util.rotation.Rotation) Text(org.spongepowered.api.text.Text) SmeltingRecipeRegistry(org.spongepowered.api.item.recipe.smelting.SmeltingRecipeRegistry) TopologicalOrder(org.spongepowered.common.util.graph.TopologicalOrder) Nullable(javax.annotation.Nullable) StatList(net.minecraft.stats.StatList) CraftingRecipeRegistry(org.spongepowered.api.item.recipe.crafting.CraftingRecipeRegistry) IOException(java.io.IOException) Field(java.lang.reflect.Field) EntityStatistic(org.spongepowered.api.statistic.EntityStatistic) SpongeTranslation(org.spongepowered.common.text.translation.SpongeTranslation) AbstractAITask(org.spongepowered.api.entity.ai.task.AbstractAITask) ResettableBuilder(org.spongepowered.api.util.ResettableBuilder) TypeSerializers(ninja.leaping.configurate.objectmapping.serialize.TypeSerializers) ResourceLocation(net.minecraft.util.ResourceLocation) RegistryModule(org.spongepowered.api.registry.RegistryModule) PluginProvidedRegistryModule(org.spongepowered.api.registry.util.PluginProvidedRegistryModule) SpongePropertyRegistry(org.spongepowered.common.data.property.SpongePropertyRegistry) Item(net.minecraft.item.Item) ExtraClassCatalogRegistryModule(org.spongepowered.api.registry.ExtraClassCatalogRegistryModule) URL(java.net.URL) Inject(com.google.inject.Inject) DefaultGameRules(org.spongepowered.api.world.gamerule.DefaultGameRules) LocaleCache(org.spongepowered.common.util.LocaleCache) GameRegistry(org.spongepowered.api.GameRegistry) CatalogRegistryModule(org.spongepowered.api.registry.CatalogRegistryModule) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) RotationRegistryModule(org.spongepowered.common.registry.type.block.RotationRegistryModule) Locale(java.util.Locale) RegistrationDependency(org.spongepowered.api.registry.util.RegistrationDependency) StatisticTypes(org.spongepowered.api.statistic.StatisticTypes) BookViewDataBuilder(org.spongepowered.api.text.serializer.BookViewDataBuilder) IdentityHashMap(java.util.IdentityHashMap) BufferedImage(java.awt.image.BufferedImage) Collection(java.util.Collection) RegistrationPhase(org.spongepowered.api.registry.RegistrationPhase) CatalogType(org.spongepowered.api.CatalogType) Sponge(org.spongepowered.api.Sponge) ResourcePack(org.spongepowered.api.resourcepack.ResourcePack) Tuple(org.spongepowered.api.util.Tuple) SpongeFavicon(org.spongepowered.common.network.status.SpongeFavicon) SetSerializer(org.spongepowered.common.util.SetSerializer) SpongeGameRegistryRegisterEvent(org.spongepowered.common.event.registry.SpongeGameRegistryRegisterEvent) Cause(org.spongepowered.api.event.cause.Cause) List(java.util.List) BlockType(org.spongepowered.api.block.BlockType) Optional(java.util.Optional) EventContext(org.spongepowered.api.event.cause.EventContext) SpongeImpl(org.spongepowered.common.SpongeImpl) CatalogTypeTypeSerializer(org.spongepowered.common.config.CatalogTypeTypeSerializer) TextTemplate(org.spongepowered.api.text.TextTemplate) SpongeCraftingRecipeRegistry(org.spongepowered.common.item.recipe.crafting.SpongeCraftingRecipeRegistry) TypeToken(com.google.common.reflect.TypeToken) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) TextConfigSerializer(org.spongepowered.api.text.serializer.TextConfigSerializer) VillagerRegistry(org.spongepowered.api.item.merchant.VillagerRegistry) DataRegistrar(org.spongepowered.common.data.DataRegistrar) Translation(org.spongepowered.api.text.translation.Translation) TextTemplateConfigSerializer(org.spongepowered.api.text.serializer.TextTemplateConfigSerializer) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SpongeExtentBufferFactory(org.spongepowered.common.world.extent.SpongeExtentBufferFactory) StatisticType(org.spongepowered.api.statistic.StatisticType) SpongeValueFactory(org.spongepowered.common.data.value.SpongeValueFactory) EntityType(org.spongepowered.api.entity.EntityType) Comparator(java.util.Comparator) ItemType(org.spongepowered.api.item.ItemType) Collections(java.util.Collections) InputStream(java.io.InputStream) DisplaySlotRegistryModule(org.spongepowered.common.registry.type.scoreboard.DisplaySlotRegistryModule) AdditionalCatalogRegistryModule(org.spongepowered.api.registry.AdditionalCatalogRegistryModule) RegistryModule(org.spongepowered.api.registry.RegistryModule) PluginProvidedRegistryModule(org.spongepowered.api.registry.util.PluginProvidedRegistryModule) ExtraClassCatalogRegistryModule(org.spongepowered.api.registry.ExtraClassCatalogRegistryModule) CatalogRegistryModule(org.spongepowered.api.registry.CatalogRegistryModule) RotationRegistryModule(org.spongepowered.common.registry.type.block.RotationRegistryModule) ArrayList(java.util.ArrayList) CyclicGraphException(org.spongepowered.common.util.graph.CyclicGraphException) CatalogType(org.spongepowered.api.CatalogType) PrettyPrinter(org.spongepowered.asm.util.PrettyPrinter) AdditionalCatalogRegistryModule(org.spongepowered.api.registry.AdditionalCatalogRegistryModule) ExtraClassCatalogRegistryModule(org.spongepowered.api.registry.ExtraClassCatalogRegistryModule) CatalogRegistryModule(org.spongepowered.api.registry.CatalogRegistryModule) DirectedGraph(org.spongepowered.common.util.graph.DirectedGraph) DataNode(org.spongepowered.common.util.graph.DirectedGraph.DataNode) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) Tuple(org.spongepowered.api.util.Tuple)

Example 12 with PrettyPrinter

use of org.spongepowered.asm.util.PrettyPrinter in project SpongeCommon by SpongePowered.

the class UnknownPacketState method unwind.

@Override
public void unwind(BasicPacketContext context) {
    final EntityPlayerMP player = context.getPacketPlayer();
    try (CauseStackManager.StackFrame frame1 = Sponge.getCauseStackManager().pushCauseFrame()) {
        Sponge.getCauseStackManager().pushCause(player);
        Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.PLACEMENT);
        context.getCapturedBlockSupplier().acceptAndClearIfNotEmpty(blocks -> TrackingUtil.processBlockCaptures(blocks, this, context));
        context.getCapturedEntitySupplier().acceptAndClearIfNotEmpty(entities -> {
            SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), entities);
            SpongeImpl.postEvent(event);
            if (!event.isCancelled()) {
                processSpawnedEntities(player, event);
            }
        });
        context.getCapturedItemsSupplier().acceptAndClearIfNotEmpty(entities -> {
            final List<Entity> items = entities.stream().map(EntityUtil::fromNative).collect(Collectors.toList());
            SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), items);
            SpongeImpl.postEvent(event);
            if (!event.isCancelled()) {
                processSpawnedEntities(player, event);
            }
        });
    }
    context.getCapturedEntityDropSupplier().acceptIfNotEmpty(map -> {
        final PrettyPrinter printer = new PrettyPrinter(80);
        printer.add("Processing An Unknown Packet for Entity Drops").centre().hr();
        printer.add("The item stacks captured are: ");
        for (Map.Entry<UUID, Collection<ItemDropData>> entry : map.asMap().entrySet()) {
            printer.add("  - Entity with UUID: %s", entry.getKey());
            for (ItemDropData stack : entry.getValue()) {
                printer.add("    - %s", stack);
            }
        }
        printer.trace(System.err);
    });
    context.getCapturedEntityItemDropSupplier().acceptIfNotEmpty(map -> {
        for (Map.Entry<UUID, Collection<EntityItem>> entry : map.asMap().entrySet()) {
            final UUID entityUuid = entry.getKey();
            final net.minecraft.entity.Entity entityFromUuid = player.getServerWorld().getEntityFromUuid(entityUuid);
            final Entity affectedEntity = EntityUtil.fromNative(entityFromUuid);
            if (entityFromUuid != null) {
                final List<Entity> entities = entry.getValue().stream().map(EntityUtil::fromNative).collect(Collectors.toList());
                if (!entities.isEmpty()) {
                    try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
                        Sponge.getCauseStackManager().pushCause(player);
                        Sponge.getCauseStackManager().pushCause(affectedEntity);
                        Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.CUSTOM);
                        DropItemEvent.Custom event = SpongeEventFactory.createDropItemEventCustom(Sponge.getCauseStackManager().getCurrentCause(), entities);
                        SpongeImpl.postEvent(event);
                        if (!event.isCancelled()) {
                            processSpawnedEntities(player, event);
                        }
                    }
                }
            }
        }
    });
    context.getCapturedItemStackSupplier().acceptAndClearIfNotEmpty(drops -> {
        final List<EntityItem> items = drops.stream().map(drop -> drop.create(player.getServerWorld())).collect(Collectors.toList());
        final List<Entity> entities = items.stream().map(EntityUtil::fromNative).collect(Collectors.toList());
        if (!entities.isEmpty()) {
            try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
                Sponge.getCauseStackManager().pushCause(player);
                Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.CUSTOM);
                DropItemEvent.Custom event = SpongeEventFactory.createDropItemEventCustom(Sponge.getCauseStackManager().getCurrentCause(), entities);
                SpongeImpl.postEvent(event);
                if (!event.isCancelled()) {
                    processSpawnedEntities(player, event);
                }
            }
        }
    });
}
Also used : EntityItem(net.minecraft.entity.item.EntityItem) SpongeImpl(org.spongepowered.common.SpongeImpl) EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) Collection(java.util.Collection) Sponge(org.spongepowered.api.Sponge) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) UUID(java.util.UUID) Entity(org.spongepowered.api.entity.Entity) PrettyPrinter(org.spongepowered.asm.util.PrettyPrinter) Collectors(java.util.stream.Collectors) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) EntityUtil(org.spongepowered.common.entity.EntityUtil) SpawnTypes(org.spongepowered.api.event.cause.entity.spawn.SpawnTypes) List(java.util.List) TrackingUtil(org.spongepowered.common.event.tracking.TrackingUtil) Map(java.util.Map) ItemDropData(org.spongepowered.common.event.tracking.context.ItemDropData) CauseStackManager(org.spongepowered.api.event.CauseStackManager) Entity(org.spongepowered.api.entity.Entity) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) PrettyPrinter(org.spongepowered.asm.util.PrettyPrinter) CauseStackManager(org.spongepowered.api.event.CauseStackManager) Collection(java.util.Collection) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) UUID(java.util.UUID) ItemDropData(org.spongepowered.common.event.tracking.context.ItemDropData) Map(java.util.Map) EntityItem(net.minecraft.entity.item.EntityItem)

Example 13 with PrettyPrinter

use of org.spongepowered.asm.util.PrettyPrinter in project SpongeCommon by SpongePowered.

the class SpongeItemStackBuilder method fromBlockState.

@Override
public ItemStack.Builder fromBlockState(BlockState blockState) {
    final IBlockState minecraftState = BlockUtil.toNative(blockState);
    final Optional<ItemType> item = blockState.getType().getItem();
    if (!item.isPresent()) {
        new PrettyPrinter(60).add("Invalid BlockState").centre().hr().add("Someone attempted to create an ItemStack from a BlockState that does not have a valid item!").add("%s : %s", "BlockState", blockState).add("%s : %s", "BlockType", blockState.getType()).add(new Exception("Stacktrace")).trace();
        return this;
    }
    itemType(item.get());
    this.damageValue = minecraftState.getBlock().damageDropped(minecraftState);
    return this;
}
Also used : PrettyPrinter(org.spongepowered.asm.util.PrettyPrinter) IBlockState(net.minecraft.block.state.IBlockState) ItemType(org.spongepowered.api.item.ItemType) InvalidDataException(org.spongepowered.api.data.persistence.InvalidDataException)

Example 14 with PrettyPrinter

use of org.spongepowered.asm.util.PrettyPrinter in project SpongeForge by SpongePowered.

the class MixinErrorHandler method itsAllGoneHorriblyWrong.

private PrettyPrinter itsAllGoneHorriblyWrong() {
    String forgeVer = Main.getManifestAttribute("TargetForgeVersion", null);
    if (forgeVer != null && !forgeVer.equals(ForgeVersion.getVersion())) {
        return new PrettyPrinter().add().add("Oh dear. It seems like this version of Sponge is not compatible with the version").add("of Forge you are running.").add().hr('-').add().add("A error was encountered whilst patching:").add().add("  One or more Sponge patches could not be applied whilst loading Sponge, this is").add("  a permanent error and you must either:").add().add("   * Use the correct build of Forge for this version of Sponge (%s)", forgeVer).add().add("   * Use a version of Sponge for built for your version of Forge").add().addWrapped("  The patch which failed requires Forge build: %s", forgeVer).addWrapped("  but you are running build:                   %s", ForgeVersion.getVersion());
    }
    String forgeMessage = forgeVer == null ? "is usually specified in the sponge mod's jar filename" : "version is for " + forgeVer;
    return new PrettyPrinter().add().add("Oh dear. Something went wrong and the server had to shut down!").add().hr('-').add().add("A critical error was encountered while blending Sponge with Forge!").add().add("  Possible causes are:").add().add("   * An incompatible Forge \"core mod\" is present. Try removing other mods to").add("     see if the problem goes away.").add().add("   * You are using the wrong version of Minecraft Forge. You must use the").addWrapped("     correct version of Forge when running Sponge, this %s (you are running %s)", forgeMessage, ForgeVersion.getVersion()).add().add("   * An error exists in Sponge itself. Ensure you are running the latest version").add("     of Sponge.").add().add("   * Gremlins are invading your computer. Did you feed a Mogwai after midnight?");
}
Also used : PrettyPrinter(org.spongepowered.asm.util.PrettyPrinter)

Example 15 with PrettyPrinter

use of org.spongepowered.asm.util.PrettyPrinter in project SpongeForge by SpongePowered.

the class MixinErrorHandler method onPrepareError.

@Override
public ErrorAction onPrepareError(IMixinConfig config, Throwable th, IMixinInfo mixin, ErrorAction action) {
    if (action == ErrorAction.ERROR && mixin.getConfig().getMixinPackage().startsWith("org.spongepowered.")) {
        PrettyPrinter errorPrinter = this.getPrettyPrinter(th);
        String targetClassName = "N/A";
        if (th instanceof MixinTargetAlreadyLoadedException) {
            targetClassName = ((MixinTargetAlreadyLoadedException) th).getTarget();
        }
        this.appendTechnicalInfo(errorPrinter, targetClassName, th, mixin).log(this.log);
        TerminateVM.terminate("net.minecraftforge.fml", -1);
    }
    return null;
}
Also used : PrettyPrinter(org.spongepowered.asm.util.PrettyPrinter) MixinTargetAlreadyLoadedException(org.spongepowered.asm.mixin.transformer.throwables.MixinTargetAlreadyLoadedException)

Aggregations

PrettyPrinter (org.spongepowered.asm.util.PrettyPrinter)27 Map (java.util.Map)9 Collection (java.util.Collection)7 ReportedException (net.minecraft.util.ReportedException)7 CauseStackManager (org.spongepowered.api.event.CauseStackManager)7 UUID (java.util.UUID)6 Entity (org.spongepowered.api.entity.Entity)6 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 SpawnEntityEvent (org.spongepowered.api.event.entity.SpawnEntityEvent)5 DropItemEvent (org.spongepowered.api.event.item.inventory.DropItemEvent)5 ItemDropData (org.spongepowered.common.event.tracking.context.ItemDropData)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 EntityItem (net.minecraft.entity.item.EntityItem)4 Sponge (org.spongepowered.api.Sponge)4 World (org.spongepowered.api.world.World)4 SpongeImpl (org.spongepowered.common.SpongeImpl)4 IOException (java.io.IOException)3 Collectors (java.util.stream.Collectors)3 Nullable (javax.annotation.Nullable)3