Jump to content

[1.8] Open gui when right click an entity - how?


Elix_x

Recommended Posts

Hi there, i have a bit difficult problem there...

Normally for TileEntities you open gui using FMLNetworkHandler.openGui(entityPlayer, mod, modGuiId, world, x, y, z).

Then in gui handler you fing entity using world.getTileEntity(x, y, z);

But with entities it's a lot harder: enties position is not int int int(float float float); And there may be multiple entities in one block (even one coord, but it's nearly impossible)!

 

How it's done in vanilla (horses):

player.displayGUIHorse(this, this.horseChest);

Where player is EntityPlayer, this is EntityHorse and this.horseChest is AnimalChest.

But there's no way i can transfer entity to FMLNetworkHandler and then to gui and container.

 

I have one idea, but it's too stupid:

Before opening gui, write in players nbt new tag that conatins my entities UUID, then in GuiHandler read this tag (from player), find entity by uuid and delete this tag... But i think there might be something easier there

 

For additional information: i need both container and gui, because this entity has inventory.

And also: i don't think there's any code to show.

Link to comment
Share on other sites

Yes it definetly works! Thanks!

Now i have another question, but this is not about renderer at all:

How do i change replace vanilla enity with mine (i can swap just class), if i can not over register with same id?

Link to comment
Share on other sites

This would give problems to players, and may be mods... How ever i'll try to use it. By the way, are there other ways to do this?

EDIT: this isn't working for me, if i cancel event, nothing happens. And entity parameter is final...

Link to comment
Share on other sites

First:

EDIT: this isn't working for me, if i cancel event, nothing happens. And entity parameter is final...

Second: i'm modifying entity horse and armor mechanics. Making it work nearly as player armor (enchants, damaging, repair (not yet)), and make possible to add new armors.

What i did: created new entity class, copied everything from EntityHorse and modified it as i need. And i got everything working... With new entity...

Third: I know that there's ASM there, but i think i have too much edits in class to use ASM...

.patch? -Can anybody tell me how to write those?

Link to comment
Share on other sites

That's not ehough, to make possible to add armor from other materials.

I know that just to make it work nearly as player armor, i could use LivingAttackEvent + setMaxDamge for vanilla armor + a bit of enums and other stuff...

But to make it possible, to add more armors... A lot more changes are needed. Even ones in HorseContainer (to make it possible put armor in slot)...

Link to comment
Share on other sites

No, you will need to do it in via the Container, you can do this via PlayerOpenContainerEvent.

Soo, PlayerOpenContainerEvent. I get container form event.entityPlayer.openContainer. Then i process slots...

But the problem is: in the case with horse, in order to give answr to methods canBeHovered() and is ItemValid(), i need EntityHorse, which is private field in ContainerHorseInventory.

Question for after: can i override entity renderer just by registering new one for same class?

Link to comment
Share on other sites

But the problem is: in the case with horse, in order to give answr to methods canBeHovered() and is ItemValid(), i need EntityHorse, which is private field in ContainerHorseInventory.

Really, private access stops you? :D Google "Java Reflection".

Question for after: can i override entity renderer just by registering new one for same class?

Yes.

Okay... I think the last question i have: how do i make this container operation on client? Because for client, i can put item inside. But for server, nope. And more problems come, when on client you can't but on server you can...

Link to comment
Share on other sites

The event should (I think) fire on both client and server. Otherwise use GuiOpenEvent for the client.

Nope, it's server only:

[15:45:55] [server thread/INFO] [sTDOUT]: [code.elix_x.mods.btam.core.horses.events.OpenHorseInventoryEvent:openInventory:22]: Server!
[15:45:55] [server thread/INFO] [sTDOUT]: [code.elix_x.mods.btam.core.horses.events.OpenHorseInventoryEvent:openInventory:22]: Server!
[15:45:55] [server thread/INFO] [sTDOUT]: [code.elix_x.mods.btam.core.horses.events.OpenHorseInventoryEvent:openInventory:22]: Server!
[15:45:55] [server thread/INFO] [sTDOUT]: [code.elix_x.mods.btam.core.horses.events.OpenHorseInventoryEvent:openInventory:22]: Server!
[15:45:55] [server thread/INFO] [sTDOUT]: [code.elix_x.mods.btam.core.horses.events.OpenHorseInventoryEvent:openInventory:22]: Server!
[15:45:55] [server thread/INFO] [sTDOUT]: [code.elix_x.mods.btam.core.horses.events.OpenHorseInventoryEvent:openInventory:22]: Server!
[15:45:55] [server thread/INFO] [sTDOUT]: [code.elix_x.mods.btam.core.horses.events.OpenHorseInventoryEvent:openInventory:22]: Server!

And i'll try to use GuiOpenEvent too...

Link to comment
Share on other sites

Okaaay, i think it works now!

How ever if i do that, i still need to edit EntityHorse. At least setHorseTexturePaths, because of one stupid if:

if (this.func_110241_cb() >= horseArmorTextures.length)
        {
            this.field_175508_bO = false;
        }

Link to comment
Share on other sites

No, i need to keep this field. How ever i'll see if it works without changing anything...

How ever, i have just found that some weird stuff is happenning: when i click armor slot in horse gui, when it has something inside, i take out a saddle from other slot. If there's no saddle in other slot, nothing happens. So i mean that i can put armor in slot, but i can't take it out.

 

BTW: i used LivingHurtEvent, to do armor calculations, but this has a problem: these are done twice... So i think i'll use reflection during post init, to overhaul some arrays in EntityHorse.class and afterwards do not tuch anything in renderer and hurting...

Link to comment
Share on other sites

He he i'm speaking that this is done twice, because armor calculations are done by: me in event, mc in main hurt code.

 

About slots...

public class OpenHorseInventoryEvent {

public OpenHorseInventoryEvent(){

}

@SubscribeEvent
public void openInventory(PlayerOpenContainerEvent event){
	if(event.entityPlayer.openContainer instanceof ContainerHorseInventory){
		ContainerHorseInventory container = (ContainerHorseInventory) event.entityPlayer.openContainer;
		Slot armorSlot = container.getSlot(1);
		//			System.out.println("Saddle valid: " + armorSlot.isItemValid(new ItemStack(Items.saddle)) + " armor valid: " + armorSlot.isItemValid(new ItemStack(Items.diamond_horse_armor)) + " random item valid: " + armorSlot.isItemValid(new ItemStack(Items.golden_hoe)));
		try {
			Object object = ReflectionHelper.getPrivateValue(ContainerHorseInventory.class, container, "theHorse");
			if(object instanceof EntityHorse){
				final EntityHorse horse = (EntityHorse) object;
				armorSlot = new Slot(armorSlot.inventory, 1, armorSlot.xDisplayPosition, armorSlot.yDisplayPosition){
					private static final String __OBFID = "CL_00001753";
					public boolean isItemValid(ItemStack itemstack)
					{
//							return false;
						return super.isItemValid(itemstack) && horse.canWearArmor() && HorseArmorRegistry.isArmorValid(itemstack);
					}
					@SideOnly(Side.CLIENT)
					public boolean canBeHovered()
					{
						return horse.canWearArmor();
					}
				};
				container.inventorySlots.remove(1);
				container.inventorySlots.add(1, armorSlot);
			}
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		}
	}
}

@SubscribeEvent
public void openInventoryGui(GuiOpenEvent event){
	if(event.gui instanceof GuiScreenHorseInventory){
		GuiScreenHorseInventory gui = (GuiScreenHorseInventory) event.gui;
		ContainerHorseInventory container = (ContainerHorseInventory) gui.inventorySlots;
		Slot armorSlot = container.getSlot(1);
		//			System.out.println("Saddle valid: " + armorSlot.isItemValid(new ItemStack(Items.saddle)) + " armor valid: " + armorSlot.isItemValid(new ItemStack(Items.diamond_horse_armor)) + " random item valid: " + armorSlot.isItemValid(new ItemStack(Items.golden_hoe)));
		try {
			Object object = ReflectionHelper.getPrivateValue(ContainerHorseInventory.class, container, "theHorse");
			if(object instanceof EntityHorse){
				final EntityHorse horse = (EntityHorse) object;
				armorSlot = new Slot(armorSlot.inventory, 1, armorSlot.xDisplayPosition, armorSlot.yDisplayPosition){
					private static final String __OBFID = "CL_00001753";
					public boolean isItemValid(ItemStack itemstack)
					{
//							return false;
						return super.isItemValid(itemstack) && horse.canWearArmor() && HorseArmorRegistry.isArmorValid(itemstack);
					}
					@SideOnly(Side.CLIENT)
					public boolean canBeHovered()
					{
						return horse.canWearArmor();
					}
				};
				container.inventorySlots.remove(1);
				container.inventorySlots.add(1, armorSlot);
			}
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		}
	}
}
}

Link to comment
Share on other sites

First of all you can just use set(i, <object>) instead of remove and add.

Are you sure?

void java.util.List.add(int index, Object element)



