Moved the core event handler parts to FML. Implemented the Forge network handler based on the new
netty strategy. Updated FML: MinecraftForge/FML@3b2994a3de Some patching touchups MinecraftForge/FML@557357fe17 Update for log4j2 MinecraftForge/FML@a2b324beb2 Copy eventhandler from Forge into FML. It is going to replace a lot of the runtime event systems. MinecraftForge/FML@4071ff38af Patch some GUIs. We're gonna add some basic mod gui config support. MinecraftForge/FML@0b419ac79c Fire a user event down the channels when a handshake has occured.
This commit is contained in:
parent
439dbd8bb3
commit
ae478c92a2
86 changed files with 281 additions and 1286 deletions
|
@ -54,7 +54,7 @@ launch4j {
|
|||
|
||||
uploadArchives {
|
||||
repositories {
|
||||
add project.repositories.mavenLocal()
|
||||
add getProject().repositories.mavenLocal()
|
||||
}
|
||||
repositories.mavenDeployer {
|
||||
configuration = configurations.deployJars
|
||||
|
|
2
fml
2
fml
|
@ -1 +1 @@
|
|||
Subproject commit 0098c57f94808751062ee45f2ee267324bb42089
|
||||
Subproject commit 0b419ac79c307579f162d47e0388a9d75bcd0a6e
|
|
@ -1,7 +1,7 @@
|
|||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.Event;
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
|
||||
@Cancelable
|
||||
public class ClientChatReceivedEvent extends Event
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package net.minecraftforge.client.event;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.client.renderer.RenderGlobal;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
@Cancelable
|
||||
public class DrawBlockHighlightEvent extends Event
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package net.minecraftforge.client.event;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.renderer.EntityRenderer;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
/**
|
||||
* Author: MachineMuse (Claire Semple)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package net.minecraftforge.client.event;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
/**
|
||||
* This event is called before any Gui will open.
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.Event;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
|
||||
/**
|
||||
* Author: MachineMuse (Claire Semple)
|
||||
* Created: 2:46 PM, 9/4/13
|
||||
|
|
|
@ -2,9 +2,10 @@ package net.minecraftforge.client.event;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
@Cancelable
|
||||
public class RenderGameOverlayEvent extends Event
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package net.minecraftforge.client.event;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.client.renderer.entity.RendererLivingEntity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
public abstract class RenderLivingEvent extends Event
|
||||
{
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package net.minecraftforge.client.event;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraft.client.renderer.entity.RenderPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
|
||||
public abstract class RenderPlayerEvent extends PlayerEvent
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package net.minecraftforge.client.event;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.client.renderer.RenderGlobal;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
public class RenderWorldLastEvent extends Event
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package net.minecraftforge.client.event;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
|
||||
public class TextureStitchEvent extends Event
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package net.minecraftforge.client.event.sound;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.client.audio.SoundManager;
|
||||
import net.minecraft.client.audio.SoundPoolEntry;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
public class SoundEvent extends Event
|
||||
{
|
||||
|
|
|
@ -44,6 +44,7 @@ import com.google.common.collect.TreeMultiset;
|
|||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
|
@ -60,7 +61,6 @@ import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
|||
import net.minecraftforge.common.config.ConfigCategory;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
/**
|
||||
* Manages chunkloading for mods.
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
|
@ -33,7 +34,6 @@ import net.minecraft.util.MathHelper;
|
|||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.WeightedRandom;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.Event;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.event.ServerChatEvent;
|
||||
import net.minecraftforge.event.entity.item.ItemTossEvent;
|
||||
|
|
|
@ -3,6 +3,8 @@ package net.minecraftforge.common;
|
|||
import java.util.UUID;
|
||||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
|
@ -14,7 +16,7 @@ import net.minecraftforge.event.world.WorldEvent;
|
|||
|
||||
public class ForgeInternalHandler
|
||||
{
|
||||
@ForgeSubscribe(priority = EventPriority.HIGHEST)
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void onEntityJoinWorld(EntityJoinWorldEvent event)
|
||||
{
|
||||
if (!event.world.isRemote)
|
||||
|
@ -58,19 +60,19 @@ public class ForgeInternalHandler
|
|||
}
|
||||
}
|
||||
|
||||
@ForgeSubscribe(priority = EventPriority.HIGHEST)
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void onDimensionLoad(WorldEvent.Load event)
|
||||
{
|
||||
ForgeChunkManager.loadWorld(event.world);
|
||||
}
|
||||
|
||||
@ForgeSubscribe(priority = EventPriority.HIGHEST)
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void onDimensionSave(WorldEvent.Save event)
|
||||
{
|
||||
ForgeChunkManager.saveWorld(event.world);
|
||||
}
|
||||
|
||||
@ForgeSubscribe(priority = EventPriority.HIGHEST)
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void onDimensionUnload(WorldEvent.Unload event)
|
||||
{
|
||||
ForgeChunkManager.unloadWorld(event.world);
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
package net.minecraftforge.common;
|
||||
|
||||
import static net.minecraftforge.common.ForgeVersion.buildVersion;
|
||||
import static net.minecraftforge.common.ForgeVersion.majorVersion;
|
||||
import static net.minecraftforge.common.ForgeVersion.minorVersion;
|
||||
import static net.minecraftforge.common.ForgeVersion.revisionVersion;
|
||||
import static net.minecraftforge.common.config.Configuration.CATEGORY_GENERAL;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
@ -7,16 +13,12 @@ import java.util.logging.Level;
|
|||
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.management.PlayerInstance;
|
||||
import net.minecraft.world.storage.SaveHandler;
|
||||
import net.minecraft.world.storage.WorldInfo;
|
||||
import net.minecraftforge.classloading.FMLForgePlugin;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import net.minecraftforge.common.network.ForgeConnectionHandler;
|
||||
import net.minecraftforge.common.network.ForgeNetworkHandler;
|
||||
import net.minecraftforge.common.network.ForgePacketHandler;
|
||||
import net.minecraftforge.common.network.ForgeTinyPacketHandler;
|
||||
import net.minecraftforge.oredict.RecipeSorter;
|
||||
import net.minecraftforge.server.command.ForgeCommand;
|
||||
|
||||
|
@ -36,17 +38,9 @@ import cpw.mods.fml.common.event.FMLLoadCompleteEvent;
|
|||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStartingEvent;
|
||||
import cpw.mods.fml.common.network.FMLNetworkHandler;
|
||||
import cpw.mods.fml.common.network.NetworkMod;
|
||||
import static net.minecraftforge.common.ForgeVersion.*;
|
||||
import static net.minecraftforge.common.config.Configuration.*;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
|
||||
|
||||
@NetworkMod(
|
||||
channels = "FORGE",
|
||||
connectionHandler = ForgeConnectionHandler.class,
|
||||
packetHandler = ForgePacketHandler.class,
|
||||
tinyPacketHandler = ForgeTinyPacketHandler.class
|
||||
)
|
||||
public class ForgeModContainer extends DummyModContainer implements WorldAccessContainer
|
||||
{
|
||||
public static int clumpingThreshold = 64;
|
||||
|
@ -179,16 +173,8 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
|
|||
@Subscribe
|
||||
public void modConstruction(FMLConstructionEvent evt)
|
||||
{
|
||||
FMLLog.info("Registering Forge Packet Handler");
|
||||
try
|
||||
{
|
||||
FMLNetworkHandler.instance().registerNetworkMod(new ForgeNetworkHandler(this));
|
||||
FMLLog.info("Succeeded registering Forge Packet Handler");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FMLLog.log(Level.SEVERE, e, "Failed to register packet handler for Forge");
|
||||
}
|
||||
NetworkRegistry.INSTANCE.register(this, this.getClass(), null, evt.getASMHarvestedData());
|
||||
ForgeNetworkHandler.registerChannel(this, evt.getSide());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
|
|
@ -7,6 +7,8 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
|||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.eventhandler.EventBus;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -18,8 +20,6 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraftforge.common.ForgeHooks.GrassEntry;
|
||||
import net.minecraftforge.common.ForgeHooks.SeedEntry;
|
||||
import net.minecraftforge.common.util.IdentityMap;
|
||||
import net.minecraftforge.event.EventBus;
|
||||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package net.minecraftforge.common.network;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import net.minecraftforge.common.network.ForgeMessage.DimensionRegisterMessage;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
|
||||
public class DimensionMessageHandler extends SimpleChannelInboundHandler<ForgeMessage.DimensionRegisterMessage>{
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, DimensionRegisterMessage msg) throws Exception
|
||||
{
|
||||
if (!DimensionManager.isDimensionRegistered(msg.dimensionId))
|
||||
{
|
||||
DimensionManager.registerDimension(msg.dimensionId, msg.providerId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package net.minecraftforge.common.network;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
|
||||
public class FluidIdRegistryMessageHandler extends SimpleChannelInboundHandler<ForgeMessage.FluidIdMapMessage> {
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, ForgeMessage.FluidIdMapMessage msg) throws Exception
|
||||
{
|
||||
// Do something with the message
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
package net.minecraftforge.common.network;
|
||||
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.NetLoginHandler;
|
||||
import net.minecraft.network.packet.NetHandler;
|
||||
import net.minecraft.network.packet.Packet1Login;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraftforge.fluids.FluidIdMapPacket;
|
||||
import cpw.mods.fml.common.network.IConnectionHandler;
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public class ForgeConnectionHandler implements IConnectionHandler {
|
||||
|
||||
@Override
|
||||
public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager)
|
||||
{
|
||||
Packet250CustomPayload[] fluidPackets = ForgePacket.makePacketSet(new FluidIdMapPacket());
|
||||
for (int i = 0; i < fluidPackets.length; i++) {
|
||||
PacketDispatcher.sendPacketToPlayer(fluidPackets[i], player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String connectionReceived(NetLoginHandler netHandler, INetworkManager manager)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionOpened(NetHandler netClientHandler, String server, int port, INetworkManager manager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionOpened(NetHandler netClientHandler, MinecraftServer server, INetworkManager manager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionClosed(INetworkManager manager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clientLoggedIn(NetHandler clientHandler, INetworkManager manager, Packet1Login login)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package net.minecraftforge.common.network;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public abstract class ForgeMessage {
|
||||
public static class DimensionRegisterMessage extends ForgeMessage {
|
||||
/** The dimension ID to register on client */
|
||||
int dimensionId;
|
||||
/** The provider ID to register with dimension on client */
|
||||
int providerId;
|
||||
@Override
|
||||
void toBytes(ByteBuf bytes)
|
||||
{
|
||||
bytes.writeInt(this.dimensionId);
|
||||
bytes.writeInt(this.providerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
void fromBytes(ByteBuf bytes)
|
||||
{
|
||||
dimensionId = bytes.readInt();
|
||||
providerId = bytes.readInt();
|
||||
}
|
||||
}
|
||||
|
||||
public static class FluidIdMapMessage extends ForgeMessage {
|
||||
BiMap<String, Integer> fluidIds = HashBiMap.create();
|
||||
@Override
|
||||
void toBytes(ByteBuf bytes)
|
||||
{
|
||||
bytes.writeInt(FluidRegistry.maxID);
|
||||
for (Map.Entry<String, Integer> entry : FluidRegistry.fluidIDs.entrySet())
|
||||
{
|
||||
ByteBufUtils.writeUTF8String(bytes,entry.getKey());
|
||||
bytes.writeInt(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void fromBytes(ByteBuf bytes)
|
||||
{
|
||||
int listSize = bytes.readInt();
|
||||
for (int i = 0; i < listSize; i++) {
|
||||
String fluidName = ByteBufUtils.readUTF8String(bytes);
|
||||
int fluidId = bytes.readInt();
|
||||
fluidIds.put(fluidName, fluidId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract void toBytes(ByteBuf bytes);
|
||||
abstract void fromBytes(ByteBuf bytes);
|
||||
}
|
|
@ -1,20 +1,39 @@
|
|||
package net.minecraftforge.common.network;
|
||||
|
||||
import net.minecraftforge.common.ForgeModContainer;
|
||||
import cpw.mods.fml.common.network.NetworkMod;
|
||||
import cpw.mods.fml.common.network.NetworkModHandler;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
|
||||
public class ForgeNetworkHandler extends NetworkModHandler
|
||||
import java.util.EnumMap;
|
||||
|
||||
import net.minecraftforge.common.ForgeModContainer;
|
||||
import cpw.mods.fml.common.network.FMLOutboundHandler;
|
||||
import cpw.mods.fml.common.network.FMLOutboundHandler.OutboundTarget;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.internal.FMLRuntimeCodec;
|
||||
import cpw.mods.fml.common.network.internal.HandshakeCompletionHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class ForgeNetworkHandler
|
||||
{
|
||||
public ForgeNetworkHandler(ForgeModContainer container)
|
||||
private static EnumMap<Side, EmbeddedChannel> channelPair;
|
||||
|
||||
public static void registerChannel(ForgeModContainer forgeModContainer, Side side)
|
||||
{
|
||||
super(container,container.getClass().getAnnotation(NetworkMod.class));
|
||||
configureNetworkMod(container);
|
||||
channelPair = NetworkRegistry.INSTANCE.newChannel(forgeModContainer, "FML", new FMLRuntimeCodec(), new HandshakeCompletionHandler());
|
||||
EmbeddedChannel embeddedChannel = channelPair.get(Side.SERVER);
|
||||
embeddedChannel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.NOWHERE);
|
||||
|
||||
if (side == Side.CLIENT)
|
||||
{
|
||||
addClientHandlers();
|
||||
}
|
||||
channelPair.get(Side.SERVER).pipeline().addAfter("ForgeRuntimeCodec#0", "ServerToClientConnection", new ServerToClientConnectionEstablishedHandler());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptVersion(String version)
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static void addClientHandlers()
|
||||
{
|
||||
return true;
|
||||
channelPair.get(Side.CLIENT).pipeline().addAfter("ForgeRuntimeCodec#0", "DimensionHandler", new DimensionMessageHandler());
|
||||
channelPair.get(Side.CLIENT).pipeline().addAfter("ForgeRuntimeCodec#0", "FluidIdRegistryHandler", new FluidIdRegistryMessageHandler());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,189 +0,0 @@
|
|||
package net.minecraftforge.common.network;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.common.network.packet.DimensionRegisterPacket;
|
||||
import net.minecraftforge.fluids.FluidIdMapPacket;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.MapMaker;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.google.common.primitives.UnsignedBytes;
|
||||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.network.FMLNetworkException;
|
||||
|
||||
public abstract class ForgePacket
|
||||
{
|
||||
public static final String CHANNEL_ID = "FORGE";
|
||||
enum Type
|
||||
{
|
||||
/**
|
||||
* Registers a dimension for a provider on client
|
||||
*/
|
||||
REGISTERDIMENSION(DimensionRegisterPacket.class),
|
||||
/**
|
||||
* The Fluid ID map to send to the client
|
||||
*/
|
||||
FLUID_IDMAP(FluidIdMapPacket.class);
|
||||
|
||||
private Class<? extends ForgePacket> packetType;
|
||||
private ConcurrentMap<INetworkManager, ForgePacket> partTracker;
|
||||
|
||||
private Type(Class<? extends ForgePacket> clazz)
|
||||
{
|
||||
this.packetType = clazz;
|
||||
}
|
||||
|
||||
ForgePacket make()
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.packetType.newInstance();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Throwables.propagateIfPossible(e);
|
||||
FMLLog.log(Level.SEVERE, e, "A bizarre critical error occured during packet encoding");
|
||||
throw new FMLNetworkException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private ForgePacket consumePart(INetworkManager network, byte[] data)
|
||||
{
|
||||
if (partTracker == null)
|
||||
{
|
||||
partTracker = new MapMaker().weakKeys().weakValues().makeMap();
|
||||
}
|
||||
if (!partTracker.containsKey(network))
|
||||
{
|
||||
partTracker.put(network, make());
|
||||
}
|
||||
|
||||
ForgePacket pkt = partTracker.get(network);
|
||||
|
||||
ByteArrayDataInput bdi = ByteStreams.newDataInput(data);
|
||||
int chunkIdx = UnsignedBytes.toInt(bdi.readByte());
|
||||
int chunkTotal = UnsignedBytes.toInt(bdi.readByte());
|
||||
int chunkLength = bdi.readInt();
|
||||
|
||||
if (pkt.partials == null)
|
||||
{
|
||||
pkt.partials = new byte[chunkTotal][];
|
||||
}
|
||||
|
||||
pkt.partials[chunkIdx] = new byte[chunkLength];
|
||||
bdi.readFully(pkt.partials[chunkIdx]);
|
||||
for (int i = 0; i < pkt.partials.length; i++)
|
||||
{
|
||||
if (pkt.partials[i] == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return pkt;
|
||||
}
|
||||
}
|
||||
|
||||
private Type type;
|
||||
private byte[][] partials;
|
||||
|
||||
public static Packet250CustomPayload[] makePacketSet(ForgePacket packet)
|
||||
{
|
||||
byte[] packetData = packet.generatePacket();
|
||||
|
||||
if (packetData.length < 32000)
|
||||
{
|
||||
return new Packet250CustomPayload[]
|
||||
{
|
||||
new Packet250CustomPayload(CHANNEL_ID,
|
||||
Bytes.concat(new byte[]
|
||||
{
|
||||
UnsignedBytes.checkedCast(0), //IsMultipart: False
|
||||
UnsignedBytes.checkedCast(packet.getID())
|
||||
},
|
||||
packetData))
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[][] chunks = new byte[packetData.length / 32000 + 1][];
|
||||
for (int i = 0; i < packetData.length / 32000 + 1; i++)
|
||||
{
|
||||
int len = Math.min(32000, packetData.length - i* 32000);
|
||||
chunks[i] = Bytes.concat(new byte[]
|
||||
{
|
||||
UnsignedBytes.checkedCast(1), //IsMultipart: True
|
||||
UnsignedBytes.checkedCast(packet.getID()), //Packet ID
|
||||
UnsignedBytes.checkedCast(i), //Part Number
|
||||
UnsignedBytes.checkedCast(chunks.length), //Total Parts
|
||||
},
|
||||
Ints.toByteArray(len), //Length
|
||||
Arrays.copyOfRange(packetData, i * 32000, len + i * 32000));
|
||||
}
|
||||
|
||||
Packet250CustomPayload[] ret = new Packet250CustomPayload[chunks.length];
|
||||
for (int i = 0; i < chunks.length; i++)
|
||||
{
|
||||
ret[i] = new Packet250CustomPayload(CHANNEL_ID, chunks[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public static ForgePacket readPacket(INetworkManager network, byte[] payload)
|
||||
{
|
||||
boolean multipart = UnsignedBytes.toInt(payload[0]) == 1;
|
||||
int type = UnsignedBytes.toInt(payload[1]);
|
||||
Type eType = Type.values()[type];
|
||||
byte[] data = Arrays.copyOfRange(payload, 2, payload.length);
|
||||
|
||||
if (multipart)
|
||||
{
|
||||
ForgePacket pkt = eType.consumePart(network, data);
|
||||
if (pkt != null)
|
||||
{
|
||||
return pkt.consumePacket(Bytes.concat(pkt.partials));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return eType.make().consumePacket(data);
|
||||
}
|
||||
}
|
||||
|
||||
public ForgePacket()
|
||||
{
|
||||
for (Type t : Type.values())
|
||||
{
|
||||
if (t.packetType == getClass())
|
||||
{
|
||||
type = t;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (type == null)
|
||||
{
|
||||
throw new RuntimeException("ForgePacket constructor called on ungregistered type.");
|
||||
}
|
||||
}
|
||||
|
||||
public byte getID()
|
||||
{
|
||||
return UnsignedBytes.checkedCast(type.ordinal());
|
||||
}
|
||||
|
||||
public abstract byte[] generatePacket();
|
||||
|
||||
public abstract ForgePacket consumePacket(byte[] data);
|
||||
|
||||
public abstract void execute(INetworkManager network, EntityPlayer player);
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package net.minecraftforge.common.network;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.NetLoginHandler;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import cpw.mods.fml.common.network.FMLPacket;
|
||||
import cpw.mods.fml.common.network.IPacketHandler;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public class ForgePacketHandler implements IPacketHandler {
|
||||
|
||||
@Override
|
||||
public void onPacketData(INetworkManager network, Packet250CustomPayload packet, Player player)
|
||||
{
|
||||
ForgePacket pkt = ForgePacket.readPacket(network, packet.data);
|
||||
// Part of an incomplete multipart packet
|
||||
if (pkt == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pkt.execute(network, (EntityPlayer)player);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package net.minecraftforge.common.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec;
|
||||
|
||||
public class ForgeRuntimeCodec extends FMLIndexedMessageToMessageCodec<ForgeMessage> {
|
||||
public ForgeRuntimeCodec()
|
||||
{
|
||||
addDiscriminator(1, ForgeMessage.DimensionRegisterMessage.class);
|
||||
}
|
||||
@Override
|
||||
public void encodeInto(ChannelHandlerContext ctx, ForgeMessage msg, ByteBuf target) throws Exception
|
||||
{
|
||||
msg.toBytes(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decodeInto(ChannelHandlerContext ctx, ByteBuf source, ForgeMessage msg)
|
||||
{
|
||||
msg.fromBytes(source);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package net.minecraftforge.common.network;
|
||||
|
||||
import cpw.mods.fml.common.network.NetworkHandshakeEstablished;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
|
||||
public class ServerToClientConnectionEstablishedHandler extends ChannelInboundHandlerAdapter {
|
||||
@Override
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception
|
||||
{
|
||||
if (evt instanceof NetworkHandshakeEstablished)
|
||||
{
|
||||
ctx.writeAndFlush(new ForgeMessage.FluidIdMapMessage());
|
||||
return;
|
||||
}
|
||||
// pass it forward
|
||||
ctx.fireUserEventTriggered(evt);
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
/**
|
||||
* This software is provided under the terms of the Minecraft Forge Public
|
||||
* License v1.0.
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.network.packet;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.NetHandler;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import net.minecraftforge.common.network.ForgePacket;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
/**
|
||||
* This class offers the ability for servers to register dimensions on client.
|
||||
*/
|
||||
public class DimensionRegisterPacket extends ForgePacket
|
||||
{
|
||||
|
||||
/** The dimension ID to register on client */
|
||||
public int dimensionId;
|
||||
/** The provider ID to register with dimension on client */
|
||||
public int providerId;
|
||||
|
||||
// nullary constructor required by ForgePacket.make()
|
||||
public DimensionRegisterPacket() {}
|
||||
|
||||
public DimensionRegisterPacket(int dimensionId, int providerId)
|
||||
{
|
||||
this.dimensionId = dimensionId;
|
||||
this.providerId = providerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] generatePacket()
|
||||
{
|
||||
ByteArrayDataOutput dat = ByteStreams.newDataOutput();
|
||||
dat.writeInt(this.dimensionId);
|
||||
dat.writeInt(this.providerId);
|
||||
return dat.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForgePacket consumePacket(byte[] data)
|
||||
{
|
||||
ByteArrayDataInput dat = ByteStreams.newDataInput(data);
|
||||
dimensionId = dat.readInt();
|
||||
providerId = dat.readInt();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(INetworkManager network, EntityPlayer player)
|
||||
{
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
{
|
||||
if (!DimensionManager.isDimensionRegistered(dimensionId))
|
||||
{
|
||||
DimensionManager.registerDimension(dimensionId, providerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,130 +0,0 @@
|
|||
package net.minecraftforge.event;
|
||||
|
||||
import static org.objectweb.asm.Opcodes.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
|
||||
public class ASMEventHandler implements IEventListener
|
||||
{
|
||||
private static int IDs = 0;
|
||||
private static final String HANDLER_DESC = Type.getInternalName(IEventListener.class);
|
||||
private static final String HANDLER_FUNC_DESC = Type.getMethodDescriptor(IEventListener.class.getDeclaredMethods()[0]);
|
||||
private static final ASMClassLoader LOADER = new ASMClassLoader();
|
||||
private static final HashMap<Method, Class<?>> cache = Maps.newHashMap();
|
||||
|
||||
private final IEventListener handler;
|
||||
private final ForgeSubscribe subInfo;
|
||||
public ASMEventHandler(Object target, Method method) throws Exception
|
||||
{
|
||||
handler = (IEventListener)createWrapper(method).getConstructor(Object.class).newInstance(target);
|
||||
subInfo = method.getAnnotation(ForgeSubscribe.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(Event event)
|
||||
{
|
||||
if (handler != null)
|
||||
{
|
||||
if (!event.isCancelable() || !event.isCanceled() || subInfo.receiveCanceled())
|
||||
{
|
||||
handler.invoke(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public EventPriority getPriority()
|
||||
{
|
||||
return subInfo.priority();
|
||||
}
|
||||
|
||||
public Class<?> createWrapper(Method callback)
|
||||
{
|
||||
if (cache.containsKey(callback))
|
||||
{
|
||||
return cache.get(callback);
|
||||
}
|
||||
|
||||
ClassWriter cw = new ClassWriter(0);
|
||||
MethodVisitor mv;
|
||||
|
||||
String name = getUniqueName(callback);
|
||||
String desc = name.replace('.', '/');
|
||||
String instType = Type.getInternalName(callback.getDeclaringClass());
|
||||
String eventType = Type.getInternalName(callback.getParameterTypes()[0]);
|
||||
|
||||
/*
|
||||
System.out.println("Name: " + name);
|
||||
System.out.println("Desc: " + desc);
|
||||
System.out.println("InstType: " + instType);
|
||||
System.out.println("Callback: " + callback.getName() + Type.getMethodDescriptor(callback));
|
||||
System.out.println("Event: " + eventType);
|
||||
*/
|
||||
|
||||
cw.visit(V1_6, ACC_PUBLIC | ACC_SUPER, desc, null, "java/lang/Object", new String[]{ HANDLER_DESC });
|
||||
|
||||
cw.visitSource(".dynamic", null);
|
||||
{
|
||||
cw.visitField(ACC_PUBLIC, "instance", "Ljava/lang/Object;", null, null).visitEnd();
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "(Ljava/lang/Object;)V", null, null);
|
||||
mv.visitCode();
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitFieldInsn(PUTFIELD, desc, "instance", "Ljava/lang/Object;");
|
||||
mv.visitInsn(RETURN);
|
||||
mv.visitMaxs(2, 2);
|
||||
mv.visitEnd();
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(ACC_PUBLIC, "invoke", HANDLER_FUNC_DESC, null, null);
|
||||
mv.visitCode();
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitFieldInsn(GETFIELD, desc, "instance", "Ljava/lang/Object;");
|
||||
mv.visitTypeInsn(CHECKCAST, instType);
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitTypeInsn(CHECKCAST, eventType);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, instType, callback.getName(), Type.getMethodDescriptor(callback));
|
||||
mv.visitInsn(RETURN);
|
||||
mv.visitMaxs(2, 2);
|
||||
mv.visitEnd();
|
||||
}
|
||||
cw.visitEnd();
|
||||
Class<?> ret = LOADER.define(name, cw.toByteArray());
|
||||
cache.put(callback, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
private String getUniqueName(Method callback)
|
||||
{
|
||||
return String.format("%s_%d_%s_%s_%s", getClass().getName(), IDs++,
|
||||
callback.getDeclaringClass().getSimpleName(),
|
||||
callback.getName(),
|
||||
callback.getParameterTypes()[0].getSimpleName());
|
||||
}
|
||||
|
||||
private static class ASMClassLoader extends ClassLoader
|
||||
{
|
||||
private ASMClassLoader()
|
||||
{
|
||||
super(ASMClassLoader.class.getClassLoader());
|
||||
}
|
||||
|
||||
public Class<?> define(String name, byte[] data)
|
||||
{
|
||||
return defineClass(name, data, 0, data.length);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package net.minecraftforge.event;
|
||||
|
||||
import static java.lang.annotation.ElementType.TYPE;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(value = RUNTIME)
|
||||
@Target(value = TYPE)
|
||||
public @interface Cancelable{}
|
|
@ -1,5 +1,7 @@
|
|||
package net.minecraftforge.event;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.command.ICommand;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
|
||||
|
|
|
@ -1,155 +0,0 @@
|
|||
package net.minecraftforge.event;
|
||||
|
||||
import static java.lang.annotation.ElementType.TYPE;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
||||
/**
|
||||
* Base Event class that all other events are derived from
|
||||
*/
|
||||
public class Event
|
||||
{
|
||||
@Retention(value = RUNTIME)
|
||||
@Target(value = TYPE)
|
||||
public @interface HasResult{}
|
||||
|
||||
public enum Result
|
||||
{
|
||||
DENY,
|
||||
DEFAULT,
|
||||
ALLOW
|
||||
}
|
||||
|
||||
private boolean isCanceled = false;
|
||||
private final boolean isCancelable;
|
||||
private Result result = Result.DEFAULT;
|
||||
private final boolean hasResult;
|
||||
private static ListenerList listeners = new ListenerList();
|
||||
|
||||
private static final Map<Class, Map<Class, Boolean>> annotationMap = new ConcurrentHashMap<Class, Map<Class, Boolean>>();
|
||||
|
||||
public Event()
|
||||
{
|
||||
setup();
|
||||
isCancelable = hasAnnotation(Cancelable.class);
|
||||
hasResult = hasAnnotation(HasResult.class);
|
||||
}
|
||||
|
||||
private boolean hasAnnotation(Class annotation)
|
||||
{
|
||||
Class me = this.getClass();
|
||||
Map<Class, Boolean> list = annotationMap.get(me);
|
||||
if (list == null)
|
||||
{
|
||||
list = new ConcurrentHashMap<Class, Boolean>();
|
||||
annotationMap.put(me, list);
|
||||
}
|
||||
|
||||
Boolean cached = list.get(annotation);
|
||||
if (cached != null)
|
||||
{
|
||||
return cached;
|
||||
}
|
||||
|
||||
Class cls = me;
|
||||
while (cls != Event.class)
|
||||
{
|
||||
if (cls.isAnnotationPresent(annotation))
|
||||
{
|
||||
list.put(annotation, true);
|
||||
return true;
|
||||
}
|
||||
cls = cls.getSuperclass();
|
||||
}
|
||||
|
||||
list.put(annotation, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this function is cancelable at all.
|
||||
* @return If access to setCanceled should be allowed
|
||||
*/
|
||||
public boolean isCancelable()
|
||||
{
|
||||
return isCancelable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this event is canceled and should stop executing.
|
||||
* @return The current canceled state
|
||||
*/
|
||||
public boolean isCanceled()
|
||||
{
|
||||
return isCanceled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the state of this event, not all events are cancelable, and any attempt to
|
||||
* cancel a event that can't be will result in a IllegalArgumentException.
|
||||
*
|
||||
* The functionality of setting the canceled state is defined on a per-event bases.
|
||||
*
|
||||
* @param cancel The new canceled value
|
||||
*/
|
||||
public void setCanceled(boolean cancel)
|
||||
{
|
||||
if (!isCancelable())
|
||||
{
|
||||
throw new IllegalArgumentException("Attempted to cancel a uncancelable event");
|
||||
}
|
||||
isCanceled = cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if this event expects a significant result value.
|
||||
*/
|
||||
public boolean hasResult()
|
||||
{
|
||||
return hasResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value set as the result of this event
|
||||
*/
|
||||
public Result getResult()
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the result value for this event, not all events can have a result set, and any attempt to
|
||||
* set a result for a event that isn't expecting it will result in a IllegalArgumentException.
|
||||
*
|
||||
* The functionality of setting the result is defined on a per-event bases.
|
||||
*
|
||||
* @param value The new result
|
||||
*/
|
||||
public void setResult(Result value)
|
||||
{
|
||||
result = value;
|
||||
}
|
||||
/**
|
||||
* Called by the base constructor, this is used by ASM generated
|
||||
* event classes to setup various functionality such as the listener's list.
|
||||
*/
|
||||
protected void setup()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a ListenerList object that contains all listeners
|
||||
* that are registered to this event.
|
||||
*
|
||||
* @return Listener List
|
||||
*/
|
||||
public ListenerList getListenerList()
|
||||
{
|
||||
return listeners;
|
||||
}
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
package net.minecraftforge.event;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
|
||||
public class EventBus
|
||||
{
|
||||
private static int maxID = 0;
|
||||
|
||||
private ConcurrentHashMap<Object, ArrayList<IEventListener>> listeners = new ConcurrentHashMap<Object, ArrayList<IEventListener>>();
|
||||
private final int busID = maxID++;
|
||||
|
||||
public EventBus()
|
||||
{
|
||||
ListenerList.resize(busID + 1);
|
||||
}
|
||||
|
||||
public void register(Object target)
|
||||
{
|
||||
if (listeners.containsKey(target))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Set<? extends Class<?>> supers = TypeToken.of(target.getClass()).getTypes().rawTypes();
|
||||
for (Method method : target.getClass().getMethods())
|
||||
{
|
||||
for (Class<?> cls : supers)
|
||||
{
|
||||
try
|
||||
{
|
||||
Method real = cls.getDeclaredMethod(method.getName(), method.getParameterTypes());
|
||||
if (real.isAnnotationPresent(ForgeSubscribe.class))
|
||||
{
|
||||
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||
if (parameterTypes.length != 1)
|
||||
{
|
||||
throw new IllegalArgumentException(
|
||||
"Method " + method + " has @ForgeSubscribe annotation, but requires " + parameterTypes.length +
|
||||
" arguments. Event handler methods must require a single argument."
|
||||
);
|
||||
}
|
||||
|
||||
Class<?> eventType = parameterTypes[0];
|
||||
|
||||
if (!Event.class.isAssignableFrom(eventType))
|
||||
{
|
||||
throw new IllegalArgumentException("Method " + method + " has @ForgeSubscribe annotation, but takes a argument that is not a Event " + eventType);
|
||||
}
|
||||
|
||||
register(eventType, target, method);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (NoSuchMethodException e)
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void register(Class<?> eventType, Object target, Method method)
|
||||
{
|
||||
try
|
||||
{
|
||||
Constructor<?> ctr = eventType.getConstructor();
|
||||
ctr.setAccessible(true);
|
||||
Event event = (Event)ctr.newInstance();
|
||||
ASMEventHandler listener = new ASMEventHandler(target, method);
|
||||
event.getListenerList().register(busID, listener.getPriority(), listener);
|
||||
|
||||
ArrayList<IEventListener> others = listeners.get(target);
|
||||
if (others == null)
|
||||
{
|
||||
others = new ArrayList<IEventListener>();
|
||||
listeners.put(target, others);
|
||||
}
|
||||
others.add(listener);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void unregister(Object object)
|
||||
{
|
||||
ArrayList<IEventListener> list = listeners.remove(object);
|
||||
for (IEventListener listener : list)
|
||||
{
|
||||
ListenerList.unregiterAll(busID, listener);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean post(Event event)
|
||||
{
|
||||
IEventListener[] listeners = event.getListenerList().getListeners(busID);
|
||||
for (IEventListener listener : listeners)
|
||||
{
|
||||
listener.invoke(event);
|
||||
}
|
||||
return (event.isCancelable() ? event.isCanceled() : false);
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package net.minecraftforge.event;
|
||||
|
||||
public enum EventPriority
|
||||
{
|
||||
/*Priority of event listeners, listeners will be sorted with respect to this priority level.
|
||||
*
|
||||
* Note:
|
||||
* Due to using a ArrayList in the ListenerList,
|
||||
* these need to stay in a contiguous index starting at 0. {Default ordinal}
|
||||
*/
|
||||
HIGHEST, //First to execute
|
||||
HIGH,
|
||||
NORMAL,
|
||||
LOW,
|
||||
LOWEST //Last to execute
|
||||
}
|
|
@ -3,6 +3,8 @@ package net.minecraftforge.event;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event.Result;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
|
@ -13,7 +15,6 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.Event.Result;
|
||||
import net.minecraftforge.event.entity.living.LivingPackSizeEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingSpawnEvent.AllowDespawn;
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
package net.minecraftforge.event;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
|
||||
@Retention(value = RUNTIME)
|
||||
@Target(value = METHOD)
|
||||
public @interface ForgeSubscribe
|
||||
{
|
||||
public EventPriority priority() default EventPriority.NORMAL;
|
||||
public boolean receiveCanceled() default false;
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package net.minecraftforge.event;
|
||||
|
||||
|
||||
|
||||
public interface IEventListener
|
||||
{
|
||||
public void invoke(Event event);
|
||||
}
|
|
@ -1,219 +0,0 @@
|
|||
package net.minecraftforge.event;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class ListenerList
|
||||
{
|
||||
private static ArrayList<ListenerList> allLists = new ArrayList<ListenerList>();
|
||||
private static int maxSize = 0;
|
||||
|
||||
private ListenerList parent;
|
||||
private ListenerListInst[] lists = new ListenerListInst[0];
|
||||
|
||||
public ListenerList()
|
||||
{
|
||||
allLists.add(this);
|
||||
resizeLists(maxSize);
|
||||
}
|
||||
|
||||
public ListenerList(ListenerList parent)
|
||||
{
|
||||
allLists.add(this);
|
||||
this.parent = parent;
|
||||
resizeLists(maxSize);
|
||||
}
|
||||
|
||||
public static void resize(int max)
|
||||
{
|
||||
if (max <= maxSize)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (ListenerList list : allLists)
|
||||
{
|
||||
list.resizeLists(max);
|
||||
}
|
||||
maxSize = max;
|
||||
}
|
||||
|
||||
public void resizeLists(int max)
|
||||
{
|
||||
if (parent != null)
|
||||
{
|
||||
parent.resizeLists(max);
|
||||
}
|
||||
|
||||
if (lists.length >= max)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ListenerListInst[] newList = new ListenerListInst[max];
|
||||
int x = 0;
|
||||
for (; x < lists.length; x++)
|
||||
{
|
||||
newList[x] = lists[x];
|
||||
}
|
||||
for(; x < max; x++)
|
||||
{
|
||||
if (parent != null)
|
||||
{
|
||||
newList[x] = new ListenerListInst(parent.getInstance(x));
|
||||
}
|
||||
else
|
||||
{
|
||||
newList[x] = new ListenerListInst();
|
||||
}
|
||||
}
|
||||
lists = newList;
|
||||
}
|
||||
|
||||
public static void clearBusID(int id)
|
||||
{
|
||||
for (ListenerList list : allLists)
|
||||
{
|
||||
list.lists[id].dispose();
|
||||
}
|
||||
}
|
||||
|
||||
protected ListenerListInst getInstance(int id)
|
||||
{
|
||||
return lists[id];
|
||||
}
|
||||
|
||||
public IEventListener[] getListeners(int id)
|
||||
{
|
||||
return lists[id].getListeners();
|
||||
}
|
||||
|
||||
public void register(int id, EventPriority priority, IEventListener listener)
|
||||
{
|
||||
lists[id].register(priority, listener);
|
||||
}
|
||||
|
||||
public void unregister(int id, IEventListener listener)
|
||||
{
|
||||
lists[id].unregister(listener);
|
||||
}
|
||||
|
||||
public static void unregiterAll(int id, IEventListener listener)
|
||||
{
|
||||
for (ListenerList list : allLists)
|
||||
{
|
||||
list.unregister(id, listener);
|
||||
}
|
||||
}
|
||||
|
||||
private class ListenerListInst
|
||||
{
|
||||
private boolean rebuild = true;
|
||||
private IEventListener[] listeners;
|
||||
private ArrayList<ArrayList<IEventListener>> priorities;
|
||||
private ListenerListInst parent;
|
||||
|
||||
private ListenerListInst()
|
||||
{
|
||||
int count = EventPriority.values().length;
|
||||
priorities = new ArrayList<ArrayList<IEventListener>>(count);
|
||||
|
||||
for (int x = 0; x < count; x++)
|
||||
{
|
||||
priorities.add(new ArrayList<IEventListener>());
|
||||
}
|
||||
}
|
||||
|
||||
public void dispose()
|
||||
{
|
||||
for (ArrayList<IEventListener> listeners : priorities)
|
||||
{
|
||||
listeners.clear();
|
||||
}
|
||||
priorities.clear();
|
||||
parent = null;
|
||||
listeners = null;
|
||||
}
|
||||
|
||||
private ListenerListInst(ListenerListInst parent)
|
||||
{
|
||||
this();
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a ArrayList containing all listeners for this event,
|
||||
* and all parent events for the specified priority.
|
||||
*
|
||||
* The list is returned with the listeners for the children events first.
|
||||
*
|
||||
* @param priority The Priority to get
|
||||
* @return ArrayList containing listeners
|
||||
*/
|
||||
public ArrayList<IEventListener> getListeners(EventPriority priority)
|
||||
{
|
||||
ArrayList<IEventListener> ret = new ArrayList<IEventListener>(priorities.get(priority.ordinal()));
|
||||
if (parent != null)
|
||||
{
|
||||
ret.addAll(parent.getListeners(priority));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a full list of all listeners for all priority levels.
|
||||
* Including all parent listeners.
|
||||
*
|
||||
* List is returned in proper priority order.
|
||||
*
|
||||
* Automatically rebuilds the internal Array cache if its information is out of date.
|
||||
*
|
||||
* @return Array containing listeners
|
||||
*/
|
||||
public IEventListener[] getListeners()
|
||||
{
|
||||
if (shouldRebuild()) buildCache();
|
||||
return listeners;
|
||||
}
|
||||
|
||||
protected boolean shouldRebuild()
|
||||
{
|
||||
return rebuild || (parent != null && parent.shouldRebuild());
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild the local Array of listeners, returns early if there is no work to do.
|
||||
*/
|
||||
private void buildCache()
|
||||
{
|
||||
if(parent != null && parent.shouldRebuild())
|
||||
{
|
||||
parent.buildCache();
|
||||
}
|
||||
|
||||
ArrayList<IEventListener> ret = new ArrayList<IEventListener>();
|
||||
for (EventPriority value : EventPriority.values())
|
||||
{
|
||||
ret.addAll(getListeners(value));
|
||||
}
|
||||
listeners = ret.toArray(new IEventListener[ret.size()]);
|
||||
rebuild = false;
|
||||
}
|
||||
|
||||
public void register(EventPriority priority, IEventListener listener)
|
||||
{
|
||||
priorities.get(priority.ordinal()).add(listener);
|
||||
rebuild = true;
|
||||
}
|
||||
|
||||
public void unregister(IEventListener listener)
|
||||
{
|
||||
for(ArrayList<IEventListener> list : priorities)
|
||||
{
|
||||
if (list.remove(listener))
|
||||
{
|
||||
rebuild = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package net.minecraftforge.event;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package net.minecraftforge.event.brewing;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
public class PotionBrewedEvent extends Event
|
||||
{
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package net.minecraftforge.event.entity;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
public class EntityEvent extends Event
|
||||
{
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package net.minecraftforge.event.entity;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
|
||||
@Cancelable
|
||||
public class EntityJoinWorldEvent extends EntityEvent
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package net.minecraftforge.event.entity;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.effect.EntityLightningBolt;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
|
||||
@Cancelable
|
||||
public class EntityStruckByLightningEvent extends EntityEvent
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package net.minecraftforge.event.entity;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
|
||||
@Cancelable
|
||||
public class PlaySoundAtEntityEvent extends EntityEvent
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package net.minecraftforge.event.entity.item;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package net.minecraftforge.event.entity.item;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
/**
|
||||
* Event for when an Enderman teleports or an ender pearl is used. Can be used to either modify the target position, or cancel the teleport outright.
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
|
||||
@Cancelable
|
||||
public class LivingAttackEvent extends LivingEvent
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
|
||||
@Cancelable
|
||||
public class LivingDeathEvent extends LivingEvent
|
||||
|
|
|
@ -2,10 +2,11 @@ package net.minecraftforge.event.entity.living;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
|
||||
@Cancelable
|
||||
public class LivingDropsEvent extends LivingEvent
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
|
||||
public class LivingEvent extends EntityEvent
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
|
||||
@Cancelable
|
||||
public class LivingFallEvent extends LivingEvent
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
|
||||
@Cancelable
|
||||
public class LivingHurtEvent extends LivingEvent
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event.HasResult;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraftforge.event.Event.HasResult;
|
||||
|
||||
@HasResult
|
||||
public class LivingPackSizeEvent extends LivingEvent
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event.HasResult;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.Event.HasResult;
|
||||
|
||||
public class LivingSpawnEvent extends LivingEvent
|
||||
{
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.monster.EntityZombie;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
|
||||
public class ZombieEvent extends EntityEvent {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package net.minecraftforge.event.entity.minecart;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraft.entity.item.EntityMinecart;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
|
||||
@Cancelable
|
||||
public class MinecartInteractEvent extends MinecartEvent
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
|
||||
@Cancelable
|
||||
public class ArrowLooseEvent extends PlayerEvent
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
|
||||
@Cancelable
|
||||
public class ArrowNockEvent extends PlayerEvent
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
|
||||
@Cancelable
|
||||
public class AttackEntityEvent extends PlayerEvent
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
@Cancelable
|
||||
@Event.HasResult
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
|
||||
@Cancelable
|
||||
public class EntityInteractEvent extends PlayerEvent
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
@Cancelable
|
||||
@Event.HasResult
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
@Cancelable
|
||||
@Event.HasResult
|
||||
|
|
|
@ -2,11 +2,12 @@ package net.minecraftforge.event.entity.player;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||
|
||||
public class PlayerEvent extends LivingEvent
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
|
||||
/**
|
||||
* Occurs when a player falls, but is able to fly. Doesn't need to be cancelable, this is mainly for notification purposes.
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.Event;
|
||||
import static net.minecraftforge.event.Event.Result;
|
||||
import static net.minecraftforge.event.Event.Result.*;
|
||||
import static cpw.mods.fml.common.eventhandler.Event.Result;
|
||||
import static cpw.mods.fml.common.eventhandler.Event.Result.*;
|
||||
|
||||
@Cancelable
|
||||
public class PlayerInteractEvent extends PlayerEvent
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event.HasResult;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraftforge.event.Event.HasResult;
|
||||
|
||||
@HasResult
|
||||
public class PlayerOpenContainerEvent extends PlayerEvent
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
@Cancelable
|
||||
@Event.HasResult
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.minecraftforge.event.terraingen;
|
||||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.world.biome.BiomeDecorator;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.minecraftforge.event.terraingen;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
import net.minecraftforge.event.*;
|
||||
|
|
|
@ -2,6 +2,8 @@ package net.minecraftforge.event.terraingen;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.*;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.minecraftforge.event.terraingen;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.world.gen.MapGenBase;
|
||||
import net.minecraftforge.event.*;
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@ package net.minecraftforge.event.terraingen;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.gen.feature.WorldGenerator;
|
||||
import net.minecraftforge.event.*;
|
||||
|
|
|
@ -2,8 +2,9 @@ package net.minecraftforge.event.terraingen;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event.HasResult;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.Event.HasResult;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,13 +2,14 @@ package net.minecraftforge.event.terraingen;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event.*;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
import net.minecraft.world.gen.MapGenBase;
|
||||
import net.minecraft.world.gen.NoiseGeneratorOctaves;
|
||||
import net.minecraft.world.gen.feature.WorldGenerator;
|
||||
import net.minecraftforge.common.*;
|
||||
import net.minecraftforge.event.Event.*;
|
||||
import net.minecraftforge.event.terraingen.DecorateBiomeEvent.*;
|
||||
import net.minecraftforge.event.terraingen.OreGenEvent.*;
|
||||
import net.minecraftforge.event.terraingen.OreGenEvent.GenerateMinable.*;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package net.minecraftforge.event.terraingen;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.world.gen.layer.GenLayer;
|
||||
import net.minecraft.world.WorldType;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
public class WorldTypeEvent extends Event
|
||||
{
|
||||
|
|
|
@ -2,13 +2,14 @@ package net.minecraftforge.event.world;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
public class BlockEvent extends Event {
|
||||
public final int x;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package net.minecraftforge.event.world;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.management.PlayerInstance;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
public class ChunkWatchEvent extends Event
|
||||
{
|
||||
|
|
|
@ -3,11 +3,12 @@ package net.minecraftforge.event.world;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
|
||||
import net.minecraft.entity.EnumCreatureType;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.SpawnListEntry;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
public class WorldEvent extends Event
|
||||
{
|
||||
|
|
|
@ -8,11 +8,12 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
/**
|
||||
* Register simple items that contain fluids here. Useful for buckets, bottles, and things that have
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
|
||||
package net.minecraftforge.fluids;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
public class FluidEvent extends Event
|
||||
{
|
||||
|
|
|
@ -6,12 +6,13 @@ import java.util.Map;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
|
||||
/**
|
||||
* Handles Fluid registrations. Fluids MUST be registered in order to function.
|
||||
*
|
||||
|
|
|
@ -7,6 +7,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
|
@ -17,7 +19,6 @@ import net.minecraft.item.crafting.IRecipe;
|
|||
import net.minecraft.item.crafting.ShapedRecipes;
|
||||
import net.minecraft.item.crafting.ShapelessRecipes;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
public class OreDictionary
|
||||
{
|
||||
|
|
|
@ -1,164 +0,0 @@
|
|||
package net.minecraftforge.transformers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
import net.minecraftforge.event.Event;
|
||||
import net.minecraftforge.event.ListenerList;
|
||||
|
||||
import org.objectweb.asm.*;
|
||||
import org.objectweb.asm.tree.*;
|
||||
import static org.objectweb.asm.Opcodes.*;
|
||||
import static org.objectweb.asm.Type.*;
|
||||
import static org.objectweb.asm.ClassWriter.*;
|
||||
|
||||
public class EventTransformer implements IClassTransformer
|
||||
{
|
||||
public EventTransformer()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(String name, String transformedName, byte[] bytes)
|
||||
{
|
||||
if (bytes == null || name.equals("net.minecraftforge.event.Event") || name.startsWith("net.minecraft.") || name.indexOf('.') == -1)
|
||||
{
|
||||
return bytes;
|
||||
}
|
||||
ClassReader cr = new ClassReader(bytes);
|
||||
ClassNode classNode = new ClassNode();
|
||||
cr.accept(classNode, 0);
|
||||
|
||||
try
|
||||
{
|
||||
if (buildEvents(classNode))
|
||||
{
|
||||
ClassWriter cw = new ClassWriter(COMPUTE_MAXS | COMPUTE_FRAMES);
|
||||
classNode.accept(cw);
|
||||
return cw.toByteArray();
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
catch (ClassNotFoundException ex)
|
||||
{
|
||||
// Discard silently- it's just noise
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private boolean buildEvents(ClassNode classNode) throws Exception
|
||||
{
|
||||
Class<?> parent = this.getClass().getClassLoader().loadClass(classNode.superName.replace('/', '.'));
|
||||
if (!Event.class.isAssignableFrom(parent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean hasSetup = false;
|
||||
boolean hasGetListenerList = false;
|
||||
boolean hasDefaultCtr = false;
|
||||
|
||||
Class<?> listenerListClazz = Class.forName("net.minecraftforge.event.ListenerList", false, getClass().getClassLoader());
|
||||
Type tList = Type.getType(listenerListClazz);
|
||||
|
||||
for (MethodNode method : (List<MethodNode>)classNode.methods)
|
||||
{
|
||||
if (method.name.equals("setup") &&
|
||||
method.desc.equals(Type.getMethodDescriptor(VOID_TYPE)) &&
|
||||
(method.access & ACC_PROTECTED) == ACC_PROTECTED)
|
||||
{
|
||||
hasSetup = true;
|
||||
}
|
||||
if (method.name.equals("getListenerList") &&
|
||||
method.desc.equals(Type.getMethodDescriptor(tList)) &&
|
||||
(method.access & ACC_PUBLIC) == ACC_PUBLIC)
|
||||
{
|
||||
hasGetListenerList = true;
|
||||
}
|
||||
if (method.name.equals("<init>") &&
|
||||
method.desc.equals(Type.getMethodDescriptor(VOID_TYPE)))
|
||||
{
|
||||
hasDefaultCtr = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasSetup)
|
||||
{
|
||||
if (!hasGetListenerList)
|
||||
{
|
||||
throw new RuntimeException("Event class defines setup() but does not define getListenerList! " + classNode.name);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Type tSuper = Type.getType(classNode.superName);
|
||||
|
||||
//Add private static ListenerList LISTENER_LIST
|
||||
classNode.fields.add(new FieldNode(ACC_PRIVATE | ACC_STATIC, "LISTENER_LIST", tList.getDescriptor(), null, null));
|
||||
|
||||
/*Add:
|
||||
* public <init>()
|
||||
* {
|
||||
* super();
|
||||
* }
|
||||
*/
|
||||
MethodNode method = new MethodNode(ASM4, ACC_PUBLIC, "<init>", getMethodDescriptor(VOID_TYPE), null, null);
|
||||
method.instructions.add(new VarInsnNode(ALOAD, 0));
|
||||
method.instructions.add(new MethodInsnNode(INVOKESPECIAL, tSuper.getInternalName(), "<init>", getMethodDescriptor(VOID_TYPE)));
|
||||
method.instructions.add(new InsnNode(RETURN));
|
||||
if (!hasDefaultCtr)
|
||||
{
|
||||
classNode.methods.add(method);
|
||||
}
|
||||
|
||||
/*Add:
|
||||
* protected void setup()
|
||||
* {
|
||||
* super.setup();
|
||||
* if (LISTENER_LIST != NULL)
|
||||
* {
|
||||
* return;
|
||||
* }
|
||||
* LISTENER_LIST = new ListenerList(super.getListenerList());
|
||||
* }
|
||||
*/
|
||||
method = new MethodNode(ASM4, ACC_PROTECTED, "setup", getMethodDescriptor(VOID_TYPE), null, null);
|
||||
method.instructions.add(new VarInsnNode(ALOAD, 0));
|
||||
method.instructions.add(new MethodInsnNode(INVOKESPECIAL, tSuper.getInternalName(), "setup", getMethodDescriptor(VOID_TYPE)));
|
||||
method.instructions.add(new FieldInsnNode(GETSTATIC, classNode.name, "LISTENER_LIST", tList.getDescriptor()));
|
||||
LabelNode initLisitener = new LabelNode();
|
||||
method.instructions.add(new JumpInsnNode(IFNULL, initLisitener));
|
||||
method.instructions.add(new InsnNode(RETURN));
|
||||
method.instructions.add(initLisitener);
|
||||
method.instructions.add(new FrameNode(F_SAME, 0, null, 0, null));
|
||||
method.instructions.add(new TypeInsnNode(NEW, tList.getInternalName()));
|
||||
method.instructions.add(new InsnNode(DUP));
|
||||
method.instructions.add(new VarInsnNode(ALOAD, 0));
|
||||
method.instructions.add(new MethodInsnNode(INVOKESPECIAL, tSuper.getInternalName(), "getListenerList", getMethodDescriptor(tList)));
|
||||
method.instructions.add(new MethodInsnNode(INVOKESPECIAL, tList.getInternalName(), "<init>", getMethodDescriptor(VOID_TYPE, tList)));
|
||||
method.instructions.add(new FieldInsnNode(PUTSTATIC, classNode.name, "LISTENER_LIST", tList.getDescriptor()));
|
||||
method.instructions.add(new InsnNode(RETURN));
|
||||
classNode.methods.add(method);
|
||||
|
||||
/*Add:
|
||||
* public ListenerList getListenerList()
|
||||
* {
|
||||
* return this.LISTENER_LIST;
|
||||
* }
|
||||
*/
|
||||
method = new MethodNode(ASM4, ACC_PUBLIC, "getListenerList", getMethodDescriptor(tList), null, null);
|
||||
method.instructions.add(new FieldInsnNode(GETSTATIC, classNode.name, "LISTENER_LIST", tList.getDescriptor()));
|
||||
method.instructions.add(new InsnNode(ARETURN));
|
||||
classNode.methods.add(method);
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue