mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 08:17:35 +00:00
[1.11] Added EnchantmentLevelSetEvent (#3433)
This commit is contained in:
1 parent
22db1965c7
commit
8dc4b5f9b5
4 files changed
+180
No files matched your search
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user