add
void add(int index,
         E element)
Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
Parameters: 
index - index at which the specified element is to be inserted 
element - element to be inserted 
Throws: 
UnsupportedOperationException - if the add operation is not supported by this list 
ClassCastException - if the class of the specified element prevents it from being added to this list 
NullPointerException - if the specified element is null and this list does not permit null elements 
IllegalArgumentException - if some property of the specified element prevents it from being added to this list 
IndexOutOfBoundsException - if the index is out of range (index < 0 || index > size()) 

 

And i think i got that error after i switched to reflction helper... Let me try witout it...

EDIT: nope, it's not because of it...

 

EDIT 2:

if i do just add, this happens:

java.util.concurrent.ExecutionException: java.lang.IndexOutOfBoundsException: Index: 38, Size: 38
at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_25]
at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_25]
at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:710) [FMLCommonHandler.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:655) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:598) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:164) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:478) [MinecraftServer.class:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_25]
Caused by: java.lang.IndexOutOfBoundsException: Index: 38, Size: 38
at java.util.ArrayList.rangeCheck(Unknown Source) ~[?:1.8.0_25]
at java.util.ArrayList.get(Unknown Source) ~[?:1.8.0_25]
at net.minecraft.inventory.Container.detectAndSendChanges(Container.java:77) ~[Container.class:?]
at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:229) ~[EntityPlayerMP.class:?]
at net.minecraft.entity.Entity.updateRidden(Entity.java:1645) ~[Entity.class:?]
at net.minecraft.entity.EntityLivingBase.updateRidden(EntityLivingBase.java:1882) ~[EntityLivingBase.class:?]
at net.minecraft.entity.player.EntityPlayer.updateRidden(EntityPlayer.java:504) ~[EntityPlayer.class:?]
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:1861) ~[World.class:?]
at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:732) ~[WorldServer.class:?]
at net.minecraft.world.World.updateEntity(World.java:1835) ~[World.class:?]
at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:280) ~[NetHandlerPlayServer.class:?]
at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:33) ~[C03PacketPlayer.class:?]
at net.minecraft.network.play.client.C03PacketPlayer$C05PacketPlayerLook.processPacket(C03PacketPlayer.java:171) ~[C03PacketPlayer$C05PacketPlayerLook.class:?]
at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:18) ~[PacketThreadUtil$1.class:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_25]
at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_25]
at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:709) ~[FMLCommonHandler.class:?]
... 5 more
[15:17:12] [server thread/ERROR]: Encountered an unexpected exception
net.minecraft.util.ReportedException: Ticking entity
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:709) ~[MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:598) ~[MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:164) ~[integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:478) [MinecraftServer.class:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_25]
Caused by: java.lang.IndexOutOfBoundsException: Index: 38, Size: 38
at java.util.ArrayList.rangeCheck(Unknown Source) ~[?:1.8.0_25]
at java.util.ArrayList.get(Unknown Source) ~[?:1.8.0_25]
at net.minecraft.inventory.Container.detectAndSendChanges(Container.java:77) ~[Container.class:?]
at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:229) ~[EntityPlayerMP.class:?]
at net.minecraft.entity.Entity.updateRidden(Entity.java:1645) ~[Entity.class:?]
at net.minecraft.entity.EntityLivingBase.updateRidden(EntityLivingBase.java:1882) ~[EntityLivingBase.class:?]
at net.minecraft.entity.player.EntityPlayer.updateRidden(EntityPlayer.java:504) ~[EntityPlayer.class:?]
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:1861) ~[World.class:?]
at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:732) ~[WorldServer.class:?]
at net.minecraft.world.World.updateEntity(World.java:1835) ~[World.class:?]
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:1924) ~[World.class:?]
at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:732) ~[WorldServer.class:?]
at net.minecraft.world.World.updateEntity(World.java:1835) ~[World.class:?]
at net.minecraft.world.World.updateEntities(World.java:1664) ~[World.class:?]
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:571) ~[WorldServer.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:703) ~[MinecraftServer.class:?]
... 4 more
[15:17:12] [server thread/ERROR]: This crash report has been saved to: C:\my\mcmodding\mods\1.8\eclipse\.\crash-reports\crash-2015-03-02_15.17.12-server.txt
[15:17:12] [server thread/INFO]: Stopping server
[15:17:12] [server thread/INFO]: Saving players
[15:17:12] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:568]: ---- Minecraft Crash Report ----
// I just don't know what went wrong 

Time: 02.03.15 15:17
Description: Ticking entity

java.lang.IndexOutOfBoundsException: Index: 38, Size: 38
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at net.minecraft.inventory.Container.detectAndSendChanges(Container.java:77)
at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:229)
at net.minecraft.entity.Entity.updateRidden(Entity.java:1645)
at net.minecraft.entity.EntityLivingBase.updateRidden(EntityLivingBase.java:1882)
at net.minecraft.entity.player.EntityPlayer.updateRidden(EntityPlayer.java:504)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:1861)
at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:732)
at net.minecraft.world.World.updateEntity(World.java:1835)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:1924)
at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:732)
at net.minecraft.world.World.updateEntity(World.java:1835)
at net.minecraft.world.World.updateEntities(World.java:1664)
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:571)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:703)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:598)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:164)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:478)
at java.lang.Thread.run(Unknown Source)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at net.minecraft.inventory.Container.detectAndSendChanges(Container.java:77)
at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:229)
at net.minecraft.entity.Entity.updateRidden(Entity.java:1645)
at net.minecraft.entity.EntityLivingBase.updateRidden(EntityLivingBase.java:1882)
at net.minecraft.entity.player.EntityPlayer.updateRidden(EntityPlayer.java:504)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:1861)
at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:732)
at net.minecraft.world.World.updateEntity(World.java:1835)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:1924)
at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:732)
at net.minecraft.world.World.updateEntity(World.java:1835)

-- Entity being ticked --
Details:
Entity Type: EntityHorse (net.minecraft.entity.passive.EntityHorse)
Entity ID: 240
Entity Name: Horse
Entity's Exact location: 177,55, 73,00, 189,43
Entity's Block location: 177,00,73,00,189,00 - World: (177,73,189), Chunk: (at 1,4,13 in 11,11; contains blocks 176,0,176 to 191,255,191), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
Entity's Momentum: 0,00, -0,08, 0,00
Entity's Rider: EntityPlayerMP['Player954'/238, l='HHorses', x=177,55, y=73,85, z=189,43]
Entity's Vehicle: ~~ERROR~~ NullPointerException: null
Stacktrace:
at net.minecraft.world.World.updateEntities(World.java:1664)
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:571)

-- Affected level --
Details:
Level name: HHorses
All players: 1 total; [EntityPlayerMP['Player954'/238, l='HHorses', x=177,55, y=73,85, z=189,43]]
Chunk stats: ServerChunkCache: 660 Drop: 0
Level seed: 7894255427046113297
Level generator: ID 00 - default, ver 1. Features enabled: true
Level generator options: 
Level spawn location: 192,00,64,00,184,00 - World: (192,64,184), Chunk: (at 0,4,8 in 12,11; contains blocks 192,0,176 to 207,255,191), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
Level time: 41553 game time, 41553 day time
Level dimension: 0
Level storage version: 0x04ABD - Anvil
Level weather: Rain time: 29509 (now: false), thunder time: 99108 (now: false)
Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true
Stacktrace:
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:703)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:598)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:164)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:478)
at java.lang.Thread.run(Unknown Source)

