Jump to content

[1.7.10] Temporarily Replace Players HUD Storage/Main Storage with a custom one


Thornack

Recommended Posts

Hi Everyone,

 

I Want to change the HUD inventory Element temporarily based on a condition (whether or not my player is morphed into his party member or not). So that when my condition is true the player gets a new inventory with a reduced # of slots and a custom gui for it, and when it is false he gets hic original inventory back. I also want to disable access to the players main inventory when my condition is true. Basically

 

 

if(x == true) {
Temporarily disable access to players current inventory and give player new custom inventory
} else if (x == false){
Temporarily re-enable access to players original inventory and disable access to custom inventory
}

 

I know how to disable the HUD but im not sure how to disable access to the main inventory for the player. Also Im not sure how to add a custom inventory to the player. So far I have the following.

 

Inventory Class

 

 

public class InventoryCustomForPlayer implements IInventory{

private final String inventoryName = "PlayerCustomInventory";
public static final int INV_SIZE = 4;
ItemStack[] inventory = new ItemStack[iNV_SIZE];

public InventoryCustomForPlayer(){

}

@Override
public int getSizeInventory() {
	return inventory.length;
}

@Override
public ItemStack getStackInSlot(int slot) {
	return inventory[slot];
}

@Override
public ItemStack decrStackSize(int slot, int amount) {
	ItemStack stack = getStackInSlot(slot);
	if (stack != null){
		if (stack.stackSize > amount){
			stack = stack.splitStack(amount);
			if (stack.stackSize == 0){
				setInventorySlotContents(slot, null);
			}
		}else{
			setInventorySlotContents(slot, null);
		} this.markDirty();
	}
	return stack;
}

@Override
public ItemStack getStackInSlotOnClosing(int slot) {
	ItemStack stack = getStackInSlot(slot);
	if (stack != null){
		setInventorySlotContents(slot, null);
	}
	return stack;
}

@Override
public void setInventorySlotContents(int slot, ItemStack itemStack) {
	this.inventory[slot] = itemStack;
	if (itemStack != null && itemStack.stackSize > this.getInventoryStackLimit()){
		itemStack.stackSize = this.getInventoryStackLimit();
	}
	this.markDirty();
	}

@Override
public String getInventoryName() {
	return inventoryName;
}

@Override
public boolean hasCustomInventoryName() {
	return inventoryName.length() > 0;
}

@Override
public int getInventoryStackLimit() {
	return 1;
}

@Override
public void markDirty() {
	for (int i = 0; i < this.getSizeInventory(); ++i){
		if (this.getStackInSlot(i) != null && this.getStackInSlot(i).stackSize == 0){
			this.setInventorySlotContents(i, null);
		}
	}

}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
	return true;
}

@Override
public void openInventory() {

}

@Override
public void closeInventory() {

}

@Override
public boolean isItemValidForSlot(int slot, ItemStack itemStack) {
	return false;
}

 public void loadInventoryFromPlayer(EntityPlayer player){
    	NBTTagCompound nbtCompound = player.getEntityData();
    	if(nbtCompound != null){
    		NBTTagList nbtTagList = nbtCompound.getTagList("PlayerCustomInventory", 10);
    		this.loadInventoryFromNBT(nbtTagList);
    	}
    }
    
    //save the player's PC inventory to NBT
    public void saveInventoryToPlayer(EntityPlayer player){
    	NBTTagCompound nbtCompound = player.getEntityData();
    	NBTTagList nbtTagList = this.saveInventoryToNBT();
    	nbtCompound.setTag("PlayerCustomInventory", nbtTagList);
    }
    
    //load,save to NBT copied from minecraft chest code
    public void loadInventoryFromNBT(NBTTagList par1NBTTagList)
    {
        int i;

        for (i = 0; i < this.getSizeInventory(); ++i)
        {
            this.setInventorySlotContents(i, (ItemStack)null);
        }

        for (i = 0; i < par1NBTTagList.tagCount(); ++i)
        {
            NBTTagCompound nbttagcompound = par1NBTTagList.getCompoundTagAt(i);
            int j = nbttagcompound.getByte("Slot") & 255;

            if (j >= 0 && j < this.getSizeInventory())
            {
                this.setInventorySlotContents(j, ItemStack.loadItemStackFromNBT(nbttagcompound));
            }
        }
    }

    //load,save to NBT copied from minecraft chest code
    public NBTTagList saveInventoryToNBT()
    {
        NBTTagList nbttaglist = new NBTTagList();

        for (int i = 0; i < this.getSizeInventory(); ++i)
        {
            ItemStack itemstack = this.getStackInSlot(i);

            if (itemstack != null)
            {
                NBTTagCompound nbttagcompound = new NBTTagCompound();
                nbttagcompound.setByte("Slot", (byte)i);
                itemstack.writeToNBT(nbttagcompound);
                nbttaglist.appendTag(nbttagcompound);
            }
        }
        return nbttaglist;
    }
}

 

 

 

Container Class

 

 

public class ContainerPlayerCustom extends Container
{   
    private final int slotCols = 1;
    private int slotRows;
private InventoryCustomForPlayer inventoryCustom;

public ContainerPlayerCustom(IInventory playerInventory, InventoryCustomForPlayer inventoryCustom){
        this.inventoryCustom = inventoryCustom;
        this.slotRows = inventoryCustom.getSizeInventory() / this.slotCols;
        inventoryCustom.openInventory();
        
        //calculate the slot positions on the screen, in pixel coordinates
        //Slot(Container, slotIndex, xDisplayPos, yDisplayPos)
        //int i = (this.slotRows - 4) * 18;
        int j;
        int k;

        //PC Inventory
        for (j = 0; j < this.slotRows; ++j){
            for (k = 0; k < this.slotCols; ++k){
            	this.addSlotToContainer(new Slot(inventoryCustom, k + j * 9, 38 + k * 18, 18 + j * 18));
            }
        }
        //player's inventory
        for (j = 0; j < 3; ++j){
            for (k = 0; k < 9; ++k){
            	this.addSlotToContainer(new Slot(playerInventory, k + j * 9 + 9, 18 + k * 18, 105 + j * 18));
            }
        }
        //player's hotbar
        for (j = 0; j < 9; ++j){
        	this.addSlotToContainer(new Slot(playerInventory, j, 18 + j * 18, 163));
        }
    }

    /**
     * Called when the container is closed.
     */
    public void onContainerClosed(EntityPlayer player)
    {
        super.onContainerClosed(player);
        this.inventoryCustom.saveInventoryToPlayer(player);
    }
    
    @Override
    public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
    {
        ItemStack itemstack = null;
        Slot slot = (Slot)this.inventorySlots.get(par2);

        if (slot != null && slot.getHasStack())
        {
            ItemStack itemstack1 = slot.getStack();
            itemstack = itemstack1.copy();

            if (par2 < this.slotRows * 9)
            {
                if (!this.mergeItemStack(itemstack1, this.slotRows * 9, this.inventorySlots.size(), true))
                {
                    return null;
                }
            }
            else if (!this.mergeItemStack(itemstack1, 0, this.slotRows * 9, false))
            {
                return null;
            }

            if (itemstack1.stackSize == 0)
            {
                slot.putStack((ItemStack)null);
            }
            else
            {
                slot.onSlotChanged();
            }
        }

        return itemstack;
    }
    
    

@Override
public boolean canInteractWith(EntityPlayer var1) {
	return true;
}
}

 

 

 

Basically I want to do this so that in the case demoed by the left image player has access to all his items. In case demoed by the right image player only can use the items in the 4 new slots that are displayed. and I want the two cases to be swappable so that when my condition changes the inventories are swapped out

 

lmT4RMs.png

Link to comment
Share on other sites

Well. I am working on sth similar right now. My ideas might not be ideal but they work. If u find sth better please tell me.

 

The problem is this WONT be compatible with other mods usiing GuiContainer.

 

U can catch minecraft triing to open up a gui. E.g. Inventory. Then u need to open ur custom inventory using ur custom data.

 

U can also try to replace player.inventory with a custom inventory, but I found this to be EXTREMLY hard because there was always one little place where minecraft somehow accessed the "original" inventory and not mine and I was unable to track that.

 

@SubscribeEvent 
public void guiOpened(GuiOpenEvent event) {
	if(event.gui!=null && event.gui instanceof GuiInventory)
	{
		if(Minecraft.getMinecraft().thePlayer.capabilities.isCreativeMode) return;
                       //open custom inventorygui here





	}

}

 

 

Link to comment
Share on other sites

This cancels the rendering of the hotbar, which is what I already know how to do, but I need to disable access to it completely (I need all access to the players normal inventory blocked off when a certain condition is true and only allow access to my custom inventory at this time/ render it at this time). But if my condition is false I need the player to only have access to his original inventory (with all behind the scenes item mechanics and everything preserved in both cases).

 

@SubscribeEvent(priority=EventPriority.NORMAL)
public void onRenderPre(RenderGameOverlayEvent.Pre event) {

	if (event.type == ElementType.HOTBAR) {
		event.setCanceled(true);
		return;
	}
}

 

Link to comment
Share on other sites

well. then u can just go on like

 

 

@SubscribeEvent

public void guiOpened(GuiOpenEvent event) {

if(event.gui==null) return;

if(event.gui instanceof GuiInventory)

{

if(Minecraft.getMinecraft().thePlayer.capabilities.isCreativeMode) return;

//open custom GuiInventory

 

}

if(event.gui instanceof GuiFurnace) {

//open custom GuiFurnace

}

}

 

This solution might be a bit hacky and i am quite sure there are better.

Link to comment
Share on other sites

Found an improvement!

 

I got to a problem when I wanted to catch the opening of a Furnace opening. Since I need to access the furnace I need its position, which is not possible thorugh GuiOpenEvent.

 

Got me to the point where I realized it is better to use PlayerInteractEvent to catch the opening of e.g. the furnace inventory and open my own

 

@SubscribeEvent
public void interact(PlayerInteractEvent event) {
	if(event.action == Action.RIGHT_CLICK_BLOCK) {
		if (event.entityPlayer.worldObj.getBlockState(event.pos).getBlock()==Blocks.furnace) {
			System.out.println("test");
			event.setCanceled(true);
		}
	}
}

I am only at the point where i syso test of course i will open my own inventory there :b

Link to comment
Share on other sites

Im not sure if this is going to work for me. It cancels opening of the inventory throgh use of the E key but it still allows access to the items I am holding/using and I need to block that also. I think it also has the issue of if I click on any container my inventory wills till show up and I need that blocked aswell. Can you use the onInteract Event to block  the inventory in all of the cases where if the player clicks on a container or a chest or a furnace etc etc it will block the inventory as well as if the player tries to open it witht he E key?

 

@SubscribeEvent 
   public void guiOpened(GuiOpenEvent event) {
      if(event.gui==null) return;
      if(event.gui instanceof GuiInventory){
    	 if(!Minecraft.getMinecraft().thePlayer.capabilities.isCreativeMode){
        	 event.setCanceled(true);
        	 return;
         //open custom GuiInventory
         }
      }
      
   }

Link to comment
Share on other sites

If I do

@SubscribeEvent 
   public void guiOpened(GuiOpenEvent event) {
      if(event.gui==null) return;
      if(event.gui instanceof GuiContainer){
    	  System.out.println("FIRED GUI INVETORY OPEN" + Minecraft.getMinecraft().thePlayer);
         if(!Minecraft.getMinecraft().thePlayer.capabilities.isCreativeMode){
        	 event.setCanceled(true);
        	 return;
         //open custom GuiInventory
         }
      }
      
   }

also if I try to replace

event.gui instanceof GuiContainer

with

 event.gui instanceof GuiChest or event.gui instanceof GuiCrafting

I get crashes also. There has to be a better way to disable the players inventory than this. this is very hacky and basically requires you to do the following ridiculous if statement-> But this crashes

 

the ridiculous if statement

@SubscribeEvent 
   public void guiOpened(GuiOpenEvent event) {
      if(event.gui==null) return;
      if(event.gui instanceof GuiInventory || event.gui instanceof GuiFurnace  || event.gui instanceof GuiCrafting|| event.gui instanceof GuiChest ||event.gui instanceof GuiBeacon || event.gui instanceof GuiBrewingStand || event.gui instanceof GuiDispenser || event.gui instanceof GuiScreenHorseInventory  ){
    	  System.out.println("FIRED GUI INVETORY OPEN" + Minecraft.getMinecraft().thePlayer);
         if(!Minecraft.getMinecraft().thePlayer.capabilities.isCreativeMode){
        	 event.setCanceled(true);
        	 return;
         //open custom GuiInventory
         }
      }
      
   }

 

 

I get this crash for container, chest, crafting table, enderchest

 

 

java.lang.IndexOutOfBoundsException: Index: 45, Size: 45

at java.util.ArrayList.rangeCheck(Unknown Source)

at java.util.ArrayList.get(Unknown Source)

at net.minecraft.inventory.Container.getSlot(Container.java:130)

at net.minecraft.inventory.Container.putStacksInSlots(Container.java:558)

at net.minecraft.client.network.NetHandlerPlayClient.handleWindowItems(NetHandlerPlayClient.java:1196)

at net.minecraft.network.play.server.S30PacketWindowItems.processPacket(S30PacketWindowItems.java:70)

at net.minecraft.network.play.server.S30PacketWindowItems.processPacket(S30PacketWindowItems.java:78)

at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241)

at net.minecraft.client.multiplayer.PlayerControllerMP.updateController(PlayerControllerMP.java:317)

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1683)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1029)

at net.minecraft.client.Minecraft.run(Minecraft.java:951)

at net.minecraft.client.main.Main.main(Main.java:164)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78)

at GradleStart.main(GradleStart.java:45)

 

 

 

seems to work for cancelling the gui for

furnace, dispenser, dropper, main inventory, and beacon

but crashes on chest, crafting table, enderchest.. etc

Link to comment
Share on other sites

wel thats strange and should not be happening. but since u want to change the hotbar anyway, I think u should consider triing to replace the player inventory. I have started to research on that but my results were not satisfacting. try looking inside EntityPlayer and finding out which variables need to be changed.. player.inventory for sure.

Link to comment
Share on other sites

Im trying something out here. Although Im having some trouble atm. Im trying to just add my inventory in with the hotbar rendering being cancelled out.

 

The Inventory Class

 

 

public class InventoryCustom implements IInventory{

private final String inventoryName = "CustomInventory";
public static final int INV_SIZE = 4;
ItemStack[] inventory = new ItemStack[iNV_SIZE];

public InventoryCustom(){

}

@Override
public int getSizeInventory() {
	return inventory.length;
}

@Override
public ItemStack getStackInSlot(int slot) {
	return inventory[slot];
}

@Override
public ItemStack decrStackSize(int slot, int amount) {
	ItemStack stack = getStackInSlot(slot);
	if (stack != null){
		if (stack.stackSize > amount){
			stack = stack.splitStack(amount);
			if (stack.stackSize == 0){
				setInventorySlotContents(slot, null);
			}
		}else{
			setInventorySlotContents(slot, null);
		} this.markDirty();
	}
	return stack;
}

@Override
public ItemStack getStackInSlotOnClosing(int slot) {
	ItemStack stack = getStackInSlot(slot);
	if (stack != null){
		setInventorySlotContents(slot, null);
	}
	return stack;
}

@Override
public void setInventorySlotContents(int slot, ItemStack itemStack) {
	this.inventory[slot] = itemStack;
	if (itemStack != null && itemStack.stackSize > this.getInventoryStackLimit()){
		itemStack.stackSize = this.getInventoryStackLimit();
	}
	this.markDirty();
	}

@Override
public String getInventoryName() {
	return inventoryName;
}

@Override
public boolean hasCustomInventoryName() {
	return inventoryName.length() > 0;
}

@Override
public int getInventoryStackLimit() {
	return 1;
}

@Override
public void markDirty() {
	for (int i = 0; i < this.getSizeInventory(); ++i){
		if (this.getStackInSlot(i) != null && this.getStackInSlot(i).stackSize == 0){
			this.setInventorySlotContents(i, null);
		}
	}

}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
	return true;
}

@Override
public void openInventory() {

}

@Override
public void closeInventory() {

}

@Override
public boolean isItemValidForSlot(int slot, ItemStack itemStack) {
	return false;
}

 public void loadInventoryFromPlayer(EntityPlayer player){
    	NBTTagCompound nbtCompound = player.getEntityData();
    	if(nbtCompound != null){
    		NBTTagList nbtTagList = nbtCompound.getTagList("CustomInventory", 10);
    		this.loadInventoryFromNBT(nbtTagList);
    	}
    }
    
    //save the player's PC inventory to NBT
    public void saveInventoryToPlayer(EntityPlayer player){
    	NBTTagCompound nbtCompound = player.getEntityData();
    	NBTTagList nbtTagList = this.saveInventoryToNBT();
    	nbtCompound.setTag("CustomInventory", nbtTagList);
    }
    
    //load,save to NBT copied from minecraft chest code
    public void loadInventoryFromNBT(NBTTagList par1NBTTagList)
    {
        int i;

        for (i = 0; i < this.getSizeInventory(); ++i)
        {
            this.setInventorySlotContents(i, (ItemStack)null);
        }

        for (i = 0; i < par1NBTTagList.tagCount(); ++i)
        {
            NBTTagCompound nbttagcompound = par1NBTTagList.getCompoundTagAt(i);
            int j = nbttagcompound.getByte("Slot") & 255;

            if (j >= 0 && j < this.getSizeInventory())
            {
                this.setInventorySlotContents(j, ItemStack.loadItemStackFromNBT(nbttagcompound));
            }
        }
    }

    //load,save to NBT copied from minecraft chest code
    public NBTTagList saveInventoryToNBT()
    {
        NBTTagList nbttaglist = new NBTTagList();

        for (int i = 0; i < this.getSizeInventory(); ++i)
        {
            ItemStack itemstack = this.getStackInSlot(i);

            if (itemstack != null)
            {
                NBTTagCompound nbttagcompound = new NBTTagCompound();
                nbttagcompound.setByte("Slot", (byte)i);
                itemstack.writeToNBT(nbttagcompound);
                nbttaglist.appendTag(nbttagcompound);
            }
        }
        return nbttaglist;
    }
}

 

 

 

The Container Class

 

 

public class ContainerCustom extends Container
{   
    private final int slotCols = 1;
    private int slotRows;
public InventoryCustom inventoryCustom;

public ContainerCustom(IInventory playerInventory, InventoryCustom inventoryCustom){
        this.inventoryCustom = inventoryCustom;
        this.slotRows = inventoryCustom.getSizeInventory() / this.slotCols;
        inventoryCustom.openInventory();
        
        //calculate the slot positions on the screen, in pixel coordinates
        //Slot(Container, slotIndex, xDisplayPos, yDisplayPos)
        //int i = (this.slotRows - 4) * 18;
        int j;
        int k;

        //PC Inventory
        for (j = 0; j < this.slotRows; ++j){
            for (k = 0; k < this.slotCols; ++k){
            	this.addSlotToContainer(new Slot(inventoryCustom, k + j * 9, 38 + k * 18, 18 + j * 18));
            }
        }
        //player's inventory
        for (j = 0; j < 3; ++j){
            for (k = 0; k < 9; ++k){
            	this.addSlotToContainer(new Slot(playerInventory, k + j * 9 + 9, 18 + k * 18, 105 + j * 18));
            }
        }
        //player's hotbar
        for (j = 0; j < 9; ++j){
        	this.addSlotToContainer(new Slot(playerInventory, j, 18 + j * 18, 163));
        }
    }

    /**
     * Called when the container is closed.
     */
    public void onContainerClosed(EntityPlayer player)
    {
        super.onContainerClosed(player);
        this.inventoryCustom.saveInventoryToPlayer(player);
    }
    
    @Override
    public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
    {
        ItemStack itemstack = null;
        Slot slot = (Slot)this.inventorySlots.get(par2);

        if (slot != null && slot.getHasStack())
        {
            ItemStack itemstack1 = slot.getStack();
            itemstack = itemstack1.copy();

            if (par2 < this.slotRows * 9)
            {
                if (!this.mergeItemStack(itemstack1, this.slotRows * 9, this.inventorySlots.size(), true))
                {
                    return null;
                }
            }
            else if (!this.mergeItemStack(itemstack1, 0, this.slotRows * 9, false))
            {
                return null;
            }

            if (itemstack1.stackSize == 0)
            {
                slot.putStack((ItemStack)null);
            }
            else
            {
                slot.onSlotChanged();
            }
        }

        return itemstack;
    }
    
    

@Override
public boolean canInteractWith(EntityPlayer var1) {
	return true;
}

}

 

 

 

The Gui Class

 

 

public class GuiAttacksInventory  extends GuiContainer
{
/** x and y size of the inventory window in pixels. Defined as float, passed as int
 * These are used for drawing the player model. */
private float xSize_lo;
private float ySize_lo;

private static final ResourceLocation iconLocation = new ResourceLocation("custommod:textures/gui/HotbarReplacement.png");

/** The inventory to render on screen */
private final InventoryCustom inventoryCustom;

public GuiAttacksInventory(ContainerCustom containerCustom)
{
	super(containerCustom);
	this.inventoryCustom = containerCustom.inventoryCustom;
}

/**
 * Draws the screen and all the components in it.
 */
public void drawScreen(int mouseX, int mouseY, float par3)
{
	super.drawScreen(mouseX, mouseY, par3);
	this.xSize_lo = (float)mouseX;
	this.ySize_lo = (float)mouseY;
}


/**
 * Draw the background layer for the GuiContainer (everything behind the items)
 */
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	this.mc.getTextureManager().bindTexture(iconLocation);
	int k = (this.width - this.xSize) / 2;
	int l = (this.height - this.ySize) / 2;
	this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
	int i1;

}

}

 

 

 

Im not sure if I set everything up correctly but those are my classes. Now, How would I get the Inventory to be open as a hotbar. Im not sure how to do this. I know it will probably require use of the RenderGameOverlayEvent.Pre and .Post I think but I am unsure how to get it to work.

 

I cancel the default Hotbar but I am unsure how to insert mine in.

 

 

@SubscribeEvent(priority=EventPriority.NORMAL)
public void onRenderPre(RenderGameOverlayEvent.Pre event) {

	if (event.type == ElementType.HOTBAR) {
		event.setCanceled(true);
		return;
	}
}

 

 

