base mod created

This commit is contained in:
Mohammad-Ali Minaie
2018-10-08 09:07:47 -04:00
parent 0a7700c356
commit b86dedad2f
7848 changed files with 584664 additions and 1 deletions

View File

@@ -0,0 +1,70 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
/**
*
* AnvilUpdateEvent is fired when a player places items in both the left and right slots of a anvil.
* If the event is canceled, vanilla behavior will not run, and the output will be set to null.
* If the event is not canceled, but the output is not null, it will set the output and not run vanilla behavior.
* if the output is null, and the event is not canceled, vanilla behavior will execute.
*/
@Cancelable
public class AnvilUpdateEvent extends Event
{
@Nonnull
private final ItemStack left; // The left side of the input
@Nonnull
private final ItemStack right; // The right side of the input
private final String name; // The name to set the item, if the user specified one.
@Nonnull
private ItemStack output; // Set this to set the output stack
private int cost; // The base cost, set this to change it if output != null
private int materialCost; // The number of items from the right slot to be consumed during the repair. Leave as 0 to consume the entire stack.
public AnvilUpdateEvent(@Nonnull ItemStack left, @Nonnull ItemStack right, String name, int cost)
{
this.left = left;
this.right = right;
this.output = ItemStack.EMPTY;
this.name = name;
this.setCost(cost);
this.setMaterialCost(0);
}
@Nonnull
public ItemStack getLeft() { return left; }
@Nonnull
public ItemStack getRight() { return right; }
public String getName() { return name; }
@Nonnull
public ItemStack getOutput() { return output; }
public void setOutput(@Nonnull ItemStack output) { this.output = output; }
public int getCost() { return cost; }
public void setCost(int cost) { this.cost = cost; }
public int getMaterialCost() { return materialCost; }
public void setMaterialCost(int materialCost) { this.materialCost = materialCost; }
}

View File

@@ -0,0 +1,80 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event;
import java.util.Collections;
import java.util.Map;
import com.google.common.collect.Maps;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fml.common.eventhandler.GenericEvent;
/**
* Fired whenever an object with Capabilities support {currently TileEntity/Item/Entity)
* is created. Allowing for the attachment of arbitrary capability providers.
*
* Please note that as this is fired for ALL object creations efficient code is recommended.
* And if possible use one of the sub-classes to filter your intended objects.
*/
public class AttachCapabilitiesEvent<T> extends GenericEvent<T>
{
private final T obj;
private final Map<ResourceLocation, ICapabilityProvider> caps = Maps.newLinkedHashMap();
private final Map<ResourceLocation, ICapabilityProvider> view = Collections.unmodifiableMap(caps);
public AttachCapabilitiesEvent(Class<T> type, T obj)
{
super(type);
this.obj = obj;
}
/**
* Retrieves the object that is being created, Not much state is set.
*/
public T getObject()
{
return this.obj;
}
/**
* Adds a capability to be attached to this object.
* Keys MUST be unique, it is suggested that you set the domain to your mod ID.
* If the capability is an instance of INBTSerializable, this key will be used when serializing this capability.
*
* @param key The name of owner of this capability provider.
* @param cap The capability provider
*/
public void addCapability(ResourceLocation key, ICapabilityProvider cap)
{
if (caps.containsKey(key))
throw new IllegalStateException("Duplicate Capability Key: " + key + " " + cap);
this.caps.put(key, cap);
}
/**
* A unmodifiable view of the capabilities that will be attached to this object.
*/
public Map<ResourceLocation, ICapabilityProvider> getCapabilities()
{
return view;
}
}

View File

@@ -0,0 +1,69 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event;
import net.minecraft.command.CommandHandler;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
/**
* CommandEvent is fired whenever a command is scheduled to be executed.
* This event is fired during the invocation of {@link CommandHandler#executeCommand(ICommandSender, String)}
* and {@link ClientCommandHandler#executeCommand(ICommandSender, String)}. <br>
* <br>
* {@link #command} contains the instance of ICommand which is representative of the currently executing command.<br>
* {@link #sender} contains the instance of ICommandSender for the given command sender.<br>
* {@link #parameters} contains the arguments passed for the command execution.<br>
* {@link #exception} begins null, but can be populated with an exception to be thrown within the command.<br>
* <br>
* This event is {@link Cancelable}. <br>
* If the event is canceled, the execution of the command does not occur.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
@Cancelable
public class CommandEvent extends Event
{
private final ICommand command;
private final ICommandSender sender;
private String[] parameters;
private Throwable exception;
public CommandEvent(ICommand command, ICommandSender sender, String[] parameters)
{
this.command = command;
this.sender = sender;
this.setParameters(parameters);
}
public ICommand getCommand() { return command; }
public ICommandSender getSender() { return sender; }
public String[] getParameters() { return parameters; }
public void setParameters(String[] parameters) { this.parameters = parameters; }
public Throwable getException() { return exception; }
public void setException(Throwable exception) { this.exception = exception; }
}

View File

@@ -0,0 +1,62 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event;
import javax.annotation.Nonnull;
import net.minecraft.world.EnumDifficulty;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
/**
* DifficultyChangeEvent is fired when difficulty is changing. <br>
* <br>
* This event is fired via the {@link ForgeHooks#onDifficultyChange(EnumDifficulty, EnumDifficulty)}.<br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
public class DifficultyChangeEvent extends Event
{
private final EnumDifficulty difficulty;
private final EnumDifficulty oldDifficulty;
public DifficultyChangeEvent(EnumDifficulty difficulty, EnumDifficulty oldDifficulty)
{
this.difficulty = difficulty;
this.oldDifficulty = oldDifficulty;
}
public EnumDifficulty getDifficulty()
{
return difficulty;
}
public EnumDifficulty getOldDifficulty()
{
return oldDifficulty;
}
}

View File

@@ -0,0 +1,783 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event;
import java.io.File;
import java.util.EnumSet;
import java.util.List;
import java.util.Random;
import net.minecraft.block.BlockPortal;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayer.SleepResult;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.entity.projectile.EntityFireball;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.MobSpawnerBaseLogic;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.ChatType;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.village.Village;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.WorldSettings;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkPrimer;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraft.world.storage.IPlayerFileData;
import net.minecraft.world.storage.SaveHandler;
import net.minecraft.world.storage.loot.LootTable;
import net.minecraft.world.storage.loot.LootTableManager;
import net.minecraftforge.client.event.ClientChatEvent;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.client.event.RenderBlockOverlayEvent;
import net.minecraftforge.client.event.RenderBlockOverlayEvent.OverlayType;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.CapabilityDispatcher;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.BlockSnapshot;
import net.minecraftforge.event.brewing.PlayerBrewedPotionEvent;
import net.minecraftforge.event.brewing.PotionBrewEvent;
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.event.entity.EntityMobGriefingEvent;
import net.minecraftforge.event.entity.EntityMountEvent;
import net.minecraftforge.event.entity.EntityStruckByLightningEvent;
import net.minecraftforge.event.entity.PlaySoundAtEntityEvent;
import net.minecraftforge.event.entity.ProjectileImpactEvent;
import net.minecraftforge.event.entity.ThrowableImpactEvent;
import net.minecraftforge.event.entity.item.ItemExpireEvent;
import net.minecraftforge.event.entity.living.AnimalTameEvent;
import net.minecraftforge.event.entity.living.LivingDestroyBlockEvent;
import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
import net.minecraftforge.event.entity.living.LivingExperienceDropEvent;
import net.minecraftforge.event.entity.living.LivingHealEvent;
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.ArrowLooseEvent;
import net.minecraftforge.event.entity.player.ArrowNockEvent;
import net.minecraftforge.event.entity.player.BonemealEvent;
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
import net.minecraftforge.event.entity.player.FillBucketEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import net.minecraftforge.event.entity.player.PlayerDropsEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerFlyableFallEvent;
import net.minecraftforge.event.entity.player.PlayerSetSpawnEvent;
import net.minecraftforge.event.entity.player.PlayerSleepInBedEvent;
import net.minecraftforge.event.entity.player.PlayerWakeUpEvent;
import net.minecraftforge.event.entity.player.SleepingLocationCheckEvent;
import net.minecraftforge.event.entity.player.UseHoeEvent;
import net.minecraftforge.event.furnace.FurnaceFuelBurnTimeEvent;
import net.minecraftforge.event.terraingen.ChunkGeneratorEvent;
import net.minecraftforge.event.terraingen.PopulateChunkEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.BlockEvent.CreateFluidSourceEvent;
import net.minecraftforge.event.world.BlockEvent.MultiPlaceEvent;
import net.minecraftforge.event.world.BlockEvent.NeighborNotifyEvent;
import net.minecraftforge.event.world.BlockEvent.PlaceEvent;
import net.minecraftforge.event.world.ExplosionEvent;
import net.minecraftforge.event.world.GetCollisionBoxesEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Event.Result;
import net.minecraftforge.fml.common.registry.GameRegistry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class ForgeEventFactory
{
public static MultiPlaceEvent onPlayerMultiBlockPlace(EntityPlayer player, List<BlockSnapshot> blockSnapshots, EnumFacing direction, EnumHand hand)
{
BlockSnapshot snap = blockSnapshots.get(0);
IBlockState placedAgainst = snap.getWorld().getBlockState(snap.getPos().offset(direction.getOpposite()));
MultiPlaceEvent event = new MultiPlaceEvent(blockSnapshots, placedAgainst, player, hand);
MinecraftForge.EVENT_BUS.post(event);
return event;
}
public static PlaceEvent onPlayerBlockPlace(@Nonnull EntityPlayer player, @Nonnull BlockSnapshot blockSnapshot, @Nonnull EnumFacing direction, @Nonnull EnumHand hand)
{
IBlockState placedAgainst = blockSnapshot.getWorld().getBlockState(blockSnapshot.getPos().offset(direction.getOpposite()));
PlaceEvent event = new PlaceEvent(blockSnapshot, placedAgainst, player, hand);
MinecraftForge.EVENT_BUS.post(event);
return event;
}
public static NeighborNotifyEvent onNeighborNotify(World world, BlockPos pos, IBlockState state, EnumSet<EnumFacing> notifiedSides, boolean forceRedstoneUpdate)
{
NeighborNotifyEvent event = new NeighborNotifyEvent(world, pos, state, notifiedSides, forceRedstoneUpdate);
MinecraftForge.EVENT_BUS.post(event);
return event;
}
public static boolean doPlayerHarvestCheck(EntityPlayer player, IBlockState state, boolean success)
{
PlayerEvent.HarvestCheck event = new PlayerEvent.HarvestCheck(player, state, success);
MinecraftForge.EVENT_BUS.post(event);
return event.canHarvest();
}
public static float getBreakSpeed(EntityPlayer player, IBlockState state, float original, BlockPos pos)
{
PlayerEvent.BreakSpeed event = new PlayerEvent.BreakSpeed(player, state, original, pos);
return (MinecraftForge.EVENT_BUS.post(event) ? -1 : event.getNewSpeed());
}
public static void onPlayerDestroyItem(EntityPlayer player, @Nonnull ItemStack stack, @Nullable EnumHand hand)
{
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, stack, hand));
}
/**
* @deprecated use {@link #canEntitySpawn(EntityLiving, World, float, float, float, MobSpawnerBaseLogic)} instead
*/
@Deprecated // TODO remove in 1.13
public static Result canEntitySpawn(EntityLiving entity, World world, float x, float y, float z)
{
return canEntitySpawn(entity, world, x, y, z, true);
}
/**
* @deprecated use {@link #canEntitySpawn(EntityLiving, World, float, float, float, MobSpawnerBaseLogic)} instead
*/
@Deprecated // Still used in base game for non-spawner spawns, which is safe
public static Result canEntitySpawn(EntityLiving entity, World world, float x, float y, float z, boolean isSpawner)
{
if (entity == null)
return Result.DEFAULT;
LivingSpawnEvent.CheckSpawn event = new LivingSpawnEvent.CheckSpawn(entity, world, x, y, z, isSpawner); // TODO: replace isSpawner with null in 1.13
MinecraftForge.EVENT_BUS.post(event);
return event.getResult();
}
public static Result canEntitySpawn(EntityLiving entity, World world, float x, float y, float z, MobSpawnerBaseLogic spawner)
{
if (entity == null)
return Result.DEFAULT;
LivingSpawnEvent.CheckSpawn event = new LivingSpawnEvent.CheckSpawn(entity, world, x, y, z, spawner);
MinecraftForge.EVENT_BUS.post(event);
return event.getResult();
}
public static boolean canEntitySpawnSpawner(EntityLiving entity, World world, float x, float y, float z, MobSpawnerBaseLogic spawner)
{
Result result = canEntitySpawn(entity, world, x, y, z, spawner);
if (result == Result.DEFAULT)
{
return entity.getCanSpawnHere() && entity.isNotColliding(); // vanilla logic
}
else
{
return result == Result.ALLOW;
}
}
/**
* @deprecated Use {@link #canEntitySpawnSpawner(EntityLiving, World, float, float, float, MobSpawnerBaseLogic)}
*/
@Deprecated // TODO remove in 1.13
public static boolean canEntitySpawnSpawner(EntityLiving entity, World world, float x, float y, float z)
{
Result result = canEntitySpawn(entity, world, x, y, z, true);
if (result == Result.DEFAULT)
{
return entity.getCanSpawnHere() && entity.isNotColliding(); // vanilla logic
}
else
{
return result == Result.ALLOW;
}
}
/**
* @deprecated Use {@link #canEntitySpawnSpawner(EntityLiving, World, float, float, float, MobSpawnerBaseLogic)}
*/
@Deprecated // Still used in base game for non-spawner spawns, which is safe
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, null));
}
public static boolean doSpecialSpawn(EntityLiving entity, World world, float x, float y, float z, MobSpawnerBaseLogic spawner)
{
return MinecraftForge.EVENT_BUS.post(new LivingSpawnEvent.SpecialSpawn(entity, world, x, y, z, spawner));
}
public static Result canEntityDespawn(EntityLiving entity)
{
AllowDespawn event = new AllowDespawn(entity);
MinecraftForge.EVENT_BUS.post(event);
return event.getResult();
}
public static int getItemBurnTime(@Nonnull ItemStack itemStack)
{
Item item = itemStack.getItem();
int burnTime = item.getItemBurnTime(itemStack);
FurnaceFuelBurnTimeEvent event = new FurnaceFuelBurnTimeEvent(itemStack, burnTime);
MinecraftForge.EVENT_BUS.post(event);
if (event.getBurnTime() < 0)
{
// legacy handling
int fuelValue = GameRegistry.getFuelValueLegacy(itemStack);
if (fuelValue > 0)
{
return fuelValue;
}
}
return event.getBurnTime();
}
public static int getExperienceDrop(EntityLivingBase entity, EntityPlayer attackingPlayer, int originalExperience)
{
LivingExperienceDropEvent event = new LivingExperienceDropEvent(entity, attackingPlayer, originalExperience);
if (MinecraftForge.EVENT_BUS.post(event))
{
return 0;
}
return event.getDroppedExperience();
}
@Nullable
public static List<Biome.SpawnListEntry> getPotentialSpawns(WorldServer world, EnumCreatureType type, BlockPos pos, List<Biome.SpawnListEntry> oldList)
{
WorldEvent.PotentialSpawns event = new WorldEvent.PotentialSpawns(world, type, pos, oldList);
if (MinecraftForge.EVENT_BUS.post(event))
{
return null;
}
return event.getList();
}
public static int getMaxSpawnPackSize(EntityLiving entity)
{
LivingPackSizeEvent maxCanSpawnEvent = new LivingPackSizeEvent(entity);
MinecraftForge.EVENT_BUS.post(maxCanSpawnEvent);
return maxCanSpawnEvent.getResult() == Result.ALLOW ? maxCanSpawnEvent.getMaxPackSize() : 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.getDisplayname();
}
public static float fireBlockHarvesting(List<ItemStack> drops, World world, BlockPos pos, IBlockState state, int fortune, float dropChance, boolean silkTouch, EntityPlayer player)
{
BlockEvent.HarvestDropsEvent event = new BlockEvent.HarvestDropsEvent(world, pos, state, fortune, dropChance, drops, player, silkTouch);
MinecraftForge.EVENT_BUS.post(event);
return event.getDropChance();
}
public static IBlockState fireFluidPlaceBlockEvent(World world, BlockPos pos, BlockPos liquidPos, IBlockState state)
{
BlockEvent.FluidPlaceBlockEvent event = new BlockEvent.FluidPlaceBlockEvent(world, pos, liquidPos, state);
MinecraftForge.EVENT_BUS.post(event);
return event.getNewState();
}
public static ItemTooltipEvent onItemTooltip(ItemStack itemStack, @Nullable EntityPlayer entityPlayer, List<String> toolTip, ITooltipFlag flags)
{
ItemTooltipEvent event = new ItemTooltipEvent(itemStack, entityPlayer, toolTip, flags);
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;
}
public static boolean onEntityStruckByLightning(Entity entity, EntityLightningBolt bolt)
{
return MinecraftForge.EVENT_BUS.post(new EntityStruckByLightningEvent(entity, bolt));
}
public static int onItemUseStart(EntityLivingBase entity, ItemStack item, int duration)
{
LivingEntityUseItemEvent event = new LivingEntityUseItemEvent.Start(entity, item, duration);
return MinecraftForge.EVENT_BUS.post(event) ? -1 : event.getDuration();
}
public static int onItemUseTick(EntityLivingBase entity, ItemStack item, int duration)
{
LivingEntityUseItemEvent event = new LivingEntityUseItemEvent.Tick(entity, item, duration);
return MinecraftForge.EVENT_BUS.post(event) ? -1 : event.getDuration();
}
public static boolean onUseItemStop(EntityLivingBase entity, ItemStack item, int duration)
{
return MinecraftForge.EVENT_BUS.post(new LivingEntityUseItemEvent.Stop(entity, item, duration));
}
public static ItemStack onItemUseFinish(EntityLivingBase entity, ItemStack item, int duration, ItemStack result)
{
LivingEntityUseItemEvent.Finish event = new LivingEntityUseItemEvent.Finish(entity, item, duration, result);
MinecraftForge.EVENT_BUS.post(event);
return event.getResultStack();
}
public static void onStartEntityTracking(Entity entity, EntityPlayer player)
{
MinecraftForge.EVENT_BUS.post(new PlayerEvent.StartTracking(player, entity));
}
public static void onStopEntityTracking(Entity entity, EntityPlayer player)
{
MinecraftForge.EVENT_BUS.post(new PlayerEvent.StopTracking(player, entity));
}
public static void firePlayerLoadingEvent(EntityPlayer player, File playerDirectory, String uuidString)
{
MinecraftForge.EVENT_BUS.post(new PlayerEvent.LoadFromFile(player, playerDirectory, uuidString));
}
public static void firePlayerSavingEvent(EntityPlayer player, File playerDirectory, String uuidString)
{
MinecraftForge.EVENT_BUS.post(new PlayerEvent.SaveToFile(player, playerDirectory, uuidString));
}
public static void firePlayerLoadingEvent(EntityPlayer player, IPlayerFileData playerFileData, String uuidString)
{
SaveHandler sh = (SaveHandler) playerFileData;
File dir = ObfuscationReflectionHelper.getPrivateValue(SaveHandler.class, sh, "playersDirectory", "field_"+"75771_c");
MinecraftForge.EVENT_BUS.post(new PlayerEvent.LoadFromFile(player, dir, uuidString));
}
@Nullable
public static ITextComponent onClientChat(ChatType type, ITextComponent message)
{
ClientChatReceivedEvent event = new ClientChatReceivedEvent(type, message);
return MinecraftForge.EVENT_BUS.post(event) ? null : event.getMessage();
}
@Nonnull
public static String onClientSendMessage(String message)
{
ClientChatEvent event = new ClientChatEvent(message);
return MinecraftForge.EVENT_BUS.post(event) ? "" : event.getMessage();
}
public static int onHoeUse(ItemStack stack, EntityPlayer player, World worldIn, BlockPos pos)
{
UseHoeEvent event = new UseHoeEvent(player, stack, worldIn, pos);
if (MinecraftForge.EVENT_BUS.post(event)) return -1;
if (event.getResult() == Result.ALLOW)
{
stack.damageItem(1, player);
return 1;
}
return 0;
}
public static int onApplyBonemeal(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull ItemStack stack, @Nullable EnumHand hand)
{
BonemealEvent event = new BonemealEvent(player, world, pos, state, hand, stack);
if (MinecraftForge.EVENT_BUS.post(event)) return -1;
if (event.getResult() == Result.ALLOW)
{
if (!world.isRemote)
stack.shrink(1);
return 1;
}
return 0;
}
@Nullable
public static ActionResult<ItemStack> onBucketUse(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull ItemStack stack, @Nullable RayTraceResult target)
{
FillBucketEvent event = new FillBucketEvent(player, stack, world, target);
if (MinecraftForge.EVENT_BUS.post(event)) return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
if (event.getResult() == Result.ALLOW)
{
if (player.capabilities.isCreativeMode)
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
stack.shrink(1);
if (stack.isEmpty())
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, event.getFilledBucket());
if (!player.inventory.addItemStackToInventory(event.getFilledBucket()))
player.dropItem(event.getFilledBucket(), false);
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
return null;
}
public static boolean canEntityUpdate(Entity entity)
{
EntityEvent.CanUpdate event = new EntityEvent.CanUpdate(entity);
MinecraftForge.EVENT_BUS.post(event);
return event.getCanUpdate();
}
public static PlaySoundAtEntityEvent onPlaySoundAtEntity(Entity entity, SoundEvent name, SoundCategory category, float volume, float pitch)
{
PlaySoundAtEntityEvent event = new PlaySoundAtEntityEvent(entity, name, category, volume, pitch);
MinecraftForge.EVENT_BUS.post(event);
return event;
}
public static int onItemExpire(EntityItem entity, @Nonnull ItemStack item)
{
if (item.isEmpty()) return -1;
ItemExpireEvent event = new ItemExpireEvent(entity, (item.isEmpty() ? 6000 : item.getItem().getEntityLifespan(item, entity.world)));
if (!MinecraftForge.EVENT_BUS.post(event)) return -1;
return event.getExtraLife();
}
public static int onItemPickup(EntityItem entityItem, EntityPlayer player)
{
Event event = new EntityItemPickupEvent(player, entityItem);
if (MinecraftForge.EVENT_BUS.post(event)) return -1;
return event.getResult() == Result.ALLOW ? 1 : 0;
}
public static void onPlayerDrops(EntityPlayer player, DamageSource cause, List<EntityItem> capturedDrops, boolean recentlyHit)
{
PlayerDropsEvent event = new PlayerDropsEvent(player, cause, capturedDrops, recentlyHit);
if (!MinecraftForge.EVENT_BUS.post(event))
{
for (EntityItem item : capturedDrops)
{
player.dropItemAndGetStack(item);
}
}
}
public static boolean canMountEntity(Entity entityMounting, Entity entityBeingMounted, boolean isMounting)
{
boolean isCanceled = MinecraftForge.EVENT_BUS.post(new EntityMountEvent(entityMounting, entityBeingMounted, entityMounting.world, isMounting));
if(isCanceled)
{
entityMounting.setPositionAndRotation(entityMounting.posX, entityMounting.posY, entityMounting.posZ, entityMounting.prevRotationYaw, entityMounting.prevRotationPitch);
return false;
}
else
return true;
}
public static boolean onAnimalTame(EntityAnimal animal, EntityPlayer tamer)
{
return MinecraftForge.EVENT_BUS.post(new AnimalTameEvent(animal, tamer));
}
public static SleepResult onPlayerSleepInBed(EntityPlayer player, BlockPos pos)
{
PlayerSleepInBedEvent event = new PlayerSleepInBedEvent(player, pos);
MinecraftForge.EVENT_BUS.post(event);
return event.getResultStatus();
}
public static void onPlayerWakeup(EntityPlayer player, boolean wakeImmediately, boolean updateWorldFlag, boolean setSpawn)
{
MinecraftForge.EVENT_BUS.post(new PlayerWakeUpEvent(player, wakeImmediately, updateWorldFlag, setSpawn));
}
public static void onPlayerFall(EntityPlayer player, float distance, float multiplier)
{
MinecraftForge.EVENT_BUS.post(new PlayerFlyableFallEvent(player, distance, multiplier));
}
public static boolean onPlayerSpawnSet(EntityPlayer player, BlockPos pos, boolean forced) {
return MinecraftForge.EVENT_BUS.post(new PlayerSetSpawnEvent(player, pos, forced));
}
public static void onPlayerClone(EntityPlayer player, EntityPlayer oldPlayer, boolean wasDeath)
{
MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.player.PlayerEvent.Clone(player, oldPlayer, wasDeath));
}
public static boolean onExplosionStart(World world, Explosion explosion)
{
return MinecraftForge.EVENT_BUS.post(new ExplosionEvent.Start(world, explosion));
}
public static void onExplosionDetonate(World world, Explosion explosion, List<Entity> list, double diameter)
{
//Filter entities to only those who are effected, to prevent modders from seeing more then will be hurt.
/* Enable this if we get issues with modders looping to much.
Iterator<Entity> itr = list.iterator();
Vec3 p = explosion.getPosition();
while (itr.hasNext())
{
Entity e = itr.next();
double dist = e.getDistance(p.xCoord, p.yCoord, p.zCoord) / diameter;
if (e.isImmuneToExplosions() || dist > 1.0F) itr.remove();
}
*/
MinecraftForge.EVENT_BUS.post(new ExplosionEvent.Detonate(world, explosion, list));
}
public static boolean onCreateWorldSpawn(World world, WorldSettings settings)
{
return MinecraftForge.EVENT_BUS.post(new WorldEvent.CreateSpawnPosition(world, settings));
}
public static float onLivingHeal(EntityLivingBase entity, float amount)
{
LivingHealEvent event = new LivingHealEvent(entity, amount);
return (MinecraftForge.EVENT_BUS.post(event) ? 0 : event.getAmount());
}
public static boolean onPotionAttemptBrew(NonNullList<ItemStack> stacks)
{
NonNullList<ItemStack> tmp = NonNullList.withSize(stacks.size(), ItemStack.EMPTY);
for (int x = 0; x < tmp.size(); x++)
tmp.set(x, stacks.get(x).copy());
PotionBrewEvent.Pre event = new PotionBrewEvent.Pre(tmp);
if (MinecraftForge.EVENT_BUS.post(event))
{
boolean changed = false;
for (int x = 0; x < stacks.size(); x++)
{
changed |= ItemStack.areItemStacksEqual(tmp.get(x), stacks.get(x));
stacks.set(x, event.getItem(x));
}
if (changed)
onPotionBrewed(stacks);
return true;
}
return false;
}
public static void onPotionBrewed(NonNullList<ItemStack> brewingItemStacks)
{
MinecraftForge.EVENT_BUS.post(new PotionBrewEvent.Post(brewingItemStacks));
}
public static void onPlayerBrewedPotion(EntityPlayer player, ItemStack stack)
{
MinecraftForge.EVENT_BUS.post(new PlayerBrewedPotionEvent(player, stack));
}
public static boolean renderFireOverlay(EntityPlayer player, float renderPartialTicks)
{
return renderBlockOverlay(player, renderPartialTicks, OverlayType.FIRE, Blocks.FIRE.getDefaultState(), new BlockPos(player));
}
public static boolean renderWaterOverlay(EntityPlayer player, float renderPartialTicks)
{
return renderBlockOverlay(player, renderPartialTicks, OverlayType.WATER, Blocks.WATER.getDefaultState(), new BlockPos(player));
}
public static boolean renderBlockOverlay(EntityPlayer player, float renderPartialTicks, OverlayType type, IBlockState block, BlockPos pos)
{
return MinecraftForge.EVENT_BUS.post(new RenderBlockOverlayEvent(player, renderPartialTicks, type, block, pos));
}
@Nullable
public static CapabilityDispatcher gatherCapabilities(TileEntity tileEntity)
{
return gatherCapabilities(new AttachCapabilitiesEvent<TileEntity>(TileEntity.class, tileEntity), null);
}
@Nullable
public static CapabilityDispatcher gatherCapabilities(Entity entity)
{
return gatherCapabilities(new AttachCapabilitiesEvent<Entity>(Entity.class, entity), null);
}
@Nullable
public static CapabilityDispatcher gatherCapabilities(Village village)
{
return gatherCapabilities(new AttachCapabilitiesEvent<Village>(Village.class, village), null);
}
@Nullable
public static CapabilityDispatcher gatherCapabilities(ItemStack stack, ICapabilityProvider parent)
{
return gatherCapabilities(new AttachCapabilitiesEvent<ItemStack>(ItemStack.class, stack), parent);
}
@Nullable
public static CapabilityDispatcher gatherCapabilities(World world, ICapabilityProvider parent)
{
return gatherCapabilities(new AttachCapabilitiesEvent<World>(World.class, world), parent);
}
@Nullable
public static CapabilityDispatcher gatherCapabilities(Chunk chunk)
{
return gatherCapabilities(new AttachCapabilitiesEvent<Chunk>(Chunk.class, chunk), null);
}
@Nullable
private static CapabilityDispatcher gatherCapabilities(AttachCapabilitiesEvent<?> event, @Nullable ICapabilityProvider parent)
{
MinecraftForge.EVENT_BUS.post(event);
return event.getCapabilities().size() > 0 || parent != null ? new CapabilityDispatcher(event.getCapabilities(), parent) : null;
}
public static boolean fireSleepingLocationCheck(EntityPlayer player, BlockPos sleepingLocation)
{
SleepingLocationCheckEvent evt = new SleepingLocationCheckEvent(player, sleepingLocation);
MinecraftForge.EVENT_BUS.post(evt);
Result canContinueSleep = evt.getResult();
if (canContinueSleep == Result.DEFAULT)
{
IBlockState state = player.world.getBlockState(player.bedLocation);
return state.getBlock().isBed(state, player.world, player.bedLocation, player);
}
else
return canContinueSleep == Result.ALLOW;
}
public static ActionResult<ItemStack> onArrowNock(ItemStack item, World world, EntityPlayer player, EnumHand hand, boolean hasAmmo)
{
ArrowNockEvent event = new ArrowNockEvent(player, item, hand, world, hasAmmo);
if (MinecraftForge.EVENT_BUS.post(event))
return new ActionResult<ItemStack>(EnumActionResult.FAIL, item);
return event.getAction();
}
public static int onArrowLoose(ItemStack stack, World world, EntityPlayer player, int charge, boolean hasAmmo)
{
ArrowLooseEvent event = new ArrowLooseEvent(player, stack, world, charge, hasAmmo);
if (MinecraftForge.EVENT_BUS.post(event))
return -1;
return event.getCharge();
}
public static boolean onProjectileImpact(Entity entity, RayTraceResult ray)
{
return MinecraftForge.EVENT_BUS.post(new ProjectileImpactEvent(entity, ray));
}
public static boolean onProjectileImpact(EntityArrow arrow, RayTraceResult ray)
{
return MinecraftForge.EVENT_BUS.post(new ProjectileImpactEvent.Arrow(arrow, ray));
}
public static boolean onProjectileImpact(EntityFireball fireball, RayTraceResult ray)
{
return MinecraftForge.EVENT_BUS.post(new ProjectileImpactEvent.Fireball(fireball, ray));
}
public static boolean onProjectileImpact(EntityThrowable throwable, RayTraceResult ray)
{
boolean oldEvent = MinecraftForge.EVENT_BUS.post(new ThrowableImpactEvent(throwable, ray));
boolean newEvent = MinecraftForge.EVENT_BUS.post(new ProjectileImpactEvent.Throwable(throwable, ray));
return oldEvent || newEvent; // TODO: clean up when old event is removed
}
public static boolean onReplaceBiomeBlocks(IChunkGenerator gen, int x, int z, ChunkPrimer primer, World world)
{
ChunkGeneratorEvent.ReplaceBiomeBlocks event = new ChunkGeneratorEvent.ReplaceBiomeBlocks(gen, x, z, primer, world);
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event);
return event.getResult() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY;
}
public static void onChunkPopulate(boolean pre, IChunkGenerator gen, World world, Random rand, int x, int z, boolean hasVillageGenerated)
{
MinecraftForge.EVENT_BUS.post(pre ? new PopulateChunkEvent.Pre(gen, world, rand, x, z, hasVillageGenerated) : new PopulateChunkEvent.Post(gen, world, rand, x, z, hasVillageGenerated));
}
public static LootTable loadLootTable(ResourceLocation name, LootTable table, LootTableManager lootTableManager)
{
LootTableLoadEvent event = new LootTableLoadEvent(name, table, lootTableManager);
if (MinecraftForge.EVENT_BUS.post(event))
return LootTable.EMPTY_LOOT_TABLE;
return event.getTable();
}
public static boolean canCreateFluidSource(World world, BlockPos pos, IBlockState state, boolean def)
{
CreateFluidSourceEvent evt = new CreateFluidSourceEvent(world, pos, state);
MinecraftForge.EVENT_BUS.post(evt);
Result result = evt.getResult();
return result == Result.DEFAULT ? def : result == Result.ALLOW;
}
public static boolean onTrySpawnPortal(World world, BlockPos pos, BlockPortal.Size size)
{
return MinecraftForge.EVENT_BUS.post(new BlockEvent.PortalSpawnEvent(world, pos, world.getBlockState(pos), size));
}
public static int onEnchantmentLevelSet(World world, BlockPos pos, int enchantRow, int power, ItemStack itemStack, int level)
{
net.minecraftforge.event.enchanting.EnchantmentLevelSetEvent e = new net.minecraftforge.event.enchanting.EnchantmentLevelSetEvent(world, pos, enchantRow, power, itemStack, level);
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(e);
return e.getLevel();
}
public static boolean onEntityDestroyBlock(EntityLivingBase entity, BlockPos pos, IBlockState state)
{
return !MinecraftForge.EVENT_BUS.post(new LivingDestroyBlockEvent(entity, pos, state));
}
public static boolean gatherCollisionBoxes(World world, Entity entity, AxisAlignedBB aabb, List<AxisAlignedBB> outList)
{
MinecraftForge.EVENT_BUS.post(new GetCollisionBoxesEvent(world, entity, aabb, outList));
return outList.isEmpty();
}
public static boolean getMobGriefingEvent(World world, Entity entity)
{
EntityMobGriefingEvent event = new EntityMobGriefingEvent(entity);
MinecraftForge.EVENT_BUS.post(event);
Result result = event.getResult();
return result == Result.DEFAULT ? world.getGameRules().getBoolean("mobGriefing") : result == Result.ALLOW;
}
}

View File

@@ -0,0 +1,70 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.storage.loot.LootTable;
import net.minecraft.world.storage.loot.LootTableManager;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
/**
* Event fired when a LootTable json is loaded from json.
* This event is fired whenever resources are loaded, or when the server starts.
* This event will NOT be fired for LootTables loaded from the world folder, these are
* considered configurations files and should not be modified by mods.
*
* Canceling the event will make it load a empty loot table.
*
*/
@Cancelable
public class LootTableLoadEvent extends Event
{
private final ResourceLocation name;
private LootTable table;
private LootTableManager lootTableManager;
public LootTableLoadEvent(ResourceLocation name, LootTable table, LootTableManager lootTableManager)
{
this.name = name;
this.table = table;
this.lootTableManager = lootTableManager;
}
public ResourceLocation getName()
{
return this.name;
}
public LootTable getTable()
{
return this.table;
}
public LootTableManager getLootTableManager()
{
return this.lootTableManager;
}
public void setTable(LootTable table)
{
this.table = table;
}
}

View File

@@ -0,0 +1,228 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event;
import java.util.Collection;
import java.util.stream.Collectors;
import org.apache.commons.lang3.Validate;
import com.google.common.collect.ImmutableList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.GenericEvent;
import net.minecraftforge.fml.common.eventhandler.IContextSetter;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.IForgeRegistryEntry;
/**
* RegistryEvent supertype.
*/
public class RegistryEvent<T extends IForgeRegistryEntry<T>> extends GenericEvent<T> implements IContextSetter
{
RegistryEvent(Class<T> clazz) {
super(clazz);
}
/**
* Register new registries when you receive this event, through the {@link RecipeBuilder}
*/
public static class NewRegistry extends Event
{
}
/**
* Register your objects for the appropriate registry type when you receive this event.
*
* <code>event.getRegistry().register(...)</code>
*
* The registries will be visited in alphabetic order of their name, except blocks and items,
* which will be visited FIRST and SECOND respectively.
*
* ObjectHolders will reload between Blocks and Items, and after all registries have been visited.
* @param <T> The registry top level type
*/
public static class Register<T extends IForgeRegistryEntry<T>> extends RegistryEvent<T>
{
private final IForgeRegistry<T> registry;
private final ResourceLocation name;
public Register(ResourceLocation name, IForgeRegistry<T> registry)
{
super(registry.getRegistrySuperType());
this.name = name;
this.registry = registry;
}
public IForgeRegistry<T> getRegistry()
{
return registry;
}
public ResourceLocation getName()
{
return name;
}
}
public static class MissingMappings<T extends IForgeRegistryEntry<T>> extends RegistryEvent<T>
{
private final IForgeRegistry<T> registry;
private final ResourceLocation name;
private final ImmutableList<Mapping<T>> mappings;
private ModContainer activeMod;
public MissingMappings(ResourceLocation name, IForgeRegistry<T> registry, Collection<Mapping<T>> missed)
{
super(registry.getRegistrySuperType());
this.registry = registry;
this.name = name;
this.mappings = ImmutableList.copyOf(missed);
}
public void setModContainer(ModContainer mod)
{
this.activeMod = mod;
}
public ResourceLocation getName()
{
return this.name;
}
public IForgeRegistry<T> getRegistry()
{
return this.registry;
}
public ImmutableList<Mapping<T>> getMappings()
{
return ImmutableList.copyOf(this.mappings.stream().filter(e -> e.key.getResourceDomain().equals(this.activeMod.getModId())).collect(Collectors.toList()));
}
public ImmutableList<Mapping<T>> getAllMappings()
{
return this.mappings;
}
/**
* Actions you can take with this missing mapping.
* <ul>
* <li>{@link #IGNORE} means this missing mapping will be ignored.
* <li>{@link #WARN} means this missing mapping will generate a warning.
* <li>{@link #FAIL} means this missing mapping will prevent the world from loading.
* </ul>
*/
public enum Action
{
/**
* Take the default action
*/
DEFAULT,
/**
* Ignore this missing mapping. This means the mapping will be abandoned
*/
IGNORE,
/**
* Generate a warning but allow loading to continue
*/
WARN,
/**
* Fail to load
*/
FAIL,
/**
* Remap this name to a new name (add a migration mapping)
*/
REMAP
}
public static class Mapping<T extends IForgeRegistryEntry<T>>
{
public final IForgeRegistry<T> registry;
private final IForgeRegistry<T> pool;
public final ResourceLocation key;
public final int id;
private Action action = Action.DEFAULT;
private T target;
public Mapping(IForgeRegistry<T> registry, IForgeRegistry<T> pool, ResourceLocation key, int id)
{
this.registry = registry;
this.pool = pool;
this.key = key;
this.id = id;
}
/**
* Ignore the missing item.
*/
public void ignore()
{
action = Action.IGNORE;
}
/**
* Warn the user about the missing item.
*/
public void warn()
{
action = Action.WARN;
}
/**
* Prevent the world from loading due to the missing item.
*/
public void fail()
{
action = Action.FAIL;
}
/**
* Remap the missing entry to the specified object.
*
* Use this if you have renamed an entry.
* Existing references using the old name will point to the new one.
*
* @param target Entry to remap to.
*/
public void remap(T target)
{
Validate.notNull(target, "Remap target can not be null");
Validate.isTrue(pool.getKey(target) != null, String.format("The specified entry %s hasn't been registered in registry yet.", target));
action = Action.REMAP;
this.target = target;
}
// internal
public Action getAction()
{
return this.action;
}
public T getTarget()
{
return target;
}
}
}
}

View File

@@ -0,0 +1,75 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.play.client.CPacketChatMessage;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.text.ITextComponent;
/**
* ServerChatEvent is fired whenever a C01PacketChatMessage is processed. <br>
* This event is fired via {@link ForgeHooks#onServerChatEvent(NetHandlerPlayServer, String, ITextComponent)},
* which is executed by the {@link NetHandlerPlayServer#processChatMessage(CPacketChatMessage)}<br>
* <br>
* {@link #username} contains the username of the player sending the chat message.<br>
* {@link #message} contains the message being sent.<br>
* {@link #player} the instance of EntityPlayerMP for the player sending the chat message.<br>
* {@link #component} contains the instance of ChatComponentTranslation for the sent message.<br>
* <br>
* This event is {@link Cancelable}. <br>
* If this event is canceled, the chat message is never distributed to all clients.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
@Cancelable
public class ServerChatEvent extends Event
{
private final String message, username;
private final EntityPlayerMP player;
private ITextComponent component;
public ServerChatEvent(EntityPlayerMP player, String message, ITextComponent component)
{
super();
this.message = message;
this.player = player;
this.username = player.getGameProfile().getName();
this.component = component;
}
public void setComponent(ITextComponent e)
{
this.component = e;
}
public ITextComponent getComponent()
{
return this.component;
}
public String getMessage() { return this.message; }
public String getUsername() { return this.username; }
public EntityPlayerMP getPlayer() { return this.player; }
}

View File

@@ -0,0 +1,49 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.brewing;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.player.PlayerEvent;
import javax.annotation.Nonnull;
/**
* This event is called when a player picks up a potion from a brewing stand.
*/
public class PlayerBrewedPotionEvent extends PlayerEvent
{
private final ItemStack stack;
public PlayerBrewedPotionEvent(EntityPlayer player, @Nonnull ItemStack stack)
{
super(player);
this.stack = stack;
}
/**
* The ItemStack of the potion.
*/
@Nonnull
public ItemStack getStack()
{
return stack;
}
}

View File