-- System Details --
Details:
Minecraft Version: 1.8
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.8.0_25, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 807279824 bytes (769 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
IntCache: cache: 5, tcache: 0, allocated: 13, tallocated: 95
FML: MCP v9.10 FML v8.0.37.1329 Minecraft Forge 11.14.1.1329 6 mods loaded, 6 mods active
mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{8.0.37.1329} [Forge Mod Loader] (forgeSrc-1.8-11.14.1.1329.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{11.14.1.1329} [Minecraft Forge] (forgeSrc-1.8-11.14.1.1329.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
avoidExplodingCreepers{1.0} [Avoid Exploding Creepers] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
BTAM{2.0} [block Tools Armor Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
toolscompressor{1.0} [Tools compresser] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Loaded coremods (and transformers): 
Profiler Position: N/A (disabled)
Player Count: 1 / 8; [EntityPlayerMP['Player954'/238, l='HHorses', x=177,55, y=73,85, z=189,43]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'
[15:17:12] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:568]: #@!@# Game crashed! Crash report saved to: #@!@# .\crash-reports\crash-2015-03-02_15.17.12-server.txt
[15:17:12] [Client thread/INFO] [FML]: Waiting for the server to terminate/save.
[15:17:12] [server thread/INFO]: Saving worlds
[15:17:12] [server thread/INFO]: Saving chunks for level 'HHorses'/Overworld
[15:17:12] [server thread/INFO]: Saving chunks for level 'HHorses'/Nether
[15:17:12] [server thread/INFO]: Saving chunks for level 'HHorses'/The End
[15:17:13] [server thread/INFO] [FML]: Unloading dimension 0
[15:17:13] [server thread/INFO] [FML]: Unloading dimension -1
[15:17:13] [server thread/INFO] [FML]: Unloading dimension 1
[15:17:13] [server thread/INFO] [FML]: Applying holder lookups
[15:17:13] [server thread/INFO] [FML]: Holder lookups applied
[15:17:13] [server thread/INFO] [FML]: The state engine was in incorrect state SERVER_STOPPING and forced into state SERVER_STOPPED. Errors may have been discarded.
[15:17:13] [Client thread/INFO] [FML]: Server terminated.
AL lib: (EE) alc_cleanup: 1 device not closed
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release

 

So i must use remove and add...

Link to comment
Share on other sites

Aaand if you want to debug it, here's simplier version of event that has still that bug and is not dependent of everything else. So just register it in MCF's event bus, and you can test it.

public class OpenHorseInventoryEvent {

public OpenHorseInventoryEvent(){

}

@SubscribeEvent
public void openInventory(PlayerOpenContainerEvent event){
	if(event.entityPlayer.openContainer instanceof ContainerHorseInventory){
		ContainerHorseInventory container = (ContainerHorseInventory) event.entityPlayer.openContainer;
		Slot armorSlot = container.getSlot(1);
		//			System.out.println("Saddle valid: " + armorSlot.isItemValid(new ItemStack(Items.saddle)) + " armor valid: " + armorSlot.isItemValid(new ItemStack(Items.diamond_horse_armor)) + " random item valid: " + armorSlot.isItemValid(new ItemStack(Items.golden_hoe)));
		try {
//				Field f = container.getClass().getField("theHorse");
			/*Field f = ContainerHorseInventory.class.getDeclaredField("theHorse");
			f.setAccessible(true);
			Object object = f.get(container);*/
			Object object = ReflectionHelper.getPrivateValue(ContainerHorseInventory.class, container, "theHorse");
			if(object instanceof EntityHorse){
				final EntityHorse horse = (EntityHorse) object;
				armorSlot = new Slot(armorSlot.inventory, 1, armorSlot.xDisplayPosition, armorSlot.yDisplayPosition){
					private static final String __OBFID = "CL_00001753";
					public boolean isItemValid(ItemStack itemstack)
					{
//							return true;
						return super.isItemValid(itemstack) && horse.canWearArmor()/* && HorseArmorRegistry.isArmorValid(itemstack)*/;
					}
					@SideOnly(Side.CLIENT)
					public boolean canBeHovered()
					{
						return horse.canWearArmor();
					}
				};
//					container.inventorySlots.remove(1);
				container.inventorySlots.set(1, armorSlot);
			}
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		}/* catch (NoSuchFieldException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}*/
	}
}

@SubscribeEvent
public void openInventoryGui(GuiOpenEvent event){
	if(event.gui instanceof GuiScreenHorseInventory){
		GuiScreenHorseInventory gui = (GuiScreenHorseInventory) event.gui;
		ContainerHorseInventory container = (ContainerHorseInventory) gui.inventorySlots;
		Slot armorSlot = container.getSlot(1);
		//			System.out.println("Saddle valid: " + armorSlot.isItemValid(new ItemStack(Items.saddle)) + " armor valid: " + armorSlot.isItemValid(new ItemStack(Items.diamond_horse_armor)) + " random item valid: " + armorSlot.isItemValid(new ItemStack(Items.golden_hoe)));
		try {
//				Field f = container.getClass().getField("theHorse");
			/*Field f = ContainerHorseInventory.class.getDeclaredField("theHorse");
			f.setAccessible(true);
			Object object = f.get(container);*/
			Object object = ReflectionHelper.getPrivateValue(ContainerHorseInventory.class, container, "theHorse");
			if(object instanceof EntityHorse){
				final EntityHorse horse = (EntityHorse) object;
				armorSlot = new Slot(armorSlot.inventory, 1, armorSlot.xDisplayPosition, armorSlot.yDisplayPosition){
					private static final String __OBFID = "CL_00001753";
					public boolean isItemValid(ItemStack itemstack)
					{
//							return true;
						return super.isItemValid(itemstack) && horse.canWearArmor()/* && HorseArmorRegistry.isArmorValid(itemstack)*/;
					}
					@SideOnly(Side.CLIENT)
					public boolean canBeHovered()
					{
						return horse.canWearArmor();
					}
				};
//					container.inventorySlots.remove(1);
				container.inventorySlots.set(1, armorSlot);
			}
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		}/* catch (NoSuchFieldException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}*/
	}
}
}

 

And BTW, yes, i can use set instead of remove and add  :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.