[1.11] Added EnchantmentLevelSetEvent (#3433)

This commit is contained in:
Rock Hymas 2016-12-17 14:06:51 -07:00 committed by LexManos
parent 22db1965c7
commit 8dc4b5f9b5
4 changed files with 180 additions and 0 deletions

View File

@ -75,3 +75,11 @@
this.field_185001_h[i1] = -1;
this.field_185002_i[i1] = -1;
@@ -212,6 +193,7 @@
{
this.field_75167_g[i1] = 0;
}
+ this.field_75167_g[i1] = net.minecraftforge.event.ForgeEventFactory.onEnchantmentLevelSet(field_75172_h, field_178150_j, i1, (int)power, itemstack, field_75167_g[i1]);
}
for (int j1 = 0; j1 < 3; ++j1)

View File

@ -639,4 +639,10 @@ public class ForgeEventFactory
return result == Result.DEFAULT ? def : result == Result.ALLOW;
}
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();
}
}

View File

@ -0,0 +1,135 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* 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;
/**
* 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;
private final ItemStack itemStack;
private final int originalLevel;
private int level;
public EnchantmentLevelSetEvent(World world, BlockPos pos, int enchantRow, int power, 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
*/
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 the new level of the enchantment (0-30)
*/
public void setLevel(int level)
{
this.level = level;
}
}

View File

@ -0,0 +1,31 @@
package net.minecraftforge.test;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.enchanting.EnchantmentLevelSetEvent;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@Mod(modid = "enchantmentlevelsettest", name = "EnchantmentLevelSetTest", version = "1.0")
public class EnchantmentLevelSetTest
{
public static final boolean ENABLE = false;
@Mod.EventHandler
public static void init(FMLInitializationEvent event)
{
if (ENABLE) {
FMLLog.info("Wiring up enchantment level set test");
MinecraftForge.EVENT_BUS.register(EnchantmentLevelSetTest.class);
}
}
@SubscribeEvent
public static void onEnchantmentLevelSet(EnchantmentLevelSetEvent event)
{
// invert enchantment level, just for fun
FMLLog.info("Enchantment row: " + event.getEnchantRow() + ", level: " + event.getLevel());
event.setLevel(30 - event.getLevel());
}
}