@@ -0,0 +1,108 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.brewing;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityBrewingStand;
import net.minecraft.util.NonNullList;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
import javax.annotation.Nonnull;
public class PotionBrewEvent extends Event
{
private NonNullList<ItemStack> stacks;
protected PotionBrewEvent(NonNullList<ItemStack> stacks)
{
this.stacks = stacks;
}
@Nonnull
public ItemStack getItem(int index)
{
if (index < 0 || index >= stacks.size()) return ItemStack.EMPTY;
return stacks.get(index);
}
public void setItem(int index, @Nonnull ItemStack stack)
{
if (index < stacks.size())
{
stacks.set(index, stack);
}
}
public int getLength()
{
return stacks.size();
}
/**
* PotionBrewEvent.Pre is fired before vanilla brewing takes place.
* All changes made to the event's array will be made to the TileEntity if the event is canceled.
* <br>
* The event is fired during the {@link TileEntityBrewingStand#brewPotions()} method invocation.<br>
* <br>
* {@link #stacks} contains the itemstack array from the TileEntityBrewer holding all items in Brewer.<br>
* <br>
* This event is {@link Cancelable}.<br>
* If the event is not canceled, the vanilla brewing will take place instead of modded brewing.
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
* <br>
* If this event is canceled, and items have been modified, PotionBrewEvent.Post will automatically be fired.
**/
@Cancelable
public static class Pre extends PotionBrewEvent
{
public Pre(NonNullList<ItemStack> stacks)
{
super(stacks);
}
}
/**
* PotionBrewEvent.Post is fired when a potion is brewed in the brewing stand.
* <br>
* The event is fired during the {@link TileEntityBrewingStand#brewPotions()} method invocation.<br>
* <br>
* {@link #stacks} contains the itemstack array from the TileEntityBrewer holding all items in Brewer.<br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class Post extends PotionBrewEvent
{
public Post(NonNullList<ItemStack> stacks)
{
super(stacks);
}
}
}

View File

@@ -0,0 +1,139 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.enchanting;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.eventhandler.Event;
import javax.annotation.Nonnull;
/**
* Fired when the enchantment level is set for each of the three potential enchantments in the enchanting table.
* The {@link #level} is set to the vanilla value and can be modified by this event handler.
*
* The {@link #enchantRow} is used to determine which enchantment level is being set, 1, 2, or 3. The {@link #power} is a number
* from 0-15 and indicates how many bookshelves surround the enchanting table. The {@link #itemStack} representing the item being
* enchanted is also available.
*/
public class EnchantmentLevelSetEvent extends Event
{
private final World world;
private final BlockPos pos;
private final int enchantRow;
private final int power;
@Nonnull
private final ItemStack itemStack;
private final int originalLevel;
private int level;
public EnchantmentLevelSetEvent(World world, BlockPos pos, int enchantRow, int power, @Nonnull ItemStack itemStack, int level)
{
this.world = world;
this.pos = pos;
this.enchantRow = enchantRow;
this.power = power;
this.itemStack = itemStack;
this.originalLevel = level;
this.level = level;
}
/**
* Get the world object
*
* @return the world object
*/
public World getWorld()
{
return world;
}
/**
* Get the pos of the enchantment table
*
* @return the pos of the enchantment table
*/
public BlockPos getPos()
{
return pos;
}
/**
* Get the row for which the enchantment level is being set
*
* @return the row for which the enchantment level is being set
*/
public int getEnchantRow()
{
return enchantRow;
}
/**
* Get the power (# of bookshelves) for the enchanting table
*
* @return the power (# of bookshelves) for the enchanting table
*/
public int getPower()
{
return power;
}
/**
* Get the item being enchanted
*
* @return the item being enchanted
*/
@Nonnull
public ItemStack getItem()
{
return itemStack;
}
/**
* Get the original level of the enchantment for this row (0-30)
*
* @return the original level of the enchantment for this row (0-30)
*/
public int getOriginalLevel()
{
return originalLevel;
}
/**
* Get the level of the enchantment for this row (0-30)
*
* @return the level of the enchantment for this row (0-30)
*/
public int getLevel()
{
return level;
}
/**
* Set the new level of the enchantment (0-30)
*
* @param level the new level of the enchantment (0-30)
*/
public void setLevel(int level)
{
this.level = level;
}
}

View File

@@ -0,0 +1,138 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.entity.Entity;
/**
* EntityEvent is fired when an event involving any Entity occurs.<br>
* If a method utilizes this {@link Event} as its parameter, the method will
* receive every child event of this class.<br>
* <br>
* {@link #entity} contains the entity that caused this event to occur.<br>
* <br>
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public class EntityEvent extends Event
{
private final Entity entity;
public EntityEvent(Entity entity)
{
this.entity = entity;
}
public Entity getEntity()
{
return entity;
}
/**
* EntityConstructing is fired when an Entity is being created. <br>
* This event is fired within the constructor of the Entity.<br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class EntityConstructing extends EntityEvent
{
public EntityConstructing(Entity entity)
{
super(entity);
}
}
/**
* CanUpdate is fired when an Entity is being created. <br>
* This event is fired whenever vanilla Minecraft determines that an entity<br>
* cannot update in {@link World#updateEntityWithOptionalForce(net.minecraft.entity.Entity, boolean)} <br>
* <br>
* {@link CanUpdate#canUpdate} contains the boolean value of whether this entity can update.<br>
* If the modder decides that this Entity can be updated, they may change canUpdate to true, <br>
* and the entity with then be updated.<br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class CanUpdate extends EntityEvent
{
private boolean canUpdate = false;
public CanUpdate(Entity entity)
{
super(entity);
}
public boolean getCanUpdate()
{
return canUpdate;
}
public void setCanUpdate(boolean canUpdate)
{
this.canUpdate = canUpdate;
}
}
/**
* EnteringChunk is fired when an Entity enters a chunk. <br>
* This event is fired whenever vanilla Minecraft determines that an entity <br>
* is entering a chunk in {@link Chunk#addEntity(net.minecraft.entity.Entity)} <br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult}
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class EnteringChunk extends EntityEvent
{
private int newChunkX;
private int newChunkZ;
private int oldChunkX;
private int oldChunkZ;
public EnteringChunk(Entity entity, int newChunkX, int newChunkZ, int oldChunkX, int oldChunkZ)
{
super(entity);
this.setNewChunkX(newChunkX);
this.setNewChunkZ(newChunkZ);
this.setOldChunkX(oldChunkX);
this.setOldChunkZ(oldChunkZ);
}
public int getNewChunkX() { return newChunkX; }
public void setNewChunkX(int newChunkX) { this.newChunkX = newChunkX; }
public int getNewChunkZ() { return newChunkZ; }
public void setNewChunkZ(int newChunkZ) { this.newChunkZ = newChunkZ; }
public int getOldChunkX() { return oldChunkX; }
public void setOldChunkX(int oldChunkX) { this.oldChunkX = oldChunkX; }
public int getOldChunkZ() { return oldChunkZ; }
public void setOldChunkZ(int oldChunkZ) { this.oldChunkZ = oldChunkZ; }
}
}

View File

@@ -0,0 +1,60 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.entity.Entity;
import net.minecraft.world.World;
import java.util.Collection;
/**
* EntityJoinWorldEvent is fired when an Entity joins the world. <br>
* This event is fired whenever an Entity is added to the world in
* {@link World#loadEntities(Collection)}, {@link WorldServer#loadEntities(Collection)} {@link World#joinEntityInSurroundings(Entity)}, and {@link World#spawnEntity(Entity)}. <br>
* <br>
* {@link #world} contains the world in which the entity is to join.<br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the Entity is not added to the world.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
@Cancelable
public class EntityJoinWorldEvent extends EntityEvent
{
private final World world;
public EntityJoinWorldEvent(Entity entity, World world)
{
super(entity);
this.world = world;
}
public World getWorld()
{
return world;
}
}

View File

@@ -0,0 +1,44 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity;
import net.minecraft.entity.Entity;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
import net.minecraftforge.fml.common.eventhandler.Event.Result;
/**
* EntityMobGriefingEvent is fired when mob griefing is about to occur and allows an event listener to specify whether it should or not.<br>
* This event is fired when ever the {@code mobGriefing} game rule is checked.<br>
* <br>
* This event has a {@link HasResult result}:
* <li>{@link Result#ALLOW} means this instance of mob griefing is allowed.</li>
* <li>{@link Result#DEFAULT} means the {@code mobGriefing} game rule is used to determine the behaviour.</li>
* <li>{@link Result#DENY} means this instance of mob griefing is not allowed.</li><br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
*/
@HasResult
public class EntityMobGriefingEvent extends EntityEvent
{
public EntityMobGriefingEvent(Entity entity)
{
super(entity);
}
}

View File

@@ -0,0 +1,85 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity;
import net.minecraft.entity.Entity;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
/**
* This event gets fired whenever a entity mounts/dismounts another entity.<br>
* <b>entityBeingMounted can be null</b>, be sure to check for that.
* <br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the entity does not mount/dismount the other entity.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
*<br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
*
*/
@Cancelable
public class EntityMountEvent extends EntityEvent
{
private final Entity entityMounting;
private final Entity entityBeingMounted;
private final World worldObj;
private final boolean isMounting;
public EntityMountEvent(Entity entityMounting, Entity entityBeingMounted, World entityWorld, boolean isMounting)
{
super(entityMounting);
this.entityMounting = entityMounting;
this.entityBeingMounted = entityBeingMounted;
this.worldObj = entityWorld;
this.isMounting = isMounting;
}
public boolean isMounting()
{
return isMounting;
}
public boolean isDismounting()
{
return !isMounting;
}
public Entity getEntityMounting()
{
return entityMounting;
}
public Entity getEntityBeingMounted()
{
return entityBeingMounted;
}
public World getWorldObj()
{
return worldObj;
}
}

View File

@@ -0,0 +1,57 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.entity.Entity;
import net.minecraft.entity.effect.EntityLightningBolt;
/**
* EntityStruckByLightningEvent is fired when an Entity is about to be struck by lightening.<br>
* This event is fired whenever an EntityLightningBolt is updated to strike an Entity in
* {@link EntityLightningBolt#onUpdate()} via {@link ForgeEventFactory#onEntityStruckByLightning(Entity, EntityLightningBolt)}.<br>
* <br>
* {@link #lightning} contains the instance of EntityLightningBolt attempting to strike an entity.<br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the Entity is not struck by the lightening.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
@Cancelable
public class EntityStruckByLightningEvent extends EntityEvent
{
private final EntityLightningBolt lightning;
public EntityStruckByLightningEvent(Entity entity, EntityLightningBolt lightning)
{
super(entity);
this.lightning = lightning;
}
public EntityLightningBolt getLightning()
{
return lightning;
}
}

View File

@@ -0,0 +1,54 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity;
import net.minecraft.entity.Entity;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
/**
* EntityTravelToDimensionEvent is fired before an Entity travels to a dimension.<br>
* <br>
* {@link #dimension} contains the id of the dimension the entity is traveling to.<br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the Entity does not travel to the dimension.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
@Cancelable
public class EntityTravelToDimensionEvent extends EntityEvent
{
private final int dimension;
public EntityTravelToDimensionEvent(Entity entity, int dimension)
{
super(entity);
this.dimension = dimension;
}
public int getDimension()
{
return dimension;
}
}

View File

@@ -0,0 +1,82 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.entity.Entity;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
/**
* PlaySoundAtEntityEvent is fired a sound is to be played at an Entity<br>
* This event is fired whenever a sound is set to be played at an Entity such as in
* {@link EntityPlayerSP#playSound(SoundEvent, float, float)} and {@link World#playSound(EntityPlayer, double, double, double, SoundEvent, SoundCategory, float, float)}.<br>
* <br>
* {@link #name} contains the name of the sound to be played at the Entity.<br>
* {@link #volume} contains the volume at which the sound is to be played originally.<br>
* {@link #pitch} contains the pitch at which the sound is to be played originally.<br>
* {@link #newVolume} contains the volume at which the sound is actually played.<br>
* {@link #newPitch} contains the pitch at which the sound is actually played.<br>
* Changing the {@link #name} field will cause the sound of this name to be played instead of the originally intended sound.<br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the sound is not played.<br>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
@Cancelable
public class PlaySoundAtEntityEvent extends EntityEvent
{
private SoundEvent name;
private SoundCategory category;
private final float volume;
private final float pitch;
private float newVolume;
private float newPitch;
public PlaySoundAtEntityEvent(Entity entity, SoundEvent name, SoundCategory category, float volume, float pitch)
{
super(entity);
this.name = name;
this.category = category;
this.volume = volume;
this.pitch = pitch;
this.newVolume = volume;
this.newPitch = pitch;
}
public SoundEvent getSound() { return this.name; }
public SoundCategory getCategory() { return this.category; }
public float getDefaultVolume() { return this.volume; }
public float getDefaultPitch() { return this.pitch; }
public float getVolume() { return this.newVolume; }
public float getPitch() { return this.newPitch; }
public void setSound(SoundEvent value) { this.name = value; }
public void setCategory(SoundCategory category) { this.category = category; }
public void setVolume(float value) { this.newVolume = value; }
public void setPitch(float value) { this.newPitch = value; }
}

View File

@@ -0,0 +1,107 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.entity.projectile.EntityFireball;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.math.RayTraceResult;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
/**
* This event is fired when a projectile entity impacts something.
* This event is fired via {@link ForgeEventFactory#onProjectileImpact(Entity, RayTraceResult)}
* Subclasses of this event exist for more specific types of projectile.
* This event is fired for all vanilla projectiles by Forge,
* custom projectiles should fire this event and check the result in a similar fashion.
* This event is cancelable. When canceled, the impact will not be processed.
* Killing or other handling of the entity after event cancellation is up to the modder.
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
*/
@Cancelable
public class ProjectileImpactEvent extends EntityEvent
{
private final RayTraceResult ray;
public ProjectileImpactEvent(Entity entity, RayTraceResult ray)
{
super(entity);
this.ray = ray;
}
public RayTraceResult getRayTraceResult()
{
return ray;
}
@Cancelable
public static class Arrow extends ProjectileImpactEvent
{
private final EntityArrow arrow;
public Arrow(EntityArrow arrow, RayTraceResult ray)
{
super(arrow, ray);
this.arrow = arrow;
}
public EntityArrow getArrow()
{
return arrow;
}
}
@Cancelable
public static class Fireball extends ProjectileImpactEvent
{
private final EntityFireball fireball;
public Fireball(EntityFireball fireball, RayTraceResult ray)
{
super(fireball, ray);
this.fireball = fireball;
}
public EntityFireball getFireball()
{
return fireball;
}
}
@Cancelable
public static class Throwable extends ProjectileImpactEvent
{
private final EntityThrowable throwable;
public Throwable(EntityThrowable throwable, RayTraceResult ray)
{
super(throwable, ray);
this.throwable = throwable;
}
public EntityThrowable getThrowable()
{
return throwable;
}
}
}

View File

@@ -0,0 +1,59 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.math.RayTraceResult;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
/**
* This event is fired before an {@link EntityThrowable} calls its {@link EntityThrowable#onImpact} method.
* This event is fired via {@link net.minecraftforge.common.ForgeHooks#onThrowableImpact}.
* This event is cancelable. When canceled, {@link EntityThrowable#onImpact} will not be called.
* Killing or other handling of the entity after event cancellation is up to the modder.
* This event is fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}.
*
* @deprecated use {@link ProjectileImpactEvent.Throwable}
*/
@Deprecated // TODO: remove (1.13)
@Cancelable
public class ThrowableImpactEvent extends EntityEvent
{
private final EntityThrowable throwable;
private final RayTraceResult ray;
public ThrowableImpactEvent(EntityThrowable throwable, RayTraceResult ray)
{
super(throwable);
this.throwable = throwable;
this.ray = ray;
}
public EntityThrowable getEntityThrowable()
{
return throwable;
}
public RayTraceResult getRayTraceResult()
{
return ray;
}
}

View File

@@ -0,0 +1,53 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
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
{
private 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;
}
/**
* The relevant EntityItem for this event, already cast for you.
*/
public EntityItem getEntityItem()
{
return entityItem;
}
}

View File

@@ -0,0 +1,58 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.item;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.entity.item.EntityItem;
/**
* 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 entities life equal to extraLife.
*/
@Cancelable
public class ItemExpireEvent extends ItemEvent
{
private 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.setExtraLife(extraLife);
}
public int getExtraLife()
{
return extraLife;
}
public void setExtraLife(int extraLife)
{
this.extraLife = extraLife;
}
}

View File

@@ -0,0 +1,57 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.item;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
/**
* 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
{
private 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;
}
/**
* The player tossing the item.
*/
public EntityPlayer getPlayer()
{
return player;
}
}

View File

@@ -0,0 +1,57 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
/**
* This event is fired when an {@link EntityAnimal} is tamed. <br>
* It is fired via {@link ForgeEventFactory#onAnimalTame(EntityAnimal, EntityPlayer)}.
* Forge fires this event for applicable vanilla animals, mods need to fire it themselves.
* This event is {@link Cancelable}. If canceled, taming the animal will fail.
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
*/
@Cancelable
public class AnimalTameEvent extends LivingEvent
{
private final EntityAnimal animal;
private final EntityPlayer tamer;
public AnimalTameEvent(EntityAnimal animal, EntityPlayer tamer)
{
super(animal);
this.animal = animal;
this.tamer = tamer;
}
public EntityAnimal getAnimal()
{
return animal;
}
public EntityPlayer getTamer()
{
return tamer;
}
}

View File

@@ -0,0 +1,105 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.ai.EntityAIMate;
import net.minecraft.entity.ai.EntityAIVillagerMate;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import javax.annotation.Nullable;
/**
* BabyEntitySpawnEvent is fired just before a baby entity is about to be spawned. <br>
* Parents will have disengaged their relationship. {@link @Cancelable} <br>
* It is possible to change the child completely by using {@link #setChild(EntityAgeable)} <br>
* This event is fired from {@link EntityAIMate#spawnBaby()} and {@link EntityAIVillagerMate#giveBirth()} <br>
* <br>
* {@link #parentA} contains the initiating parent entity.<br>
* {@link #parentB} contains the secondary parent entity.<br>
* {@link #causedByPlayer} contains the player responsible for the breading (if applicable).<br>
* {@link #child} contains the child that will be spawned.<br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the child Entity is not added to the world, and the parents <br>
* will no longer attempt to mate.
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
@Cancelable
public class BabyEntitySpawnEvent extends Event
{
private final EntityLiving parentA;
private final EntityLiving parentB;
private final EntityPlayer causedByPlayer;
private EntityAgeable child;
public BabyEntitySpawnEvent(EntityLiving parentA, EntityLiving parentB, @Nullable EntityAgeable proposedChild)
{
//causedByPlayer calculated here to simplify the patch.
EntityPlayer causedByPlayer = null;
if (parentA instanceof EntityAnimal) {
causedByPlayer = ((EntityAnimal)parentA).getLoveCause();
}
if (causedByPlayer == null && parentB instanceof EntityAnimal)
{
causedByPlayer = ((EntityAnimal)parentB).getLoveCause();
}
this.parentA = parentA;
this.parentB = parentB;
this.causedByPlayer = causedByPlayer;
this.child = proposedChild;
}
public EntityLiving getParentA()
{
return parentA;
}
public EntityLiving getParentB()
{
return parentB;
}
@Nullable
public EntityPlayer getCausedByPlayer()
{
return causedByPlayer;
}
@Nullable
public EntityAgeable getChild()
{
return child;
}
public void setChild(EntityAgeable proposedChild)
{
child = proposedChild;
}
}

View File

@@ -0,0 +1,56 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.entity.EntityLivingBase;
/**
* Event for when an Enderman/Shulker 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
{
private double targetX;
private double targetY;
private double targetZ;
private float attackDamage;
public EnderTeleportEvent(EntityLivingBase entity, double targetX, double targetY, double targetZ, float attackDamage)
{
super(entity);
this.setTargetX(targetX);
this.setTargetY(targetY);
this.setTargetZ(targetZ);
this.setAttackDamage(attackDamage);
}
public double getTargetX() { return targetX; }
public void setTargetX(double targetX) { this.targetX = targetX; }
public double getTargetY() { return targetY; }
public void setTargetY(double targetY) { this.targetY = targetY; }
public double getTargetZ() { return targetZ; }
public void setTargetZ(double targetZ) { this.targetZ = targetZ; }
public float getAttackDamage() { return attackDamage; }
public void setAttackDamage(float attackDamage) { this.attackDamage = attackDamage; }
}

View File

@@ -0,0 +1,61 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.util.DamageSource;
import net.minecraft.entity.EntityLivingBase;
/**
* LivingAttackEvent is fired when a living Entity is attacked. <br>
* This event is fired whenever an Entity is attacked in
* {@link EntityLivingBase#attackEntityFrom(DamageSource, float)} and
* {@link EntityPlayer#attackEntityFrom(DamageSource, float)}. <br>
* <br>
* This event is fired via the {@link ForgeHooks#onLivingAttack(EntityLivingBase, DamageSource, float)}.<br>
* <br>
* {@link #source} contains the DamageSource of the attack. <br>
* {@link #amount} contains the amount of damage dealt to the entity. <br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the Entity does not take attack damage.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
*<br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
@Cancelable
public class LivingAttackEvent extends LivingEvent
{
private final DamageSource source;
private final float amount;
public LivingAttackEvent(EntityLivingBase entity, DamageSource source, float amount)
{
super(entity);
this.source = source;
this.amount = amount;
}
public DamageSource getSource() { return source; }
public float getAmount() { return amount; }
}

View File

@@ -0,0 +1,64 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.util.DamageSource;
import net.minecraft.entity.EntityLivingBase;
/**
* LivingDamageEvent is fired just before damage is applied to entity.<br>
* At this point armor, potion and absorption modifiers have already been applied to damage - this is FINAL value.<br>
* Also note that appropriate resources (like armor durability and absorption extra hearths) have already been consumed.<br>
* This event is fired whenever an Entity is damaged in
* {@link EntityLivingBase#damageEntity(DamageSource, float)} and
* {@link EntityPlayer#damageEntity(DamageSource, float)}.<br>
* <br>
* This event is fired via the {@link ForgeHooks#onLivingDamage(EntityLivingBase, DamageSource, float)}.<br>
* <br>
* {@link #source} contains the DamageSource that caused this Entity to be hurt. <br>
* {@link #amount} contains the final amount of damage that will be dealt to entity. <br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the Entity is not hurt. Used resources WILL NOT be restored.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* @see LivingHurtEvent
**/
@Cancelable
public class LivingDamageEvent extends LivingEvent
{
private final DamageSource source;
private float amount;
public LivingDamageEvent(EntityLivingBase entity, DamageSource source, float amount)
{
super(entity);
this.source = source;
this.amount = amount;
}
public DamageSource getSource() { return source; }
public float getAmount() { return amount; }
public void setAmount(float amount) { this.amount = amount; }
}

View File

@@ -0,0 +1,62 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.util.DamageSource;
import net.minecraft.entity.EntityLivingBase;
/**
* LivingDeathEvent is fired when an Entity dies. <br>
* This event is fired whenever an Entity dies in
* {@link EntityLivingBase#onDeath(DamageSource)},
* {@link EntityPlayer#onDeath(DamageSource)}, and
* {@link EntityPlayerMP#onDeath(DamageSource)}. <br>
* <br>
* This event is fired via the {@link ForgeHooks#onLivingDeath(EntityLivingBase, DamageSource)}.<br>
* <br>
* {@link #source} contains the DamageSource that caused the entity to die. <br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the Entity does not die.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
@Cancelable
public class LivingDeathEvent extends LivingEvent
{
private final DamageSource source;
public LivingDeathEvent(EntityLivingBase entity, DamageSource source)
{
super(entity);
this.source = source;
}
public DamageSource getSource()
{
return source;
}
}

View File

@@ -0,0 +1,63 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
/**
* Fired when the ender dragon or wither attempts to destroy a block and when ever a zombie attempts to break a door. Basically a event version of {@link Block#canEntityDestroy(IBlockState, IBlockAccess, BlockPos, Entity)}<br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the block will not be destroyed.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
@Cancelable
public class LivingDestroyBlockEvent extends LivingEvent
{
private final BlockPos pos;
private final IBlockState state;
public LivingDestroyBlockEvent(EntityLivingBase entity, BlockPos pos, IBlockState state)
{
super(entity);
this.pos = pos;
this.state = state;
}
public IBlockState getState()
{
return state;
}
public BlockPos getPos()
{
return pos;
}
}

View File

@@ -0,0 +1,87 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import java.util.ArrayList;
import java.util.List;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.util.DamageSource;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.EntityLivingBase;
/**
* LivingDropsEvent is fired when an Entity's death causes dropped items to appear.<br>
* This event is fired whenever an Entity dies and drops items in
* {@link EntityLivingBase#onDeath(DamageSource)}.<br>
* <br>
* This event is fired via the {@link ForgeHooks#onLivingDrops(EntityLivingBase, DamageSource, ArrayList, int, boolean)}.<br>
* <br>
* {@link #source} contains the DamageSource that caused the drop to occur.<br>
* {@link #drops} contains the ArrayList of EntityItems that will be dropped.<br>
* {@link #lootingLevel} contains the amount of loot that will be dropped.<br>
* {@link #recentlyHit} determines whether the Entity doing the drop has recently been damaged.<br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the Entity does not drop anything.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
@Cancelable
public class LivingDropsEvent extends LivingEvent
{
private final DamageSource source;
private final List<EntityItem> drops;
private final int lootingLevel;
private final boolean recentlyHit;
public LivingDropsEvent(EntityLivingBase entity, DamageSource source, List<EntityItem> drops, int lootingLevel, boolean recentlyHit)
{
super(entity);
this.source = source;
this.drops = drops;
this.lootingLevel = lootingLevel;
this.recentlyHit = recentlyHit;
}
public DamageSource getSource()
{
return source;
}
public List<EntityItem> getDrops()
{
return drops;
}
public int getLootingLevel()
{
return lootingLevel;
}
public boolean isRecentlyHit()
{
return recentlyHit;
}
}

View File

@@ -0,0 +1,144 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import javax.annotation.Nonnull;
public class LivingEntityUseItemEvent extends LivingEvent
{
private final ItemStack item;
private int duration;
private LivingEntityUseItemEvent(EntityLivingBase entity, @Nonnull ItemStack item, int duration)
{
super(entity);
this.item = item;
this.setDuration(duration);
}
@Nonnull
public ItemStack getItem()
{
return item;
}
public int getDuration()
{
return duration;
}
public void setDuration(int duration)
{
this.duration = duration;
}
/**
* Fired when a player starts 'using' an item, typically when they hold right mouse.
* Examples:
* Drawing a bow
* Eating Food
* Drinking Potions/Milk
* Guarding with a sword
*
* Cancel the event, or set the duration or <= 0 to prevent it from processing.
*
*/
@Cancelable
public static class Start extends LivingEntityUseItemEvent
{
public Start(EntityLivingBase entity, @Nonnull ItemStack item, int duration)
{
super(entity, item, duration);
}
}
/**
* Fired every tick that a player is 'using' an item, see {@link Start} for info.
*
* Cancel the event, or set the duration or <= 0 to cause the player to stop using the item.
*
*/
@Cancelable
public static class Tick extends LivingEntityUseItemEvent
{
public Tick(EntityLivingBase entity, @Nonnull ItemStack item, int duration)
{
super(entity, item, duration);
}
}
/**
* Fired when a player stops using an item without the use duration timing out.
* Example:
* Stop eating 1/2 way through
* Stop defending with sword
* Stop drawing bow. This case would fire the arrow
*
* Duration on this event is how long the item had left in it's count down before 'finishing'
*
* Canceling this event will prevent the Item from being notified that it has stopped being used,
* The only vanilla item this would effect are bows, and it would cause them NOT to fire there arrow.
*/
@Cancelable
public static class Stop extends LivingEntityUseItemEvent
{
public Stop(EntityLivingBase entity, @Nonnull ItemStack item, int duration)
{
super(entity, item, duration);
}
}
/**
* Fired after an item has fully finished being used.
* The item has been notified that it was used, and the item/result stacks reflect after that state.
* This means that when this is fired for a Potion, the potion effect has already been applied.
*
* {@link LivingEntityUseItemEvent#item} is a copy of the item BEFORE it was used.
*
* If you wish to cancel those effects, you should cancel one of the above events.
*
* The result item stack is the stack that is placed in the player's inventory in replacement of the stack that is currently being used.
*
*/
public static class Finish extends LivingEntityUseItemEvent
{
private ItemStack result;
public Finish(EntityLivingBase entity, @Nonnull ItemStack item, int duration, @Nonnull ItemStack result)
{
super(entity, item, duration);
this.setResultStack(result);
}
@Nonnull
public ItemStack getResultStack()
{
return result;
}
public void setResultStack(@Nonnull ItemStack result)
{
this.result = result;
}
}
}

View File

