Skip to content

Commit

Permalink
Merge branch 'bleeding' into bleeding-1.10
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Sanders <[email protected]>
  • Loading branch information
Zidane committed Jun 25, 2016
2 parents de3d41b + 07312ea commit 7428985
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 2 deletions.
2 changes: 1 addition & 1 deletion SpongeCommon
Empty file removed run/.gitkeep
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ public static DropItemEvent.Dispense callItemTossEvent(Event event) {
EntitySpawnCause spawnCause = (EntitySpawnCause) source;
Entity entity = EntityUtil.toNative(spawnCause.getEntity());
EntityItem item = (EntityItem) spongeEvent.getEntities().get(0);
if (entity == null || !(entity instanceof Player)) {
if (entity == null || item == null || item.getEntityItem() == null || !(entity instanceof Player)) {
return spongeEvent;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.mod.mixin.core.fml.common;

import com.google.common.collect.Maps;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.discovery.ModDiscoverer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.common.SpongeImpl;

import java.io.File;
import java.util.Map;
import java.util.Map.Entry;

/**
* MixinLoader adds support for a second, user-defined, mods search directory.
*
* <p>As well as supporting fully-qualified paths, the configured value can also
* contain some pre-defined values which are supplied in the form of ant-style
* tokens.</p>
*/
@Mixin(value = Loader.class, remap = false)
public abstract class MixinLoader {

/**
* Token which contains the fully-qualified path to FML's "mods" folder
*/
private static final String PATHTOKEN_CANONICAL_MODS_DIR = "CANONICAL_MODS_DIR";

/**
* Token which contains the fully-qualified path to the game directory (profile root)
*/
private static final String PATHTOKEN_CANONICAL_GAME_DIR = "CANONICAL_GAME_DIR";

/**
* Token which contains the current minecraft version as a string
*/
private static final String PATHTOKEN_MC_VERSION = "MC_VERSION";

// Shadowed for tokens
@Shadow private static File minecraftDir;
@Shadow private File canonicalModsDir;

@Redirect(method = "identifyMods", at = @At(
value = "INVOKE",
target = "Lnet/minecraftforge/fml/common/discovery/ModDiscoverer;findModDirMods(Ljava/io/File;[Ljava/io/File;)V"
))
private void discoverMods(ModDiscoverer modDiscoverer, File modsDir, File[] additionalMods) {
modDiscoverer.findModDirMods(modsDir);

File pluginsDir = this.getPluginsDir();
if (pluginsDir.isDirectory() && !pluginsDir.equals(modsDir)) {
FMLLog.info("Searching %s for plugins", pluginsDir.getAbsolutePath());
this.discoverPlugins(modDiscoverer, pluginsDir);
}
}

@Unique
private void discoverPlugins(ModDiscoverer modDiscoverer, File pluginsDir) {
modDiscoverer.findModDirMods(pluginsDir, new File[0]);
}

@Unique
private File getPluginsDir() {
String pluginsDirName = SpongeImpl.getGlobalConfig().getConfig().getGeneral().pluginsDir();
Map<String, String> tokens = this.getPathTokens();
for (Entry<String, String> token : tokens.entrySet()) {
pluginsDirName = pluginsDirName.replace(token.getKey(), token.getValue());
}

return new File(pluginsDirName);
}

@Unique
private Map<String, String> getPathTokens() {
Map<String, String> tokens = Maps.newHashMap();
tokens.put(MixinLoader.formatToken(MixinLoader.PATHTOKEN_CANONICAL_MODS_DIR), this.canonicalModsDir.getAbsolutePath());
tokens.put(MixinLoader.formatToken(MixinLoader.PATHTOKEN_CANONICAL_GAME_DIR), MixinLoader.minecraftDir.getAbsolutePath());
tokens.put(MixinLoader.formatToken(MixinLoader.PATHTOKEN_MC_VERSION), Loader.MC_VERSION);
return tokens;
}

@Unique
private static String formatToken(String name) {
return String.format("${%s}", name);
}

}
1 change: 1 addition & 0 deletions src/main/resources/mixins.forge.preinit.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"target": "@env(PREINIT)",
"compatibilityLevel": "JAVA_8",
"mixins": [
"fml.common.MixinLoader",
"fml.common.MixinModMetadata",
"fml.common.MixinModContainer",
"fml.common.eventhandler.MixinASMEventHandler",
Expand Down

0 comments on commit 7428985

Please sign in to comment.