Added EquipmentChangeEvent (#3411)
This commit is contained in:
parent
5da0ac73b9
commit
dac8e49f50
3 changed files with 127 additions and 6 deletions
|
@ -199,7 +199,15 @@
|
|||
super.func_70071_h_();
|
||||
this.func_184608_ct();
|
||||
|
||||
@@ -2488,6 +2514,40 @@
|
||||
@@ -2015,6 +2041,7 @@
|
||||
if (!ItemStack.func_77989_b(itemstack1, itemstack))
|
||||
{
|
||||
((WorldServer)this.field_70170_p).func_73039_n().func_151247_a(this, new SPacketEntityEquipment(this.func_145782_y(), entityequipmentslot, itemstack1));
|
||||
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.living.LivingEquipmentChangeEvent(this, entityequipmentslot, itemstack, itemstack1));
|
||||
|
||||
if (!itemstack.func_190926_b())
|
||||
{
|
||||
@@ -2488,6 +2515,40 @@
|
||||
this.field_70752_e = true;
|
||||
}
|
||||
|
||||
|
@ -240,7 +248,7 @@
|
|||
public abstract EnumHandSide func_184591_cq();
|
||||
|
||||
public boolean func_184587_cr()
|
||||
@@ -2508,12 +2568,19 @@
|
||||
@@ -2508,12 +2569,19 @@
|
||||
|
||||
if (itemstack == this.field_184627_bm)
|
||||
{
|
||||
|
@ -261,7 +269,7 @@
|
|||
{
|
||||
this.func_71036_o();
|
||||
}
|
||||
@@ -2531,8 +2598,10 @@
|
||||
@@ -2531,8 +2599,10 @@
|
||||
|
||||
if (!itemstack.func_190926_b() && !this.func_184587_cr())
|
||||
{
|
||||
|
@ -273,7 +281,7 @@
|
|||
|
||||
if (!this.field_70170_p.field_72995_K)
|
||||
{
|
||||
@@ -2613,7 +2682,9 @@
|
||||
@@ -2613,7 +2683,9 @@
|
||||
if (!this.field_184627_bm.func_190926_b() && this.func_184587_cr())
|
||||
{
|
||||
this.func_184584_a(this.field_184627_bm, 16);
|
||||
|
@ -284,7 +292,7 @@
|
|||
this.func_184602_cy();
|
||||
}
|
||||
}
|
||||
@@ -2637,7 +2708,8 @@
|
||||
@@ -2637,7 +2709,8 @@
|
||||
{
|
||||
if (!this.field_184627_bm.func_190926_b())
|
||||
{
|
||||
|
@ -294,7 +302,7 @@
|
|||
}
|
||||
|
||||
this.func_184602_cy();
|
||||
@@ -2761,4 +2833,29 @@
|
||||
@@ -2761,4 +2834,29 @@
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* 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.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;
|
||||
|
||||
/**
|
||||
* {@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, ItemStack from, ItemStack to)
|
||||
{
|
||||
super(entity);
|
||||
this.slot = slot;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
public EntityEquipmentSlot getSlot() { return this.slot; }
|
||||
public ItemStack getFrom() { return this.from; }
|
||||
public ItemStack getTo() { return this.to; }
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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.debug;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.living.LivingEquipmentChangeEvent;
|
||||
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 = "equipment_change_test", version = "1.0.0")
|
||||
public class EquipmentChangeTest
|
||||
{
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onInit(FMLInitializationEvent event)
|
||||
{
|
||||
//register the eventhandler
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* the Method handling the {@link LivingEquipmentChangeEvent}
|
||||
* Serverside only!
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public void onEquipmentChange(LivingEquipmentChangeEvent event)
|
||||
{
|
||||
//a debug console print
|
||||
FMLLog.info("[Equipment-Change] " + event.getEntity() + " changed his Equipment in "
|
||||
+ event.getSlot() + " from " + event.getFrom() + " to " + event.getTo());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue