Jump to content

Recommended Posts

Posted

I made a mob and a GUI.

When I right-click the mob, it will open the GUI, just as I wanted.

There is a button on the gui, when I click the event is called, just as I wanted.

But when I quit the game and open the world again, The event is cancelled.

 

lets say a block would appear above its head, when the button is clicked.

It will happen and it will stay there until the session is ended.

When I quit and open the world again, the block is gone.

 

What is the solution?

 

Here is the interact code I use:

public boolean interact(EntityPlayer par1EntityPlayer)
{
	if(par1EntityPlayer.isSneaking() && par1EntityPlayer.getCommandSenderName().equalsIgnoreCase(this.getOwnerName()) && this.isTamed() && par1EntityPlayer.inventory.getCurrentItem() == null)
	{
		Minecraft mc = Minecraft.getMinecraft();
		mc.displayGuiScreen(new Gui(this));
	}
	else{

	}
	return super.interact(par1EntityPlayer);
}

 

This is the GUI code:

private static final ResourceLocation tex = new ResourceLocation(Core.getModID(), "textures/gui/hireable.png");

public final int xSizeOfTexture = 128;
public final int ySizeOfTexture = 166;

EntityHireable hireable;

public GuiHireable(EntityHireable entity)
{
	hireable = entity;
}

@Override
public void drawScreen(int x, int y, float f)
{
	if(hireable.worldObj.isRemote){
		drawDefaultBackground();

		GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
		this.mc.renderEngine.bindTexture(tex);

		int posX = (this.width - xSizeOfTexture) / 2;
		int posY = (this.height - ySizeOfTexture) / 2;

		this.drawTexturedModalRect(posX, posY, 0, 0, this.xSizeOfTexture, this.ySizeOfTexture);

		String s = this.hireable.hasCustomNameTag() ? this.hireable.getCustomNameTag() : I18n.format("entity." + Core.getModID() + "." + hireable.getName() + ".name", new Object[0]);
		this.fontRendererObj.drawString(s + " " + I18n.format("entity.gui.stat", new Object[0]), (this.width / 2) - this.fontRendererObj.getStringWidth(s + " " + I18n.format("entity.gui.stat", new Object[0])) / 2, posY + 7, 4210752);
		this.fontRendererObj.drawString(I18n.format("entity.gui.level", new Object[0]) + " = " + hireable.getLevel(), posX + 6, posY + 7 + 9, 4210752);
		this.fontRendererObj.drawString(I18n.format("entity.gui.health", new Object[0]) + " = " + hireable.getHealth() + " / " + hireable.getMaxHealth(), posX + 6, posY + 7 + (9 * 2), 4210752);

		super.drawScreen(x, y, f);
	}
}

public void initGui()
{
		this.buttonList.clear();

		int posX = (this.width - xSizeOfTexture) / 2;
		int posY = (this.height - ySizeOfTexture) / 2;

		this.buttonList.add(new GuiButton(0, posX+ 6, posY + 10 + (9 * 11), 100, 20, "level up"));
}

public void actionPerformed(GuiButton button)
{
	int i = hireable.getLevel();

		switch(button.id)
		{
		case 0: hireable.setLevel(i + 1);
		break;
		default:
	}
}

private String EquipmentDamage(int i){
	if(hireable.getEquipmentInSlot(i) != null){
		return "" + (hireable.getEquipmentInSlot(i).getMaxDamage() - hireable.getEquipmentInSlot(i).getItemDamage());
	}else{
		return I18n.format("entity.gui.none", new Object[0]);
	}
}

}

Coding, Testing, Smiling, Publishing!

Posted

Okay, I got things running now.

I'm using a methode that will detect a mob in front of you.

When the mob is in front of you, it will open the gui.

 

EntityPlayer.opengui(more stuff);

 

It is working, Im also using a Container, it looks great.

The only downside -> the container does not do its job.

 

When I place a ItemStack in a Slot and I quit and open the world again, all the changes I made are gone.

 

I have Guihandler and I Know that the server part for the container is called. just like the client side, GUI.

 

Why is it still not behaving properly?

 

code:

 

Gui:

private static final ResourceLocation tex = new ResourceLocation(Core.getModID(), "textures/gui/hireable.png");

EntityHireable hireable;

public GuiHireable(EntityPlayer player, EntityHireable entity)
{
	super(new ContainerHireable(player, entity));
	hireable = entity;
}	

protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_)
{
                //TODO
}

@Override
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_)
    {
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.getTextureManager().bindTexture(tex);
        int k = (this.width - this.xSize) / 2;
        int l = (this.height - this.ySize) / 2;
        this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
        
    }

 

Container:

extends Container{

EntityHireable Hire;

public ContainerHireable(EntityPlayer player, EntityHireable entity){
	Hire = entity;

	int i;

	this.addSlotToContainer(new slotInv(entity, 0, 80, 62)
	{
		private static final String __OBFID = "CL_00001755";
		public int getSlotStackLimit()
		{
			return 1;
		}

		public boolean isItemValid(ItemStack par1ItemStack)
		{
			if (par1ItemStack == null) return false;
			return par1ItemStack.getItem() instanceof ItemSword;
		}
	});

	for (i = 0; i < 4; ++i)
	{
		final int k = i;
		this.addSlotToContainer(new slotInv(entity, 4 - i, 8, 8 + i * 18)
		{
			private static final String __OBFID = "CL_00001755";
			public int getSlotStackLimit()
			{
				return 1;
			}

			public boolean isItemValid(ItemStack par1ItemStack)
			{
				if (par1ItemStack == null) return false;
				return par1ItemStack.getItem().isValidArmor(par1ItemStack, k, Hire);
			}

			@SideOnly(Side.CLIENT)
			public IIcon getBackgroundIconIndex()
			{
				return ItemArmor.func_94602_b(k);
			}
		});
	}


	for (i = 0; i < 3; ++i)
	{
		for (int j = 0; j < 9; ++j)
		{
			this.addSlotToContainer(new Slot(player.inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
		}
	}

	for (i = 0; i < 9; ++i)
	{
		this.addSlotToContainer(new Slot(player.inventory, i, 8 + i * 18, 142));
	}
}


@Override
public boolean canInteractWith(EntityPlayer par1EntityPlayer)
{
	return this.Hire.isEntityAlive() && this.Hire.getDistanceToEntity(par1EntityPlayer) < 8.0F;
}

//TODO
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 == 0)
		{
			if (!this.mergeItemStack(itemstack1, 0, 39, true))
			{
				return null;
			}

			slot.onSlotChange(itemstack1, itemstack);
		}
		else if (par2 != 1 && par2 != 0)
		{
			if (par2 >= 3 && par2 < 30)
			{
				if (!this.mergeItemStack(itemstack1, 30, 39, false))
				{
					return null;
				}
			}
			else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
			{
				return null;
			}
		}
		else if (!this.mergeItemStack(itemstack1, 3, 39, false))
		{
			return null;
		}

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

		if (itemstack1.stackSize == itemstack.stackSize)
		{
			return null;
		}

		slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
	}

	return itemstack;
}
}

 

Interact part of the EntityHireable:

public boolean interact(EntityPlayer par1EntityPlayer)
{
	EntityHireable hire = GuiHandler.getUnitMouseOver(5, 0, par1EntityPlayer);
	if(hire != null && hire.isTamed() && !hire.isAngry() && par1EntityPlayer.getCommandSenderName() == hire.getOwnerName()) {
		System.out.println("wohoo");
		par1EntityPlayer.openGui(Core.instance, 5, par1EntityPlayer.worldObj, 0, 0, 0);
	}
	return super.interact(par1EntityPlayer);
}

 

GuiHandler.getUnitMouseOver is a methode that will retun a EntityHireable in this case.

I can use this in the GuiHandler class to get the entity of which I want to get information

Trust me the MouseOver methode works.

 

@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { 
	switch(id){
	case 5:
		EntityHireable hire = getUnitMouseOver(5, 0, player);
		System.out.println("calling Container");
		return new ContainerHireable(player, hire);
	}

	return null;
}

@Override
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
	switch(id){
	case 5:
		EntityHireable hire = getUnitMouseOver(5, 0, player);
		System.out.println("calling Gui");
		return new GuiHireable(player, hire);
	}

	return null;

}

Coding, Testing, Smiling, Publishing!

Posted

Alright, but that does not answer my question about the container. It is nog called by the server.

everytime I change something in the container, it will not save.

 

when i quit and load again, it does not load the changed stuff.

Coding, Testing, Smiling, Publishing!

Posted

Let me be clear with the different slot I created,

It basicly is the normal slot, but then modified to change the EntityHireable's equipment.

It works fine, but it does not save it to the entity.

When I quit en open the world again, the entity has not changed equipment.

 

Code here:

package mefa.client.Gui;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mefa.Entities.EntityHireable;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;

public class slotInv extends Slot
{
    /** The index of the slot in the inventory. */
    private final int slotIndex;
    /** The inventory we want to extract a slot from. */
    public final IInventory inventory;
    public final EntityHireable hireable;
    /** the id of the slot(also the index in the inventory arraylist) */
    public int slotNumber;
    /** display position of the inventory slot on the screen x axis */
    public int xDisplayPosition;
    /** display position of the inventory slot on the screen y axis */
    public int yDisplayPosition;
    private static final String __OBFID = "CL_00001762";

    /** Position within background texture file, normally -1 which causes no background to be drawn. */
    protected IIcon backgroundIcon = null;

    /** Background texture file assigned to this slot, if any. Vanilla "/gui/items.png" is used if this is null. */
    @SideOnly(Side.CLIENT)
    protected ResourceLocation texture;

    public slotInv(IInventory par1IInventory, int par2, int par3, int par4)
    {
    	super(par1IInventory, par2, par3, par4);
        this.inventory = par1IInventory;
        this.hireable = null;
        this.slotIndex = par2;
        this.xDisplayPosition = par3;
        this.yDisplayPosition = par4;
    }
    
    public slotInv(EntityHireable par1IInventory, int par2, int par3, int par4)
    {
    	super(null, par2, par3, par4);
        this.hireable = par1IInventory;
        this.inventory = null;
        this.slotIndex = par2;
        this.xDisplayPosition = par3;
        this.yDisplayPosition = par4;
    }

    public void onSlotChange(ItemStack par1ItemStack, ItemStack par2ItemStack)
    {
        if (par1ItemStack != null && par2ItemStack != null)
        {
            if (par1ItemStack.getItem() == par2ItemStack.getItem())
            {
                int i = par2ItemStack.stackSize - par1ItemStack.stackSize;

                if (i > 0)
                {
                    this.onCrafting(par1ItemStack, i);
                }
            }
        }
    }

    protected void onCrafting(ItemStack par1ItemStack, int par2) {}

    protected void onCrafting(ItemStack par1ItemStack) {}

    public void onPickupFromSlot(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack)
    {
        this.onSlotChanged();
    }

    public boolean isItemValid(ItemStack par1ItemStack)
    {
        return true;
    }

    public ItemStack getStack()
    {
    	if(this.inventory != null){
    		return this.inventory.getStackInSlot(this.slotIndex);
    	}else{
    		return this.hireable.getEquipmentInSlot(this.slotIndex);
    	}
    }

    public boolean getHasStack()
    {
        return this.getStack() != null;
    }

    public void putStack(ItemStack par1ItemStack)
    {
    	if(this.inventory != null){
    		this.inventory.setInventorySlotContents(slotIndex, par1ItemStack);
    	}else{
    		this.hireable.setCurrentItemOrArmor(slotIndex, par1ItemStack);
    	}
        this.onSlotChanged();
    }

    public void onSlotChanged()
    {
        if(this.inventory != null){
        	this.inventory.markDirty();;
    	}
    }

    public int getSlotStackLimit()
    {
    	if(this.inventory != null){
    		return this.inventory.getInventoryStackLimit();
    	}else{
    		return 5;
    	}
    }

    public ItemStack decrStackSize(int par1)
    {
    	int i = this.hireable.getEquipmentInSlot(this.slotIndex).stackSize;
    	ItemStack item = this.hireable.getEquipmentInSlot(this.slotIndex);
    	boolean Size = item.stackSize - par1 > 0;
    	ItemStack item2 = new ItemStack(item.getItem(), item.getItemDamage(), item.stackSize - par1);
    	
    	if(this.inventory != null){
    		return this.inventory.decrStackSize(this.slotIndex, par1);
    	}else{
    		return Size ? item2 : (ItemStack)null;
    	}
    }

    public boolean isSlotInInventory(IInventory par1IInventory, int par2)
    {
        return par1IInventory == this.inventory && par2 == this.slotIndex;
    }

    public boolean canTakeStack(EntityPlayer par1EntityPlayer)
    {
        return true;
    }