Link to comment
Share on other sites

I have some of this figured out but I have a few questions.

 

1) I have no idea how to override vanilla keybinding to temporarily disable the 1,2,3,4,5,6,7,8,9 and E keys from allowing access to the default vanilla inventory when my custom one is enabled.

 

2) I need a way to unhook the currently held item from the player so that it is "left" behind in the vanilla inventory when the new custom inventory replaces the default one

 

3) I have my Inventory Class, Container Class and Gui Class As follows and am not sure where to go from this point to achieve the above goals. I dont know how to get my inventory to be linked to my player and am currently stuck at this point. Here are my classes -> The inventory does not work atm it doesnt show up.

 

Any and all help is greatly appreciated

Link to comment
Share on other sites

Alright. I will tell you what I know, but as I said I abandoned this try because I wasnt able to fix all problems occuring.

 

The player has two instances of his inventory.

Player#inventory

Player#openContainer

 

Overriding these two is the first step of chaning the player inventory.

If you do that u wont have a need to interrupt the keys, because they will fetch the data from the overwritten instances.

Link to comment
Share on other sites

Ya I think this method might work for me though. My main question atm is how do I get my custom inventory to show up in the player HUD. I think I am missing something. Ive never worked with the container class and I followed a tutorial but I dont think it was exactly complete.

Link to comment
Share on other sites

Ya Im unsure what the issue is, If anyone knows what im missing id appreciate your input.

 

As a side note, Thanks to coolAlias I got the cancellation of hotbar key input to work based on my condition. So to cancel the vanilla hotbar completely this is what you need.

I use 2 events,

 

KeyInputEvent -> it is a EventsFMLCommon event so register it properly-> (Also to get the instance of the player for my IEEP properties I needed to set up a method in Client proxy to get the player (I believe this was necessary) seems to work on dedicated and integrated server so thats sweet).

 

 

@SubscribeEvent
  public void onKeyInput(KeyInputEvent event) {
	  ExtendedPlayerProperties epp = ExtendedPlayerProperties.get(ClientProxy.getPlayer());

	if(epp.myCondition()){

   if (Keyboard.getEventKeyState()) {
  int kb = Keyboard.getEventKey();
  for (KeyBinding b : ClientProxy.getMinecraft().gameSettings.keyBindsHotbar) {

   if (kb == b.getKeyCode() && b.isPressed()) { // add #isPressed to the condition to decrement the counter

   KeyBinding.setKeyBindState(kb, false);

   System.out.println("Unpressing key " + b.getKeyDescription() + "; is key still pressed? " + b.isPressed());

   return; 

   }

   }
  }}
  }

 

 

Please note that-> "Setting the keybinding state to false is not, in itself, sufficient - you MUST call #isPressed() to decrement the 'pressed' counter in the keybinding or #isPressed will still return true once even after the key state is set to false." - coolAlias

 

Then you should cancel the rendering of the hotbar by using RenderGameOverlayEvent.Pre event -> This is an event that needs to be fired client side only so again register it properly

 

 

@SubscribeEvent(priority=EventPriority.NORMAL)
public void onRenderPre(RenderGameOverlayEvent.Pre event) {
	ExtendedPlayerProperties epp = ExtendedPlayerProperties.get(this.mc.thePlayer);
	if (event.type == ElementType.HOTBAR && epp.myCondition()) {
		event.setCanceled(true);
		return;
	}}

 

 

And that is it for cancelling Vanilla Hotbar Inventory.

 

Note* I Still dont know how to unhook the currently selected item from the hotbar so that when you transfer inventories you dont "bring it with you". The above will intercept the 1,2,3,4,5,6,7,8,and 9 key presses and cancel them. To disable the main inventory from use I used

 

 

 

@SubscribeEvent 
   public void guiOpened(GuiOpenEvent event) {
      if(event.gui==null) return;
      if(event.gui instanceof GuiInventory || event.gui instanceof GuiFurnace || event.gui instanceof GuiBeacon || event.gui instanceof GuiBrewingStand || event.gui instanceof GuiDispenser || event.gui instanceof GuiScreenHorseInventory  ){
    	  ExtendedPlayerProperties epp = ExtendedPlayerProperties.get(Minecraft.getMinecraft().thePlayer);
         if(epp.isMorphed()){
        	 event.setCanceled(true);
        	 return;
        
         }
      }
      
   }

 

 

Which cancels the opening of the inventory GUI for most cases -> for some reason I get a crash when cancelling the container, chest, enderchest, and crafting table

 

