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);
}
}
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);
}
}
}
});
}
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;
}
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?");
}
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;
}
Aggregations