Step 2: The Reformation

This commit is contained in:
AbrarSyed committed 2013-11-09 15:57:08 -06:00
1 parent 9332673944
commit 797399ff7f
198 files changed
+24 -10

No files matched your search

@@ -0,0 +1,130 @@
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);
}
}
}
@@ -0,0 +1,11 @@
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{}
@@ -0,0 +1,21 @@
package net.minecraftforge.event;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
@Cancelable
public class CommandEvent extends Event
{
public final ICommand command;
public final ICommandSender sender;
public String[] parameters;
public Throwable exception;
public CommandEvent(ICommand command, ICommandSender sender, String[] parameters)
{
this.command = command;
this.sender = sender;
this.parameters = parameters;
}
}
@@ -0,0 +1,155 @@
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;
}
}
@@ -0,0 +1,112 @@
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);
}
}
@@ -0,0 +1,16 @@
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
}
@@ -0,0 +1,120 @@
package net.minecraftforge.event;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.player.EntityPlayer;
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;
import net.minecraftforge.event.entity.living.ZombieEvent.SummonAidEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.WorldEvent;
@SuppressWarnings("deprecation")
public class ForgeEventFactory
{
public static boolean doPlayerHarvestCheck(EntityPlayer player, Block block, boolean success)
{
PlayerEvent.HarvestCheck event = new PlayerEvent.HarvestCheck(player, block, success);
MinecraftForge.EVENT_BUS.post(event);
return event.success;
}
public static float getBreakSpeed(EntityPlayer player, Block block, int metadata, float original)
{
PlayerEvent.BreakSpeed event = new PlayerEvent.BreakSpeed(player, block, metadata, original);
return (MinecraftForge.EVENT_BUS.post(event) ? -1 : event.newSpeed);
}
public static PlayerInteractEvent onPlayerInteract(EntityPlayer player, Action action, int x, int y, int z, int face)
{
PlayerInteractEvent event = new PlayerInteractEvent(player, action, x, y, z, face);
MinecraftForge.EVENT_BUS.post(event);
return event;
}
public static void onPlayerDestroyItem(EntityPlayer player, ItemStack stack)
{
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, stack));
}
public static Result canEntitySpawn(EntityLiving entity, World world, float x, float y, float z)
{
LivingSpawnEvent.CheckSpawn event = new LivingSpawnEvent.CheckSpawn(entity, world, x, y, z);
MinecraftForge.EVENT_BUS.post(event);
return event.getResult();
}
public static boolean doSpecialSpawn(EntityLiving entity, World world, float x, float y, float z)
{
return MinecraftForge.EVENT_BUS.post(new LivingSpawnEvent.SpecialSpawn(entity, world, x, y, z));
}
public static Result canEntityDespawn(EntityLiving entity)
{
AllowDespawn event = new AllowDespawn(entity);
MinecraftForge.EVENT_BUS.post(event);
return event.getResult();
}
public static List getPotentialSpawns(WorldServer world, EnumCreatureType type, int x, int y, int z, List oldList)
{
WorldEvent.PotentialSpawns event = new WorldEvent.PotentialSpawns(world, type, x, y, z, oldList);
if (MinecraftForge.EVENT_BUS.post(event))
{
return null;
}
return event.list;
}
public static int getMaxSpawnPackSize(EntityLiving entity)
{
LivingPackSizeEvent maxCanSpawnEvent = new LivingPackSizeEvent(entity);
MinecraftForge.EVENT_BUS.post(maxCanSpawnEvent);
return maxCanSpawnEvent.getResult() == Result.ALLOW ? maxCanSpawnEvent.maxPackSize : entity.getMaxSpawnedInChunk();
}
public static String getPlayerDisplayName(EntityPlayer player, String username)
{
PlayerEvent.NameFormat event = new PlayerEvent.NameFormat(player, username);
MinecraftForge.EVENT_BUS.post(event);
return event.displayname;
}
public static float fireBlockHarvesting(ArrayList<ItemStack> drops, World world, Block block, int x, int y, int z, int meta, int fortune, float dropChance, boolean silkTouch, EntityPlayer player)
{
BlockEvent.HarvestDropsEvent event = new BlockEvent.HarvestDropsEvent(x, y, z, world, block, meta, fortune, dropChance, drops, player, silkTouch);
MinecraftForge.EVENT_BUS.post(event);
return event.dropChance;
}
public static ItemTooltipEvent onItemTooltip(ItemStack itemStack, EntityPlayer entityPlayer, List<String> toolTip, boolean showAdvancedItemTooltips)
{
ItemTooltipEvent event = new ItemTooltipEvent(itemStack, entityPlayer, toolTip, showAdvancedItemTooltips);
MinecraftForge.EVENT_BUS.post(event);
return event;
}
public static SummonAidEvent fireZombieSummonAid(EntityZombie zombie, World world, int x, int y, int z, EntityLivingBase attacker, double summonChance)
{
SummonAidEvent summonEvent = new SummonAidEvent(zombie, world, x, y, z, attacker, summonChance);
MinecraftForge.EVENT_BUS.post(summonEvent);
return summonEvent;
}
}
@@ -0,0 +1,15 @@
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;
}
@@ -0,0 +1,8 @@
package net.minecraftforge.event;
public interface IEventListener
{
public void invoke(Event event);
}
@@ -0,0 +1,219 @@
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;
}
}
}
}
}
@@ -0,0 +1,20 @@
package net.minecraftforge.event;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.ChatMessageComponent;
@Cancelable
public class ServerChatEvent extends Event
{
public final String message, username;
public final EntityPlayerMP player;
public ChatMessageComponent component;
public ServerChatEvent(EntityPlayerMP player, String message, ChatMessageComponent component)
{
super();
this.message = message;
this.player = player;
this.username = player.username;
this.component = component;
}
}
@@ -0,0 +1,16 @@
package net.minecraftforge.event.brewing;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.Event;
public class PotionBrewedEvent extends Event
{
/**
* The brewing stacks in the brewing stand. Each index has the possibility to be null, so make sure you check.
*/
public ItemStack[] brewingStacks;
public PotionBrewedEvent(ItemStack[] brewingStacks)
{
this.brewingStacks = brewingStacks;
}
}
@@ -0,0 +1,49 @@
package net.minecraftforge.event.entity;
import net.minecraft.entity.Entity;
import net.minecraft.world.World;
import net.minecraftforge.event.Event;
public class EntityEvent extends Event
{
public final Entity entity;
public EntityEvent(Entity entity)
{
this.entity = entity;
}
public static class EntityConstructing extends EntityEvent
{
public EntityConstructing(Entity entity)
{
super(entity);
}
}
public static class CanUpdate extends EntityEvent
{
public boolean canUpdate = false;
public CanUpdate(Entity entity)
{
super(entity);
}
}
public static class EnteringChunk extends EntityEvent
{
public int newChunkX;
public int newChunkZ;
public int oldChunkX;
public int oldChunkZ;
public EnteringChunk(Entity entity, int newChunkX, int newChunkZ, int oldChunkX, int oldChunkZ)
{
super(entity);
this.newChunkX = newChunkX;
this.newChunkZ = newChunkZ;
this.oldChunkX = oldChunkX;
this.oldChunkZ = oldChunkZ;
}
}
}
@@ -0,0 +1,18 @@
package net.minecraftforge.event.entity;
import net.minecraft.entity.Entity;
import net.minecraft.world.World;
import net.minecraftforge.event.Cancelable;
@Cancelable
public class EntityJoinWorldEvent extends EntityEvent
{
public final World world;
public EntityJoinWorldEvent(Entity entity, World world)
{
super(entity);
this.world = world;
}
}
@@ -0,0 +1,17 @@
package net.minecraftforge.event.entity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraftforge.event.Cancelable;
@Cancelable
public class EntityStruckByLightningEvent extends EntityEvent
{
public final EntityLightningBolt lightning;
public EntityStruckByLightningEvent(Entity entity, EntityLightningBolt lightning)
{
super(entity);
this.lightning = lightning;
}
}
@@ -0,0 +1,20 @@
package net.minecraftforge.event.entity;
import net.minecraft.entity.Entity;
import net.minecraftforge.event.Cancelable;
@Cancelable
public class PlaySoundAtEntityEvent extends EntityEvent
{
public String name;
public final float volume;
public final float pitch;
public PlaySoundAtEntityEvent(Entity entity, String name, float volume, float pitch)
{
super(entity);
this.name = name;
this.volume = volume;
this.pitch = pitch;
}
}
@@ -0,0 +1,29 @@
package net.minecraftforge.event.entity.item;
import net.minecraft.entity.item.EntityItem;
import net.minecraftforge.event.entity.EntityEvent;
/**
* Base class for all EntityItem events. Contains a reference to the
* EntityItem of interest. For most EntityItem events, there's little to no
* additional useful data from the firing method that isn't already contained
* within the EntityItem instance.
*/
public class ItemEvent extends EntityEvent
{
/**
* The relevant EntityItem for this event, already cast for you.
*/
public final EntityItem entityItem;
/**
* Creates a new event for an EntityItem.
*
* @param itemEntity The EntityItem for this event
*/
public ItemEvent(EntityItem itemEntity)
{
super(itemEntity);
this.entityItem = itemEntity;
}
}
@@ -0,0 +1,30 @@
package net.minecraftforge.event.entity.item;
import net.minecraft.entity.item.EntityItem;
import net.minecraftforge.event.Cancelable;
import net.minecraftforge.event.entity.EntityEvent;
/**
* Event that is fired when an EntityItem's age has reached its maximum
* lifespan. Canceling this event will prevent the EntityItem from being
* flagged as dead, thus staying it's removal from the world. If canceled
* it will add more time to the entitie's life equal to extraLife.
*/
@Cancelable
public class ItemExpireEvent extends ItemEvent
{
public int extraLife;
/**
* Creates a new event for an expiring EntityItem.
*
* @param entityItem The EntityItem being deleted.
* @param extraLife The amount of time to be added to this entities lifespan if the event is canceled.
*/
public ItemExpireEvent(EntityItem entityItem, int extraLife)
{
super(entityItem);
this.extraLife = extraLife;
}
}
@@ -0,0 +1,34 @@
package net.minecraftforge.event.entity.item;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.event.Cancelable;
import net.minecraftforge.event.entity.EntityEvent;
/**
* Event that is fired whenever a player tosses (Q) an item or drag-n-drops a
* stack of items outside the inventory GUI screens. Canceling the event will
* stop the items from entering the world, but will not prevent them being
* removed from the inventory - and thus removed from the system.
*/
@Cancelable
public class ItemTossEvent extends ItemEvent
{
/**
* The player tossing the item.
*/
public final EntityPlayer player;
/**
* Creates a new event for EntityItems tossed by a player.
*
* @param entityItem The EntityItem being tossed.
* @param player The player tossing the item.
*/
public ItemTossEvent(EntityItem entityItem, EntityPlayer player)
{
super(entityItem);
this.player = player;
}
}
@@ -0,0 +1,30 @@
package net.minecraftforge.event.entity.living;
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.
* @author Mithion
*
*/
@Cancelable
public class EnderTeleportEvent extends LivingEvent
{
public double targetX;
public double targetY;
public double targetZ;
public float attackDamage;
public EnderTeleportEvent(EntityLivingBase entity, double targetX, double targetY, double targetZ, float attackDamage)
{
super(entity);
this.targetX = targetX;
this.targetY = targetY;
this.targetZ = targetZ;
this.attackDamage = attackDamage;
}
}
@@ -0,0 +1,18 @@
package net.minecraftforge.event.entity.living;
import net.minecraft.util.DamageSource;
import net.minecraft.entity.EntityLivingBase;
import net.minecraftforge.event.Cancelable;
@Cancelable
public class LivingAttackEvent extends LivingEvent
{
public final DamageSource source;
public final float ammount;
public LivingAttackEvent(EntityLivingBase entity, DamageSource source, float ammount)
{
super(entity);
this.source = source;
this.ammount = ammount;
}
}
@@ -0,0 +1,17 @@
package net.minecraftforge.event.entity.living;
import net.minecraft.util.DamageSource;
import net.minecraft.entity.EntityLivingBase;
import net.minecraftforge.event.Cancelable;
@Cancelable
public class LivingDeathEvent extends LivingEvent
{
public final DamageSource source;
public LivingDeathEvent(EntityLivingBase entity, DamageSource source)
{
super(entity);
this.source = source;
}
}
@@ -0,0 +1,28 @@
package net.minecraftforge.event.entity.living;
import java.util.ArrayList;
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
{
public final DamageSource source;
public final ArrayList<EntityItem> drops;
public final int lootingLevel;
public final boolean recentlyHit;
public final int specialDropValue;
public LivingDropsEvent(EntityLivingBase entity, DamageSource source, ArrayList<EntityItem> drops, int lootingLevel, boolean recentlyHit, int specialDropValue)
{
super(entity);
this.source = source;
this.drops = drops;
this.lootingLevel = lootingLevel;
this.recentlyHit = recentlyHit;
this.specialDropValue = specialDropValue;
}
}
@@ -0,0 +1,26 @@
package net.minecraftforge.event.entity.living;
import net.minecraft.entity.EntityLivingBase;
import net.minecraftforge.event.Cancelable;
import net.minecraftforge.event.entity.EntityEvent;
public class LivingEvent extends EntityEvent
{
public final EntityLivingBase entityLiving;
public LivingEvent(EntityLivingBase entity)
{
super(entity);
entityLiving = entity;
}
@Cancelable
public static class LivingUpdateEvent extends LivingEvent
{
public LivingUpdateEvent(EntityLivingBase e){ super(e); }
}
public static class LivingJumpEvent extends LivingEvent
{
public LivingJumpEvent(EntityLivingBase e){ super(e); }
}
}
@@ -0,0 +1,15 @@
package net.minecraftforge.event.entity.living;
import net.minecraft.entity.EntityLivingBase;
import net.minecraftforge.event.Cancelable;
@Cancelable
public class LivingFallEvent extends LivingEvent
{
public float distance;
public LivingFallEvent(EntityLivingBase entity, float distance)
{
super(entity);
this.distance = distance;
}
}
@@ -0,0 +1,19 @@
package net.minecraftforge.event.entity.living;
import net.minecraft.util.DamageSource;
import net.minecraft.entity.EntityLivingBase;
import net.minecraftforge.event.Cancelable;
@Cancelable
public class LivingHurtEvent extends LivingEvent
{
public final DamageSource source;
public float ammount;
public LivingHurtEvent(EntityLivingBase entity, DamageSource source, float ammount)
{
super(entity);
this.source = source;
this.ammount = ammount;
}
}
@@ -0,0 +1,23 @@
package net.minecraftforge.event.entity.living;
import net.minecraft.entity.EntityLiving;
import net.minecraftforge.event.Event.HasResult;
@HasResult
public class LivingPackSizeEvent extends LivingEvent
{
/**
* This event is fired when the spawning system determines the
* maximum amount of the selected entity that can spawn at the same
* time.
*
* If you set the result to 'ALLOW', it means that you want to return
* the value of maxPackSize as the maximum pack size for current entity.
*/
public int maxPackSize;
public LivingPackSizeEvent(EntityLiving entity)
{
super(entity);
}
}
@@ -0,0 +1,15 @@
package net.minecraftforge.event.entity.living;
import net.minecraft.entity.EntityLivingBase;
public class LivingSetAttackTargetEvent extends LivingEvent
{
public final EntityLivingBase target;
public LivingSetAttackTargetEvent(EntityLivingBase entity, EntityLivingBase target)
{
super(entity);
this.target = target;
}
}
@@ -0,0 +1,73 @@
package net.minecraftforge.event.entity.living;
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
{
public final World world;
public final float x;
public final float y;
public final float z;
public LivingSpawnEvent(EntityLiving entity, World world, float x, float y, float z)
{
super(entity);
this.world = world;
this.x = x;
this.y = y;
this.z = z;
}
/**
* Fires before mob spawn events.
*
* Result is significant:
* DEFAULT: use vanilla spawn rules
* ALLOW: allow the spawn
* DENY: deny the spawn
*
*/
@HasResult
public static class CheckSpawn extends LivingSpawnEvent
{
public CheckSpawn(EntityLiving entity, World world, float x, float y, float z)
{
super(entity, world, x, y, z);
}
}
@Cancelable
public static class SpecialSpawn extends LivingSpawnEvent
{
public SpecialSpawn(EntityLiving entity, World world, float x, float y, float z)
{
super(entity, world, x, y, z);
}
}
/**
* Fired each tick for despawnable mobs to allow control over despawning.
* {@link Result#DEFAULT} will pass the mob on to vanilla despawn mechanics.
* {@link Result#ALLOW} will force the mob to despawn.
* {@link Result#DENY} will force the mob to remain.
* This is fired every tick for every despawnable entity. Be efficient in your handlers.
*
* Note: this is not fired <em>if</em> the mob is definitely going to otherwise despawn. It is fired to check if
* the mob can be allowed to despawn. See {@link EntityLiving#despawnEntity}
*
* @author cpw
*
*/
@HasResult
public static class AllowDespawn extends LivingSpawnEvent
{
public AllowDespawn(EntityLiving entity)
{
super(entity, entity.worldObj, (float)entity.posX, (float)entity.posY, (float)entity.posZ);
}
}
}
@@ -0,0 +1,48 @@
package net.minecraftforge.event.entity.living;
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 {
public ZombieEvent(EntityZombie entity)
{
super(entity);
}
public EntityZombie getSummoner()
{
return (EntityZombie) entity;
}
@HasResult
public static class SummonAidEvent extends ZombieEvent {
/**
* Populate this field to have a custom zombie instead of a normal zombie summoned
*/
public EntityZombie customSummonedAid;
public final World world;
public final int x;
public final int y;
public final int z;
public final EntityLivingBase attacker;
public final double summonChance;
public SummonAidEvent(EntityZombie entity, World world, int x, int y, int z, EntityLivingBase attacker, double summonChance)
{
super(entity);
this.world = world;
this.x = x;
this.y = y;
this.z = z;
this.attacker = attacker;
this.summonChance = summonChance;
}
}
}
@@ -0,0 +1,15 @@
package net.minecraftforge.event.entity.minecart;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityMinecart;
public class MinecartCollisionEvent extends MinecartEvent
{
public final Entity collider;
public MinecartCollisionEvent(EntityMinecart minecart, Entity collider)
{
super(minecart);
this.collider = collider;
}
}
@@ -0,0 +1,16 @@
package net.minecraftforge.event.entity.minecart;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraftforge.event.entity.EntityEvent;
public class MinecartEvent extends EntityEvent
{
public final EntityMinecart minecart;
public MinecartEvent(EntityMinecart minecart)
{
super(minecart);
this.minecart = minecart;
}
}
@@ -0,0 +1,17 @@
package net.minecraftforge.event.entity.minecart;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.event.Cancelable;
@Cancelable
public class MinecartInteractEvent extends MinecartEvent
{
public final EntityPlayer player;
public MinecartInteractEvent(EntityMinecart minecart, EntityPlayer player)
{
super(minecart);
this.player = player;
}
}
@@ -0,0 +1,18 @@
package net.minecraftforge.event.entity.minecart;
import net.minecraft.entity.item.EntityMinecart;
public class MinecartUpdateEvent extends MinecartEvent
{
public final float x;
public final float y;
public final float z;
public MinecartUpdateEvent(EntityMinecart minecart, float x, float y, float z)
{
super(minecart);
this.x = x;
this.y = y;
this.z = z;
}
}
@@ -0,0 +1,19 @@
package net.minecraftforge.event.entity.player;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.Cancelable;
@Cancelable
public class ArrowLooseEvent extends PlayerEvent
{
public final ItemStack bow;
public int charge;
public ArrowLooseEvent(EntityPlayer player, ItemStack bow, int charge)
{
super(player);
this.bow = bow;
this.charge = charge;
}
}
@@ -0,0 +1,17 @@
package net.minecraftforge.event.entity.player;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.Cancelable;
@Cancelable
public class ArrowNockEvent extends PlayerEvent
{
public ItemStack result;
public ArrowNockEvent(EntityPlayer player, ItemStack result)
{
super(player);
this.result = result;
}
}
@@ -0,0 +1,16 @@
package net.minecraftforge.event.entity.player;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.event.Cancelable;
@Cancelable
public class AttackEntityEvent extends PlayerEvent
{
public final Entity target;
public AttackEntityEvent(EntityPlayer player, Entity target)
{
super(player);
this.target = target;
}
}
@@ -0,0 +1,37 @@
package net.minecraftforge.event.entity.player;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraftforge.event.Cancelable;
import net.minecraftforge.event.Event;
@Cancelable
@Event.HasResult
public class BonemealEvent extends PlayerEvent
{
/**
* This event is called when a player attempts to use Bonemeal on a block.
* It can be canceled to completely prevent any further processing.
*
* You can also set the result to ALLOW to mark the event as processed
* and use up a bonemeal from the stack but do no further processing.
*
* setResult(ALLOW) is the same as the old setHandeled()
*/
public final World world;
public final int ID;
public final int X;
public final int Y;
public final int Z;
public BonemealEvent(EntityPlayer player, World world, int id, int x, int y, int z)
{
super(player);
this.world = world;
this.ID = id;
this.X = x;
this.Y = y;
this.Z = z;
}
}
@@ -0,0 +1,16 @@
package net.minecraftforge.event.entity.player;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.event.Cancelable;
@Cancelable
public class EntityInteractEvent extends PlayerEvent
{
public final Entity target;
public EntityInteractEvent(EntityPlayer player, Entity target)
{
super(player);
this.target = target;
}
}
@@ -0,0 +1,32 @@
package net.minecraftforge.event.entity.player;
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
public class EntityItemPickupEvent extends PlayerEvent
{
/**
* This event is called when a player collides with a EntityItem on the ground.
* The event can be canceled, and no further processing will be done.
*
* You can set the result of this event to ALLOW which will trigger the
* processing of achievements, FML's event, play the sound, and kill the
* entity if all the items are picked up.
*
* setResult(ALLOW) is the same as the old setHandled()
*/
public final EntityItem item;
private boolean handled = false;
public EntityItemPickupEvent(EntityPlayer player, EntityItem item)
{
super(player);
this.item = item;
}
}
@@ -0,0 +1,37 @@
package net.minecraftforge.event.entity.player;
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
public class FillBucketEvent extends PlayerEvent
{
/**
* This event is fired when a player attempts to use a Empty bucket, it
* can be canceled to completely prevent any further processing.
*
* If you set the result to 'ALLOW', it means that you have processed
* the event and wants the basic functionality of adding the new
* ItemStack to your inventory and reducing the stack size to process.
* setResult(ALLOW) is the same as the old setHandeled();
*/
public final ItemStack current;
public final World world;
public final MovingObjectPosition target;
public ItemStack result;
public FillBucketEvent(EntityPlayer player, ItemStack current, World world, MovingObjectPosition target)
{
super(player);
this.current = current;
this.world = world;
this.target = target;
}
}
@@ -0,0 +1,32 @@
package net.minecraftforge.event.entity.player;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
public class ItemTooltipEvent extends PlayerEvent
{
/**
* Whether the advanced information on item tooltips is being shown, toggled by F3+H.
*/
public final boolean showAdvancedItemTooltips;
/**
* The {@link ItemStack} with the tooltip.
*/
public final ItemStack itemStack;
/**
* The {@link ItemStack} tooltip.
*/
public final List<String> toolTip;
/**
* This event is fired in {@link ItemStack#getTooltip(EntityPlayer, boolean)}, which in turn is called from it's respective GUIContainer.
*/
public ItemTooltipEvent(ItemStack itemStack, EntityPlayer entityPlayer, List<String> toolTip, boolean showAdvancedItemTooltips)
{
super(entityPlayer);
this.itemStack = itemStack;
this.toolTip = toolTip;
this.showAdvancedItemTooltips = showAdvancedItemTooltips;
}
}
@@ -0,0 +1,15 @@
package net.minecraftforge.event.entity.player;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
public class PlayerDestroyItemEvent extends PlayerEvent
{
public final ItemStack original;
public PlayerDestroyItemEvent(EntityPlayer player, ItemStack original)
{
super(player);
this.original = original;
}
}
@@ -0,0 +1,38 @@
package net.minecraftforge.event.entity.player;
import java.util.ArrayList;
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;
/**
* Child class of LivingDropEvent that is fired specifically when a
* player dies. Canceling the event will prevent ALL drops from entering the
* world.
*/
@Cancelable
public class PlayerDropsEvent extends LivingDropsEvent
{
public final EntityPlayer entityPlayer;
/**
* Creates a new event containing all the items that will drop into the
* world when a player dies.
* @param entity The dying player.
* @param source The source of the damage which is killing the player.
* @param drops List of all drops entering the world.
*/
public PlayerDropsEvent(EntityPlayer entity, DamageSource source, ArrayList<EntityItem> drops, boolean recentlyHit)
{
super(entity, source, drops,
(source.getEntity() instanceof EntityPlayer) ?
EnchantmentHelper.getLootingModifier(((EntityPlayer)source.getEntity())) : 0,
recentlyHit, 0);
this.entityPlayer = entity;
}
}
@@ -0,0 +1,60 @@
package net.minecraftforge.event.entity.player;
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
{
public final EntityPlayer entityPlayer;
public PlayerEvent(EntityPlayer player)
{
super(player);
entityPlayer = player;
}
public static class HarvestCheck extends PlayerEvent
{
public final Block block;
public boolean success;
public HarvestCheck(EntityPlayer player, Block block, boolean success)
{
super(player);
this.block = block;
this.success = success;
}
}
@Cancelable
public static class BreakSpeed extends PlayerEvent
{
public final Block block;
public final int metadata;
public final float originalSpeed;
public float newSpeed = 0.0f;
public BreakSpeed(EntityPlayer player, Block block, int metadata, float original)
{
super(player);
this.block = block;
this.metadata = metadata;
this.originalSpeed = original;
this.newSpeed = original;
}
}
public static class NameFormat extends PlayerEvent
{
public final String username;
public String displayname;
public NameFormat(EntityPlayer player, String username) {
super(player);
this.username = username;
this.displayname = username;
}
}
}
@@ -0,0 +1,22 @@
package net.minecraftforge.event.entity.player;
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.
* @author Mithion
*
*/
public class PlayerFlyableFallEvent extends PlayerEvent
{
public float distance;
public PlayerFlyableFallEvent(EntityPlayer player, float f)
{
super(player);
this.distance = f;
}
}
@@ -0,0 +1,47 @@
package net.minecraftforge.event.entity.player;
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.*;
@Cancelable
public class PlayerInteractEvent extends PlayerEvent
{
public static enum Action
{
RIGHT_CLICK_AIR,
RIGHT_CLICK_BLOCK,
LEFT_CLICK_BLOCK
}
public final Action action;
public final int x;
public final int y;
public final int z;
public final int face;
public Result useBlock = DEFAULT;
public Result useItem = DEFAULT;
public PlayerInteractEvent(EntityPlayer player, Action action, int x, int y, int z, int face)
{
super(player);
this.action = action;
this.x = x;
this.y = y;
this.z = z;
this.face = face;
if (face == -1) useBlock = DENY;
}
@Override
public void setCanceled(boolean cancel)
{
super.setCanceled(cancel);
useBlock = (cancel ? DENY : useBlock == DENY ? DEFAULT : useBlock);
useItem = (cancel ? DENY : useItem == DENY ? DEFAULT : useItem);
}
}
@@ -0,0 +1,29 @@
package net.minecraftforge.event.entity.player;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraftforge.event.Event.HasResult;
@HasResult
public class PlayerOpenContainerEvent extends PlayerEvent
{
public final boolean canInteractWith;
/**
* This event is fired when a player attempts to view a container during
* player tick.
*
* setResult ALLOW to allow the container to stay open
* setResult DENY to force close the container (denying access)
*
* DEFAULT is vanilla behaviour
*
*/
public PlayerOpenContainerEvent(EntityPlayer player, Container openContainer)
{
super(player);
this.canInteractWith = openContainer.canInteractWith(player);
}
}
@@ -0,0 +1,21 @@
package net.minecraftforge.event.entity.player;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EnumStatus;
public class PlayerSleepInBedEvent extends PlayerEvent
{
public EnumStatus result = null;
public final int x;
public final int y;
public final int z;
public PlayerSleepInBedEvent(EntityPlayer player, int x, int y, int z)
{
super(player);
this.x = x;
this.y = y;
this.z = z;
}
}
@@ -0,0 +1,40 @@
package net.minecraftforge.event.entity.player;
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
public class UseHoeEvent extends PlayerEvent
{
/**
* This event is fired when a player attempts to use a Hoe on a block, it
* can be canceled to completely prevent any further processing.
*
* You can also set the result to ALLOW to mark the event as processed
* and damage the hoe.
*
* setResult(ALLOW) is the same as the old setHandeled();
*/
public final ItemStack current;
public final World world;
public final int x;
public final int y;
public final int z;
private boolean handeled = false;
public UseHoeEvent(EntityPlayer player, ItemStack current, World world, int x, int y, int z)
{
super(player);
this.current = current;
this.world = world;
this.x = x;
this.y = y;
this.z = z;
}
}
@@ -0,0 +1,120 @@
package net.minecraftforge.event.terraingen;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.world.biome.BiomeDecorator;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.event.*;
public class BiomeEvent extends Event
{
public final BiomeGenBase biome;
public BiomeEvent(BiomeGenBase biome)
{
this.biome = biome;
}
public static class CreateDecorator extends BiomeEvent
{
public final BiomeDecorator originalBiomeDecorator;
public BiomeDecorator newBiomeDecorator;
public CreateDecorator(BiomeGenBase biome, BiomeDecorator original)
{
super(biome);
originalBiomeDecorator = original;
newBiomeDecorator = original;
}
}
public static class BlockReplacement extends BiomeEvent
{
public final int original;
public int replacement;
public BlockReplacement(BiomeGenBase biome, int original, int replacement)
{
super(biome);
this.original = original;
this.replacement = replacement;
}
}
public static class BiomeColor extends BiomeEvent
{
public final int originalColor;
public int newColor;
public BiomeColor(BiomeGenBase biome, int original)
{
super(biome);
originalColor = original;
newColor = original;
}
}
/**
* This event is fired when the village generator attempts to choose a block ID
* based on the village's biome.
*
* You can set the result to DENY to prevent the default block ID selection.
*/
@HasResult
public static class GetVillageBlockID extends BlockReplacement
{
public GetVillageBlockID(BiomeGenBase biome, int original, int replacement)
{
super(biome, original, replacement);
}
}
/**
* This event is fired when the village generator attempts to choose a block
* metadata based on the village's biome.
*
* You can set the result to DENY to prevent the default block metadata selection.
*/
@HasResult
public static class GetVillageBlockMeta extends BlockReplacement
{
public GetVillageBlockMeta(BiomeGenBase biome, int original, int replacement)
{
super(biome, original, replacement);
}
}
/**
* This event is fired when a biome is queried for its grass color.
*/
public static class GetGrassColor extends BiomeColor
{
public GetGrassColor(BiomeGenBase biome, int original)
{
super(biome, original);
}
}
/**
* This event is fired when a biome is queried for its grass color.
*/
public static class GetFoliageColor extends BiomeColor
{
public GetFoliageColor(BiomeGenBase biome, int original)
{
super(biome, original);
}
}
/**
* This event is fired when a biome is queried for its water color.
*/
public static class GetWaterColor extends BiomeColor
{
public GetWaterColor(BiomeGenBase biome, int original)
{
super(biome, original);
}
}
}
@@ -0,0 +1,71 @@
package net.minecraftforge.event.terraingen;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraftforge.event.*;
public class ChunkProviderEvent extends Event
{
public final IChunkProvider chunkProvider;
public ChunkProviderEvent(IChunkProvider chunkProvider)
{
this.chunkProvider = chunkProvider;
}
/**
* This event is fired when a chunks blocks are replaced by a biomes top and
* filler blocks.
*
* You can set the result to DENY to prevent the default replacement.
*/
@HasResult
public static class ReplaceBiomeBlocks extends ChunkProviderEvent
{
public final int chunkX;
public final int chunkZ;
public final byte[] blockArray;
public final BiomeGenBase[] biomeArray;
public ReplaceBiomeBlocks(IChunkProvider chunkProvider, int chunkX, int chunkZ, byte[] blockArray, BiomeGenBase[] biomeArray)
{
super(chunkProvider);
this.chunkX = chunkX;
this.chunkZ = chunkZ;
this.blockArray = blockArray;
this.biomeArray = biomeArray;
}
}
/**
* This event is fired before a chunks terrain noise field is initialized.
*
* You can set the result to DENY to substitute your own noise field.
*/
@HasResult
public static class InitNoiseField extends ChunkProviderEvent
{
public double[] noisefield;
public final int posX;
public final int posY;
public final int posZ;
public final int sizeX;
public final int sizeY;
public final int sizeZ;
public InitNoiseField(IChunkProvider chunkProvider, double[] noisefield, int posX, int posY, int posZ, int sizeX, int sizeY, int sizeZ)
{
super(chunkProvider);
this.noisefield = noisefield;
this.posX = posX;
this.posY = posY;
this.posZ = posZ;
this.sizeX = sizeX;
this.sizeY = sizeY;
this.sizeZ = sizeZ;
}
}
}
@@ -0,0 +1,59 @@
package net.minecraftforge.event.terraingen;
import java.util.Random;
import net.minecraft.world.World;
import net.minecraftforge.event.*;
public class DecorateBiomeEvent extends Event
{
public final World world;
public final Random rand;
public final int chunkX;
public final int chunkZ;
public DecorateBiomeEvent(World world, Random rand, int worldX, int worldZ)
{
this.world = world;
this.rand = rand;
this.chunkX = worldX;
this.chunkZ = worldZ;
}
public static class Pre extends DecorateBiomeEvent
{
public Pre(World world, Random rand, int worldX, int worldZ)
{
super(world, rand, worldX, worldZ);
}
}
public static class Post extends DecorateBiomeEvent
{
public Post(World world, Random rand, int worldX, int worldZ)
{
super(world, rand, worldX, worldZ);
}
}
/**
* This event is fired when a chunk is decorated with a biome feature.
*
* You can set the result to DENY to prevent the default biome decoration.
*/
@HasResult
public static class Decorate extends DecorateBiomeEvent
{
/** Use CUSTOM to filter custom event types
*/
public static enum EventType { BIG_SHROOM, CACTUS, CLAY, DEAD_BUSH, LILYPAD, FLOWERS, GRASS, LAKE, PUMPKIN, REED, SAND, SAND_PASS2, SHROOM, TREE, CUSTOM }
public final EventType type;
public Decorate(World world, Random rand, int worldX, int worldZ, EventType type)
{
super(world, rand, worldX, worldZ);
this.type = type;
}
}
}
@@ -0,0 +1,47 @@
package net.minecraftforge.event.terraingen;
import java.util.Random;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeDecorator;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.MinecraftForge;
public class DeferredBiomeDecorator extends BiomeDecorator {
private BiomeDecorator wrapped;
public DeferredBiomeDecorator(BiomeGenBase biomeGenBase, BiomeDecorator wrappedOriginal)
{
super(biomeGenBase);
this.wrapped = wrappedOriginal;
}
@Override
public void decorate(World par1World, Random par2Random, int par3, int par4)
{
fireCreateEventAndReplace();
// On first call to decorate, we fire and substitute ourselves, if we haven't already done so
biome.theBiomeDecorator.decorate(par1World, par2Random, par3, par4);
}
public void fireCreateEventAndReplace()
{
// Copy any configuration from us to the real instance.
wrapped.bigMushroomsPerChunk = bigMushroomsPerChunk;
wrapped.cactiPerChunk = cactiPerChunk;
wrapped.clayPerChunk = clayPerChunk;
wrapped.deadBushPerChunk = deadBushPerChunk;
wrapped.flowersPerChunk = flowersPerChunk;
wrapped.generateLakes = generateLakes;
wrapped.grassPerChunk = grassPerChunk;
wrapped.mushroomsPerChunk = mushroomsPerChunk;
wrapped.reedsPerChunk = reedsPerChunk;
wrapped.sandPerChunk = sandPerChunk;
wrapped.sandPerChunk2 = sandPerChunk2;
wrapped.treesPerChunk = treesPerChunk;
wrapped.waterlilyPerChunk = waterlilyPerChunk;
BiomeEvent.CreateDecorator event = new BiomeEvent.CreateDecorator(biome, wrapped);
MinecraftForge.TERRAIN_GEN_BUS.post(event);
biome.theBiomeDecorator = event.newBiomeDecorator;
}
}
@@ -0,0 +1,22 @@
package net.minecraftforge.event.terraingen;
import net.minecraft.world.gen.MapGenBase;
import net.minecraftforge.event.*;
public class InitMapGenEvent extends Event
{
/** Use CUSTOM to filter custom event types
*/
public static enum EventType { CAVE, MINESHAFT, NETHER_BRIDGE, NETHER_CAVE, RAVINE, SCATTERED_FEATURE, STRONGHOLD, VILLAGE, CUSTOM }
public final EventType type;
public final MapGenBase originalGen;
public MapGenBase newGen;
InitMapGenEvent(EventType type, MapGenBase original)
{
this.type = type;
this.originalGen = original;
this.newGen = original;
}
}
@@ -0,0 +1,22 @@
package net.minecraftforge.event.terraingen;
import java.util.Random;
import net.minecraft.world.World;
import net.minecraft.world.gen.NoiseGeneratorOctaves;
import net.minecraftforge.event.world.*;
public class InitNoiseGensEvent extends WorldEvent
{
public final Random rand;
public final NoiseGeneratorOctaves[] originalNoiseGens;
public NoiseGeneratorOctaves[] newNoiseGens;
public InitNoiseGensEvent(World world, Random rand, NoiseGeneratorOctaves[] original)
{
super(world);
this.rand = rand;
originalNoiseGens = original;
newNoiseGens = original.clone();
}
}
@@ -0,0 +1,60 @@
package net.minecraftforge.event.terraingen;
import java.util.Random;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.event.*;
public class OreGenEvent extends Event
{
public final World world;
public final Random rand;
public final int worldX;
public final int worldZ;
public OreGenEvent(World world, Random rand, int worldX, int worldZ)
{
this.world = world;
this.rand = rand;
this.worldX = worldX;
this.worldZ = worldZ;
}
public static class Pre extends OreGenEvent
{
public Pre(World world, Random rand, int worldX, int worldZ)
{
super(world, rand, worldX, worldZ);
}
}
public static class Post extends OreGenEvent
{
public Post(World world, Random rand, int worldX, int worldZ)
{
super(world, rand, worldX, worldZ);
}
}
/**
* This event is fired when an ore is generated in a chunk.
*
* You can set the result to DENY to prevent the default ore generation.
*/
@HasResult
public static class GenerateMinable extends OreGenEvent
{
public static enum EventType { COAL, DIAMOND, DIRT, GOLD, GRAVEL, IRON, LAPIS, REDSTONE, CUSTOM }
public final EventType type;
public final WorldGenerator generator;
public GenerateMinable(World world, Random rand, WorldGenerator generator, int worldX, int worldZ, EventType type)
{
super(world, rand, worldX, worldZ);
this.generator = generator;
this.type = type;
}
}
}
@@ -0,0 +1,64 @@
package net.minecraftforge.event.terraingen;
import java.util.Random;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraftforge.event.world.*;
public class PopulateChunkEvent extends ChunkProviderEvent
{
public final World world;
public final Random rand;
public final int chunkX;
public final int chunkZ;
public final boolean hasVillageGenerated;
public PopulateChunkEvent(IChunkProvider chunkProvider, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGenerated)
{
super(chunkProvider);
this.world = world;
this.rand = rand;
this.chunkX = chunkX;
this.chunkZ = chunkZ;
this.hasVillageGenerated = hasVillageGenerated;
}
public static class Pre extends PopulateChunkEvent
{
public Pre(IChunkProvider chunkProvider, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGenerated)
{
super(chunkProvider, world, rand, chunkX, chunkZ, hasVillageGenerated);
}
}
public static class Post extends PopulateChunkEvent
{
public Post(IChunkProvider chunkProvider, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGenerated)
{
super(chunkProvider, world, rand, chunkX, chunkZ, hasVillageGenerated);
}
}
/**
* This event is fired when a chunk is populated with a terrain feature.
*
* You can set the result to DENY to prevent the default generation
* of a terrain feature.
*/
@HasResult
public static class Populate extends PopulateChunkEvent
{
/** Use CUSTOM to filter custom event types
*/
public static enum EventType { DUNGEON, FIRE, GLOWSTONE, ICE, LAKE, LAVA, NETHER_LAVA, CUSTOM }
public final EventType type;
public Populate(IChunkProvider chunkProvider, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGenerated, EventType type)
{
super(chunkProvider, world, rand, chunkX, chunkZ, hasVillageGenerated);
this.type = type;
}
}
}
@@ -0,0 +1,30 @@
package net.minecraftforge.event.terraingen;
import java.util.Random;
import net.minecraft.world.World;
import net.minecraftforge.event.Event.HasResult;
import net.minecraftforge.event.world.WorldEvent;
/**
* This event is fired when a sapling grows a tree.
*
* You can set the result to DENY to prevent the default tree growth.
*/
@HasResult
public class SaplingGrowTreeEvent extends WorldEvent
{
public final int x;
public final int y;
public final int z;
public final Random rand;
public SaplingGrowTreeEvent(World world, Random rand, int x, int y, int z)
{
super(world);
this.rand = rand;
this.x = x;
this.y = y;
this.z = z;
}
}
@@ -0,0 +1,60 @@
package net.minecraftforge.event.terraingen;
import java.util.Random;
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.*;
import net.minecraftforge.event.terraingen.PopulateChunkEvent.*;
public abstract class TerrainGen
{
public static NoiseGeneratorOctaves[] getModdedNoiseGenerators(World world, Random rand, NoiseGeneratorOctaves[] original)
{
InitNoiseGensEvent event = new InitNoiseGensEvent(world, rand, original);
MinecraftForge.TERRAIN_GEN_BUS.post(event);
return event.newNoiseGens;
}
public static MapGenBase getModdedMapGen(MapGenBase original, InitMapGenEvent.EventType type)
{
InitMapGenEvent event = new InitMapGenEvent(type, original);
MinecraftForge.TERRAIN_GEN_BUS.post(event);
return event.newGen;
}
public static boolean populate(IChunkProvider chunkProvider, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGenerated, Populate.EventType type)
{
PopulateChunkEvent.Populate event = new PopulateChunkEvent.Populate(chunkProvider, world, rand, chunkX, chunkZ, hasVillageGenerated, type);
MinecraftForge.TERRAIN_GEN_BUS.post(event);
return event.getResult() != Result.DENY;
}
public static boolean decorate(World world, Random rand, int chunkX, int chunkZ, Decorate.EventType type)
{
Decorate event = new Decorate(world, rand, chunkX, chunkZ, type);
MinecraftForge.TERRAIN_GEN_BUS.post(event);
return event.getResult() != Result.DENY;
}
public static boolean generateOre(World world, Random rand, WorldGenerator generator, int worldX, int worldZ, GenerateMinable.EventType type)
{
GenerateMinable event = new GenerateMinable(world, rand, generator, worldX, worldZ, type);
MinecraftForge.ORE_GEN_BUS.post(event);
return event.getResult() != Result.DENY;
}
public static boolean saplingGrowTree(World world, Random rand, int x, int y, int z)
{
SaplingGrowTreeEvent event = new SaplingGrowTreeEvent(world, rand, x, y, z);
MinecraftForge.TERRAIN_GEN_BUS.post(event);
return event.getResult() != Result.DENY;
}
}
@@ -0,0 +1,43 @@
package net.minecraftforge.event.terraingen;
import net.minecraft.world.gen.layer.GenLayer;
import net.minecraft.world.WorldType;
import net.minecraftforge.event.Event;
public class WorldTypeEvent extends Event
{
public final WorldType worldType;
public WorldTypeEvent(WorldType worldType)
{
this.worldType = worldType;
}
public static class BiomeSize extends WorldTypeEvent
{
public final byte originalSize;
public byte newSize;
public BiomeSize(WorldType worldType, byte original)
{
super(worldType);
originalSize = original;
newSize = original;
}
}
public static class InitBiomeGens extends WorldTypeEvent
{
public final long seed;
public final GenLayer[] originalBiomeGens;
public GenLayer[] newBiomeGens;
public InitBiomeGens(WorldType worldType, long seed, GenLayer[] original)
{
super(worldType);
this.seed = seed;
originalBiomeGens = original;
newBiomeGens = original.clone();
}
}
}
@@ -0,0 +1,113 @@
package net.minecraftforge.event.world;
import java.util.ArrayList;
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;
public final int y;
public final int z;
public final World world;
public final Block block;
public final int blockMetadata;
public BlockEvent(int x, int y, int z, World world, Block block, int blockMetadata)
{
this.x = x;
this.y = y;
this.z = z;
this.world = world;
this.block = block;
this.blockMetadata = blockMetadata;
}
/**
* Fired when a block is about to drop it's harvested items. The {@link #drops} array can be amended, as can the {@link #dropChance}.
* <strong>Note well:</strong> the {@link #harvester} player field is null in a variety of scenarios. Code expecting null.
*
* The {@link #dropChance} is used to determine which items in this array will actually drop, compared to a random number. If you wish, you
* can pre-filter yourself, and set {@link #dropChance} to 1.0f to always drop the contents of the {@link #drops} array.
*
* {@link #isSilkTouching} is set if this is considered a silk touch harvesting operation, vs a normal harvesting operation. Act accordingly.
*
* @author cpw
*/
public static class HarvestDropsEvent extends BlockEvent {
public final int fortuneLevel;
public final ArrayList<ItemStack> drops;
public final boolean isSilkTouching;
public float dropChance; // Change to e.g. 1.0f, if you manipulate the list and want to guarantee it always drops
public final EntityPlayer harvester; // May be null for non-player harvesting such as explosions or machines
public HarvestDropsEvent(int x, int y, int z, World world, Block block, int blockMetadata, int fortuneLevel, float dropChance, ArrayList<ItemStack> drops, EntityPlayer harvester, boolean isSilkTouching)
{
super(x, y, z, world, block, blockMetadata);
this.fortuneLevel = fortuneLevel;
this.dropChance = dropChance;
this.drops = drops;
this.isSilkTouching = isSilkTouching;
this.harvester = harvester;
}
}
/**
* Event that is fired when an Block is about to be broken by a player
* Canceling this event will prevent the Block from being broken.
*/
@Cancelable
public static class BreakEvent extends BlockEvent
{
/** Reference to the Player who broke the block. If no player is available, use a EntityFakePlayer */
private final EntityPlayer player;
private int exp;
public BreakEvent(int x, int y, int z, World world, Block block, int blockMetadata, EntityPlayer player)
{
super(x, y, z, world, block, blockMetadata);
this.player = player;
if (block == null || !player.canHarvestBlock(block) || // Handle empty block or player unable to break block scenario
block.canSilkHarvest(world, player, x, y, z, blockMetadata) && EnchantmentHelper.getSilkTouchModifier(player)) // If the block is being silk harvested, the exp dropped is 0
{
this.exp = 0;
}
else
{
int meta = block.getDamageValue(world, x, y, z);
int bonusLevel = EnchantmentHelper.getFortuneModifier(player);
this.exp = block.getExpDrop(world, meta, bonusLevel);
}
}
public EntityPlayer getPlayer()
{
return player;
}
/**
* Get the experience dropped by the block after the event has processed
*
* @return The experience to drop or 0 if the event was canceled
*/
public int getExpToDrop()
{
return this.isCanceled() ? 0 : exp;
}
/**
* Set the amount of experience dropped by the block after the event has processed
*
* @param exp 1 or higher to drop experience, else nothing will drop
*/
public void setExpToDrop(int exp)
{
this.exp = exp;
}
}
}
@@ -0,0 +1,36 @@
package net.minecraftforge.event.world;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.nbt.NBTTagCompound;
public class ChunkDataEvent extends ChunkEvent
{
private final NBTTagCompound data;
public ChunkDataEvent(Chunk chunk, NBTTagCompound data)
{
super(chunk);
this.data = data;
}
public NBTTagCompound getData()
{
return data;
}
public static class Load extends ChunkDataEvent
{
public Load(Chunk chunk, NBTTagCompound data)
{
super(chunk, data);
}
}
public static class Save extends ChunkDataEvent
{
public Save(Chunk chunk, NBTTagCompound data)
{
super(chunk, data);
}
}
}
@@ -0,0 +1,37 @@
package net.minecraftforge.event.world;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
public class ChunkEvent extends WorldEvent
{
private final Chunk chunk;
public ChunkEvent(Chunk chunk)
{
super(chunk.worldObj);
this.chunk = chunk;
}
public Chunk getChunk()
{
return chunk;
}
public static class Load extends ChunkEvent
{
public Load(Chunk chunk)
{
super(chunk);
}
}
public static class Unload extends ChunkEvent
{
public Unload(Chunk chunk)
{
super(chunk);
}
}
}
@@ -0,0 +1,29 @@
package net.minecraftforge.event.world;
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
{
public final ChunkCoordIntPair chunk;
public final EntityPlayerMP player;
public ChunkWatchEvent(ChunkCoordIntPair chunk, EntityPlayerMP player)
{
this.chunk = chunk;
this.player = player;
}
public static class Watch extends ChunkWatchEvent
{
public Watch(ChunkCoordIntPair chunk, EntityPlayerMP player) { super(chunk, player); }
}
public static class UnWatch extends ChunkWatchEvent
{
public UnWatch(ChunkCoordIntPair chunkLocation, EntityPlayerMP player) { super(chunkLocation, player); }
}
}
@@ -0,0 +1,66 @@
package net.minecraftforge.event.world;
import java.util.ArrayList;
import java.util.List;
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
{
public final World world;
public WorldEvent(World world)
{
this.world = world;
}
public static class Load extends WorldEvent
{
public Load(World world) { super(world); }
}
public static class Unload extends WorldEvent
{
public Unload(World world) { super(world); }
}
public static class Save extends WorldEvent
{
public Save(World world) { super(world); }
}
/**
* Called by WorldServer to gather a list of all possible entities that can spawn at the specified location.
* Canceling the event will result in a empty list, meaning no entity will be spawned.
*/
@Cancelable
public static class PotentialSpawns extends WorldEvent
{
public final EnumCreatureType type;
public final int x;
public final int y;
public final int z;
public final List<SpawnListEntry> list;
public PotentialSpawns(World world, EnumCreatureType type, int x, int y, int z, List oldList)
{
super(world);
this.x = x;
this.y = y;
this.z = z;
this.type = type;
if (oldList != null)
{
this.list = (List<SpawnListEntry>)oldList;
}
else
{
this.list = new ArrayList<SpawnListEntry>();
}
}
}
}