@@ -0,0 +1,65 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import javax.annotation.Nonnull;
/**
* {@link LivingEquipmentChangeEvent} is fired when the Equipment of a Entity changes. <br>
* This event is fired whenever changes in Equipment are detected in {@link EntityLivingBase#onUpdate()}. <br>
* This also includes entities joining the World, as well as being cloned. <br>
* This event is fired on server-side only. <br>
* <br>
* {@link #slot} contains the affected {@link EntityEquipmentSlot}. <br>
* {@link #from} contains the {@link ItemStack} that was equipped previously. <br>
* {@link #to} contains the {@link ItemStack} that is equipped now. <br>
* <br>
* This event is not {@link Cancelable}. <br>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
public class LivingEquipmentChangeEvent extends LivingEvent
{
private final EntityEquipmentSlot slot;
private final ItemStack from;
private final ItemStack to;
public LivingEquipmentChangeEvent(EntityLivingBase entity, EntityEquipmentSlot slot, @Nonnull ItemStack from, @Nonnull ItemStack to)
{
super(entity);
this.slot = slot;
this.from = from;
this.to = to;
}
public EntityEquipmentSlot getSlot() { return this.slot; }
@Nonnull
public ItemStack getFrom() { return this.from; }
@Nonnull
public ItemStack getTo() { return this.to; }
}

View File

@@ -0,0 +1,90 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityMagmaCube;
import net.minecraft.entity.passive.EntityHorse;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.EntityEvent;
/**
* LivingEvent is fired whenever an event involving Living entities occurs.<br>
* If a method utilizes this {@link Event} as its parameter, the method will
* receive every child event of this class.<br>
* <br>
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public class LivingEvent extends EntityEvent
{
private final EntityLivingBase entityLiving;
public LivingEvent(EntityLivingBase entity)
{
super(entity);
entityLiving = entity;
}
public EntityLivingBase getEntityLiving()
{
return entityLiving;
}
/**
* LivingUpdateEvent is fired when an Entity is updated. <br>
* This event is fired whenever an Entity is updated in
* {@link EntityLivingBase#onUpdate()}. <br>
* <br>
* This event is fired via the {@link ForgeHooks#onLivingUpdate(EntityLivingBase)}.<br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the Entity does not update.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
@Cancelable
public static class LivingUpdateEvent extends LivingEvent
{
public LivingUpdateEvent(EntityLivingBase e){ super(e); }
}
/**
* LivingJumpEvent is fired when an Entity jumps.<br>
* This event is fired whenever an Entity jumps in
* {@link EntityLivingBase#jump()}, {@link EntityMagmaCube#jump()},
* and {@link EntityHorse#jump()}.<br>
* <br>
* This event is fired via the {@link ForgeHooks#onLivingJump(EntityLivingBase)}.<br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
public static class LivingJumpEvent extends LivingEvent
{
public LivingJumpEvent(EntityLivingBase e){ super(e); }
}
}

View File

@@ -0,0 +1,66 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
/**
* Event for when an entity drops experience on its death, can be used to change
* the amount of experience points dropped or completely prevent dropping of experience
* by canceling the event.
*/
@Cancelable
public class LivingExperienceDropEvent extends LivingEvent
{
private final EntityPlayer attackingPlayer;
private final int originalExperiencePoints;
private int droppedExperiencePoints;
public LivingExperienceDropEvent(EntityLivingBase entity, EntityPlayer attackingPlayer, int originalExperience)
{
super(entity);
this.attackingPlayer = attackingPlayer;
this.originalExperiencePoints = this.droppedExperiencePoints = originalExperience;
}
public int getDroppedExperience()
{
return droppedExperiencePoints;
}
public void setDroppedExperience(int droppedExperience)
{
this.droppedExperiencePoints = droppedExperience;
}
public EntityPlayer getAttackingPlayer()
{
return attackingPlayer;
}
public int getOriginalExperience()
{
return originalExperiencePoints;
}
}

View File

@@ -0,0 +1,59 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.entity.EntityLivingBase;
/**
* LivingFallEvent is fired when an Entity is set to be falling.<br>
* This event is fired whenever an Entity is set to fall in
* {@link EntityLivingBase#fall(float, float)}.<br>
* <br>
* This event is fired via the {@link ForgeHooks#onLivingFall(EntityLivingBase, float, float)}.<br>
* <br>
* {@link #distance} contains the distance the Entity is to fall. If this event is canceled, this value is set to 0.0F.
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the Entity does not fall.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
@Cancelable
public class LivingFallEvent extends LivingEvent
{
private float distance;
private float damageMultiplier;
public LivingFallEvent(EntityLivingBase entity, float distance, float damageMultiplier)
{
super(entity);
this.setDistance(distance);
this.setDamageMultiplier(damageMultiplier);
}
public float getDistance() { return distance; }
public void setDistance(float distance) { this.distance = distance; }
public float getDamageMultiplier() { return damageMultiplier; }
public void setDamageMultiplier(float damageMultiplier) { this.damageMultiplier = damageMultiplier; }
}

View File

@@ -0,0 +1,61 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.entity.EntityLivingBase;
/**
* LivingHealEvent is fired when an Entity is set to be healed. <br>
* This event is fired whenever an Entity is healed in {@link EntityLivingBase#heal(float)}<br>
* <br>
* This event is fired via the {@link ForgeEventFactory#onLivingHeal(EntityLivingBase, float)}.<br>
* <br>
* {@link #amount} contains the amount of healing done to the Entity that was healed. <br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the Entity is not healed.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
@Cancelable
public class LivingHealEvent extends LivingEvent
{
private float amount;
public LivingHealEvent(EntityLivingBase entity, float amount)
{
super(entity);
this.setAmount(amount);
}
public float getAmount()
{
return amount;
}
public void setAmount(float amount)
{
this.amount = amount;
}
}

View File

@@ -0,0 +1,65 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.util.DamageSource;
import net.minecraft.entity.EntityLivingBase;
/**
* LivingHurtEvent is fired when an Entity is set to be hurt. <br>
* This event is fired whenever an Entity is hurt in
* {@link EntityLivingBase#damageEntity(DamageSource, float)} and
* {@link EntityPlayer#damageEntity(DamageSource, float)}.<br>
* <br>
* This event is fired via the {@link ForgeHooks#onLivingHurt(EntityLivingBase, DamageSource, float)}.<br>
* <br>
* {@link #source} contains the DamageSource that caused this Entity to be hurt. <br>
* {@link #amount} contains the amount of damage dealt to the Entity that was hurt. <br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the Entity is not hurt.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
* @see LivingDamageEvent
**/
@Cancelable
public class LivingHurtEvent extends LivingEvent
{
private final DamageSource source;
private float amount;
public LivingHurtEvent(EntityLivingBase entity, DamageSource source, float amount)
{
super(entity);
this.source = source;
this.amount = amount;
}
public DamageSource getSource() { return source; }
public float getAmount() { return amount; }
public void setAmount(float amount) { this.amount = amount; }
}

View File

@@ -0,0 +1,95 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.DamageSource;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
/**
* LivingKnockBackEvent is fired when a living entity is about to be knocked back. <br>
* This event is fired whenever an Entity is knocked back in
* {@link EntityLivingBase#attackEntityFrom(DamageSource, float)},
* {@link EntityLivingBase#blockWithShield(EntityLivingBase)},
* {@link EntityMob#attackEntityAsMob(Entity)} and
* {@link EntityPlayer#attackTargetEntityWithCurrentItem(Entity)} <br>
* <br>
* This event is fired via {@link ForgeHooks#onLivingKnockBack(EntityLivingBase, Entity, float, double, double)}.<br>
* <br>
* {@link #attacker} contains the Entity that caused the knock back. <br>
* {@link #strength} contains the strength of the knock back. <br>
* {@link #ratioX} contains the x ratio of the knock back. <br>
* {@link #ratioZ} contains the z ratio of the knock back. <br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the entity is not knocked back.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
*<br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
@Cancelable
public class LivingKnockBackEvent extends LivingEvent
{
protected Entity attacker;
protected float strength;
protected double ratioX, ratioZ;
protected final Entity originalAttacker;
protected final float originalStrength;
protected final double originalRatioX, originalRatioZ;
public LivingKnockBackEvent(EntityLivingBase target, Entity attacker, float strength, double ratioX, double ratioZ)
{
super(target);
this.attacker = this.originalAttacker = attacker;
this.strength = this.originalStrength = strength;
this.ratioX = this.originalRatioX = ratioX;
this.ratioZ = this.originalRatioZ = ratioZ;
}
public Entity getAttacker() {return this.attacker;}
public float getStrength() {return this.strength;}
public double getRatioX() {return this.ratioX;}
public double getRatioZ() {return this.ratioZ;}
public Entity getOriginalAttacker() {return this.originalAttacker;}
public float getOriginalStrength() {return this.originalStrength;}
public double getOriginalRatioX() {return this.originalRatioX;}
public double getOriginalRatioZ() {return this.originalRatioZ;}
public void setAttacker(Entity attacker) {this.attacker = attacker;}
public void setStrength(float strength) {this.strength = strength;}
public void setRatioX(double ratioX) {this.ratioX = ratioX;}
public void setRatioZ(double ratioZ) {this.ratioZ = ratioZ;}
}

View File

@@ -0,0 +1,52 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
import net.minecraft.entity.EntityLiving;
@HasResult
public class LivingPackSizeEvent extends LivingEvent
{
private int maxPackSize;
public LivingPackSizeEvent(EntityLiving entity)
{
super(entity);
}
/**
* 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 getMaxPackSize()
{
return maxPackSize;
}
public void setMaxPackSize(int maxPackSize)
{
this.maxPackSize = maxPackSize;
}
}

View File

@@ -0,0 +1,58 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
/**
* LivingSetAttackTargetEvent is fired when an Entity sets a target to attack.<br>
* This event is fired whenever an Entity sets a target to attack in
* {@link EntityLiving#setAttackTarget(EntityLivingBase)} and
* {@link EntityLivingBase#setRevengeTarget(EntityLivingBase)}.<br>
* <br>
* This event is fired via the {@link ForgeHooks#onLivingSetAttackTarget(EntityLivingBase, EntityLivingBase)}.<br>
* <br>
* {@link #target} contains the newly targeted Entity.<br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
public class LivingSetAttackTargetEvent extends LivingEvent
{
private final EntityLivingBase target;
public LivingSetAttackTargetEvent(EntityLivingBase entity, EntityLivingBase target)
{
super(entity);
this.target = target;
}
public EntityLivingBase getTarget()
{
return target;
}
}

View File

@@ -0,0 +1,209 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import javax.annotation.Nullable;
import net.minecraft.tileentity.MobSpawnerBaseLogic;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.entity.EntityLiving;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
/**
* LivingSpawnEvent is fired for any events associated with Living Enttnies spawn status. <br>
* If a method utilizes this {@link Event} as its parameter, the method will
* receive every child event of this class.<br>
* <br>
* {@link #world} contains the world in which this living Entity is being spawned.<br>
* {@link #x} contains the x-coordinate this entity is being spawned at.<br>
* {@link #y} contains the y-coordinate this entity is being spawned at.<br>
* {@link #z} contains the z-coordinate this entity is being spawned at.<br>
* <br>
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.
**/
public class LivingSpawnEvent extends LivingEvent
{
private final World world;
private final float x;
private final float y;
private 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;
}
public World getWorld() { return world; }
public float getX() { return x; }
public float getY() { return y; }
public float getZ() { return 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
{
private final boolean isSpawner; // TODO: remove in 1.13
@Nullable
private final MobSpawnerBaseLogic spawner;
/**
* CheckSpawn is fired when an Entity is about to be spawned.
* @param entity the spawning entity
* @param world the world to spawn in
* @param x x coordinate
* @param y y coordinate
* @param z z coordinate
* @param spawner position of the MobSpawner
* null if it this spawn is coming from a WorldSpawner
*/
public CheckSpawn(EntityLiving entity, World world, float x, float y, float z, @Nullable MobSpawnerBaseLogic spawner)
{
super(entity, world, x, y, z);
this.isSpawner = spawner != null;
this.spawner = spawner;
}
/**
* @deprecated Use {@link CheckSpawn##CheckSpawn(EntityLiving, World, float, float, float, MobSpawnerBaseLogic)}
* with a spawner instance, or null if not a spawner
* CheckSpawn is fired when an Entity is about to be spawned.
* @param entity the spawning entity
* @param world the world to spawn in
* @param x x coordinate
* @param y y coordinate
* @param z z coordinate
* @param isSpawner true if this spawn is done by a MobSpawner,
* false if it this spawn is coming from a WorldSpawner
*/
@Deprecated // TODO: Remove in 1.13
public CheckSpawn(EntityLiving entity, World world, float x, float y, float z, boolean isSpawner)
{
super(entity, world, x, y, z);
this.isSpawner = isSpawner;
spawner = null;
}
/**
* @deprecated Use {@link CheckSpawn#CheckSpawn(EntityLiving, World, float, float, float, MobSpawnerBaseLogic)} instead
*/
@Deprecated // TODO: Remove in 1.13
public CheckSpawn(EntityLiving entity, World world, float x, float y, float z)
{
this(entity, world, x, y, z, true);
}
public boolean isSpawner()
{
return isSpawner; // TODO: replace with spawner null check in 1.13
}
@Nullable
public MobSpawnerBaseLogic getSpawner()
{
return spawner;
}
}
/**
* SpecialSpawn is fired when an Entity is to be spawned.<br>
* This allows you to do special inializers in the new entity.<br>
* <br>
* This event is fired via the {@link ForgeEventFactory#doSpecialSpawn(EntityLiving, World, float, float, float)}.<br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the Entity is not spawned.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
@Cancelable
public static class SpecialSpawn extends LivingSpawnEvent
{
@Nullable
private final MobSpawnerBaseLogic spawner;
/**
* @deprecated Use {@link SpecialSpawn#SpecialSpawn(EntityLiving, World, float, float, float, MobSpawnerBaseLogic)}
* with originating spawner instance or null
*/
@Deprecated // TODO: remove in 1.13
public SpecialSpawn(EntityLiving entity, World world, float x, float y, float z)
{
super(entity, world, x, y, z);
spawner = null;
}
/**
* @param spawner the position of a tileentity or approximate position of an entity that initiated the spawn if any
*/
public SpecialSpawn(EntityLiving entity, World world, float x, float y, float z, @Nullable MobSpawnerBaseLogic spawner)
{
super(entity, world, x, y, z);
this.spawner = spawner;
}
@Nullable
public MobSpawnerBaseLogic getSpawner()
{
return spawner;
}
}
/**
* 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.world, (float)entity.posX, (float)entity.posY, (float)entity.posZ);
}
}
}

View File

@@ -0,0 +1,48 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.DamageSource;
public class LootingLevelEvent extends LivingEvent {
private final DamageSource damageSource;
private int lootingLevel;
public LootingLevelEvent(EntityLivingBase entity, DamageSource damageSource, int lootingLevel) {
super(entity);
this.damageSource = damageSource;
this.lootingLevel = lootingLevel;
}
public DamageSource getDamageSource() {
return damageSource;
}
public int getLootingLevel() {
return lootingLevel;
}
public void setLootingLevel(int lootingLevel) {
this.lootingLevel = lootingLevel;
}
}

View File

@@ -0,0 +1,78 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import java.util.Collection;
import java.util.Collections;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.potion.PotionEffect;
/**
* Fires after Potion Color Calculation.
*
* this event is not {@link Cancelable}
*
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
*/
public class PotionColorCalculationEvent extends LivingEvent
{
private int color;
private boolean hideParticle;
private final Collection<PotionEffect> effectList;
public PotionColorCalculationEvent(EntityLivingBase entity, int color, boolean hideParticle,
Collection<PotionEffect> effectList)
{
super(entity);
this.color = color;
this.effectList = effectList;
this.hideParticle = hideParticle;
}
public int getColor()
{
return color;
}
public void setColor(int color)
{
this.color = color;
}
public boolean areParticlesHidden()
{
return hideParticle;
}
public void shouldHideParticles(boolean hideParticle)
{
this.hideParticle = hideParticle;
}
/**
* Note that returned list is unmodifiable.
*
* @return effects
*/
public Collection<PotionEffect> getEffects()
{
return Collections.unmodifiableCollection(effectList);
}
}

View File

@@ -0,0 +1,111 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
/**
* ZombieEvent is fired whenever a zombie is spawned for aid.
* If a method utilizes this {@link Event} as its parameter, the method will
* receive every child event of this class.
*
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.
**/
public class ZombieEvent extends EntityEvent {
public ZombieEvent(EntityZombie entity)
{
super(entity);
}
public EntityZombie getSummoner()
{
return (EntityZombie) getEntity();
}
/**
* SummonAidEvent is fired when a Zombie Entity is summoned.
* This event is fired whenever a Zombie Entity is summoned in
* {@link EntityZombie#attackEntityFrom(DamageSource, float)}.
*
* This event is fired via the {@link ForgeEventFactory#fireZombieSummonAid(EntityZombie, World, int, int, int, EntityLivingBase, double)}.
*
* {@link #customSummonedAid} remains null, but can be populated with a custom EntityZombie which will be spawned.
* {@link #world} contains the world that this summoning is occurring in.
* {@link #x} contains the x-coordinate at which this summoning event is occurring.
* {@link #y} contains the y-coordinate at which this summoning event is occurring.
* {@link #z} contains the z-coordinate at which this summoning event is occurring.
* {@link #attacker} contains the living Entity that attacked and caused this event to fire.
* {@link #summonChance} contains the likelihood that a Zombie would successfully be summoned.
*
* This event is not {@link Cancelable}.
*
* This event has a result. {@link HasResult}
* {@link Result#ALLOW} Zombie is summoned.
* {@link Result#DENY} Zombie is not summoned.
*
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
@HasResult
public static class SummonAidEvent extends ZombieEvent {
private EntityZombie customSummonedAid;
private final World world;
private final int x;
private final int y;
private final int z;
private final EntityLivingBase attacker;
private 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;
}
/**
* Populate this field to have a custom zombie instead of a normal zombie summoned
*/
public EntityZombie getCustomSummonedAid() { return customSummonedAid; }
public void setCustomSummonedAid(EntityZombie customSummonedAid) { this.customSummonedAid = customSummonedAid; }
public World getWorld() { return world; }
public int getX() { return x; }
public int getY() { return y; }
public int getZ() { return z; }
public EntityLivingBase getAttacker() { return attacker; }
public double getSummonChance() { return summonChance; }
}
}

View File

@@ -0,0 +1,54 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.minecart;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
/**
* MinecartCollisionEvent is fired when a minecart collides with an Entity.
* This event is fired whenever a minecraft collides in
* {@link EntityMinecart#applyEntityCollision(Entity)}.
*
* {@link #collider} contains the Entity the Minecart collided with.
*
* This event is not {@link Cancelable}.
*
* This event does not have a result. {@link HasResult}
*
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
public class MinecartCollisionEvent extends MinecartEvent
{
private final Entity collider;
public MinecartCollisionEvent(EntityMinecart minecart, Entity collider)
{
super(minecart);
this.collider = collider;
}
public Entity getCollider()
{
return collider;
}
}

View File

@@ -0,0 +1,50 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.minecart;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.fml.common.eventhandler.Event;
/**
* MinecartEvent is fired whenever an event involving minecart entities occurs. <br>
* If a method utilizes this {@link Event} as its parameter, the method will <br>
* receive every child event of this class.<br>
* <br>
* {@link #minecart} contains the minecart entity involved with this event.<br>
* <br>
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public class MinecartEvent extends EntityEvent
{
private final EntityMinecart minecart;
public MinecartEvent(EntityMinecart minecart)
{
super(minecart);
this.minecart = minecart;
}
public EntityMinecart getMinecart()
{
return minecart;
}
}

View File

@@ -0,0 +1,67 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.minecart;
import net.minecraft.entity.item.EntityMinecartContainer;
import net.minecraft.entity.item.EntityMinecartEmpty;
import net.minecraft.entity.item.EntityMinecartFurnace;
import net.minecraft.entity.item.EntityMinecartHopper;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import javax.annotation.Nonnull;
/**
* MinecartInteractEvent is fired when a player interacts with a minecart. <br>
* This event is fired whenever a player interacts with a minecart in
* {@link EntityMinecart#processInitialInteract(EntityPlayer, EnumHand)}.
* <br>
* <br>
* {@link #player} contains the EntityPlayer that is involved with this minecart interaction.<br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the player does not interact with the minecart.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
@Cancelable
public class MinecartInteractEvent extends MinecartEvent
{
private final EntityPlayer player;
private final EnumHand hand;
public MinecartInteractEvent(EntityMinecart minecart, EntityPlayer player, EnumHand hand)
{
super(minecart);
this.player = player;
this.hand = hand;
}
public EntityPlayer getPlayer() { return player; }
@Nonnull
public ItemStack getItem() { return player.getHeldItem(hand); }
public EnumHand getHand() { return hand; }
}

View File

@@ -0,0 +1,54 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.minecart;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
/**
* MinecartUpdateEvent is fired when a minecart is updated.<br>
* This event is fired whenever a minecart is updated in
* {@link EntityMinecart#onUpdate()}.<br>
* <br>
* {@link #pos} contains the coordinate of the track the entity is on {if applicable}.<br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
public class MinecartUpdateEvent extends MinecartEvent
{
private final BlockPos pos;
public MinecartUpdateEvent(EntityMinecart minecart, BlockPos pos)
{
super(minecart);
this.pos = pos;
}
public BlockPos getPos()
{
return pos;
}
}

View File

@@ -0,0 +1,50 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import net.minecraft.advancements.Advancement;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
/**
* This event is fired when a player gets an advancement.
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
*/
public class AdvancementEvent extends PlayerEvent
{
private final Advancement advancement;
public AdvancementEvent(EntityPlayer player, Advancement advancement)
{
super(player);
this.advancement = advancement;
}
public Advancement getAdvancement()
{
return advancement;
}
}

View File

@@ -0,0 +1,98 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
/**
* Fired when the player removes a "repaired" item from the Anvil's Output slot.
*
* breakChance specifies as a percentage the chance that the anvil will be "damaged" when used.
*
* ItemStacks are the inputs/output from the anvil. They cannot be edited.
*/
public class AnvilRepairEvent extends PlayerEvent
{
@Nonnull
private final ItemStack left; // The left side of the input
@Nonnull
private final ItemStack right; // The right side of the input
@Nonnull
private final ItemStack output; // Set this to set the output stack
private float breakChance; // Anvil's chance to break (reduced by 1 durability) when this is complete. Default is 12% (0.12f)
public AnvilRepairEvent(EntityPlayer player, @Nonnull ItemStack left, @Nonnull ItemStack right, @Nonnull ItemStack output)
{
super(player);
this.output = output;
this.left = left;
this.right = right;
this.setBreakChance(0.12f);
}
/**
* Deprecated in favour of {@link #getItemInput()} - this is actually the output slot of the anvil
* @return the output slot
*/
@Deprecated
@Nonnull
public ItemStack getLeft() { return output; }
/**
* Deprecated in favour of {@link #getIngredientInput()}} - this is actually the first input slot of the anvil
* @return the first input slot
*/
@Deprecated
@Nonnull
public ItemStack getRight() { return left; }
/**
* Deprecated in favour of {@link #getItemResult()} - this is actually the second input slot of the anvil
* @return the second input slot
*/
@Deprecated
@Nonnull
public ItemStack getOutput() { return right; }
/**
* Get the output result from the anvil
* @return the output
*/
@Nonnull
public ItemStack getItemResult() { return output; }
/**
* Get the first item input into the anvil
* @return the first input slot
*/
@Nonnull
public ItemStack getItemInput() { return left; }
/**
* Get the second item input into the anvil
* @return the second input slot
*/
@Nonnull
public ItemStack getIngredientInput() { return right; }
public float getBreakChance() { return breakChance; }
public void setBreakChance(float breakChance) { this.breakChance = breakChance; }
}

View File

@@ -0,0 +1,70 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemBow;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
/**
* ArrowLooseEvent is fired when a player stops using a bow.<br>
* This event is fired whenever a player stops using a bow in
* {@link ItemBow#onPlayerStoppedUsing(ItemStack, World, EntityLivingBase, int)}.<br>
* <br>
* {@link #bow} contains the ItemBow ItemStack that was used in this event.<br>
* {@link #charge} contains the value for how much the player had charged before stopping the shot.<br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the player does not stop using the bow.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
@Cancelable
public class ArrowLooseEvent extends PlayerEvent
{
private final ItemStack bow;
private final World world;
private final boolean hasAmmo;
private int charge;
public ArrowLooseEvent(EntityPlayer player, @Nonnull ItemStack bow, World world, int charge, boolean hasAmmo)
{
super(player);
this.bow = bow;
this.world = world;
this.charge = charge;
this.hasAmmo = hasAmmo;
}
@Nonnull
public ItemStack getBow() { return this.bow; }
public World getWorld() { return this.world; }
public boolean hasAmmo() { return this.hasAmmo; }
public int getCharge() { return this.charge; }
public void setCharge(int charge) { this.charge = charge; }
}

View File

@@ -0,0 +1,70 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import javax.annotation.Nonnull;
/**
* ArrowNockEvent is fired when a player begins using a bow.<br>
* This event is fired whenever a player begins using a bow in
* {@link ItemBow#onItemRightClick(World, EntityPlayer, EnumHand)}.<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
public class ArrowNockEvent extends PlayerEvent
{
private final ItemStack bow;
private final EnumHand hand;
private final World world;
private final boolean hasAmmo;
private ActionResult<ItemStack> action;
public ArrowNockEvent(EntityPlayer player, @Nonnull ItemStack item, EnumHand hand, World world, boolean hasAmmo)
{
super(player);
this.bow = item;
this.hand = hand;
this.world = world;
this.hasAmmo = hasAmmo;
}
@Nonnull
public ItemStack getBow() { return this.bow; }
public World getWorld() { return this.world; }
public EnumHand getHand() { return this.hand; }
public boolean hasAmmo() { return this.hasAmmo; }
public ActionResult<ItemStack> getAction()
{
return this.action;
}
public void setAction(ActionResult<ItemStack> action)
{
this.action = action;
}
}

View File

@@ -0,0 +1,55 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
/**
* AttackEntityEvent is fired when a player attacks an Entity.<br>
* This event is fired whenever a player attacks an Entity in
* {@link EntityPlayer#attackTargetEntityWithCurrentItem(Entity)}.<br>
* <br>
* {@link #target} contains the Entity that was damaged by the player. <br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the player does not attack the Entity.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
@Cancelable
public class AttackEntityEvent extends PlayerEvent
{
private final Entity target;
public AttackEntityEvent(EntityPlayer player, Entity target)
{
super(player);
this.target = target;
}
public Entity getTarget()
{
return target;
}
}

View File

@@ -0,0 +1,91 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* 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 setHandled()
*/
@Cancelable
@Event.HasResult
public class BonemealEvent extends PlayerEvent
{
private final World world;
private final BlockPos pos;
private final IBlockState block;
private final EnumHand hand;
private final ItemStack stack;
public BonemealEvent(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState block, @Nullable EnumHand hand,
@Nonnull ItemStack stack)
{
super(player);
this.world = world;
this.pos = pos;
this.block = block;
this.hand = hand;
this.stack = stack;
}
public World getWorld()
{
return world;
}
public BlockPos getPos()
{
return pos;
}
public IBlockState getBlock()
{
return block;
}
@Nullable
public EnumHand getHand()
{
return hand;
}
@Nonnull
public ItemStack getStack()
{
return stack;
}
}

View File

@@ -0,0 +1,100 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.common.MinecraftForge;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
/**
* This event is fired whenever a player attacks an Entity in
* EntityPlayer#attackTargetEntityWithCurrentItem(Entity).<br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event has a result. {@link HasResult}<br>
* DEFAULT: means the vanilla logic will determine if this a critical hit.<br>
* DENY: it will not be a critical hit but the player still will attack<br>
* ALLOW: this attack is forced to be critical
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
@HasResult
public class CriticalHitEvent extends PlayerEvent
{
private float damageModifier;
private final float oldDamageModifier;
private final Entity target;
private final boolean vanillaCritical;
public CriticalHitEvent(EntityPlayer player, Entity target, float damageModifier, boolean vanillaCritical)
{
super(player);
this.target = target;
this.damageModifier = damageModifier;
this.oldDamageModifier = damageModifier;
this.vanillaCritical = vanillaCritical;
}
/**
* The Entity that was damaged by the player.
*/
public Entity getTarget()
{
return target;
}
/**
* This set the damage multiplier for the hit.
* If you set it to 0, then the particles are still generated but damage is not done.
*/
public void setDamageModifier(float mod)
{
this.damageModifier = mod;
}
/**
* The damage modifier for the hit.<br>
* This is by default 1.5F for ciritcal hits and 1F for normal hits .
*/
public float getDamageModifier()
{
return this.damageModifier;
}
/**
* The orignal damage modifier for the hit wthout any changes.<br>
* This is 1.5F for ciritcal hits and 1F for normal hits .
*/
public float getOldDamageModifier()
{
return this.oldDamageModifier;
}
/**
* Returns true if this hit was critical by vanilla
*/
public boolean isVanillaCritical()
{
return vanillaCritical;
}
}

View File

@@ -0,0 +1,53 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
/**
* 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()
*/
@Cancelable
@Event.HasResult
public class EntityItemPickupEvent extends PlayerEvent
{
private final EntityItem item;
public EntityItemPickupEvent(EntityPlayer player, EntityItem item)
{
super(player);
this.item = item;
}
public EntityItem getItem()
{
return item;
}
}

View File

@@ -0,0 +1,69 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* 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 setHandled();
*/
@Cancelable
@Event.HasResult
public class FillBucketEvent extends PlayerEvent
{
private final ItemStack current;
private final World world;
@Nullable
private final RayTraceResult target;
private ItemStack result;
public FillBucketEvent(EntityPlayer player, @Nonnull ItemStack current, World world, @Nullable RayTraceResult target)
{
super(player);
this.current = current;
this.world = world;
this.target = target;
}
@Nonnull
public ItemStack getEmptyBucket() { return this.current; }
public World getWorld(){ return this.world; }
@Nullable
public RayTraceResult getTarget() { return this.target; }
@Nonnull
public ItemStack getFilledBucket() { return this.result; }
public void setFilledBucket(@Nonnull ItemStack bucket) { this.result = bucket; }
}

View File

@@ -0,0 +1,90 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import com.google.common.base.Preconditions;
import net.minecraft.entity.projectile.EntityFishHook;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import javax.annotation.Nonnegative;
import java.util.List;
/**
* This event is called when a player fishes an item.
*
* This event is {@link net.minecraftforge.fml.common.eventhandler.Cancelable}
* Canceling the event will cause the player to receive no items at all.
* The hook will still take the damage specified
*/
@Cancelable
public class ItemFishedEvent extends PlayerEvent
{
private final NonNullList<ItemStack> stacks = NonNullList.create();
private final EntityFishHook hook;
private int rodDamage;
public ItemFishedEvent(List<ItemStack> stacks, int rodDamage, EntityFishHook hook)
{
super(hook.getAngler());
this.stacks.addAll(stacks);
this.rodDamage = rodDamage;
this.hook = hook;
}
/**
* Get the damage the rod will take.
* @return The damage the rod will take
*/
public int getRodDamage()
{
return rodDamage;
}
/**
* Specifies the amount of damage that the fishing rod should take.
* This is not added to the pre-existing damage to be taken.
* @param rodDamage The damage the rod will take. Must be nonnegative
*/
public void damageRodBy(@Nonnegative int rodDamage)
{
Preconditions.checkArgument(rodDamage >= 0);
this.rodDamage = rodDamage;
}
/**
* Use this to get the items the player will receive.
* You cannot use this to modify the drops the player will get.
* If you want to affect the loot, you should use LootTables.
*/
public NonNullList<ItemStack> getDrops()
{
return stacks;
}
/**
* Use this to stuff related to the hook itself, like the position of the bobber.
*/
public EntityFishHook getHookEntity()
{
return hook;
}
}

View File

@@ -0,0 +1,85 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class ItemTooltipEvent extends PlayerEvent
{
private final ITooltipFlag flags;
@Nonnull
private final ItemStack itemStack;
private final List<String> toolTip;
/**
* This event is fired in {@link ItemStack#getTooltip(EntityPlayer, ITooltipFlag)}, which in turn is called from it's respective GUIContainer.
* Tooltips are also gathered with a null entityPlayer during startup by {@link Minecraft#populateSearchTreeManager()}.
*/
public ItemTooltipEvent(@Nonnull ItemStack itemStack, @Nullable EntityPlayer entityPlayer, List<String> toolTip, ITooltipFlag flags)
{
super(entityPlayer);
this.itemStack = itemStack;
this.toolTip = toolTip;
this.flags = flags;
}
/**
* Use to determine if the advanced information on item tooltips is being shown, toggled by F3+H.
*/
public ITooltipFlag getFlags()
{
return flags;
}
/**
* The {@link ItemStack} with the tooltip.
*/
@Nonnull
public ItemStack getItemStack()
{
return itemStack;
}
/**
* The {@link ItemStack} tooltip.
*/
public List<String> getToolTip()
{
return toolTip;
}
/**
* This event is fired with a null player during startup when populating search trees for tooltips.
*/
@Override
@Nullable
public EntityPlayer getEntityPlayer()
{
return super.getEntityPlayer();
}
}

View File

@@ -0,0 +1,53 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
public class PlayerContainerEvent extends PlayerEvent
{
private final Container container;
public PlayerContainerEvent(EntityPlayer player, Container container)
{
super(player);
this.container = container;
}
public static class Open extends PlayerContainerEvent
{
public Open(EntityPlayer player, Container container)
{
super(player, container);
}
}
public static class Close extends PlayerContainerEvent
{
public Close(EntityPlayer player, Container container)
{
super(player, container);
}
}
public Container getContainer()
{
return container;
}
}

View File

