Simple implementation of a Open/Close container event (#3017)

This commit is contained in:
luacs1998 2016-06-26 00:34:42 +08:00 committed by cpw
parent 174394d6df
commit 8e3bc83c3b
3 changed files with 87 additions and 1 deletions

View File

@ -73,7 +73,39 @@
{
BlockPos blockpos1 = blockpos.func_177977_b();
IBlockState iblockstate1 = this.field_70170_p.func_180495_p(blockpos1);
@@ -921,6 +937,7 @@
@@ -740,6 +756,7 @@
this.field_71070_bA = p_180468_1_.func_174876_a(this.field_71071_by, this);
this.field_71070_bA.field_75152_c = this.field_71139_cq;
this.field_71070_bA.func_75132_a(this);
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.player.PlayerContainerEvent.Open(this, this.field_71070_bA));
}
}
@@ -783,6 +800,7 @@
this.field_71070_bA.field_75152_c = this.field_71139_cq;
this.field_71070_bA.func_75132_a(this);
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.player.PlayerContainerEvent.Open(this, this.field_71070_bA));
}
}
@@ -792,6 +810,7 @@
this.field_71070_bA = new ContainerMerchant(this.field_71071_by, p_180472_1_, this.field_70170_p);
this.field_71070_bA.field_75152_c = this.field_71139_cq;
this.field_71070_bA.func_75132_a(this);
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.player.PlayerContainerEvent.Open(this, this.field_71070_bA));
IInventory iinventory = ((ContainerMerchant)this.field_71070_bA).func_75174_d();
ITextComponent itextcomponent = p_180472_1_.func_145748_c_();
this.field_71135_a.func_147359_a(new SPacketOpenWindow(this.field_71139_cq, "minecraft:villager", itextcomponent, iinventory.func_70302_i_()));
@@ -890,6 +909,7 @@
public void func_71128_l()
{
this.field_71070_bA.func_75134_a(this);
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.player.PlayerContainerEvent.Close(this, this.field_71070_bA));
this.field_71070_bA = this.field_71069_bz;
}
@@ -921,6 +941,7 @@
{
if (p_71064_1_ != null)
{

View File

@ -0,0 +1,53 @@
/*
* 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.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

@ -98,6 +98,7 @@ public class FMLNetworkHandler
entityPlayerMP.openContainer = remoteGuiContainer;
entityPlayerMP.openContainer.windowId = windowId;
entityPlayerMP.openContainer.addListener(entityPlayerMP);
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.player.PlayerContainerEvent.Open(entityPlayer, entityPlayer.openContainer));
}
}
else if (entityPlayer instanceof FakePlayer)