Now I need to implement my custom storage and this is where I am stuck. I know I have to register it and I know I have to somehow have it show up in the player HUD and then remap the 1,2,3,4,5,6,7,8,9 and E keys to work with/open my inventory. But the getting it to show up in HUD is a problem. Im not sure how to do that.

Link to comment
Share on other sites

For anyone interested, my full responses to this topic are here, only because I happened to see it there first.

 

I suggested using the vanilla mechanics: i.e., when you switch to your special mode, store the current hot bar inventory in an array in your IEEP, and swap the items from your custom hot bar into the vanilla slots. Then vanilla handles all of the work for you, you still get to use the number keys and all that to operate your custom hot bar, and the only reason you'd want to mess with the vanilla hot bar rendering would be to limit the number of slots rendered.

 

When the player presses 'E', that results in GuiOpenEvent being triggered so you should be able to cancel the vanilla inventory opening and swap in your own with just a few lines of code.

Link to comment
Share on other sites

So basically inside my IEEP class

 

 

public ItemStack[] hotbarItems = new ItemStack[9];

public void rememberHotBarItems(EntityPlayer player){
	for(int i = 0; i < 9; i++){
	player.inventory.mainInventory[i] = hotbarItems[i];
	}
}

 

 

 

how would I ensure that they are saved correctly. I dont think Ive ever saved an Itemstack array to NBT

 

In My IEEP class I have the NBT methods but how do you save an itemstack to NBT properly

@Override
public final void saveNBTData(NBTTagCompound compound) {
	NBTTagCompound properties = new NBTTagCompound();

	compound.setTag("ExtendedPlayerProperties", properties);
}