@@ -0,0 +1,84 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.entity.Entity;
import net.minecraft.server.management.PlayerInteractionManager;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* PlayerDestroyItemEvent is fired when a player destroys an item.<br>
* This event is fired whenever a player destroys an item in
* {@link PlayerControllerMP#onPlayerDestroyBlock(BlockPos)},
* {@link PlayerControllerMP#processRightClick(EntityPlayer, World, EnumHand)},
* {@link PlayerControllerMP#processRightClickBlock(EntityPlayerSP, WorldClient, BlockPos, EnumFacing, Vec3d, EnumHand)},
* {@link EntityPlayer#attackTargetEntityWithCurrentItem(Entity)},
* {@link EntityPlayer#damageShield(float)},
* {@link EntityPlayer#interactOn(Entity, EnumHand)},
* {@link ForgeHooks#getContainerItem(ItemStack)},
* {@link PlayerInteractionManager#processRightClick(EntityPlayer, World, ItemStack, EnumHand)},
* {@link PlayerInteractionManager#processRightClickBlock(EntityPlayer, World, ItemStack, EnumHand, BlockPos, EnumFacing, float, float, float)}
* and {@link PlayerInteractionManager#tryHarvestBlock(BlockPos)}.<br>
* <br>
* {@link #original} contains the original ItemStack before the item was destroyed. <br>
* (@link #hand) contains the hand that the current item was held in.<br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired from {@link ForgeEventFactory#onPlayerDestroyItem(EntityPlayer, ItemStack, EnumHand)}.<br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
public class PlayerDestroyItemEvent extends PlayerEvent
{
@Nonnull
private final ItemStack original;
@Nullable
private final EnumHand hand; // May be null if this player destroys the item by any use besides holding it.
public PlayerDestroyItemEvent(EntityPlayer player, @Nonnull ItemStack original, @Nullable EnumHand hand)
{
super(player);
this.original = original;
this.hand = hand;
}
@Nonnull
public ItemStack getOriginal() { return this.original; }
@Nullable
public EnumHand getHand() { return this.hand; }
}

View File

@@ -0,0 +1,60 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import java.util.List;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.DamageSource;
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
{
private 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, List<EntityItem> drops, boolean recentlyHit)
{
super(entity, source, drops, ForgeHooks.getLootingLevel(entity, source.getTrueSource(), source), recentlyHit);
this.entityPlayer = entity;
}
public EntityPlayer getEntityPlayer()
{
return entityPlayer;
}
}

View File

@@ -0,0 +1,386 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import java.io.File;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.fml.common.eventhandler.Event;
/**
* PlayerEvent is fired whenever an event involving Living entities occurs. <br>
* If a method utilizes this {@link Event} as its parameter, the method will
* receive every child event of this class.<br>
* <br>
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.
**/
public class PlayerEvent extends LivingEvent
{
private final EntityPlayer entityPlayer;
public PlayerEvent(EntityPlayer player)
{
super(player);
entityPlayer = player;
}
public EntityPlayer getEntityPlayer()
{
return entityPlayer;
}
/**
* HarvestCheck is fired when a player attempts to harvest a block.<br>
* This event is fired whenever a player attempts to harvest a block in
* {@link EntityPlayer#canHarvestBlock(IBlockState)}.<br>
* <br>
* This event is fired via the {@link ForgeEventFactory#doPlayerHarvestCheck(EntityPlayer, IBlockState, boolean)}.<br>
* <br>
* {@link #state} contains the {@link IBlockState} that is being checked for harvesting. <br>
* {@link #success} contains the boolean value for whether the Block will be successfully harvested. <br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
public static class HarvestCheck extends PlayerEvent
{
private final IBlockState state;
private boolean success;
public HarvestCheck(EntityPlayer player, IBlockState state, boolean success)
{
super(player);
this.state = state;
this.success = success;
}
public IBlockState getTargetBlock() { return this.state; }
public boolean canHarvest() { return this.success; }
public void setCanHarvest(boolean success){ this.success = success; }
}
/**
* BreakSpeed is fired when a player attempts to harvest a block.<br>
* This event is fired whenever a player attempts to harvest a block in
* {@link EntityPlayer#canHarvestBlock(IBlockState)}.<br>
* <br>
* This event is fired via the {@link ForgeEventFactory#getBreakSpeed(EntityPlayer, IBlockState, float, BlockPos)}.<br>
* <br>
* {@link #state} contains the block being broken. <br>
* {@link #originalSpeed} contains the original speed at which the player broke the block. <br>
* {@link #newSpeed} contains the newSpeed at which the player will break the block. <br>
* {@link #pos} contains the coordinates at which this event is occurring. Y value -1 means location is unknown.<br>
* <br>
* This event is {@link Cancelable}.<br>
* If it is canceled, the player is unable to break the block.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
@Cancelable
public static class BreakSpeed extends PlayerEvent
{
private final IBlockState state;
private final float originalSpeed;
private float newSpeed = 0.0f;
private final BlockPos pos; // Y position of -1 notes unknown location
public BreakSpeed(EntityPlayer player, IBlockState state, float original, BlockPos pos)
{
super(player);
this.state = state;
this.originalSpeed = original;
this.setNewSpeed(original);
this.pos = pos;
}
public IBlockState getState() { return state; }
public float getOriginalSpeed() { return originalSpeed; }
public float getNewSpeed() { return newSpeed; }
public void setNewSpeed(float newSpeed) { this.newSpeed = newSpeed; }
public BlockPos getPos() { return pos; }
}
/**
* NameFormat is fired when a player's display name is retrieved.<br>
* This event is fired whenever a player's name is retrieved in
* {@link EntityPlayer#getDisplayName()} or {@link EntityPlayer#refreshDisplayName()}.<br>
* <br>
* This event is fired via the {@link ForgeEventFactory#getPlayerDisplayName(EntityPlayer, String)}.<br>
* <br>
* {@link #username} contains the username of the player.
* {@link #displayname} contains the display name of the player.
* <br>
* This event is not {@link Cancelable}.
* <br>
* This event does not have a result. {@link HasResult}
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
public static class NameFormat extends PlayerEvent
{
private final String username;
private String displayname;
public NameFormat(EntityPlayer player, String username) {
super(player);
this.username = username;
this.setDisplayname(username);
}
public String getUsername()
{
return username;
}
public String getDisplayname()
{
return displayname;
}
public void setDisplayname(String displayname)
{
this.displayname = displayname;
}
}
/**
* Fired when the EntityPlayer is cloned, typically caused by the network sending a RESPAWN_PLAYER event.
* Either caused by death, or by traveling from the End to the overworld.
*/
public static class Clone extends PlayerEvent
{
private final EntityPlayer original;
private final boolean wasDeath;
public Clone(EntityPlayer _new, EntityPlayer oldPlayer, boolean wasDeath)
{
super(_new);
this.original = oldPlayer;
this.wasDeath = wasDeath;
}
/**
* The old EntityPlayer that this new entity is a clone of.
*/
public EntityPlayer getOriginal()
{
return original;
}
/**
* True if this event was fired because the player died.
* False if it was fired because the entity switched dimensions.
*/
public boolean isWasDeath()
{
return wasDeath;
}
}
/**
* Fired when an Entity is started to be "tracked" by this player (the player receives updates about this entity, e.g. motion).
*
*/
public static class StartTracking extends PlayerEvent {
private final Entity target;
public StartTracking(EntityPlayer player, Entity target)
{
super(player);
this.target = target;
}
/**
* The Entity now being tracked.
*/
public Entity getTarget()
{
return target;
}
}
/**
* Fired when an Entity is stopped to be "tracked" by this player (the player no longer receives updates about this entity, e.g. motion).
*
*/
public static class StopTracking extends PlayerEvent {
private final Entity target;
public StopTracking(EntityPlayer player, Entity target)
{
super(player);
this.target = target;
}
/**
* The Entity no longer being tracked.
*/
public Entity getTarget()
{
return target;
}
}
/**
* The player is being loaded from the world save. Note that the
* player won't have been added to the world yet. Intended to
* allow mods to load an additional file from the players directory
* containing additional mod related player data.
*/
public static class LoadFromFile extends PlayerEvent {
private final File playerDirectory;
private final String playerUUID;
public LoadFromFile(EntityPlayer player, File originDirectory, String playerUUID)
{
super(player);
this.playerDirectory = originDirectory;
this.playerUUID = playerUUID;
}
/**
* Construct and return a recommended file for the supplied suffix
* @param suffix The suffix to use.
* @return
*/
public File getPlayerFile(String suffix)
{
if ("dat".equals(suffix)) throw new IllegalArgumentException("The suffix 'dat' is reserved");
return new File(this.getPlayerDirectory(), this.getPlayerUUID() +"."+suffix);
}
/**
* The directory where player data is being stored. Use this
* to locate your mod additional file.
*/
public File getPlayerDirectory()
{
return playerDirectory;
}
/**
* The UUID is the standard for player related file storage.
* It is broken out here for convenience for quick file generation.
*/
public String getPlayerUUID()
{
return playerUUID;
}
}
/**
* The player is being saved to the world store. Note that the
* player may be in the process of logging out or otherwise departing
* from the world. Don't assume it's association with the world.
* This allows mods to load an additional file from the players directory
* containing additional mod related player data.
* <br>
* Use this event to save the additional mod related player data to the world.
*
* <br>
* <em>WARNING</em>: Do not overwrite the player's .dat file here. You will
* corrupt the world state.
*/
public static class SaveToFile extends PlayerEvent {
private final File playerDirectory;
private final String playerUUID;
public SaveToFile(EntityPlayer player, File originDirectory, String playerUUID)
{
super(player);
this.playerDirectory = originDirectory;
this.playerUUID = playerUUID;
}
/**
* Construct and return a recommended file for the supplied suffix
* @param suffix The suffix to use.
* @return
*/
public File getPlayerFile(String suffix)
{
if ("dat".equals(suffix)) throw new IllegalArgumentException("The suffix 'dat' is reserved");
return new File(this.getPlayerDirectory(), this.getPlayerUUID() +"."+suffix);
}
/**
* The directory where player data is being stored. Use this
* to locate your mod additional file.
*/
public File getPlayerDirectory()
{
return playerDirectory;
}
/**
* The UUID is the standard for player related file storage.
* It is broken out here for convenience for quick file generation.
*/
public String getPlayerUUID()
{
return playerUUID;
}
}
/**
* Fired when the world checks if a player is near enough to be attacked by an entity.
* The resulting visibility modifier is multiplied by the one calculated by Minecraft (based on sneaking and more) and used to calculate the radius a player has to be in (targetDistance*modifier).
* This can also be used to increase the visibility of a player, if it was decreased by Minecraft or other mods. But the resulting value cannot be higher than the standard target distance.
*/
public static class Visibility extends PlayerEvent
{
private double visibilityModifier = 1D;
public Visibility(EntityPlayer player)
{
super(player);
}
/**
* @param mod Is multiplied with the current modifier
*/
public void modifyVisibility(double mod)
{
visibilityModifier *= mod;
}
/**
* @return The current modifier
*/
public double getVisibilityModifier()
{
return visibilityModifier;
}
}
}

View File

@@ -0,0 +1,45 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import net.minecraft.entity.player.EntityPlayer;
/**
* 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
{
private float distance;
private float multiplier;
public PlayerFlyableFallEvent(EntityPlayer player, float distance, float multiplier)
{
super(player);
this.distance = distance;
this.multiplier = multiplier;
}
public float getDistance() { return distance;}
public void setDistance(float distance) { this.distance = distance; }
public float getMultiplier() { return multiplier; }
public void setMultiplier(float multiplier) { this.multiplier = multiplier; }
}

View File

@@ -0,0 +1,401 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import com.google.common.base.Preconditions;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.relauncher.Side;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static net.minecraftforge.fml.common.eventhandler.Event.Result.DEFAULT;
import static net.minecraftforge.fml.common.eventhandler.Event.Result.DENY;
import net.minecraftforge.fml.common.eventhandler.Event.Result;
/**
* PlayerInteractEvent is fired when a player interacts in some way.
* All subclasses are fired on {@link MinecraftForge#EVENT_BUS}.
* See the individual documentation on each subevent for more details.
**/
public class PlayerInteractEvent extends PlayerEvent
{
private final EnumHand hand;
private final BlockPos pos;
@Nullable
private final EnumFacing face;
private EnumActionResult cancellationResult = EnumActionResult.PASS;
private PlayerInteractEvent(EntityPlayer player, EnumHand hand, BlockPos pos, @Nullable EnumFacing face)
{
super(Preconditions.checkNotNull(player, "Null player in PlayerInteractEvent!"));
this.hand = Preconditions.checkNotNull(hand, "Null hand in PlayerInteractEvent!");
this.pos = Preconditions.checkNotNull(pos, "Null position in PlayerInteractEvent!");
this.face = face;
}
/**
* This event is fired on both sides whenever a player right clicks an entity.
*
* "Interact at" is an interact where the local vector (which part of the entity you clicked) is known.
* The state of this event affects whether {@link Entity#applyPlayerInteraction} is called.
*
* Let result be the return value of {@link Entity#applyPlayerInteraction}, or {@link #cancellationResult} if the event is cancelled.
* If we are on the client and result is not {@link EnumActionResult#SUCCESS}, the client will then try {@link EntityInteract}.
*/
@Cancelable
public static class EntityInteractSpecific extends PlayerInteractEvent
{
private final Vec3d localPos;
private final Entity target;
public EntityInteractSpecific(EntityPlayer player, EnumHand hand, Entity target, Vec3d localPos)
{
super(player, hand, new BlockPos(target), null);
this.localPos = localPos;
this.target = target;
}
/**
* Returns the local interaction position. This is a 3D vector, where (0, 0, 0) is centered exactly at the
* center of the entity's bounding box at their feet. This means the X and Z values will be in the range
* [-width / 2, width / 2] while Y values will be in the range [0, height]
* @return The local position
*/
public Vec3d getLocalPos()
{
return localPos;
}
public Entity getTarget()
{
return target;
}
}
/**
* This event is fired on both sides when the player right clicks an entity.
* It is responsible for all general entity interactions.
*
* This event is fired only if the result of the above {@link EntityInteractSpecific} is not {@link EnumActionResult#SUCCESS}.
* This event's state affects whether {@link Entity#processInitialInteract} and {@link net.minecraft.item.Item#itemInteractionForEntity} are called.
*
* Let result be {@link EnumActionResult#SUCCESS} if {@link Entity#processInitialInteract} or {@link net.minecraft.item.Item#itemInteractionForEntity} return true,
* or {@link #cancellationResult} if the event is cancelled.
* If we are on the client and result is not {@link EnumActionResult#SUCCESS}, the client will then try {@link RightClickItem}.
*/
@Cancelable
public static class EntityInteract extends PlayerInteractEvent
{
private final Entity target;
public EntityInteract(EntityPlayer player, EnumHand hand, Entity target)
{
super(player, hand, new BlockPos(target), null);
this.target = target;
}
public Entity getTarget()
{
return target;
}
}
/**
* This event is fired on both sides whenever the player right clicks while targeting a block.
* This event controls which of {@link net.minecraft.block.Block#onBlockActivated} and/or {@link net.minecraft.item.Item#onItemUse}
* will be called after {@link net.minecraft.item.Item#onItemUseFirst} is called.
* Canceling the event will cause none of the above three to be called
*
* Let result be a return value of the above three methods, or {@link #cancellationResult} if the event is cancelled.
* If we are on the client and result is not {@link EnumActionResult#SUCCESS}, the client will then try {@link RightClickItem}.
*
* There are various results to this event, see the getters below.
* Note that handling things differently on the client vs server may cause desynchronizations!
*/
@Cancelable
public static class RightClickBlock extends PlayerInteractEvent
{
private Result useBlock = DEFAULT;
private Result useItem = DEFAULT;
private final Vec3d hitVec;
public RightClickBlock(EntityPlayer player, EnumHand hand, BlockPos pos, EnumFacing face, Vec3d hitVec) {
super(player, hand, pos, face);
this.hitVec = hitVec;
}
/**
* @return The hit vector of this click
*/
public Vec3d getHitVec()
{
return hitVec;
}
/**
* @return If {@link net.minecraft.block.Block#onBlockActivated} should be called
*/
public Result getUseBlock()
{
return useBlock;
}
/**
* @return If {@link net.minecraft.item.Item#onItemUseFirst} and {@link net.minecraft.item.Item#onItemUse} should be called
*/
public Result getUseItem()
{
return useItem;
}
/**
* DENY: Block will never be used.
* DEFAULT: Default behaviour (sneak will not use block, unless all items return true in {@link net.minecraft.item.Item#doesSneakBypassUse}).
* ALLOW: Block will always be used, regardless of sneaking and doesSneakBypassUse.
*/
public void setUseBlock(Result triggerBlock)
{
this.useBlock = triggerBlock;
}
/**
* DENY: The item will never be used.
* DEFAULT: The item will be used if the block fails.
* ALLOW: The item will always be used.
*/
public void setUseItem(Result triggerItem)
{
this.useItem = triggerItem;
}
@Override
public void setCanceled(boolean canceled)
{
super.setCanceled(canceled);
if (canceled)
{
useBlock = DENY;
useItem = DENY;
}
}
}
/**
* This event is fired on both sides before the player triggers {@link net.minecraft.item.Item#onItemRightClick}.
* Note that this is NOT fired if the player is targeting a block {@link RightClickBlock} or entity {@link EntityInteract} {@link EntityInteractSpecific}.
*
* Let result be the return value of {@link net.minecraft.item.Item#onItemRightClick}, or {@link #cancellationResult} if the event is cancelled.
* If we are on the client and result is not {@link EnumActionResult#SUCCESS}, the client will then continue to other hands.
*/
@Cancelable
public static class RightClickItem extends PlayerInteractEvent
{
public RightClickItem(EntityPlayer player, EnumHand hand)
{
super(player, hand, new BlockPos(player), null);
}
}
/**
* This event is fired on the client side when the player right clicks empty space with an empty hand.
* The server is not aware of when the client right clicks empty space with an empty hand, you will need to tell the server yourself.
* This event cannot be canceled.
*/
public static class RightClickEmpty extends PlayerInteractEvent
{
public RightClickEmpty(EntityPlayer player, EnumHand hand)
{
super(player, hand, new BlockPos(player), null);
}
}
/**
* This event is fired when a player left clicks while targeting a block.
* This event controls which of {@link net.minecraft.block.Block#onBlockClicked} and/or the item harvesting methods will be called
* Canceling the event will cause none of the above noted methods to be called.
* There are various results to this event, see the getters below.
*
* Note that if the event is canceled and the player holds down left mouse, the event will continue to fire.
* This is due to how vanilla calls the left click handler methods.
*
* Also note that creative mode directly breaks the block without running any other logic.
* Therefore, in creative mode, {@link #setUseBlock} and {@link #setUseItem} have no effect.
*/
@Cancelable
public static class LeftClickBlock extends PlayerInteractEvent
{
private Result useBlock = DEFAULT;
private Result useItem = DEFAULT;
private final Vec3d hitVec;
public LeftClickBlock(EntityPlayer player, BlockPos pos, EnumFacing face, Vec3d hitVec)
{
super(player, EnumHand.MAIN_HAND, pos, face);
this.hitVec = hitVec;
}
/**
* @return The local hit vector of this click
*/
public Vec3d getHitVec()
{
return hitVec;
}
/**
* @return If {@link net.minecraft.block.Block#onBlockClicked} should be called. Changing this has no effect in creative mode
*/
public Result getUseBlock()
{
return useBlock;
}
/**
* @return If the block should be attempted to be mined with the current item. Changing this has no effect in creative mode
*/
public Result getUseItem()
{
return useItem;
}
public void setUseBlock(Result triggerBlock)
{
this.useBlock = triggerBlock;
}
public void setUseItem(Result triggerItem)
{
this.useItem = triggerItem;
}
@Override
public void setCanceled(boolean canceled)
{
super.setCanceled(canceled);
if (canceled)
{
useBlock = DENY;
useItem = DENY;
}
}
}
/**
* This event is fired on the client side when the player left clicks empty space with any ItemStack.
* The server is not aware of when the client left clicks empty space, you will need to tell the server yourself.
* This event cannot be canceled.
*/
public static class LeftClickEmpty extends PlayerInteractEvent
{
public LeftClickEmpty(EntityPlayer player)
{
super(player, EnumHand.MAIN_HAND, new BlockPos(player), null);
}
}
/**
* @return The hand involved in this interaction. Will never be null.
*/
@Nonnull
public EnumHand getHand()
{
return hand;
}
/**
* @return The itemstack involved in this interaction, {@code ItemStack.EMPTY} if the hand was empty.
*/
@Nonnull
public ItemStack getItemStack()
{
return getEntityPlayer().getHeldItem(hand);
}
/**
* If the interaction was on an entity, will be a BlockPos centered on the entity.
* If the interaction was on a block, will be the position of that block.
* Otherwise, will be a BlockPos centered on the player.
* Will never be null.
* @return The position involved in this interaction.
*/
@Nonnull
public BlockPos getPos()
{
return pos;
}
/**
* @return The face involved in this interaction. For all non-block interactions, this will return null.
*/
@Nullable
public EnumFacing getFace()
{
return face;
}
/**
* @return Convenience method to get the world of this interaction.
*/
public World getWorld()
{
return getEntityPlayer().getEntityWorld();
}
/**
* @return The effective, i.e. logical, side of this interaction. This will be {@link Side#CLIENT} on the client thread, and {@link Side#SERVER} on the server thread.
*/
public Side getSide()
{
return getWorld().isRemote ? Side.CLIENT : Side.SERVER;
}
/**
* @return The EnumActionResult that will be returned to vanilla if the event is cancelled, instead of calling the relevant
* method of the event. By default, this is {@link EnumActionResult#PASS}, meaning cancelled events will cause
* the client to keep trying more interactions until something works.
*/
public EnumActionResult getCancellationResult()
{
return cancellationResult;
}
/**
* Set the EnumActionResult that will be returned to vanilla if the event is cancelled, instead of calling the relevant
* method of the event.
* Note that this only has an effect on {@link RightClickBlock}, {@link RightClickItem}, {@link EntityInteract}, and {@link EntityInteractSpecific}.
*/
public void setCancellationResult(EnumActionResult result)
{
this.cancellationResult = result;
}
}

View File

@@ -0,0 +1,45 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.player.EntityPlayer;
/**
* This event is called when a player collides with a EntityXPOrb on the ground.
* The event can be canceled, and no further processing will be done.
*/
@Cancelable
public class PlayerPickupXpEvent extends PlayerEvent
{
private final EntityXPOrb orb;
public PlayerPickupXpEvent(EntityPlayer player, EntityXPOrb orb)
{
super(player);
this.orb = orb;
}
public EntityXPOrb getOrb()
{
return orb;
}
}

View File

@@ -0,0 +1,51 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
@Cancelable
public class PlayerSetSpawnEvent extends PlayerEvent
{
private final boolean forced;
private final BlockPos newSpawn;
public PlayerSetSpawnEvent(EntityPlayer player, BlockPos newSpawn, boolean forced) {
super(player);
this.newSpawn = newSpawn;
this.forced = forced;
}
/**
* This event is called before a player's spawn point is changed.
* The event can be canceled, and no further processing will be done.
*/
public boolean isForced()
{
return forced;
}
public BlockPos getNewSpawn()
{
return newSpawn;
}
}

View File

@@ -0,0 +1,67 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayer.SleepResult;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
/**
* PlayerSleepInBedEvent is fired when a player sleeps in a bed.
* <br>
* This event is fired whenever a player sleeps in a bed in
* {@link EntityPlayer#trySleep(BlockPos)}.<br>
* <br>
* {@link #result} contains whether the player is able to sleep. <br>
* <br>
* This event is not {@link Cancelable}.
* <br>
* This event does not have a result. {@link HasResult}
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
public class PlayerSleepInBedEvent extends PlayerEvent
{
private SleepResult result = null;
private final BlockPos pos;
public PlayerSleepInBedEvent(EntityPlayer player, BlockPos pos)
{
super(player);
this.pos = pos;
}
public SleepResult getResultStatus()
{
return result;
}
public void setResult(SleepResult result)
{
this.result = result;
}
public BlockPos getPos()
{
return pos;
}
}

View File

@@ -0,0 +1,62 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import net.minecraft.entity.player.EntityPlayer;
/**
* This event is fired when the player is waking up.<br/>
* This is merely for purposes of listening for this to happen.<br/>
* There is nothing that can be manipulated with this event.
*/
public class PlayerWakeUpEvent extends PlayerEvent
{
private final boolean wakeImmediately;
private final boolean updateWorld;
private final boolean setSpawn;
public PlayerWakeUpEvent(EntityPlayer player, boolean wakeImmediately, boolean updateWorld, boolean setSpawn)
{
super(player);
this.wakeImmediately = wakeImmediately;
this.updateWorld = updateWorld;
this.setSpawn = setSpawn;
}
/**
* Used for the 'wake up animation'.
* This is false if the player is considered 'sleepy' and the overlay should slowly fade away.
*/
public boolean wakeImmediately() { return wakeImmediately; }
/**
* Indicates if the server should be notified of sleeping changes.
* This will only be false if the server is considered 'up to date' already, because, for example, it initiated the call.
*/
public boolean updateWorld() { return updateWorld; }
/**
* Indicates if the player's sleep was considered successful.
* In vanilla, this is used to determine if the spawn chunk is to be set to the bed's position.
*/
public boolean shouldSetSpawn() { return setSpawn; }
}

View File

@@ -0,0 +1,55 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
/**
* This event is fired when game checks, if sleeping player should be still considered "in bed".<br>
* Failing this check will cause player to wake up.<br>
*
* This event has a result. {@link HasResult}<br>
*
* setResult(ALLOW) informs game that player is still "in bed"<br>
* setResult(DEFAULT) causes game to check {@link Block#isBed(IBlockState, IBlockAccess, BlockPos, Entity)} instead
*/
@HasResult
public class SleepingLocationCheckEvent extends PlayerEvent
{
private final BlockPos sleepingLocation;
public SleepingLocationCheckEvent(EntityPlayer player, BlockPos sleepingLocation)
{
super(player);
this.sleepingLocation = sleepingLocation;
}
public BlockPos getSleepingLocation()
{
return sleepingLocation;
}
}

View File

@@ -0,0 +1,72 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import javax.annotation.Nonnull;
/**
* 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 setHandled();
*/
@Cancelable
@Event.HasResult
public class UseHoeEvent extends PlayerEvent
{
private final ItemStack current;
private final World world;
private final BlockPos pos;
public UseHoeEvent(EntityPlayer player, @Nonnull ItemStack current, World world, BlockPos pos)
{
super(player);
this.current = current;
this.world = world;
this.pos = pos;
}
@Nonnull
public ItemStack getCurrent()
{
return current;
}
public World getWorld()
{
return world;
}
public BlockPos getPos()
{
return pos;
}
}

View File

@@ -0,0 +1,86 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.furnace;
import javax.annotation.Nonnull;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
/**
* {@link FurnaceFuelBurnTimeEvent} is fired when determining the fuel value for an ItemStack. <br>
* <br>
* To set the burn time of your own item, use {@link Item#getItemBurnTime(ItemStack)} instead.<br>
* <br>
* This event is fired from {@link ForgeEventFactory#getItemBurnTime(ItemStack)}.<br>
* <br>
* This event is {@link Cancelable} to prevent later handlers from changing the value.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
@Cancelable
public class FurnaceFuelBurnTimeEvent extends Event
{
@Nonnull
private final ItemStack itemStack;
private int burnTime;
public FurnaceFuelBurnTimeEvent(@Nonnull ItemStack itemStack, int burnTime)
{
this.itemStack = itemStack;
this.burnTime = burnTime;
}
/**
* Get the ItemStack "fuel" in question.
*/
@Nonnull
public ItemStack getItemStack()
{
return itemStack;
}
/**
* Set the burn time for the given ItemStack.
* Setting it to 0 will prevent the item from being used as fuel, overriding vanilla's decision.
* Setting it to -1 will let vanilla decide on the fuel value, this is the default.
*/
public void setBurnTime(int burnTime)
{
this.burnTime = burnTime;
setCanceled(true);
}
/**
* The resulting value of this event, the burn time for the ItemStack.
* A value of 0 will prevent the item from being used as fuel, overriding vanilla's decision.
* A value of -1 will let vanilla decide on the fuel value, this is the default for {@link Item#getItemBurnTime(ItemStack)}.
*/
public int getBurnTime()
{
return burnTime;
}
}

View File

@@ -0,0 +1,196 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.terraingen;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.block.state.IBlockState;
import net.minecraft.world.biome.BiomeDecorator;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
/**
* BiomeEvent is fired whenever an event involving biomes occurs.<br>
* If a method utilizes this {@link Event} as its parameter, the method will
* receive every child event of this class.<br>
* <br>
* All children of this event are fired on the {@link MinecraftForge#TERRAIN_GEN_BUS}
* unless stated otherwise in their Javadocs.
**/
public class BiomeEvent extends Event
{
private final Biome biome;
public BiomeEvent(Biome biome)
{
this.biome = biome;
}
public Biome getBiome()
{
return biome;
}
/**
* CreateDecorator is fired when a BiomeDecorator is created.<br>
* This event is fired whenever a BiomeDecorator is created in
* {@link DeferredBiomeDecorator#fireCreateEventAndReplace(Biome)}.<br>
* <br>
* {@link #originalBiomeDecorator} contains the original BiomeDecorator that would be used in vanilla.
* {@link #newBiomeDecorator} contains the new BiomeDecoration to be used by Minecraft.
* <br>
* This event is not {@link Cancelable}.
* <br>
* This event does not have a result. {@link HasResult}
* <br>
* This event is fired on the {@link MinecraftForge#TERRAIN_GEN_BUS}.
**/
public static class CreateDecorator extends BiomeEvent
{
private final BiomeDecorator originalBiomeDecorator;
private BiomeDecorator newBiomeDecorator;
public CreateDecorator(Biome biome, BiomeDecorator original)
{
super(biome);
originalBiomeDecorator = original;
setNewBiomeDecorator(original);
}
public BiomeDecorator getOriginalBiomeDecorator()
{
return originalBiomeDecorator;
}
public BiomeDecorator getNewBiomeDecorator()
{
return newBiomeDecorator;
}
public void setNewBiomeDecorator(BiomeDecorator newBiomeDecorator)
{
this.newBiomeDecorator = newBiomeDecorator;
}
}
/**
* BiomeColor is fired whenever an event involving biome colors occurs. <br>
* If a method utilizes this {@link Event} as its parameter, the method will
* receive every child event of this class.<br>
* <br>
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.
**/
public static class BiomeColor extends BiomeEvent
{
private final int originalColor;
private int newColor;
public BiomeColor(Biome biome, int original)
{
super(biome);
originalColor = original;
setNewColor(original);
}
public int getOriginalColor()
{
return originalColor;
}
public int getNewColor()
{
return newColor;
}
public void setNewColor(int newColor)
{
this.newColor = newColor;
}
}
/**
* This event is fired when the village generator attempts to choose a block ID
* based on the village's biome.
*
* You can cancel the event to override default values
*/
@HasResult
public static class GetVillageBlockID extends BiomeEvent
{
private final IBlockState original;
private IBlockState replacement;
public GetVillageBlockID(Biome biome, IBlockState original)
{
super(biome);
this.original = original;
}
public IBlockState getOriginal()
{
return original;
}
public IBlockState getReplacement()
{
return replacement;
}
public void setReplacement(IBlockState replacement)
{
this.replacement = replacement;
}
}
/**
* This event is fired when a biome is queried for its grass color.
*/
public static class GetGrassColor extends BiomeColor
{
public GetGrassColor(Biome 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(Biome 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(Biome biome, int original)
{
super(biome, original);
}
}
}

View File

@@ -0,0 +1,111 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.terraingen;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.world.World;
import net.minecraft.world.chunk.ChunkPrimer;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
public class ChunkGeneratorEvent extends Event
{
private final IChunkGenerator gen;
public ChunkGeneratorEvent(IChunkGenerator gen)
{
this.gen = gen;
}
public IChunkGenerator getGenerator() { return this.getGen(); }
public IChunkGenerator getGen()
{
return gen;
}
/**
* 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 ChunkGeneratorEvent
{
private final int x;
private final int z;
private final ChunkPrimer primer;
private final World world; // CAN BE NULL
public ReplaceBiomeBlocks(IChunkGenerator chunkProvider, int x, int z, ChunkPrimer primer, World world)
{
super(chunkProvider);
this.x = x;
this.z = z;
this.primer = primer;
this.world = world;
}
public int getX() { return x; }
public int getZ() { return z; }
public ChunkPrimer getPrimer() { return primer; }
public World getWorld() { return world; }
}
/**
* 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 ChunkGeneratorEvent
{
private double[] noisefield;
private final int posX;
private final int posY;
private final int posZ;
private final int sizeX;
private final int sizeY;
private final int sizeZ;
public InitNoiseField(IChunkGenerator chunkProvider, double[] noisefield, int posX, int posY, int posZ, int sizeX, int sizeY, int sizeZ)
{
super(chunkProvider);
this.setNoisefield(noisefield);
this.posX = posX;
this.posY = posY;
this.posZ = posZ;
this.sizeX = sizeX;
this.sizeY = sizeY;
this.sizeZ = sizeZ;
}
public double[] getNoisefield() { return noisefield; }
public void setNoisefield(double[] noisefield) { this.noisefield = noisefield; }
public int getPosX() { return posX; }
public int getPosY() { return posY; }
public int getPosZ() { return posZ; }
public int getSizeX() { return sizeX; }
public int getSizeY() { return sizeY; }
public int getSizeZ() { return sizeZ; }
}
}

View File

@@ -0,0 +1,188 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.terraingen;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
/**
* DecorateBiomeEvent is fired when a BiomeDecorator is created.
* <br>
* This event is fired whenever a BiomeDecorator is created in
* {@link DeferredBiomeDecorator#fireCreateEventAndReplace(Biome)}.<br>
* <br>
* {@link #world} contains the world that is being decorated. <br>
* {@link #rand} contains an instance of Random to be used. <br>
* {@link #chunkPos} contains the original chunk for the decorator. <br>
* <br>
* This event is not {@link Cancelable}.
* <br>
* This event does not have a result. {@link HasResult}
* <br>
* This event is fired on the {@link MinecraftForge#TERRAIN_GEN_BUS}.
**/
public class DecorateBiomeEvent extends Event
{
private final World world;
private final Random rand;
/** @deprecated use {@link #chunkPos} */
@Deprecated // TODO remove in 1.13
private final BlockPos pos;
private final ChunkPos chunkPos;
public DecorateBiomeEvent(World world, Random rand, ChunkPos chunkPos)
{
this.world = world;
this.rand = rand;
this.pos = chunkPos.getBlock(0, 0, 0);
this.chunkPos = chunkPos;
}
@Deprecated // TODO: remove in 1.13
public DecorateBiomeEvent(World world, Random rand, BlockPos pos)
{
this.world = world;
this.rand = rand;
this.pos = pos;
this.chunkPos = new ChunkPos(pos);
}
public World getWorld()
{
return world;
}
public Random getRand()
{
return rand;
}
/**
* @deprecated use {@link #getChunkPos()} or {@link Decorate#getPlacementPos} instead.
*/
@Deprecated
public BlockPos getPos()
{
return pos;
}
public ChunkPos getChunkPos()
{
return chunkPos;
}
/**
* This event is fired before a chunk is decorated with a biome feature.
*/
public static class Pre extends DecorateBiomeEvent
{
public Pre(World world, Random rand, ChunkPos chunkPos)
{
super(world, rand, chunkPos);
}
@Deprecated // TODO: remove in 1.13
public Pre(World world, Random rand, BlockPos pos)
{
this(world, rand, new ChunkPos(pos));
}
}
/**
* This event is fired after a chunk is decorated with a biome feature.
*/
public static class Post extends DecorateBiomeEvent
{
public Post(World world, Random rand, ChunkPos chunkPos)
{
super(world, rand, chunkPos);
}
@Deprecated //TODO: remove in 1.13
public Post(World world, Random rand, BlockPos pos)
{
this(world, rand, new ChunkPos(pos));
}
}
/**
* This event is fired when a chunk is decorated with a biome feature.
* <p>
* You can set the result to DENY to prevent the default biome decoration.
*/
@HasResult
public static class Decorate extends DecorateBiomeEvent
{
/**
* Use {@link EventType#CUSTOM} to filter custom event types
*/
public enum EventType
{
BIG_SHROOM, CACTUS, CLAY, DEAD_BUSH, DESERT_WELL, LILYPAD, FLOWERS, FOSSIL, GRASS, ICE, LAKE_WATER, LAKE_LAVA, PUMPKIN, REED, ROCK, SAND, SAND_PASS2, SHROOM, TREE, CUSTOM
}
private final EventType type;
@Nullable
private final BlockPos placementPos;
public Decorate(World world, Random rand, ChunkPos chunkPos, @Nullable BlockPos placementPos, EventType type)
{
super(world, rand, chunkPos);
this.type = type;
this.placementPos = placementPos;
}
@Deprecated // TODO: remove in 1.13
public Decorate(World world, Random rand, BlockPos pos, EventType type)
{
super(world, rand, pos);
this.type = type;
this.placementPos = null;
}
public EventType getType()
{
return type;
}
/**
* This may be anywhere inside the 2x2 chunk area for generation.
* To get the original chunk position of the generation before a random location was chosen, use {@link #getChunkPos()}.
*
* @return the position used for original decoration, or null if it is not specified.
*/
@Nullable
public BlockPos getPlacementPos()
{
return this.placementPos;
}
}
}

View File

@@ -0,0 +1,65 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.terraingen;
import java.util.Random;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeDecorator;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.MinecraftForge;
public class DeferredBiomeDecorator extends BiomeDecorator {
private BiomeDecorator wrapped;
public DeferredBiomeDecorator(BiomeDecorator wrappedOriginal)
{
this.wrapped = wrappedOriginal;
}
@Override
public void decorate(World par1World, Random par2Random, Biome biome, BlockPos pos)
{
fireCreateEventAndReplace(biome);
// On first call to decorate, we fire and substitute ourselves, if we haven't already done so
biome.decorator.decorate(par1World, par2Random, biome, pos);
}
public void fireCreateEventAndReplace(Biome biome)
{
// 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.generateFalls = generateFalls;
wrapped.grassPerChunk = grassPerChunk;
wrapped.mushroomsPerChunk = mushroomsPerChunk;
wrapped.reedsPerChunk = reedsPerChunk;
wrapped.gravelPatchesPerChunk = gravelPatchesPerChunk;
wrapped.sandPatchesPerChunk = sandPatchesPerChunk;
wrapped.treesPerChunk = treesPerChunk;
wrapped.waterlilyPerChunk = waterlilyPerChunk;
BiomeEvent.CreateDecorator event = new BiomeEvent.CreateDecorator(biome, wrapped);
MinecraftForge.TERRAIN_GEN_BUS.post(event);
biome.decorator = event.getNewBiomeDecorator();
}
}

View File

@@ -0,0 +1,45 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.terraingen;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.world.gen.MapGenBase;
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, OCEAN_MONUMENT, WOODLAND_MANSION, END_CITY, CUSTOM }
private final EventType type;
private final MapGenBase originalGen;
private MapGenBase newGen;
InitMapGenEvent(EventType type, MapGenBase original)
{
this.type = type;
this.originalGen = original;
this.setNewGen(original);
}
public EventType getType() { return type; }
public MapGenBase getOriginalGen() { return originalGen; }
public MapGenBase getNewGen() { return newGen; }
public void setNewGen(MapGenBase newGen) { this.newGen = newGen; }
}

View File

@@ -0,0 +1,135 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.terraingen;
import java.util.Random;
import net.minecraft.world.World;
import net.minecraft.world.gen.NoiseGeneratorOctaves;
import net.minecraft.world.gen.NoiseGeneratorPerlin;
import net.minecraft.world.gen.NoiseGeneratorSimplex;
import net.minecraftforge.event.world.WorldEvent;
public class InitNoiseGensEvent<T extends InitNoiseGensEvent.Context> extends WorldEvent
{
private final Random rand;
private final T original;
private T newValues;
@SuppressWarnings("unchecked")
public InitNoiseGensEvent(World world, Random rand, T original)
{
super(world);
this.rand = rand;
this.original = original;
this.newValues = (T)original.clone();
}
public Random getRandom() { return this.rand; }
public T getOriginal() { return this.original; }
public T getNewValues() { return this.newValues; }
public static class Context
{
private NoiseGeneratorOctaves lperlin1;
private NoiseGeneratorOctaves lperlin2;
private NoiseGeneratorOctaves perlin;
private NoiseGeneratorOctaves scale;
private NoiseGeneratorOctaves depth;
public Context(NoiseGeneratorOctaves lperlin1, NoiseGeneratorOctaves lperlin2, NoiseGeneratorOctaves perlin,
NoiseGeneratorOctaves scale, NoiseGeneratorOctaves depth)
{
this.lperlin1 = lperlin1;
this.lperlin2 = lperlin2;
this.perlin = perlin;
this.scale = scale;
this.depth = depth;
}
public NoiseGeneratorOctaves getLPerlin1() { return lperlin1; }
public NoiseGeneratorOctaves getLPerlin2() { return lperlin2; }
public NoiseGeneratorOctaves getPerlin() { return perlin; }
public NoiseGeneratorOctaves getScale() { return scale; }
public NoiseGeneratorOctaves getDepth() { return depth; }
public void setLPerlin1(NoiseGeneratorOctaves value) { this.lperlin1 = value; }
public void getLPerlin2(NoiseGeneratorOctaves value) { this.lperlin2 = value; }
public void getPerlin (NoiseGeneratorOctaves value) { this.perlin = value; }
public void getScale (NoiseGeneratorOctaves value) { this.scale = value; }
public void getDepth (NoiseGeneratorOctaves value) { this.depth = value; }
@Override
public Context clone(){ return new Context(lperlin1, lperlin2, perlin, scale, depth); }
}
public static class ContextOverworld extends Context
{
private NoiseGeneratorPerlin height;
private NoiseGeneratorOctaves forest;
public ContextOverworld(NoiseGeneratorOctaves lperlin1, NoiseGeneratorOctaves lperlin2, NoiseGeneratorOctaves perlin,
NoiseGeneratorPerlin height, NoiseGeneratorOctaves scale, NoiseGeneratorOctaves depth, NoiseGeneratorOctaves forest)
{
super(lperlin1, lperlin2, perlin, scale, depth);
this.height = height;
this.forest = forest;
}
@Override
public ContextOverworld clone() { return new ContextOverworld(getLPerlin1(), getLPerlin2(), getPerlin(), height, getScale(), getDepth(), forest); }
public NoiseGeneratorPerlin getHeight() { return height; }
public NoiseGeneratorOctaves getForest() { return forest; }
public void getHeight (NoiseGeneratorPerlin value) { this.height = value; }
public void getForest (NoiseGeneratorOctaves value) { this.forest = value; }
}
public static class ContextEnd extends Context
{
private NoiseGeneratorSimplex island;
public ContextEnd(NoiseGeneratorOctaves lperlin1, NoiseGeneratorOctaves lperlin2, NoiseGeneratorOctaves perlin,
NoiseGeneratorOctaves scale, NoiseGeneratorOctaves depth, NoiseGeneratorSimplex island)
{
super(lperlin1, lperlin2, perlin, scale, depth);
this.island = island;
}
@Override
public ContextEnd clone() { return new ContextEnd(getLPerlin1(), getLPerlin2(), getPerlin(), getScale(), getDepth(), island); }
public NoiseGeneratorSimplex getIsland() { return island; }
public void getIsland (NoiseGeneratorSimplex value) { this.island = value; }
}
public static class ContextHell extends Context
{
private NoiseGeneratorOctaves perlin2;
private NoiseGeneratorOctaves perlin3;
public ContextHell(NoiseGeneratorOctaves lperlin1, NoiseGeneratorOctaves lperlin2, NoiseGeneratorOctaves perlin,
NoiseGeneratorOctaves perlin2, NoiseGeneratorOctaves perlin3, NoiseGeneratorOctaves scale, NoiseGeneratorOctaves depth)
{
super(lperlin1, lperlin2, perlin, scale, depth);
this.perlin2 = perlin2;
this.perlin3 = perlin3;
}
@Override
public ContextHell clone() { return new ContextHell(getLPerlin1(), getLPerlin2(), getPerlin(), perlin2, perlin3, getScale(), getDepth()); }
public NoiseGeneratorOctaves getPerlin2() { return perlin2; }
public NoiseGeneratorOctaves getPerlin3() { return perlin3; }
public void getPerlin2 (NoiseGeneratorOctaves value) { this.perlin2 = value; }
public void getPerlin3 (NoiseGeneratorOctaves value) { this.perlin3 = value; }
}
}

View File

@@ -0,0 +1,150 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.terraingen;
import java.util.Random;
import net.minecraft.world.biome.BiomeDecorator;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;
/**
* OreGenEvent is fired when an event involving ore generation occurs.<br>
* If a method utilizes this {@link Event} as its parameter, the method will
* receive every child event of this class.<br>
* <br>
* {@link #world} contains the world this event is occurring in.<br>
* {@link #rand} contains an instance of random that can be used in this event.<br>
* {@link #pos} contains the coordinates of the chunk position currently being populated with ores.<br>
* <br>
* All children of this event are fired on the {@link MinecraftForge#ORE_GEN_BUS}.<br>
**/
public class OreGenEvent extends Event
{
private final World world;
private final Random rand;
private final BlockPos pos;
public OreGenEvent(World world, Random rand, BlockPos pos)
{
this.world = world;
this.rand = rand;
this.pos = pos;
}
public World getWorld()
{
return world;
}
public Random getRand()
{
return rand;
}
public BlockPos getPos()
{
return pos;
}
/**
* OreGenEvent.Pre is fired just before a chunk is populated with ores.<br>
* This event is fired just before ore generation in
* {@link BiomeDecorator#generateOres(World, Random)}.<br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
* This event is fired on the {@link MinecraftForge#ORE_GEN_BUS}.<br>
**/
public static class Pre extends OreGenEvent
{
public Pre(World world, Random rand, BlockPos pos)
{
super(world, rand, pos);
}
}
/**
* OreGenEvent.Post is fired just after a chunk is populated with ores.<br>
* This event is fired just after ore generation in
* {@link BiomeDecorator#generateOres(World, Random)}.<br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
* This event is fired on the {@link MinecraftForge#ORE_GEN_BUS}.<br>
**/
public static class Post extends OreGenEvent
{
public Post(World world, Random rand, BlockPos pos)
{
super(world, rand, pos);
}
}
/**
* GenerateMinable is fired when a mineable block is generated in a chunk.<br>
* This event is fired just after ore generation in
* {@link BiomeDecorator#generateOres(World, Random)}.<br>
* <br>
* {@link #type} contains the enum value for the Ore attempting to be generated.<br>
* {@link #generator} contains the WorldGenerator generating this ore. <br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event has a result. {@link HasResult} <br>
* This result determines whether the ore is allowed to be generated.<br>
* <br>
* This event is fired on the {@link MinecraftForge#ORE_GEN_BUS}.<br>
**/
@HasResult
public static class GenerateMinable extends OreGenEvent
{
public static enum EventType { COAL, DIAMOND, DIRT, GOLD, GRAVEL, IRON, LAPIS, REDSTONE, QUARTZ, DIORITE, GRANITE, ANDESITE, EMERALD, SILVERFISH, CUSTOM }
private final EventType type;
private final WorldGenerator generator;
public GenerateMinable(World world, Random rand, WorldGenerator generator, BlockPos pos, EventType type)
{
super(world, rand, pos);
this.generator = generator;
this.type = type;
}
public EventType getType()
{
return type;
}
public WorldGenerator getGenerator()
{
return generator;
}
}
}

View File

@@ -0,0 +1,146 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.terraingen;
import java.util.Random;
import net.minecraft.world.World;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
/**
* PopulateChunkEvent is fired when an event involving chunk terrain feature population occurs.<br>
* If a method utilizes this {@link Event} as its parameter, the method will
* receive every child event of this class.<br>
* <br>
* {@link #world} contains the world this event is occurring in.<br>
* {@link #rand} contains an instance of random that can be used in this event.<br>
* {@link #chunkX} contains the x-coordinate of the chunk currently being populated with a terrain feature.<br>
* {@link #chunkZ} contains the z-coordinate of the chunk currently being populated with ores.<br>
* {@link #hasVillageGenerated} contains the boolean value stating if the chunk already has a village spawned in it.<br>
* <br>
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}, except {@link Populate}, which fires on the {@link MinecraftForge#TERRAIN_GEN_BUS}.<br>
**/
public class PopulateChunkEvent extends ChunkGeneratorEvent
{
private final World world;
private final Random rand;
private final int chunkX;
private final int chunkZ;
private final boolean hasVillageGenerated;
public PopulateChunkEvent(IChunkGenerator gen, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGenerated)
{
super(gen);
this.world = world;
this.rand = rand;
this.chunkX = chunkX;
this.chunkZ = chunkZ;
this.hasVillageGenerated = hasVillageGenerated;
}
public World getWorld() { return world; }
public Random getRand() { return rand; }
public int getChunkX() { return chunkX; }
public int getChunkZ() { return chunkZ; }
public boolean isHasVillageGenerated() { return hasVillageGenerated; }
/**
* PopulateChunkEvent.Pre is fired just before a chunk is populated a terrain feature.<br>
* This event is fired just before terrain feature generation in
* {@link ChunkProviderEnd#populate(int, int)},
* {@link ChunkProviderOverworld#populate(int, int)},
* and {@link ChunkProviderHell#populate(int, int)}. <br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class Pre extends PopulateChunkEvent
{
public Pre(IChunkGenerator gen, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGenerated)
{
super(gen, world, rand, chunkX, chunkZ, hasVillageGenerated);
}
}
/**
* PopulateChunkEvent.Post is fired just after a chunk is populated with a terrain feature.<br>
* This event is fired just after terrain feature generation in
* {@link ChunkProviderEnd#populate(int, int)},
* {@link ChunkProviderOverworld#populate(int, int)},
* and {@link ChunkProviderHell#populate(int, int)}. <br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class Post extends PopulateChunkEvent
{
public Post(IChunkGenerator chunkProvider, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGenerated)
{
super(chunkProvider, world, rand, chunkX, chunkZ, hasVillageGenerated);
}
}
/**
* PopulateChunkEvent.Populate is fired when a chunk is populated with a terrain feature.<br>
* This event is fired during terrain feature generation in
* {@link ChunkProviderEnd#populate(int, int)},
* {@link ChunkProviderOverworld#populate(int, int)},
* and {@link ChunkProviderHell#populate(int, int)}. <br>
* <br>
* {@link #type} contains the enum value for the terrain feature being generated. <br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event has a result. {@link HasResult} <br>
* This result determines if the chunk is populated with the terrain feature. <br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
@HasResult
public static class Populate extends PopulateChunkEvent
{
public EventType getType()
{
return type;
}
/** Use CUSTOM to filter custom event types
*/
public static enum EventType { DUNGEON, FIRE, GLOWSTONE, ICE, LAKE, LAVA, NETHER_LAVA, NETHER_LAVA2, NETHER_MAGMA, ANIMALS, CUSTOM }
private final EventType type;
public Populate(IChunkGenerator gen, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGenerated, EventType type)
{
super(gen, world, rand, chunkX, chunkZ, hasVillageGenerated);
this.type = type;
}
}
}

View File

@@ -0,0 +1,70 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.terraingen;
import java.util.Random;
import net.minecraft.block.BlockSapling;
import net.minecraft.block.state.IBlockState;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.event.world.WorldEvent;
/**
* SaplingGrowTreeEvent is fired when a sapling grows into a tree.<br>
* This event is fired during sapling growth in
* {@link BlockSapling#generateTree(World, BlockPos, IBlockState, Random)}.<br>
* <br>
* {@link #pos} contains the coordinates of the growing sapling. <br>
* {@link #rand} contains an instance of Random for use. <br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event has a result. {@link HasResult} <br>
* This result determines if the sapling is allowed to grow. <br>
* <br>
* This event is fired on the {@link MinecraftForge#TERRAIN_GEN_BUS}.<br>
**/
@HasResult
public class SaplingGrowTreeEvent extends WorldEvent
{
private final BlockPos pos;
private final Random rand;
public SaplingGrowTreeEvent(World world, Random rand, BlockPos pos)
{
super(world);
this.rand = rand;
this.pos = pos;
}
public BlockPos getPos()
{
return pos;
}
public Random getRand()
{
return rand;
}
}

View File

@@ -0,0 +1,111 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.terraingen;
import java.util.Random;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraft.world.gen.MapGenBase;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate;
import net.minecraftforge.event.terraingen.OreGenEvent.GenerateMinable;
import net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate;
import net.minecraftforge.fml.common.eventhandler.Event.Result;
public abstract class TerrainGen
{
public static <T extends InitNoiseGensEvent.Context> T getModdedNoiseGenerators(World world, Random rand, T original)
{
InitNoiseGensEvent<T> event = new InitNoiseGensEvent<>(world, rand, original);
MinecraftForge.TERRAIN_GEN_BUS.post(event);
return event.getNewValues();
}
public static MapGenBase getModdedMapGen(MapGenBase original, InitMapGenEvent.EventType type)
{
InitMapGenEvent event = new InitMapGenEvent(type, original);
MinecraftForge.TERRAIN_GEN_BUS.post(event);
return event.getNewGen();
}
public static boolean populate(IChunkGenerator 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;
}
/**
* Use this method when there is a specific BlockPos location given for decoration.
* If only the chunk position is available, use {@link #decorate(World, Random, ChunkPos, Decorate.EventType)} instead.
*
* @param world the world being generated in
* @param rand the random generator used for decoration
* @param chunkPos the original chunk position used for generation, passed to the decorator
* @param placementPos the specific position used for generating a feature, somewhere in the 2x2 chunks used for decoration
* @param type the type of decoration
*/
public static boolean decorate(World world, Random rand, ChunkPos chunkPos, BlockPos placementPos, Decorate.EventType type)
{
Decorate event = new Decorate(world, rand, chunkPos, placementPos, type);
MinecraftForge.TERRAIN_GEN_BUS.post(event);
return event.getResult() != Result.DENY;
}
/**
* Use this method when generation doesn't have a specific BlockPos location for generation in the chunk.
* If a specific BlockPos for generation is available, use {@link #decorate(World, Random, ChunkPos, BlockPos, Decorate.EventType)} instead.
*
* @param world the world being generated in
* @param rand the random generator used for decoration
* @param chunkPos the original chunk position used for generation, passed to the decorator
* @param type the type of decoration
*/
public static boolean decorate(World world, Random rand, ChunkPos chunkPos, Decorate.EventType type)
{
Decorate event = new Decorate(world, rand, chunkPos, null, type);
MinecraftForge.TERRAIN_GEN_BUS.post(event);
return event.getResult() != Result.DENY;
}
@Deprecated
public static boolean decorate(World world, Random rand, BlockPos pos, Decorate.EventType type)
{
return decorate(world, rand, new ChunkPos(pos), type);
}
public static boolean generateOre(World world, Random rand, WorldGenerator generator, BlockPos pos, GenerateMinable.EventType type)
{
GenerateMinable event = new GenerateMinable(world, rand, generator, pos, type);
MinecraftForge.ORE_GEN_BUS.post(event);
return event.getResult() != Result.DENY;
}
public static boolean saplingGrowTree(World world, Random rand, BlockPos pos)
{
SaplingGrowTreeEvent event = new SaplingGrowTreeEvent(world, rand, pos);
MinecraftForge.TERRAIN_GEN_BUS.post(event);
return event.getResult() != Result.DENY;
}
}

View File

@@ -0,0 +1,145 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.terraingen;
import net.minecraft.world.biome.BiomeProvider;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.world.gen.layer.GenLayer;
import net.minecraft.world.WorldType;
/**
* WorldTypeEvent is fired when an event involving the world occurs.<br>
* If a method utilizes this {@link Event} as its parameter, the method will
* receive every child event of this class.<br>
* <br>
* {@link #worldType} contains the WorldType of the world this event is occurring in.<br>
* <br>
* All children of this event are fired on the {@link MinecraftForge#TERRAIN_GEN_BUS}.<br>
**/
public class WorldTypeEvent extends Event
{
private final WorldType worldType;
public WorldTypeEvent(WorldType worldType)
{
this.worldType = worldType;
}
public WorldType getWorldType()
{
return worldType;
}
/**
* BiomeSize is fired when vanilla Minecraft attempts to generate biomes.<br>
* This event is fired during biome generation in
* {@link GenLayer#initializeAllBiomeGenerators(long, WorldType, ChunkProviderSettings)}. <br>
* <br>
* {@link #originalSize} the original size of the Biome. <br>
* {@link #newSize} the new size of the biome. Initially set to the {@link #originalSize}. <br>
* If {@link #newSize} is set to a new value, that value will be used for the Biome size. <br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
* This event is fired on the {@link MinecraftForge#TERRAIN_GEN_BUS}.<br>
**/
public static class BiomeSize extends WorldTypeEvent
{
private final int originalSize;
private int newSize;
public BiomeSize(WorldType worldType, int original)
{
super(worldType);
originalSize = original;
setNewSize(original);
}
public int getOriginalSize()
{
return originalSize;
}
public int getNewSize()
{
return newSize;
}
public void setNewSize(int newSize)
{
this.newSize = newSize;
}
}
/**
* InitBiomeGens is fired when vanilla Minecraft attempts to initialize the biome providers.<br>
* This event is fired just during biome provider initialization in
* {@link BiomeProvider#BiomeProvider(long, WorldType, String)}. <br>
* <br>
* {@link #seed} the seed of the world. <br>
* {@link #originalBiomeGens} the array of GenLayers original intended for this Biome generation. <br>
* {@link #newBiomeGens} the array of GenLayers that will now be used for this Biome generation. <br>
* If {@link #newBiomeGens} is set to a new value, that value will be used for the Biome generator. <br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
* This event is fired on the {@link MinecraftForge#TERRAIN_GEN_BUS}.<br>
**/
public static class InitBiomeGens extends WorldTypeEvent
{
private final long seed;
private final GenLayer[] originalBiomeGens;
private GenLayer[] newBiomeGens;
public InitBiomeGens(WorldType worldType, long seed, GenLayer[] original)
{
super(worldType);
this.seed = seed;
originalBiomeGens = original;
setNewBiomeGens(original.clone());
}
public long getSeed()
{
return seed;
}
public GenLayer[] getOriginalBiomeGens()
{
return originalBiomeGens;
}
public GenLayer[] getNewBiomeGens()
{
return newBiomeGens;
}
public void setNewBiomeGens(GenLayer[] newBiomeGens)
{
this.newBiomeGens = newBiomeGens;
}
}
}

View File

@@ -0,0 +1,451 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.world;
import java.util.EnumSet;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.BlockPortal;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Enchantments;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.util.BlockSnapshot;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import com.google.common.collect.ImmutableList;
import javax.annotation.Nonnull;
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
public class BlockEvent extends Event
{
private static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("forge.debugBlockEvent", "false"));
private final World world;
private final BlockPos pos;
private final IBlockState state;
public BlockEvent(World world, BlockPos pos, IBlockState state)
{
this.pos = pos;
this.world = world;
this.state = state;
}
public World getWorld()
{
return world;
}
public BlockPos getPos()
{
return pos;
}
public IBlockState getState()
{
return state;
}
/**
* 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
{
private final int fortuneLevel;
private final List<ItemStack> drops;
private final boolean isSilkTouching;
private float dropChance; // Change to e.g. 1.0f, if you manipulate the list and want to guarantee it always drops
private final EntityPlayer harvester; // May be null for non-player harvesting such as explosions or machines
public HarvestDropsEvent(World world, BlockPos pos, IBlockState state, int fortuneLevel, float dropChance, List<ItemStack> drops, EntityPlayer harvester, boolean isSilkTouching)
{
super(world, pos, state);
this.fortuneLevel = fortuneLevel;
this.setDropChance(dropChance);
this.drops = drops;
this.isSilkTouching = isSilkTouching;
this.harvester = harvester;
}
public int getFortuneLevel() { return fortuneLevel; }
public List<ItemStack> getDrops() { return drops; }
public boolean isSilkTouching() { return isSilkTouching; }
public float getDropChance() { return dropChance; }
public void setDropChance(float dropChance) { this.dropChance = dropChance; }
public EntityPlayer getHarvester() { return 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(World world, BlockPos pos, IBlockState state, EntityPlayer player)
{
super(world, pos, state);
this.player = player;
if (state == null || !ForgeHooks.canHarvestBlock(state.getBlock(), player, world, pos) || // Handle empty block or player unable to break block scenario
(state.getBlock().canSilkHarvest(world, pos, world.getBlockState(pos), player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, player.getHeldItemMainhand()) > 0)) // If the block is being silk harvested, the exp dropped is 0
{
this.exp = 0;
}
else
{
int bonusLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, player.getHeldItemMainhand());
this.exp = state.getBlock().getExpDrop(state, world, pos, 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;
}
}
/**
* Called when a block is placed by a player.
*
* If a Block Place event is cancelled, the block will not be placed.
*/
@Cancelable
public static class PlaceEvent extends BlockEvent
{
private final EntityPlayer player;
private final BlockSnapshot blockSnapshot;
private final IBlockState placedBlock;
private final IBlockState placedAgainst;
private final EnumHand hand;
public PlaceEvent(@Nonnull BlockSnapshot blockSnapshot, @Nonnull IBlockState placedAgainst, @Nonnull EntityPlayer player, @Nonnull EnumHand hand) {
super(blockSnapshot.getWorld(), blockSnapshot.getPos(), blockSnapshot.getCurrentBlock());
this.player = player;
this.blockSnapshot = blockSnapshot;
this.placedBlock = blockSnapshot.getCurrentBlock();
this.placedAgainst = placedAgainst;
this.hand = hand;
if (DEBUG)
{
System.out.printf("Created PlaceEvent - [PlacedBlock: %s ][PlacedAgainst: %s ][ItemStack: %s ][Player: %s ][Hand: %s]\n", getPlacedBlock(), placedAgainst, player.getHeldItem(hand), player, hand);
}
}
public EntityPlayer getPlayer() { return player; }
@Nonnull
@Deprecated
public ItemStack getItemInHand() { return player.getHeldItem(hand); }
public BlockSnapshot getBlockSnapshot() { return blockSnapshot; }
public IBlockState getPlacedBlock() { return placedBlock; }
public IBlockState getPlacedAgainst() { return placedAgainst; }
public EnumHand getHand() { return hand; }
}
/**
* Fired when a single block placement action of a player triggers the
* creation of multiple blocks(e.g. placing a bed block). The block returned
* by {@link #state} and its related methods is the block where
* the placed block would exist if the placement only affected a single
* block.
*/
@Cancelable
public static class MultiPlaceEvent extends PlaceEvent
{
private final List<BlockSnapshot> blockSnapshots;
public MultiPlaceEvent(@Nonnull List<BlockSnapshot> blockSnapshots, @Nonnull IBlockState placedAgainst, @Nonnull EntityPlayer player, @Nonnull EnumHand hand) {
super(blockSnapshots.get(0), placedAgainst, player, hand);
this.blockSnapshots = ImmutableList.copyOf(blockSnapshots);
if (DEBUG)
{
System.out.printf("Created MultiPlaceEvent - [PlacedAgainst: %s ][ItemInHand: %s ][Player: %s ]\n", placedAgainst, player.getHeldItem(hand), player);
}
}
/**
* Gets a list of BlockSnapshots for all blocks which were replaced by the
* placement of the new blocks. Most of these blocks will just be of type AIR.
*
* @return immutable list of replaced BlockSnapshots
*/
public List<BlockSnapshot> getReplacedBlockSnapshots()
{
return blockSnapshots;
}
}
/**
* Fired when a physics update occurs on a block. This event acts as
* a way for mods to detect physics updates, in the same way a BUD switch
* does. This event is only called on the server.
*/
@Cancelable
public static class NeighborNotifyEvent extends BlockEvent
{
private final EnumSet<EnumFacing> notifiedSides;
private final boolean forceRedstoneUpdate;
public NeighborNotifyEvent(World world, BlockPos pos, IBlockState state, EnumSet<EnumFacing> notifiedSides, boolean forceRedstoneUpdate)
{
super(world, pos, state);
this.notifiedSides = notifiedSides;
this.forceRedstoneUpdate = forceRedstoneUpdate;
}
/**
* Gets a list of directions from the base block that updates will occur upon.
*
* @return list of notified directions
*/
public EnumSet<EnumFacing> getNotifiedSides()
{
return notifiedSides;
}
/**
* Get if redstone update was forced during setBlock call (0x16 to flags)
* @return if the flag was set
*/
public boolean getForceRedstoneUpdate()
{
return forceRedstoneUpdate;
}
}
/**
* Fired to check whether a non-source block can turn into a source block.
* A result of ALLOW causes a source block to be created even if the liquid
* usually doesn't do that (like lava), and a result of DENY prevents creation
* even if the liquid usually does do that (like water).
*/
@HasResult
public static class CreateFluidSourceEvent extends BlockEvent
{
public CreateFluidSourceEvent(World world, BlockPos pos, IBlockState state)
{
super(world, pos, state);
}
}
/**
* Fired when a liquid places a block. Use {@link #setNewState(IBlockState)} to change the result of
* a cobblestone generator or add variants of obsidian. Alternatively, you could execute
* arbitrary code when lava sets blocks on fire, even preventing it.
*
* {@link #getState()} will return the block that was originally going to be placed.
* {@link #getPos()} will return the position of the block to be changed.
*/
@Cancelable
public static class FluidPlaceBlockEvent extends BlockEvent
{
private final BlockPos liquidPos;
private IBlockState newState;
private IBlockState origState;
public FluidPlaceBlockEvent(World world, BlockPos pos, BlockPos liquidPos, IBlockState state)
{
super(world, pos, state);
this.liquidPos = liquidPos;
this.newState = state;
this.origState = world.getBlockState(pos);
}
/**
* @return The position of the liquid this event originated from. This may be the same as {@link #getPos()}.
*/
public BlockPos getLiquidPos()
{
return liquidPos;
}
/**
* @return The block state that will be placed after this event resolves.
*/
public IBlockState getNewState()
{
return newState;
}
public void setNewState(IBlockState state)
{
this.newState = state;
}
/**
* @return The state of the block to be changed before the event was fired.
*/
public IBlockState getOriginalState()
{
return origState;
}
}
/**
* Fired when a crop block grows. See subevents.
*
*/
public static class CropGrowEvent extends BlockEvent
{
public CropGrowEvent(World world, BlockPos pos, IBlockState state)
{
super(world, pos, state);
}
/**
* Fired when any "growing age" blocks (for example cacti, chorus plants, or crops
* in vanilla) attempt to advance to the next growth age state during a random tick.<br>
* <br>
* {@link Result#DEFAULT} will pass on to the vanilla growth mechanics.<br>
* {@link Result#ALLOW} will force the plant to advance a growth stage.<br>
* {@link Result#DENY} will prevent the plant from advancing a growth stage.<br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
*/
@HasResult
public static class Pre extends CropGrowEvent
{
public Pre(World world, BlockPos pos, IBlockState state)
{
super(world, pos, state);
}
}
/**
* Fired when "growing age" blocks (for example cacti, chorus plants, or crops
* in vanilla) have successfully grown. The block's original state is available,
* in addition to its new state.<br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
*/
public static class Post extends CropGrowEvent
{
private final IBlockState originalState;
public Post(World world, BlockPos pos, IBlockState original, IBlockState state)
{
super(world, pos, state);
originalState = original;
}
public IBlockState getOriginalState()
{
return originalState;
}
}
}
/**
* Fired when when farmland gets trampled
* This event is {@link Cancelable}
*/
@Cancelable
public static class FarmlandTrampleEvent extends BlockEvent
{
private final Entity entity;
private final float fallDistance;
public FarmlandTrampleEvent(World world, BlockPos pos, IBlockState state, float fallDistance, Entity entity)
{
super(world, pos, state);
this.entity = entity;
this.fallDistance = fallDistance;
}
public Entity getEntity() {
return entity;
}
public float getFallDistance() {
return fallDistance;
}
}
/* Fired when an attempt is made to spawn a nether portal from
* {@link net.minecraft.block.BlockPortal#trySpawnPortal(World, BlockPos)}.
*
* If cancelled, the portal will not be spawned.
*/
@Cancelable
public static class PortalSpawnEvent extends BlockEvent
{
private final BlockPortal.Size size;
public PortalSpawnEvent(World world, BlockPos pos, IBlockState state, BlockPortal.Size size)
{
super(world, pos, state);
this.size = size;
}
public BlockPortal.Size getPortalSize()
{
return size;
}
}
}

View File

@@ -0,0 +1,91 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.world;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.chunk.storage.AnvilChunkLoader;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
/**
* ChunkDataEvent is fired when an event involving chunk data occurs.<br>
* If a method utilizes this {@link Event} as its parameter, the method will
* receive every child event of this class.<br>
* <br>
* {@link #data} contains the NBTTagCompound containing the chunk data for this event.<br>
* <br>
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
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;
}
/**
* ChunkDataEvent.Load is fired when vanilla Minecraft attempts to load Chunk data.<br>
* This event is fired during chunk loading in
* {@link net.minecraftforge.common.chunkio.ChunkIOProvider#syncCallback()}.<br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class Load extends ChunkDataEvent
{
public Load(Chunk chunk, NBTTagCompound data)
{
super(chunk, data);
}
}
/**
* ChunkDataEvent.Save is fired when vanilla Minecraft attempts to save Chunk data.<br>
* This event is fired during chunk saving in
* {@link AnvilChunkLoader#saveChunk(World, Chunk)}. <br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class Save extends ChunkDataEvent
{
public Save(Chunk chunk, NBTTagCompound data)
{
super(chunk, data);
}
}
}

View File

@@ -0,0 +1,90 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.world;
import net.minecraft.client.multiplayer.ChunkProviderClient;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
/**
* ChunkEvent is fired when an event involving a chunk occurs.<br>
* If a method utilizes this {@link Event} as its parameter, the method will
* receive every child event of this class.<br>
* <br>
* {@link #chunk} contains the Chunk this event is affecting.<br>
* <br>
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public class ChunkEvent extends WorldEvent
{
private final Chunk chunk;
public ChunkEvent(Chunk chunk)
{
super(chunk.getWorld());
this.chunk = chunk;
}
public Chunk getChunk()
{
return chunk;
}
/**
* ChunkEvent.Load is fired when vanilla Minecraft attempts to load a Chunk into the world.<br>
* This event is fired during chunk loading in <br>
* {@link ChunkProviderClient#loadChunk(int, int)}, <br>
* Chunk.onChunkLoad(). <br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class Load extends ChunkEvent
{
public Load(Chunk chunk)
{
super(chunk);
}
}
/**
* ChunkEvent.Unload is fired when vanilla Minecraft attempts to unload a Chunk from the world.<br>
* This event is fired during chunk unloading in <br>
* Chunk.onChunkUnload(). <br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class Unload extends ChunkEvent
{
public Unload(Chunk chunk)
{
super(chunk);
}
}
}

View File

@@ -0,0 +1,126 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.world;
import net.minecraft.server.management.PlayerChunkMapEntry;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import javax.annotation.Nullable;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
/**
* ChunkWatchEvent is fired when an event involving a chunk being watched occurs.<br>
* If a method utilizes this {@link Event} as its parameter, the method will
* receive every child event of this class.<br>
* <br>
* {@link #chunk} contains the ChunkPos of the Chunk this event is affecting.<br>
* {@link #player} contains the EntityPlayer that is involved with this chunk being watched. <br>
* {@link #chunkInstance} contains the instance of the Chunk. <br>
* <br>
* The {@link #player}'s world may not be the same as the world of the chunk
* when the player is teleporting to another dimension.<br>
* <br>
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public class ChunkWatchEvent extends Event //TODO: extend ChunkEvent in 1.13
{
@Deprecated //TODO: Remove in 1.13
private final ChunkPos chunk;
private final EntityPlayerMP player;
private final Chunk chunkInstance;
@Deprecated //TODO: Remove in 1.13
public ChunkWatchEvent(ChunkPos chunk, EntityPlayerMP player)
{
this.chunk = chunk;
this.player = player;
this.chunkInstance = null;
}
public ChunkWatchEvent(Chunk chunk, EntityPlayerMP player)
{
this.chunk = chunk.getPos();
this.player = player;
this.chunkInstance = chunk;
}
@Deprecated //TODO: Remove in 1.13
public ChunkPos getChunk()
{
return chunk;
}
public EntityPlayerMP getPlayer()
{
return player;
}
/**
* The affected chunk.
* @return The affected chunk.
*/
@Nullable
public Chunk getChunkInstance()
{
return chunkInstance;
}
/**
* ChunkWatchEvent.Watch is fired when an EntityPlayer begins watching a chunk.<br>
* This event is fired when a chunk is added to the watched chunks of an EntityPlayer in
* {@link PlayerChunkMapEntry#addPlayer(EntityPlayerMP)} and {@link PlayerChunkMapEntry#sendToPlayers()}. <br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class Watch extends ChunkWatchEvent
{
@Deprecated //TODO: Remove in 1.13
public Watch(ChunkPos chunk, EntityPlayerMP player) { super(chunk, player); }
public Watch(Chunk chunk, EntityPlayerMP player) { super(chunk, player); }
}
/**
* ChunkWatchEvent.UnWatch is fired when an EntityPlayer stops watching a chunk.<br>
* This event is fired when a chunk is removed from the watched chunks of an EntityPlayer in
* {@link PlayerChunkMapEntry#removePlayer(EntityPlayerMP)}. <br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class UnWatch extends ChunkWatchEvent
{
@Deprecated //TODO: Remove in 1.13
public UnWatch(ChunkPos chunkLocation, EntityPlayerMP player) { super(chunkLocation, player); }
public UnWatch(Chunk chunk, EntityPlayerMP player) { super(chunk, player); }
}
}

View File

@@ -0,0 +1,106 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.world;
import java.util.List;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
/** ExplosionEvent triggers when an explosion happens in the world.<br>
* <br>
* ExplosionEvent.Start is fired before the explosion actually occurs.<br>
* ExplosionEvent.Detonate is fired once the explosion has a list of affected blocks and entities.<br>
* <br>
* ExplosionEvent.Start is {@link Cancelable}.<br>
* ExplosionEvent.Detonate can modify the affected blocks and entities.<br>
* Children do not use {@link HasResult}.<br>
* Children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
*/
public class ExplosionEvent extends Event
{
private final World world;
private final Explosion explosion;
public ExplosionEvent(World world, Explosion explosion)
{
this.world = world;
this.explosion = explosion;
}
public World getWorld()
{
return world;
}
public Explosion getExplosion()
{
return explosion;
}
/** ExplosionEvent.Start is fired before the explosion actually occurs. Canceling this event will stop the explosion.<br>
* <br>
* This event is {@link Cancelable}.<br>
* This event does not use {@link HasResult}.<br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
*/
@Cancelable
public static class Start extends ExplosionEvent
{
public Start(World world, Explosion explosion)
{
super(world, explosion);
}
}
/** ExplosionEvent.Detonate is fired once the explosion has a list of affected blocks and entities. These lists can be modified to change the outcome.<br>
* <br>
* This event is not {@link Cancelable}.<br>
* This event does not use {@link HasResult}.<br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
*/
public static class Detonate extends ExplosionEvent
{
private final List<Entity> entityList;
public Detonate(World world, Explosion explosion, List<Entity> entityList)
{
super(world, explosion);
this.entityList = entityList;
}
/** return the list of blocks affected by the explosion. */
public List<BlockPos> getAffectedBlocks()
{
return getExplosion().getAffectedBlockPositions();
}
/** return the list of entities affected by the explosion. */
public List<Entity> getAffectedEntities()
{
return entityList;
}
}
}

View File

@@ -0,0 +1,73 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.world;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import javax.annotation.Nullable;
import java.util.List;
/**
* This event is fired during {@link World#collidesWithAnyBlock(AxisAlignedBB)}
* and before returning the list in {@link World#getCollisionBoxes(Entity, AxisAlignedBB)}<br>
* <br>
* {@link #entity} contains the entity passed in the {@link World#getCollisionBoxes(Entity, AxisAlignedBB)}. <b>Can be null.</b> Calls from {@link World#collidesWithAnyBlock(AxisAlignedBB)} will be null.<br>
* {@link #aabb} contains the AxisAlignedBB passed in the method.<br>
* {@link #collisionBoxesList} contains the list of detected collision boxes intersecting with {@link #aabb}. The list can be modified.<br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public class GetCollisionBoxesEvent extends WorldEvent
{
private final Entity entity;
private final AxisAlignedBB aabb;
private final List<AxisAlignedBB> collisionBoxesList;
public GetCollisionBoxesEvent(World world, @Nullable Entity entity, AxisAlignedBB aabb, List<AxisAlignedBB> collisionBoxesList)
{
super(world);
this.entity = entity;
this.aabb = aabb;
this.collisionBoxesList = collisionBoxesList;
}
public Entity getEntity()
{
return entity;
}
public AxisAlignedBB getAabb()
{
return aabb;
}
public List<AxisAlignedBB> getCollisionBoxesList()
{
return collisionBoxesList;
}
}

View File

@@ -0,0 +1,207 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.world;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import com.google.common.base.Preconditions;
/**
* Base class for Noteblock Events
*
*/
public class NoteBlockEvent extends BlockEvent
{
private int noteId;
protected NoteBlockEvent(World world, BlockPos pos, IBlockState state, int note)
{
super(world, pos, state);
this.noteId = note;
}
/**
* Get the Note the Noteblock is tuned to
* @return the Note
*/
public Note getNote()
{
return Note.fromId(noteId);
}
/**
* Get the Octave of the note this Noteblock is tuned to
* @return the Octave
*/
public Octave getOctave()
{
return Octave.fromId(noteId);
}
/**
* get the vanilla note-id, which contains information about both Note and Octave. Most modders should not need this.
* @return an ID for the note
*/
public int getVanillaNoteId()
{
return noteId;
}
/**
* Set Note and Octave for this event.<br>
* If octave is Octave.HIGH, note may only be Note.F_SHARP
* @param note the Note
* @param octave the Octave
*/
public void setNote(Note note, Octave octave)
{
Preconditions.checkArgument(octave != Octave.HIGH || note == Note.F_SHARP, "Octave.HIGH is only valid for Note.F_SHARP!");
this.noteId = note.ordinal() + octave.ordinal() * 12;
}
/**
* Fired when a Noteblock plays it's note. You can override the note and instrument
* Canceling this event will stop the note from playing.
*/
@Cancelable
public static class Play extends NoteBlockEvent
{
private Instrument instrument;
public Play(World world, BlockPos pos, IBlockState state, int note, int instrument)
{
super(world, pos, state, note);
this.setInstrument(Instrument.fromId(instrument));
}
public Instrument getInstrument()
{
return instrument;
}
public void setInstrument(Instrument instrument)
{
this.instrument = instrument;
}
}
/**
* Fired when a Noteblock is changed. You can adjust the note it will change to via {@link #setNote(Note, Octave)}.
* Canceling this event will not change the note and also stop the Noteblock from playing it's note.
*/
@Cancelable
public static class Change extends NoteBlockEvent
{
private final Note oldNote;
private final Octave oldOctave;
public Change(World world, BlockPos pos, IBlockState state, int oldNote, int newNote)
{
super(world, pos, state, newNote);
this.oldNote = Note.fromId(oldNote);
this.oldOctave = Octave.fromId(oldNote);
}
public Note getOldNote()
{
return oldNote;
}
public Octave getOldOctave()
{
return oldOctave;
}
}
/**
* Describes the types of musical Instruments that can be played by a Noteblock.
* The Instrument being played can be overridden with {@link NoteBlockEvent.Play#setInstrument(Instrument)}
*/
public static enum Instrument
{
PIANO,
BASSDRUM,
SNARE,
CLICKS,
BASSGUITAR,
FLUTE,
BELL,
GUITAR,
CHIME,
XYLOPHONE;
// cache to avoid creating a new array every time
private static final Instrument[] values = values();
static Instrument fromId(int id)
{
return id < 0 || id >= values.length ? PIANO : values[id];
}
}
/**
* Information about the pitch of a Noteblock note.
* For altered notes such as G-Sharp / A-Flat the Sharp variant is used here.
*
*/
public static enum Note
{
F_SHARP,
G,
G_SHARP,
A,
A_SHARP,
B,
C,
C_SHARP,
D,
D_SHARP,
E,
F;
private static final Note[] values = values();
static Note fromId(int id)
{
return values[id % 12];
}
}
/**
* Describes the Octave of a Note being played by a Noteblock.
* Together with {@link Note} it fully describes the note.
*
*/
public static enum Octave
{
LOW,
MID,
HIGH; // only valid for F_SHARP
static Octave fromId(int id)
{
return id < 12 ? LOW : id == 24 ? HIGH : MID;
}
}
}

View File

@@ -0,0 +1,187 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.world;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.profiler.Profiler;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.integrated.IntegratedServer;
import net.minecraft.util.IProgressUpdate;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.WorldSettings;
import net.minecraft.world.biome.Biome.SpawnListEntry;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
/**
* WorldEvent is fired when an event involving the world occurs.<br>
* If a method utilizes this {@link Event} as its parameter, the method will
* receive every child event of this class.<br>
* <br>
* {@link #world} contains the World this event is occurring in.<br>
* <br>
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public class WorldEvent extends Event
{
private final World world;
public WorldEvent(World world)
{
this.world = world;
}
public World getWorld()
{
return world;
}
/**
* WorldEvent.Load is fired when Minecraft loads a world.<br>
* This event is fired when a world is loaded in
* {@link WorldClient#WorldClient(NetHandlerPlayClient, WorldSettings, int, EnumDifficulty, Profiler)},
* {@link MinecraftServer#loadAllWorlds(String, String, long, WorldType, String)},
* {@link IntegratedServer#loadAllWorlds(String, String, long, WorldType, String)}
* {@link DimensionManager#initDimension(int)},
* and {@link ForgeInternalHandler#onDimensionLoad(Load)}. <br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class Load extends WorldEvent
{
public Load(World world) { super(world); }
}
/**
* WorldEvent.Unload is fired when Minecraft unloads a world.<br>
* This event is fired when a world is unloaded in
* {@link Minecraft#loadWorld(WorldClient, String)},
* {@link MinecraftServer#stopServer()},
* {@link DimensionManager#unloadWorlds(Hashtable)},
* {@link ForgeInternalHandler#onDimensionUnload(Unload)}. <br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class Unload extends WorldEvent
{
public Unload(World world) { super(world); }
}
/**
* WorldEvent.Save is fired when Minecraft saves a world.<br>
* This event is fired when a world is saved in
* {@link WorldServer#saveAllChunks(boolean, IProgressUpdate)},
* {@link ForgeInternalHandler#onDimensionSave(Save)}. <br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
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.
* If an entry is added to the list, it needs to be a globally unique instance.
* The event is called in {@link WorldServer#getSpawnListEntryForTypeAt(EnumCreatureType, BlockPos)} as well as
* {@link WorldServer#canCreatureTypeSpawnHere(EnumCreatureType, SpawnListEntry, BlockPos)}
* where the latter checks for identity, meaning both events must add the same instance.
* Canceling the event will result in a empty list, meaning no entity will be spawned.
*/
@Cancelable
public static class PotentialSpawns extends WorldEvent
{
private final EnumCreatureType type;
private final BlockPos pos;
private final List<SpawnListEntry> list;
public PotentialSpawns(World world, EnumCreatureType type, BlockPos pos, List<SpawnListEntry> oldList)
{
super(world);
this.pos = pos;
this.type = type;
if (oldList != null)
{
this.list = new ArrayList<SpawnListEntry>(oldList);
}
else
{
this.list = new ArrayList<SpawnListEntry>();
}
}
public EnumCreatureType getType()
{
return type;
}
public BlockPos getPos()
{
return pos;
}
public List<SpawnListEntry> getList()
{
return list;
}
}
/**
* Called by WorldServer when it attempts to create a spawnpoint for a dimension.
* Canceling the event will prevent the vanilla code from running.
*/
@Cancelable
public static class CreateSpawnPosition extends WorldEvent
{
private final WorldSettings settings;
public CreateSpawnPosition(World world, WorldSettings settings)
{
super(world);
this.settings = settings;
}
public WorldSettings getSettings()
{
return settings;
}
}
}