More work on compile errors, New system for ToolClasses, using a ToolType class instead to de-stringify things.

This commit is contained in:
LexManos committed 2018-09-21 01:47:12 -07:00
1 parent 0cd21ebe7e
commit cdfa7caaeb
33 files changed
+1668 -519

No files matched your search

@@ -1,69 +0,0 @@
/*
* 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.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.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 net.minecraftforge.eventbus.api.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; }
}
@@ -89,7 +89,6 @@ 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;
@@ -127,7 +126,6 @@ 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.eventbus.api.Event;
import net.minecraftforge.eventbus.api.Event.Result;
import net.minecraftforge.fml.common.registry.GameRegistry;
@@ -180,27 +178,6 @@ public class ForgeEventFactory
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)
@@ -223,32 +200,6 @@ public class ForgeEventFactory
}
}
/**
* @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));
@@ -261,21 +212,10 @@ public class ForgeEventFactory
return event.getResult();
}
public static int getItemBurnTime(@Nonnull ItemStack itemStack)
public static int getItemBurnTime(@Nonnull ItemStack itemStack, int burnTime)
{
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();
}
@@ -393,9 +333,7 @@ public class ForgeEventFactory
public static void firePlayerLoadingEvent(EntityPlayer player, IPlayerFileData playerFileData, String uuidString)
{
SaveHandler sh = (SaveHandler) playerFileData;
File dir = sh.getPlayersDirectory();
MinecraftForge.EVENT_BUS.post(new PlayerEvent.LoadFromFile(player, dir, uuidString));
MinecraftForge.EVENT_BUS.post(new PlayerEvent.LoadFromFile(player, ((SaveHandler)playerFileData).playersDirectory, uuidString));
}
@Nullable
@@ -624,13 +562,13 @@ public class ForgeEventFactory
{
return MinecraftForge.EVENT_BUS.post(new RenderBlockOverlayEvent(player, renderPartialTicks, type, block, pos));
}
@Nullable
public static <T extends ICapabilityProvider> CapabilityDispatcher gatherCapabilities(Class<? extends T> type, T provider)
{
return gatherCapabilities(type, provider, null);
}
@SuppressWarnings("unchecked")
@Nullable
public static <T extends ICapabilityProvider> CapabilityDispatcher gatherCapabilities(Class<? extends T> type, T provider, @Nullable ICapabilityProvider parent)
@@ -705,9 +643,7 @@ public class ForgeEventFactory
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
return MinecraftForge.EVENT_BUS.post(new ProjectileImpactEvent.Throwable(throwable, ray));
}
public static boolean onReplaceBiomeBlocks(IChunkGenerator gen, int x, int z, ChunkPrimer primer, World world)
@@ -23,13 +23,12 @@ import javax.annotation.Nullable;
import net.minecraft.tileentity.MobSpawnerBaseLogic;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;
import net.minecraft.entity.EntityLiving;
import net.minecraft.world.World;
/**
* LivingSpawnEvent is fired for any events associated with Living Enttnies spawn status. <br>
* LivingSpawnEvent is fired for any events associated with Living Entities 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>
@@ -72,7 +71,6 @@ public class LivingSpawnEvent extends LivingEvent
@HasResult
public static class CheckSpawn extends LivingSpawnEvent
{
private final boolean isSpawner; // TODO: remove in 1.13
@Nullable
private final MobSpawnerBaseLogic spawner;
@@ -90,42 +88,12 @@ public class LivingSpawnEvent extends LivingEvent
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
return spawner != null; // TODO: replace with spawner null check in 1.13
}
@Nullable
@@ -154,17 +122,6 @@ public class LivingSpawnEvent extends LivingEvent
@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
*/
@@ -203,4 +160,4 @@ public class LivingSpawnEvent extends LivingEvent
}
}
}
}
@@ -31,7 +31,7 @@ import net.minecraftforge.eventbus.api.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>
* To set the burn time of your own item, use {@link Item#getBurnTime(ItemStack)} instead.<br>
* <br>
* This event is fired from {@link ForgeEventFactory#getItemBurnTime(ItemStack)}.<br>
* <br>
@@ -66,18 +66,19 @@ public class FurnaceFuelBurnTimeEvent extends Event
/**
* 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);
if (burnTime >= 0)
{
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()
{
@@ -127,8 +127,8 @@ public class BlockEvent extends Event
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
if (state == null || !ForgeHooks.canHarvestBlock(state, player, world, pos) || // Handle empty block or player unable to break block scenario
(state.canSilkHarvest(world, 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;
}
@@ -88,7 +88,7 @@ public class WorldEvent extends Event
* This event is fired when a world is unloaded in
* {@link Minecraft#loadWorld(WorldClient, String)},
* {@link MinecraftServer#stopServer()},
* {@link DimensionManager#unloadWorlds(Hashtable)},
* {@link DimensionManager#unloadWorlds()},
* {@link ForgeInternalHandler#onDimensionUnload(Unload)}. <br>
* <br>
* This event is not {@link Cancelable}.<br>