mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-26 06:53:20 +00:00
WOW 😲 such broken. Many brokes.
This commit is contained in:
1 parent
c1f0e1b68f
commit
f942eb184a
266 files changed
+1717
-4018
No files matched your search
@@ -53,7 +53,7 @@ import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
@@ -390,7 +390,8 @@ public class ForgeChunkManager
|
||||
}
|
||||
}
|
||||
|
||||
public static class ForceChunkEvent extends Event {
|
||||
public static class ForceChunkEvent extends net.minecraftforge.eventbus.api.Event
|
||||
{
|
||||
private final Ticket ticket;
|
||||
private final ChunkPos location;
|
||||
|
||||
@@ -411,7 +412,8 @@ public class ForgeChunkManager
|
||||
}
|
||||
}
|
||||
|
||||
public static class UnforceChunkEvent extends Event {
|
||||
public static class UnforceChunkEvent extends net.minecraftforge.eventbus.api.Event
|
||||
{
|
||||
private final Ticket ticket;
|
||||
private final ChunkPos location;
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.LoaderState;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.common.network.handshake.NetworkDispatcher;
|
||||
import net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.ConnectionType;
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
@@ -1279,7 +1279,7 @@ public class ForgeHooks
|
||||
{
|
||||
BlockEvent ev = new BlockEvent.CropGrowEvent.Pre(worldIn,pos,state);
|
||||
MinecraftForge.EVENT_BUS.post(ev);
|
||||
return (ev.getResult() == Event.Result.ALLOW || (ev.getResult() == Event.Result.DEFAULT && def));
|
||||
return (ev.getResult() == net.minecraftforge.eventbus.api.Event.Result.ALLOW || (ev.getResult() == net.minecraftforge.eventbus.api.Event.Result.DEFAULT && def));
|
||||
}
|
||||
|
||||
public static void onCropsGrowPost(World worldIn, BlockPos pos, IBlockState state, IBlockState blockState)
|
||||
@@ -1320,7 +1320,7 @@ public class ForgeHooks
|
||||
{
|
||||
CriticalHitEvent hitResult = new CriticalHitEvent(player, target, damageModifier, vanillaCritical);
|
||||
MinecraftForge.EVENT_BUS.post(hitResult);
|
||||
if (hitResult.getResult() == Event.Result.ALLOW || (vanillaCritical && hitResult.getResult() == Event.Result.DEFAULT))
|
||||
if (hitResult.getResult() == net.minecraftforge.eventbus.api.Event.Result.ALLOW || (vanillaCritical && hitResult.getResult() == net.minecraftforge.eventbus.api.Event.Result.DEFAULT))
|
||||
{
|
||||
return hitResult;
|
||||
}
|
||||
|
||||
@@ -28,9 +28,8 @@ import net.minecraftforge.common.util.FakePlayerFactory;
|
||||
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.eventbus.api.EventPriority;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
|
||||
@@ -64,7 +63,7 @@ public class ForgeInternalHandler
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
@net.minecraftforge.eventbus.api.SubscribeEvent(priority = net.minecraftforge.eventbus.api.EventPriority.HIGHEST)
|
||||
public void onDimensionLoad(WorldEvent.Load event)
|
||||
{
|
||||
ForgeChunkManager.loadWorld(event.getWorld());
|
||||
@@ -76,7 +75,7 @@ public class ForgeInternalHandler
|
||||
ForgeChunkManager.saveWorld(event.getWorld());
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
@net.minecraftforge.eventbus.api.SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void onDimensionUnload(WorldEvent.Unload event)
|
||||
{
|
||||
ForgeChunkManager.unloadWorld(event.getWorld());
|
||||
|
||||
@@ -94,7 +94,7 @@ import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLServerStoppingEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
@@ -415,7 +415,7 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
@net.minecraftforge.eventbus.api.SubscribeEvent
|
||||
public void playerLogin(PlayerEvent.PlayerLoggedInEvent event)
|
||||
{
|
||||
UsernameCache.setUsername(event.player.getPersistentID(), event.player.getGameProfile().getName());
|
||||
@@ -491,7 +491,7 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
@net.minecraftforge.eventbus.api.SubscribeEvent
|
||||
public void registrItems(RegistryEvent.Register<Item> event)
|
||||
{
|
||||
// Add and register the forge universal bucket, if it's enabled
|
||||
|
||||
@@ -21,12 +21,9 @@ package net.minecraftforge.common;
|
||||
|
||||
import static net.minecraftforge.common.ForgeVersion.Status.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
@@ -43,6 +40,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import com.electronwill.nightconfig.core.Config;
|
||||
import com.electronwill.nightconfig.core.UnmodifiableConfig;
|
||||
import com.electronwill.nightconfig.core.path.PathConfig;
|
||||
import net.minecraftforge.fml.VersionChecker;
|
||||
import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
|
||||
import org.apache.logging.log4j.Level;
|
||||
@@ -52,6 +50,7 @@ import org.apache.logging.log4j.Logger;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.InjectedModContainer;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
@@ -75,15 +74,9 @@ public class ForgeVersion
|
||||
public static final String mcVersion = "1.12.2";
|
||||
// This is the MCP data version we're using
|
||||
public static final String mcpVersion = "9.42";
|
||||
@SuppressWarnings("unused")
|
||||
private static Status status = PENDING;
|
||||
@SuppressWarnings("unused")
|
||||
private static String target = null;
|
||||
|
||||
private static final Logger log = LogManager.getLogger("ForgeVersionCheck");
|
||||
|
||||
private static final int MAX_HTTP_REDIRECTS = Integer.getInteger("http.maxRedirects", 20);
|
||||
|
||||
public static int getMajorVersion()
|
||||
{
|
||||
return majorVersion;
|
||||
@@ -104,299 +97,20 @@ public class ForgeVersion
|
||||
return buildVersion;
|
||||
}
|
||||
|
||||
public static Status getStatus()
|
||||
{
|
||||
return getResult(ForgeModContainer.getInstance()).status;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getTarget()
|
||||
{
|
||||
CheckResult res = getResult(ForgeModContainer.getInstance());
|
||||
return res.target != null ? res.target.toString() : null;
|
||||
}
|
||||
|
||||
public static String getVersion()
|
||||
{
|
||||
return String.format("%d.%d.%d.%d", majorVersion, minorVersion, revisionVersion, buildVersion);
|
||||
}
|
||||
|
||||
public static List<ModInfo> getModInfos()
|
||||
public static VersionChecker.Status getStatus()
|
||||
{
|
||||
PathConfig minecraftmod;
|
||||
PathConfig forgemod;
|
||||
try
|
||||
{
|
||||
minecraftmod = PathConfig.of(Paths.get(ForgeVersion.class.getClassLoader().getResource("minecraftmod.toml").toURI()));
|
||||
forgemod = PathConfig.of(Paths.get(ForgeVersion.class.getClassLoader().getResource("forgemod.toml").toURI()));
|
||||
minecraftmod.load();
|
||||
forgemod.load();
|
||||
}
|
||||
catch (URISyntaxException | NullPointerException e)
|
||||
{
|
||||
throw new RuntimeException("Missing toml configs for minecraft and forge!", e);
|
||||
}
|
||||
return Arrays.asList(
|
||||
new ModInfo(null, minecraftmod),
|
||||
new ModInfo(null, forgemod)
|
||||
);
|
||||
return VersionChecker.Status.PENDING;
|
||||
}
|
||||
|
||||
public static enum Status
|
||||
@Nullable
|
||||
public static String getTarget()
|
||||
{
|
||||
PENDING(),
|
||||
FAILED(),
|
||||
UP_TO_DATE(),
|
||||
OUTDATED(3, true),
|
||||
AHEAD(),
|
||||
BETA(),
|
||||
BETA_OUTDATED(6, true);
|
||||
|
||||
final int sheetOffset;
|
||||
final boolean draw, animated;
|
||||
|
||||
Status()
|
||||
{
|
||||
this(0, false, false);
|
||||
}
|
||||
|
||||
Status(int sheetOffset)
|
||||
{
|
||||
this(sheetOffset, true, false);
|
||||
}
|
||||
|
||||
Status(int sheetOffset, boolean animated)
|
||||
{
|
||||
this(sheetOffset, true, animated);
|
||||
}
|
||||
|
||||
Status(int sheetOffset, boolean draw, boolean animated)
|
||||
{
|
||||
this.sheetOffset = sheetOffset;
|
||||
this.draw = draw;
|
||||
this.animated = animated;
|
||||
}
|
||||
|
||||
public int getSheetOffset()
|
||||
{
|
||||
return sheetOffset;
|
||||
}
|
||||
|
||||
public boolean shouldDraw()
|
||||
{
|
||||
return draw;
|
||||
}
|
||||
|
||||
public boolean isAnimated()
|
||||
{
|
||||
return animated;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class CheckResult
|
||||
{
|
||||
public final Status status;
|
||||
@Nullable
|
||||
public final ComparableVersion target;
|
||||
public final Map<ComparableVersion, String> changes;
|
||||
@Nullable
|
||||
public final String url;
|
||||
|
||||
private CheckResult(Status status, @Nullable ComparableVersion target, @Nullable Map<ComparableVersion, String> changes, @Nullable String url)
|
||||
{
|
||||
this.status = status;
|
||||
this.target = target;
|
||||
this.changes = changes == null ? Collections.<ComparableVersion, String>emptyMap() : Collections.unmodifiableMap(changes);
|
||||
this.url = url;
|
||||
}
|
||||
}
|
||||
|
||||
public static void startVersionCheck()
|
||||
{
|
||||
new Thread("Forge Version Check")
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (!ForgeModContainer.getConfig().get(ForgeModContainer.VERSION_CHECK_CAT, "Global", true).getBoolean())
|
||||
{
|
||||
log.info("Global Forge version check system disabled, no further processing.");
|
||||
return;
|
||||
}
|
||||
|
||||
for (Entry<ModContainer, URL> entry : gatherMods().entrySet())
|
||||
{
|
||||
ModContainer mod = entry.getKey();
|
||||
if (ForgeModContainer.getConfig().get(ForgeModContainer.VERSION_CHECK_CAT, mod.getModId(), true).getBoolean())
|
||||
{
|
||||
process(mod, entry.getValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
log.info("[{}] Skipped version check", mod.getModId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens stream for given URL while following redirects
|
||||
*/
|
||||
private InputStream openUrlStream(URL url) throws IOException
|
||||
{
|
||||
URL currentUrl = url;
|
||||
for (int redirects = 0; redirects < MAX_HTTP_REDIRECTS; redirects++)
|
||||
{
|
||||
URLConnection c = currentUrl.openConnection();
|
||||
if (c instanceof HttpURLConnection)
|
||||
{
|
||||
HttpURLConnection huc = (HttpURLConnection) c;
|
||||
huc.setInstanceFollowRedirects(false);
|
||||
int responseCode = huc.getResponseCode();
|
||||
if (responseCode >= 300 && responseCode <= 399)
|
||||
{
|
||||
try
|
||||
{
|
||||
String loc = huc.getHeaderField("Location");
|
||||
currentUrl = new URL(currentUrl, loc);
|
||||
continue;
|
||||
}
|
||||
finally
|
||||
{
|
||||
huc.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return c.getInputStream();
|
||||
}
|
||||
throw new IOException("Too many redirects while trying to fetch " + url);
|
||||
}
|
||||
|
||||
private void process(ModContainer mod, URL url)
|
||||
{
|
||||
try
|
||||
{
|
||||
log.info("[{}] Starting version check at {}", mod.getModId(), url.toString());
|
||||
Status status = PENDING;
|
||||
ComparableVersion target = null;
|
||||
|
||||
InputStream con = openUrlStream(url);
|
||||
String data = new String(ByteStreams.toByteArray(con), "UTF-8");
|
||||
con.close();
|
||||
|
||||
log.debug("[{}] Received version check data:\n{}", mod.getModId(), data);
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> json = new Gson().fromJson(data, Map.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> promos = (Map<String, String>)json.get("promos");
|
||||
String display_url = (String)json.get("homepage");
|
||||
|
||||
String rec = promos.get(MinecraftForge.MC_VERSION + "-recommended");
|
||||
String lat = promos.get(MinecraftForge.MC_VERSION + "-latest");
|
||||
ComparableVersion current = new ComparableVersion(mod.getVersion());
|
||||
|
||||
if (rec != null)
|
||||
{
|
||||
ComparableVersion recommended = new ComparableVersion(rec);
|
||||
int diff = recommended.compareTo(current);
|
||||
|
||||
if (diff == 0)
|
||||
status = UP_TO_DATE;
|
||||
else if (diff < 0)
|
||||
{
|
||||
status = AHEAD;
|
||||
if (lat != null)
|
||||
{
|
||||
ComparableVersion latest = new ComparableVersion(lat);
|
||||
if (current.compareTo(latest) < 0)
|
||||
{
|
||||
status = OUTDATED;
|
||||
target = latest;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status = OUTDATED;
|
||||
target = recommended;
|
||||
}
|
||||
}
|
||||
else if (lat != null)
|
||||
{
|
||||
ComparableVersion latest = new ComparableVersion(lat);
|
||||
if (current.compareTo(latest) < 0)
|
||||
{
|
||||
status = BETA_OUTDATED;
|
||||
target = latest;
|
||||
}
|
||||
else
|
||||
status = BETA;
|
||||
}
|
||||
else
|
||||
status = BETA;
|
||||
|
||||
log.info("[{}] Found status: {} Target: {}", mod.getModId(), status, target);
|
||||
|
||||
Map<ComparableVersion, String> changes = new LinkedHashMap<ComparableVersion, String>();
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> tmp = (Map<String, String>)json.get(MinecraftForge.MC_VERSION);
|
||||
if (tmp != null)
|
||||
{
|
||||
List<ComparableVersion> ordered = new ArrayList<ComparableVersion>();
|
||||
for (String key : tmp.keySet())
|
||||
{
|
||||
ComparableVersion ver = new ComparableVersion(key);
|
||||
if (ver.compareTo(current) > 0 && (target == null || ver.compareTo(target) < 1))
|
||||
{
|
||||
ordered.add(ver);
|
||||
}
|
||||
}
|
||||
Collections.sort(ordered);
|
||||
|
||||
for (ComparableVersion ver : ordered)
|
||||
{
|
||||
changes.put(ver, tmp.get(ver.toString()));
|
||||
}
|
||||
}
|
||||
if (mod instanceof InjectedModContainer)
|
||||
mod = ((InjectedModContainer)mod).wrappedContainer;
|
||||
results.put(mod, new CheckResult(status, target, changes, display_url));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.debug("Failed to process update information", e);
|
||||
status = FAILED;
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
// Gather a list of mods that have opted in to this update system by providing a URL.
|
||||
public static Map<ModContainer, URL> gatherMods()
|
||||
{
|
||||
Map<ModContainer, URL> ret = new HashMap<ModContainer, URL>();
|
||||
for (ModContainer mod : Loader.instance().getActiveModList())
|
||||
{
|
||||
URL url = mod.getUpdateUrl();
|
||||
if (url != null)
|
||||
ret.put(mod, url);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static Map<ModContainer, CheckResult> results = new ConcurrentHashMap<ModContainer, CheckResult>();
|
||||
private static final CheckResult PENDING_CHECK = new CheckResult(PENDING, null, null, null);
|
||||
|
||||
public static CheckResult getResult(ModContainer mod)
|
||||
{
|
||||
if (mod == null) return PENDING_CHECK;
|
||||
if (mod instanceof InjectedModContainer)
|
||||
mod = ((InjectedModContainer)mod).wrappedContainer;
|
||||
CheckResult ret = results.get(mod);
|
||||
return ret == null ? PENDING_CHECK : ret;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,14 +24,12 @@ import net.minecraftforge.fml.common.ICrashCallable;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.discovery.ASMDataTable;
|
||||
import net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventBus;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.crash.CrashReport;
|
||||
@@ -53,9 +51,9 @@ public class MinecraftForge
|
||||
* ORE_GEN_BUS for ore gen events
|
||||
* EVENT_BUS for everything else
|
||||
*/
|
||||
public static final EventBus EVENT_BUS = new EventBus();
|
||||
public static final EventBus TERRAIN_GEN_BUS = new EventBus();
|
||||
public static final EventBus ORE_GEN_BUS = new EventBus();
|
||||
public static final IEventBus EVENT_BUS = IEventBus.create();
|
||||
public static final IEventBus TERRAIN_GEN_BUS = IEventBus.create();
|
||||
public static final IEventBus ORE_GEN_BUS = IEventBus.create();
|
||||
public static final String MC_VERSION = Loader.MC_VERSION;
|
||||
|
||||
static final ForgeInternalHandler INTERNAL_HANDLER = new ForgeInternalHandler();
|
||||
|
||||
Reference in new issue
Block a user