    @SideOnly(Side.CLIENT)
    public IIcon getBackgroundIconIndex()
    {
        return backgroundIcon;
    }

    @SideOnly(Side.CLIENT)
    public boolean func_111238_b()
    {
        return true;
    }

    @SideOnly(Side.CLIENT)
    public ResourceLocation getBackgroundIconTexture()
    {
        return (texture == null ? TextureMap.locationItemsTexture : texture);
    }

    public void setBackgroundIcon(IIcon icon)
    {
        backgroundIcon = icon;
    }

    @SideOnly(Side.CLIENT)
    public void setBackgroundIconTexture(ResourceLocation texture)
    {
        this.texture = texture;
    }

    public int getSlotIndex()
    {
        /** The index of the slot in the inventory. */
        return slotIndex;
    }
}[code]

Coding, Testing, Smiling, Publishing!

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

    • I have no idea why it sent twice im really sorry
    • Was launching forge for the first time and it crashed: Processor failed, invalid outputs: /home/frenchy/.local/share/PrismLauncher/libraries/net/minecraft/client/1.20.1-20230612.114412/client-1.20.1-20230612.114412-slim.jar Expected: de86b035d2da0f78940796bb95c39a932ed84834 Actual: a8fb49bc364562847d6e7e6775e3a1b3f6b2bb05 /home/frenchy/.local/share/PrismLauncher/libraries/net/minecraft/client/1.20.1-20230612.114412/client-1.20.1-20230612.114412-extra.jar Expected: 8c5a95cbce940cfdb304376ae9fea47968d02587 Actual: cf941ba69e11f5a9de15d0c319d61854c456a116 No idea why I think it's because I'm on linux or something  
    • Game crashed on launch with:  Processor failed, invalid outputs: /home/user/.local/share/PrismLauncher/libraries/net/minecraft/client/1.20.1-20230612.114412/client-1.20.1-20230612.114412-slim.jar Expected: de86b035d2da0f78940796bb95c39a932ed84834 Actual: a8fb49bc364562847d6e7e6775e3a1b3f6b2bb05 /home/user/.local/share/PrismLauncher/libraries/net/minecraft/client/1.20.1-20230612.114412/client-1.20.1-20230612.114412-extra.jar Expected: 8c5a95cbce940cfdb304376ae9fea47968d02587 Actual: cf941ba69e11f5a9de15d0c319d61854c456a116 No idea why, but im on linux which might matter
    • PixelmonGo est un incroyable serveur Pixelmon disponible grâce à notre launcher en version 1.16.5 Ce serveur accepte les joueurs premiums comme les cracks ! Un gameplay unique vous attend.. Rejoignez nous dès maintenant ! Site: https://pixelmongo.fr/ Launcher: https://pixelmongo.fr/launcher/ Discord: https://discord.gg/pixelmongo Découvrez notre serveur minecraft Pixelmon moddé basé sur un univers mélangeant Minecraft et Pokémon. Plus de 900 Pokémon à capturer ainsi que des fusions unique au serveur, un hôtel des ventes, un monde aventure reproduisant l'aventure de sinnoh, Explorez des donjons de chaque team maléfique au début de votre aventure, accomplissez des quêtes et remportez des récompenses quotidiennes. Revivez vos meilleurs souvenirs Pokémon au sein d'une communauté multijoueur dynamique. Rejoignez le meilleur serveur minecraft pixelmon français des maintenant en téléchargeant notre launcher. Pixelmongo est la référence en serveur pixelmon en France ! Présentation Amenez votre Minecraft dans le monde des Pokémon, ou des Pokémon dans votre monde Minecraft ! Avec Pixelmon, découvrez votre monde Minecraft sous un nouvel angle. Pixelmon est un mod populaire pour Minecraft qui permet aux joueurs d'attraper, d'entraîner et de combattre des Pokémon dans le monde de Minecraft. Développé par un groupe de fans dévoués, le mod ajoute une large gamme de créatures Pokémon au jeu. Il possède des fonctionnalités et des mécanismes uniques qui en font une expérience amusante et engageante pour les joueurs de tous âges. Le mod Pixelmon est disponible pour les mondes Minecraft solo et multijoueur et peut être téléchargé et installé à l'aide de divers lanceurs et modpacks. Une fois installé, les joueurs peuvent explorer le monde et rencontrer des Pokémon dans la nature, se battre avec d'autres entraîneurs et créer leur propre équipe de créatures puissantes. L'une des fonctionnalités clés de Pixelmon est la possibilité de capturer et d'entraîner des Pokémon en utilisant diverses méthodes. Les joueurs peuvent fabriquer des Pokéballs et les utiliser pour capturer des Pokémon sauvages, qui peuvent ensuite être entraînés et améliorés au fil du temps. Chaque Pokémon a des capacités et des mouvements uniques, ce qui rend important pour les joueurs de choisir la bonne équipe de créatures pour chaque combat. Capturez des Pokémons, constituez une équipe, entraînez-les et remportez des combats contre d'autres joueurs ! Dans un univers reprenant les standards du jeu Nintendo original : Dresseurs, centres Pokémon, mais aussi fossiles et matériaux divers. Les Pokémon comme dans le jeu original sont classés par type (Insecte, Ténèbres, Dragon, Électrique, Combat, Feu, Vol, Spectre, Plante, Sol, Glace, Normal, Poison, Psy, Pierre, Acier, Eau), ce qui définira les faiblesses et les spécificités des Pokémons. Par exemple, un Pokémon de type Feu subira deux fois plus de dégâts si l'attaque du Pokémon ennemi est de type Glace. Le mod possède 900 Pokémon différents plus ou moins rares qui apparaîtront en fonction de leur environnement (jour, nuit et biomes). Les Pokémon évoluent en fonction de leur niveau (jusqu'à 100). Plus leur niveau est élevé, plus ils seront forts et auront des attaques plus puissantes. Pour augmenter le niveau de votre Pokémon, et ainsi évoluer, vous devrez combattre d'autres Pokémon et les vaincre. Plus vos adversaires sont forts, plus ils vous rapporteront de l'expérience. Les Pokémons ont également leurs propres statistiques (attaque, défense, vitesse, vitesse d'attaque et vitesse de défense). Ils peuvent également avoir des tailles et des formes différentes, et peuvent occasionnellement vous donner des objets une fois tués. Pour les capturer, vous devrez utiliser des pokéballs, qui selon leur forme seront plus ou moins efficaces. Pixelmon est un mod amusant et engageant pour Minecraft qui ajoute une touche unique et passionnante au jeu. Avec sa large gamme de fonctionnalités et de mécanismes, il offre aux joueurs des possibilités infinies d'exploration et de plaisir, ce qui en fait un choix populaire pour les fans de Minecraft et de Pokemon.  
    • Hi all,  I have the following issue: I'd like to parse some json using gson and rely on the (somewhat new) java record types. This is supported in gson 2.10+. Gson is already a dependency used by minecraft, however it's 2.8.x for 1.19.2 which I'm targeting at the moment. My idea was to include the newer version of the library in my mod and then shadow it so it gets used inside the scope of my mod instead of the older 2.8. This works fine for building the jar: If I decompile my mod.jar, I can see that it's correctly using the shadowed classes. However obviously when using the runClient intellj config, the shadowing doesn't get invoked. Is there any way of invoking shadow when using runClient, or am I on the wrong track and there's a better way of doing this entirely?   Thanks in advance!   Edit: After some further thinking, I've come up with this abomination:   build.gradle // New task for extracting the result of shadowJar into the classes directory // This includes our shadowed gson jar tasks.register("extractShadowJar", Copy) { // Depend on shadowJar so we always use the up to date version of the shadowed content dependsOn shadowJar from(zipTree(shadowJar.archiveFile)) { // filter to copy only our code (and ignore assets, META-INF, etc) // Also copies gson as it gets shadowed into com.oppendev.shadow.gson include "com/**" } duplicatesStrategy(DuplicatesStrategy.INCLUDE) into("$buildDir/classes/java/main") // Extract into the classes directory } // Tell gradle to invoke our new task before executing any java code. This way we ensure that we use the shadowed gson tasks.withType(JavaExec).configureEach { dependsOn(extractShadowJar) } // Shadow config shadowJar { relocate 'com.google.gson', 'com.oppendev.shadow.gson' configurations = [project.configurations.runtimeClasspath] zip64 true dependencies { include(dependency('com.google.code.gson:gson')) } } Is this a reasonable thing to do? Is this completely cursed and I should burn in dev ops hell? Is there a better way to do this? Feel free to grill me in the replies
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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