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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • As the title say, game suddenly crushed during the loading. I got this error message The game crashed whilst rendering overlay Error: java.lang.RuntimeException: null   And Here's the link of crash log bit.ly/3IcVUQG
    • Do these mods have incompatibles: Dynamic View[Forge] (by someaddon) Server Performance - Smooth Chunk Save[Forge/Fabric] (by someaddon) EdivadLib (by 3divad99) Krypton Reforged (by Anthxny) AttributeFix (by DarkhaxDev) Create Stuff & Additions (by Furti_Two) Cristel Lib (by Cristelknight) Resourceful Config (by ThatGravyBoat) Applied Cooking (by ItsSebastrn) Thermal Cultivation (by TeamCoFH) SuperMartijn642's Config Lib (by SuperMartijn642) Create: Bells & Whistles (by sudolev) Thermal Integration (by TeamCoFH) SebastrnLib (by ItsSebastrn) Farmer's Delight (by vectorwing) Right Click, Get Crops (by TeamCoFH) Observable (by tasgon) FPS optimizer (by The_TCT) Dungeons and Taverns (by Nova_Wostra) Explorify – Dungeons & Structures (by bebebea_loste) Fast Leaf Decay (by olafskiii) Create: Vintage Improvements (by Negodya1) Sophisticated Backpacks (by P3pp3rF1y) SuperMartijn642's Core Lib (by SuperMartijn642) Create Crafts & Additions (by MRHminer) Structory (by botanydev) Oculus (by Asek3) Tectonic (by Apollo) Embeddium (Rubidium) Extra (by dimadencep) Athena (by CodexAdrian) Jade 🔍 (by Snownee) Mekanism Tools (by bradyaidanc) Carry On (by Tschipp) Create: Sweets & Treats (by AstralButOnCurseForge) Extreme Reactors Create Compat (by ZeroNoRyouki) AI Improvements (by QueenOfMissiles) AE2 QoL Recipes (by Christofmeg) Create: ComputerCraft (CC: Tweaked) (by EndRage) Create Enchantment Industry (by DragonsPlus) Macaw's Fences and Walls (by sketch_macaw) Better Villages - Forge (by jtl_elisa) Puzzles Lib [Forge & Fabric] (by Fuzs) Mekanism (by bradyaidanc) Create Recycle Everything (by nocubeyt) Searchables (by Jaredlll08) Immersive Paintings [Fabric/Forge] (by Conczin) Create Deco (by talrey) Thermal Foundation (by TeamCoFH) Controlling (by Jaredlll08) Kotlin for Forge (by thedarkcolour) Lithostitched (by Apollo) Let Me Despawn (by frikinjay) MCEF (Minecraft Chromium Embedded Framework) (by ds58) FPS Boost (by The_TCT) Ad Astra (by AlexNijjar) TerraBlender (Forge) (by TheAdubbz) Falling Leaves (Forge) (by Cheaterpaul) CC:C Bridge (by Sammy_echt) Xaero's Minimap (by xaero96) CoFH Core (by TeamCoFH) Create: Applied Kinetics (by Forsteri123) AE Additions - ExtraCells2 Fork (by MasterYodAT9G) Just Enough Items (JEI) (by mezz) Biomes O' Plenty (by Forstride) Curios API (Forge/NeoForge) (by TheIllusiveC4) AE2 Network Analyser (by GlodBlock) Resourceful Lib (by ThatGravyBoat) ChoiceTheorem's Overhauled Village (by ChoiceTheorem) Clockwork: Create x Valkyrien Skies (by triode_) Architectury API (Fabric/Forge/NeoForge) (by shedaniel) Canary (by AbdElAziz333) Structure Essentials[Forge/Fabric] (by someaddon) Library Ferret - Forge (by jtl_elisa) Create Confectionery (by Furti_Two) Leaky - Farm leak detection[Forge/Fabric] (by someaddon) Game Menu Mod Option [Forge] (by morimori0317) Macaw's Bridges (by sketch_macaw) FramedBlocks (by XFactHD) Cherished Worlds (Fabric/Forge/NeoForge/Quilt) (by TheIllusiveC4) Entangled (by SuperMartijn642) Refined Storage: Requestify (by Buuz135) ME Requester (by Relentless) Inventory Sorter (by cpw) Xaero's World Map (by xaero96) William Wythers' Expanded Ecosphere (by Cristelknight) Cloth Config API (Fabric/Forge/NeoForge) (by shedaniel) FTB Library (Forge) (by FTB) Cupboard (by someaddon) Thermal Dynamics (by TeamCoFH) Patchouli (by Vazkii) Entity Culling Fabric/Forge (by tr7zw) Chipped (by terrariumearth) FTB XMod Compat (by FTB) FerriteCore ((Neo)Forge) (by malte0811) Extra Disks (by MelanX) Nature's Compass (by Chaosyr) Thermal Locomotion (by TeamCoFH) TexTrue's Embeddium Options (by TexTrue) Traveler's Backpack (by Tiviacz1337) Geophilic – Vanilla Biome Overhauls (by bebebea_loste) Create: Power Loader (by Lysine) Polymorph (Fabric/Forge/Quilt) (by TheIllusiveC4) Enlightend (by lixir) Create Central Kitchen (by DragonsPlus) Energy Meter (by Relentless) Botarium (by CodexAdrian) FTB Teams (Forge) (by FTB) Storage Drawers (by Texelsaur) Create: Extended Cogwheels (by Rabbitminers) Embeddium/Rubidium Dynamic Lights (by Anthxny) Biome Makeover (Forge) (by Lemonszz) Create Guardian Beam Defense (by ibarnstormer_) Create: The Factory Must Grow (by Dr_Mango_Tea) Create Chunkloading (by embeddedt) Balm (Forge Edition) (by BlayTheNinth) Glodium (by GlodBlock) Thermal Expansion (by TeamCoFH) Chunk-Pregenerator (by Speiger) Advanced Peripherals (by srrendi) Create: Garnished (by DakotaPrideModding) Tidal Towns (by joshieman) Easy Magic [Forge & Fabric] (by Fuzs) Extreme Reactors (by ZeroNoRyouki) Applied Energistics 2 Wireless Terminals (by Mari_023) Redstone Arsenal (by TeamCoFH) ExtraStorage (by 3divad99) Thermal Innovation (by TeamCoFH) Collective (by Serilum) Wizard's Reborn (by MaxBogomol) GraveStone Mod (by henkelmax) Mekanism Additions (by bradyaidanc) Create: New Age (by nilBlade) Refined Storage (by raoulvdberge) Embeddium/Rubidium Extras (by Anthxny) ZeroCore 2 (by ZeroNoRyouki) Mekanism Generators (by bradyaidanc) WebDisplays (by ds58) Clumps (by Jaredlll08) Vein Mining (Fabric/Forge/Quilt) (by TheIllusiveC4) Villager Names (by Serilum) Create Slice & Dice (by possible_triangle) Embeddium (by embeddedt) Create: Steam 'n' Rails (by mattentosh) Get It Together, Drops! (by bl4ckscor3) Sophisticated Core (by P3pp3rF1y) Supplementaries (by MehVahdJukaar) Jade Addons (Forge) (by Snownee) Create: Design n' Decor (by MilkyFur) Construction Wand (by ThetaDev) Create: Diesel Generators (by george8188262) Create : Misc & Things (by to0pa_fr) Valkyrien Skies (Forge/Fabric) (by triode_) Refined Storage Addons (by raoulvdberge) FTB Chunks (Forge) (by FTB) FTB Ranks (Forge) (by FTB) Moonlight Lib (by MehVahdJukaar) CC: Tweaked (by SquidDev) Waystones (by BlayTheNinth) Applied Energistics 2 (by thetechnici4n) Trowels fork (by Luciano_cz) Cooking for Blockheads (by BlayTheNinth) Create (by simibubi) Towns and Towers (by Biban_Auriu)
    • Hi, you guys are probably all tired of having to deal with the same topic everytimes. I want to play mods, but forge doesn't want me to. And after days of videos and forum, i have no choices to ask before giving up.. The classic Error code 1 ( here's my debug.log : https://paste.ee/p/0WMSP). I tryed everything. The Forge version fit the mod version. I have java jdk 17 and the path to java is set. My mods folder is empty. My Minecraft luncher path has been changed. Java, Minecraft and Forged has been reinstalled 3 times. I tryed with the curseforge luncher. The only thing i didn't do, and I think it might be the problem, is updating my graphic card drivers. For the only reason that my computer is an Ace Magician ( Tiny pc) that don't have a graphic card. But then I went with Fabric. And it works just fine.  Anyway I can't find anything so thank you for your help. Sorry for my english if there's any mistake. Razziel.  
    • I am trying to make my own modpack and at the moment it crashes before I can get to the main menu. I have been trying to google and figure it out myself but would really appreciate some help. I've been using CurseForge to install mod and think I've gotten all the dependencies but I'm not 100% sure. I hope I got the paste.ee thing right Thanks in advance! https://paste.ee/p/NXdSO
  • Topics

×
×
  • Create New...

Important Information

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