@Override
public final void loadNBTData(NBTTagCompound compound) {
	NBTTagCompound properties = (NBTTagCompound) compound.getTag("ExtendedPlayerProperties");


 

Also, im not sure if this will work as I need to be able to discriminate what kinds of items can go into my custom hotbar inventory. And when a player picks up an item while the custom condition is true I need the item to remain unpicked up so as to not add it to player storage or to the HUD as I want to only allow special items to be placed into the custom HUD.

Link to comment
Share on other sites

So I suspect I still need a custom inventory to accomplish all of that as I dont think vanilla will let me do the discrimination bit. The items will still get added to the players main inventory even if I run a check for the HUD slots since the way I disable the main inventory just stops the gui from opening but still preserve all of the regular item pickup mechanics for the player.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • FREEBET SLOT : SLOT FREEBET TANPA DEPOSIT FREECHIP 20K 30K 50K TO KECIL RENDAH x2 x3 x4 x5 - SLOT GRATIS TANPA DEPOSIT KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << SITUS SLOT GACOR 88 MAXWIN X500 HARI INI TERBAIK DAN TERPERCAYA GAMPANG MENANG Dunia Game gacor terus bertambah besar seiring berjalannya waktu, dan sudah tentu dunia itu terus berkembang serta merta bersamaan dengan berkembangnya SLOT GACOR sebagai website number #1 yang pernah ada dan tidak pernah mengecewakan sekalipun. Dengan banyaknya member yang sudah mempercayakan untuk terus menghasilkan uang bersama dengan SLOT GACOR pastinya mereka sudah percaya untuk bermain Game online bersama dengan kami dengan banyaknya testimoni yang sudah membuktikan betapa seringnya member mendapatkan jackpot besar yang bisa mencapai ratusan juta rupiah. Best online Game website that give you more money everyday, itu lah slogan yang tepat untuk bermain bersama SLOT GACOR yang sudah pasti menang setiap harinya dan bisa menjadikan bandar ini sebagai patokan untuk mendapatkan penghasilan tambahan yang efisien dan juga sesuatu hal yang fix setiap hari nya. Kami juga mendapatkan julukan sebagai Number #1 website bocor yang berarti terus memberikan member uang asli dan jackpot setiap hari nya, tidak lupa bocor itu juga bisa diartikan dalam bentuk berbagi promosi untuk para official member yang terus setia bermain bersama dengan kami. Berbagai provider Game terus bertambah banyak setiap harinya dan terus melakukan support untuk membuat para official member terus bisa menang dan terus maxwin dalam bentuk apapun maka itu langsung untuk feel free to try yourself, play with SLOT GACOR now or never !
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑   Daftar Slot Ratuasia77 adalah bocoran slot rekomendasi gacor dari Ratuasia77 yang bisa anda temukan di SLOT Ratuasia77. Situs SLOT Ratuasia77 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Ratuasia77 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Ratuasia77 merupakan SLOT Ratuasia77 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Ratuasia77. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Ratuasia77 hari ini yang telah disediakan SLOT Ratuasia77. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Ratuasia77 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Ratuasia77 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Ratuasia77 di link SLOT Ratuasia77.
    • 20 SLOT DEMO GRATIS PRAGMATIC PLAY x500 RUPIAH ANTI LAG & 20 DEMO SLOT MAHJONG WAYS PG SOFT GRATIS ANTI RUNGKAD KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << SITUS SLOT GACOR 88 MAXWIN X500 HARI INI TERBAIK DAN TERPERCAYA GAMPANG MENANG Dunia Game gacor terus bertambah besar seiring berjalannya waktu, dan sudah tentu dunia itu terus berkembang serta merta bersamaan dengan berkembangnya SLOT GACOR sebagai website number #1 yang pernah ada dan tidak pernah mengecewakan sekalipun. Dengan banyaknya member yang sudah mempercayakan untuk terus menghasilkan uang bersama dengan SLOT GACOR pastinya mereka sudah percaya untuk bermain Game online bersama dengan kami dengan banyaknya testimoni yang sudah membuktikan betapa seringnya member mendapatkan jackpot besar yang bisa mencapai ratusan juta rupiah. Best online Game website that give you more money everyday, itu lah slogan yang tepat untuk bermain bersama SLOT GACOR yang sudah pasti menang setiap harinya dan bisa menjadikan bandar ini sebagai patokan untuk mendapatkan penghasilan tambahan yang efisien dan juga sesuatu hal yang fix setiap hari nya. Kami juga mendapatkan julukan sebagai Number #1 website bocor yang berarti terus memberikan member uang asli dan jackpot setiap hari nya, tidak lupa bocor itu juga bisa diartikan dalam bentuk berbagi promosi untuk para official member yang terus setia bermain bersama dengan kami. Berbagai provider Game terus bertambah banyak setiap harinya dan terus melakukan support untuk membuat para official member terus bisa menang dan terus maxwin dalam bentuk apapun maka itu langsung untuk feel free to try yourself, play with SLOT GACOR now or never !
    • BOCORAN POLA SLOT GACOR MAHJONG WAYS MAXWIN x500 PETIR MERAH HARI INI HINGGA MALAM INI KLIK DISINI DAFTAR SLOT VVIP << KLIK DISINI DAFTAR SLOT VVIP << KLIK DISINI DAFTAR SLOT VVIP << KLIK DISINI DAFTAR SLOT VVIP << SITUS SLOT GACOR 88 MAXWIN X500 HARI INI TERBAIK DAN TERPERCAYA GAMPANG MENANG Dunia Game gacor terus bertambah besar seiring berjalannya waktu, dan sudah tentu dunia itu terus berkembang serta merta bersamaan dengan berkembangnya SLOT GACOR sebagai website number #1 yang pernah ada dan tidak pernah mengecewakan sekalipun. Dengan banyaknya member yang sudah mempercayakan untuk terus menghasilkan uang bersama dengan SLOT GACOR pastinya mereka sudah percaya untuk bermain Game online bersama dengan kami dengan banyaknya testimoni yang sudah membuktikan betapa seringnya member mendapatkan jackpot besar yang bisa mencapai ratusan juta rupiah. Best online Game website that give you more money everyday, itu lah slogan yang tepat untuk bermain bersama SLOT GACOR yang sudah pasti menang setiap harinya dan bisa menjadikan bandar ini sebagai patokan untuk mendapatkan penghasilan tambahan yang efisien dan juga sesuatu hal yang fix setiap hari nya. Kami juga mendapatkan julukan sebagai Number #1 website bocor yang berarti terus memberikan member uang asli dan jackpot setiap hari nya, tidak lupa bocor itu juga bisa diartikan dalam bentuk berbagi promosi untuk para official member yang terus setia bermain bersama dengan kami. Berbagai provider Game terus bertambah banyak setiap harinya dan terus melakukan support untuk membuat para official member terus bisa menang dan terus maxwin dalam bentuk apapun maka itu langsung untuk feel free to try yourself, play with SLOT GACOR now or never !
    • Museumbola merupakan wadah judi online terkhusus untuk sbobet atau judi bola. Dengan daftar dan deposit menggunakan BANK BCA, Anda berkesempatan mendapatkan prediksi jitu pertandingan secara update setiap hari yang bisa anda jadikan acuan untuk bermain judi bola. Hanya dengan 10 ribu rupiah dan anda bermain Mix Parlay menggunakan prediksi yang telah di sediakan oleh kami, anda akan memenangkan jutaan rupiah. Yuk segera klik DAFTAR sekarang juga.
  • Topics

×
×
  • Create New...

Important Information

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