Jump to content

[SORTA SOLVED][1.6.4] getting int with metadata from ItemStack


Recommended Posts

Posted

Heres the code i need help with:

 

this.tasks.addTask(3, new ChickAITempt(this, 1.0D, new ItemStack(Item.dyePowder, 1, 3).itemID, false));

 

i need to pass new ItemStack(Item.dyePowder, 1, 3).itemID on to ChickAITempt with the metadata of 3. but i cant get it to send without changing the constructor of ChickAITempt, which will break it with all the other mobs. could someone show me what i need to do to send the metadata to the ChickAITempt class?

Posted

You probably can't, as the constructor deals with only an item ID (which, why you'd create an item stack only to get the item's ID out of it, when you could just skip the item stack, I have no idea).  If you take a peek inside AITempt, you'll either find out that it doesn't care OR you'll find the variable that holds the information and how to set it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

the constructor asks for an int, i can change that if i wanted, but i would have to change several other classes to match it, as for it not caring, thats because it simply is just that, unless there is a way, it doesnt care, and any dye will do what im trying to do, but i only want the cocoa beans to be used.

 

heres the code for EntityAIChick:

package mods.mochickens.misc;

import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

public class ChickAITempt extends EntityAIBase
{
    /** The entity using this AI that is tempted by the player. */
    private EntityCreature temptedEntity;
    private double field_75282_b;

    /** X position of player tempting this mob */
    private double targetX;

    /** Y position of player tempting this mob */
    private double targetY;

    /** Z position of player tempting this mob */
    private double targetZ;
    private double field_75278_f;
    private double field_75279_g;

    /** The player that is tempting the entity that is using this AI. */
    private EntityPlayer temptingPlayer;

    /**
     * A counter that is decremented each time the shouldExecute method is called. The shouldExecute method will always
     * return false if delayTemptCounter is greater than 0.
     */
    private int delayTemptCounter;

    /** True if this EntityAITempt task is running */
    private boolean isRunning;

    /**
     * This field saves the ID of the items that can be used to breed entities with this behaviour.
     */
    private int breedingFood;

    /**
     * Whether the entity using this AI will be scared by the tempter's sudden movement.
     */
    private boolean scaredByPlayerMovement;
    private boolean field_75286_m;

    public ChickAITempt(EntityCreature par1EntityCreature, double par2, int par4, boolean par5)
    {
        this.setTemptedEntity(par1EntityCreature);
        this.field_75282_b = par2;
        this.setBreedingFood(par4);
        this.scaredByPlayerMovement = par5;
        this.setMutexBits(3);
    }

    /**
     * Returns whether the EntityAIBase should begin execution.
     */
    public boolean shouldExecute()
    {
    	String owner = this.getTemptedEntity().getDataWatcher()
    			.getWatchableObjectString(17);
    	
    	if (this.getDelayTemptCounter() > 0) {
		this.setDelayTemptCounter(this.getDelayTemptCounter() - 1);
		return false;
	} else {
		this.setTemptingPlayer(this.getTemptedEntity().worldObj
				.getClosestPlayerToEntity(this.getTemptedEntity(), 10.0D));

		if (this.getTemptingPlayer() == null) {
			return false;
		} else if (this.getTemptingPlayer().getEntityName() != owner) {
			return false;
		} else {
			ItemStack itemstack = this.getTemptingPlayer()
					.getCurrentEquippedItem();
			return itemstack == null ? false : itemstack.itemID == this
					.getBreedingFood();
		}
	}
    }

    /**
     * Returns whether an in-progress EntityAIBase should continue executing
     */
    public boolean continueExecuting()
    {
        if (this.scaredByPlayerMovement)
        {
            if (this.getTemptedEntity().getDistanceSqToEntity(this.getTemptingPlayer()) < 36.0D)
            {
                if (this.getTemptingPlayer().getDistanceSq(this.targetX, this.targetY, this.targetZ) > 0.010000000000000002D)
                {
                    return false;
                }

                if (Math.abs((double)this.getTemptingPlayer().rotationPitch - this.field_75278_f) > 5.0D || Math.abs((double)this.getTemptingPlayer().rotationYaw - this.field_75279_g) > 5.0D)
                {
                    return false;
                }
            }
            else
            {
                this.targetX = this.getTemptingPlayer().posX;
                this.targetY = this.getTemptingPlayer().posY;
                this.targetZ = this.getTemptingPlayer().posZ;
            }

            this.field_75278_f = (double)this.getTemptingPlayer().rotationPitch;
            this.field_75279_g = (double)this.getTemptingPlayer().rotationYaw;
        }

        return this.shouldExecute();
    }

    /**
     * Execute a one shot task or start executing a continuous task
     */
    public void startExecuting()
    {
        this.targetX = this.getTemptingPlayer().posX;
        this.targetY = this.getTemptingPlayer().posY;
        this.targetZ = this.getTemptingPlayer().posZ;
        this.isRunning = true;
        this.field_75286_m = this.getTemptedEntity().getNavigator().getAvoidsWater();
        this.getTemptedEntity().getNavigator().setAvoidsWater(false);
    }

    /**
     * Resets the task
     */
    public void resetTask()
    {
        this.setTemptingPlayer(null);
        this.getTemptedEntity().getNavigator().clearPathEntity();
        this.setDelayTemptCounter(100);
        this.isRunning = false;
        this.getTemptedEntity().getNavigator().setAvoidsWater(this.field_75286_m);
    }

    /**
     * Updates the task
     */
    public void updateTask()
    {
        this.getTemptedEntity().getLookHelper().setLookPositionWithEntity(this.getTemptingPlayer(), 30.0F, (float)this.getTemptedEntity().getVerticalFaceSpeed());

        if (this.getTemptedEntity().getDistanceSqToEntity(this.getTemptingPlayer()) < 6.25D)
        {
            this.getTemptedEntity().getNavigator().clearPathEntity();
        }
        else
        {
            this.getTemptedEntity().getNavigator().tryMoveToEntityLiving(this.getTemptingPlayer(), this.field_75282_b);
        }
    }

    /**
     * @see #isRunning
     */
    public boolean isRunning()
    {
        return this.isRunning;
    }

public int getDelayTemptCounter() {
	return delayTemptCounter;
}

public void setDelayTemptCounter(int delayTemptCounter) {
	this.delayTemptCounter = delayTemptCounter;
}

public EntityPlayer getTemptingPlayer() {
	return temptingPlayer;
}

public void setTemptingPlayer(EntityPlayer temptingPlayer) {
	this.temptingPlayer = temptingPlayer;
}

public EntityCreature getTemptedEntity() {
	return temptedEntity;
}

public void setTemptedEntity(EntityCreature temptedEntity) {
	this.temptedEntity = temptedEntity;
}

public int getBreedingFood() {
	return breedingFood;
}

public void setBreedingFood(int breedingFood) {
	this.breedingFood = breedingFood;
}
}

Posted

Create (add, not replace) your own AI class that acceps an ItemStack?

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

Posted

this IS my own, i had to do it customize a few things in it. i could probably change it around a bit more, though if i dont want to do that if i dont have to. thats why i came here and asked.

Posted

You know you can have multiple constructors...right?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

tried multiple constructors and it still didnt work, so i decided just to make another AI class to deal with meta blocks which now works.

 

package mods.mochickens.misc;

import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;

public class ChickAITemptDye extends EntityAIBase {
/** The entity using this AI that is tempted by the player. */
private EntityCreature temptedEntity;
private double field_75282_b;

/** X position of player tempting this mob */
private double targetX;

/** Y position of player tempting this mob */
private double targetY;

/** Z position of player tempting this mob */
private double targetZ;
private double field_75278_f;
private double field_75279_g;

/** The player that is tempting the entity that is using this AI. */
private EntityPlayer temptingPlayer;

/**
 * A counter that is decremented each time the shouldExecute method is
 * called. The shouldExecute method will always return false if
 * delayTemptCounter is greater than 0.
 */
private int delayTemptCounter;

/** True if this EntityAITempt task is running */
private boolean isRunning;

/**
 * This field saves the ID of the items that can be used to breed entities
 * with this behaviour.
 */
private String breedingFood;

/**
 * Whether the entity using this AI will be scared by the tempter's sudden
 * movement.
 */
private boolean scaredByPlayerMovement;
private boolean field_75286_m;

public ChickAITemptDye(EntityCreature par1EntityCreature, double par2,
		String par4, boolean par5) {
	this.setTemptedEntity(par1EntityCreature);
	this.field_75282_b = par2;
	this.setBreedingFood(par4);
	this.scaredByPlayerMovement = par5;
	this.setMutexBits(3);
}

/**
 * Returns whether the EntityAIBase should begin execution.
 */
public boolean shouldExecute() {
	String owner = this.getTemptedEntity().getDataWatcher()
			.getWatchableObjectString(17);

	if (this.getDelayTemptCounter() > 0) {
		this.setDelayTemptCounter(this.getDelayTemptCounter() - 1);
		return false;
	} else {
		this.setTemptingPlayer(this.getTemptedEntity().worldObj
				.getClosestPlayerToEntity(this.getTemptedEntity(), 10.0D));

		if (this.getTemptingPlayer() == null) {
			return false;
		} else if (this.getTemptingPlayer().getEntityName() != owner) {
			return false;
		} else {
			ItemStack itemstack = this.getTemptingPlayer()
					.getCurrentEquippedItem();
			return itemstack == null ? false : itemstack.getDisplayName().equalsIgnoreCase(this.getBreedingFood());
		}
	}
}

/**
 * Returns whether an in-progress EntityAIBase should continue executing
 */
public boolean continueExecuting() {
	if (this.scaredByPlayerMovement) {
		if (this.getTemptedEntity().getDistanceSqToEntity(
				this.getTemptingPlayer()) < 36.0D) {
			if (this.getTemptingPlayer().getDistanceSq(this.targetX,
					this.targetY, this.targetZ) > 0.010000000000000002D) {
				return false;
			}

			if (Math.abs((double) this.getTemptingPlayer().rotationPitch
					- this.field_75278_f) > 5.0D
					|| Math.abs((double) this.getTemptingPlayer().rotationYaw
							- this.field_75279_g) > 5.0D) {
				return false;
			}
		} else {
			this.targetX = this.getTemptingPlayer().posX;
			this.targetY = this.getTemptingPlayer().posY;
			this.targetZ = this.getTemptingPlayer().posZ;
		}

		this.field_75278_f = (double) this.getTemptingPlayer().rotationPitch;
		this.field_75279_g = (double) this.getTemptingPlayer().rotationYaw;
	}

	return this.shouldExecute();
}

/**
 * Execute a one shot task or start executing a continuous task
 */
public void startExecuting() {
	this.targetX = this.getTemptingPlayer().posX;
	this.targetY = this.getTemptingPlayer().posY;
	this.targetZ = this.getTemptingPlayer().posZ;
	this.isRunning = true;
	this.field_75286_m = this.getTemptedEntity().getNavigator()
			.getAvoidsWater();
	this.getTemptedEntity().getNavigator().setAvoidsWater(false);
}

/**
 * Resets the task
 */
public void resetTask() {
	this.setTemptingPlayer(null);
	this.getTemptedEntity().getNavigator().clearPathEntity();
	this.setDelayTemptCounter(100);
	this.isRunning = false;
	this.getTemptedEntity().getNavigator()
			.setAvoidsWater(this.field_75286_m);
}

/**
 * Updates the task
 */
public void updateTask() {
	this.getTemptedEntity()
			.getLookHelper()
			.setLookPositionWithEntity(this.getTemptingPlayer(), 30.0F,
					(float) this.getTemptedEntity().getVerticalFaceSpeed());

	if (this.getTemptedEntity().getDistanceSqToEntity(
			this.getTemptingPlayer()) < 6.25D) {
		this.getTemptedEntity().getNavigator().clearPathEntity();
	} else {
		this.getTemptedEntity()
				.getNavigator()
				.tryMoveToEntityLiving(this.getTemptingPlayer(),
						this.field_75282_b);
	}
}

/**
 * @see #isRunning
 */
public boolean isRunning() {
	return this.isRunning;
}

public int getDelayTemptCounter() {
	return delayTemptCounter;
}

public void setDelayTemptCounter(int delayTemptCounter) {
	this.delayTemptCounter = delayTemptCounter;
}

public EntityPlayer getTemptingPlayer() {
	return temptingPlayer;
}

public void setTemptingPlayer(EntityPlayer temptingPlayer) {
	this.temptingPlayer = temptingPlayer;
}

public EntityCreature getTemptedEntity() {
	return temptedEntity;
}

public void setTemptedEntity(EntityCreature temptedEntity) {
	this.temptedEntity = temptedEntity;
}

public String getBreedingFood() {
	return breedingFood;
}


public void setBreedingFood(String par4) {
	this.breedingFood = par4;
}
}

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • The specific issue is that items in my inventory wont stack properly. For instance, if I punch a tree down to collect wood, the first block I collected goes to my hand. So when I punch the second block of wood to collect it, it drops, but instead of stacking with the piece of wood already in my hand, it goes to the second slot in my hotbar instead. Another example is that I'll get some dirt, and then when I'm placing it down later I'll accidentally place a block where I don't want it. When I harvest it again, it doesn't go back to the stack that it came from on my hotbar, where it should have gone, but rather into my inventory. That means that if my inventory is full, then the dirt wont be picked up even though there should be space available in the stack I'm holding. The forge version I'm using is 40.3.0, for java 1.18.2. I'll leave the mods I'm using here, and I'd appreciate it if anybody can point me in the right direction in regards to figuring out how to fix this. I forgot to mention that I think it only happens on my server but I&#39;m not entirely sure. PLEASE HELP ME! LIST OF THE MODS. aaa_particles Adorn AdvancementPlaques AI-Improvements AkashicTome alexsdelight alexsmobs AmbientSounds amwplushies Animalistic another_furniture AppleSkin Aquaculture aquamirae architectury artifacts Atlas-Lib AutoLeveling AutoRegLib auudio balm betterfpsdist biggerstacks biomancy BiomesOPlenty blockui blueprint Bookshelf born_in_chaos Botania braincell BrassAmberBattleTowers brutalbosses camera CasinoCraft cfm (MrCrayfish’s Furniture Mod) chat_heads citadel cloth-config Clumps CMDCam CNB cobweb collective comforts convenientcurioscontainer cookingforblockheads coroutil CosmeticArmorReworked CozyHome CrabbersDelight crashexploitfixer crashutilities Create CreativeCore creeperoverhaul cristellib crittersandcompanions Croptopia CroptopiaAdditions CullLessLeaves curios curiouslanterns curiouslights Curses' Naturals CustomNPCs CyclopsCore dannys_expansion decocraft Decoration Mod DecorationDelightRefurbished Decorative Blocks Disenchanting DistantHorizons doubledoors DramaticDoors drippyloadingscreen durabilitytooltip dynamic-fps dynamiclights DynamicTrees DynamicTreesBOP DynamicTreesPlus Easy Dungeons EasyAnvils EasyMagic easy_npc eatinganimation ecologics effective_fg elevatorid embeddium emotecraft enchantlimiter EnchantmentDescriptions EnderMail engineersdecor entityculling entity_model_features entity_texture_features epicfight EvilCraft exlinefurniture expandability explosiveenhancement factory-blocks fairylights fancymenu FancyVideo FarmersDelight fast-ip-ping FastSuite ferritecore finsandtails FixMySpawnR Forge Middle Ages fossil FpsReducer2 furnish GamingDeco geckolib goblintraders goldenfood goodall H.e.b habitat harvest-with-ease hexerei hole_filler huge-structure-blocks HunterIllager iammusicplayer Iceberg illuminations immersive_paintings incubation infinitybuttons inventoryhud InventoryProfilesNext invocore ItemBorders itemzoom Jade jei (Just Enough Items) JetAndEliasArmors journeymap JRFTL justzoom kiwiboi Kobolds konkrete kotlinforforge lazydfu LegendaryTooltips libIPN lightspeed lmft lodestone LongNbtKiller LuckPerms Lucky77 MagmaMonsters malum ManyIdeasCore ManyIdeasDoors marbledsarsenal marg mcw-furniture mcw-lights mcw-paths mcw-stairs mcw-trapdoors mcw-windows meetyourfight melody memoryleakfix Mimic minecraft-comes-alive MineTraps minibosses MmmMmmMmmMmm MOAdecor (ART, BATH, COOKERY, GARDEN, HOLIDAYS, LIGHTS, SCIENCE) MobCatcher modonomicon mods_optimizer morehitboxes mowziesmobs MutantMonsters mysticalworld naturalist NaturesAura neapolitan NekosEnchantedBooks neoncraft2 nerb nifty NightConfigFixes nightlights nocube's_villagers_sell_animals NoSeeNoTick notenoughanimations obscure_api oculus oresabovediamonds otyacraftengine Paraglider Patchouli physics-mod Pillagers Gun PizzaCraft placeableitems Placebo player-animation-lib pneumaticcraft-repressurized polymorph PrettyPipes Prism projectbrazier Psychadelic-Chemistry PuzzlesLib realmrpg_imps_and_demons RecipesLibrary reeves-furniture RegionsUnexplored restrictedportals revive-me Scary_Mobs_And_Bosses selene shetiphiancore ShoulderSurfing smoothboot
    • Hi everyone, I'm currently developing a Forge 1.21 mod for Minecraft and I want to display a custom HUD overlay for a minigame. My goal: When the game starts, all players should see an item/block icon (from the base game, not a custom texture) plus its name/text in the HUD – similar to how the bossbar overlay works. The HUD should appear centered above the hotbar (or at a similar prominent spot), and update dynamically (icon and name change as the target item changes). What I've tried: I looked at many online tutorials and several GitHub repos (e.g. SeasonHUD, MiniHUD), but most of them use NeoForge or Forge versions <1.20 that provide the IGuiOverlay API (e.g. implements IGuiOverlay, RegisterGuiOverlaysEvent). In Forge 1.21, it seems that neither IGuiOverlay nor RegisterGuiOverlaysEvent exist anymore – at least, I can't import them and they are missing from the docs and code completion. I tried using RenderLevelStageEvent as a workaround but it is probably not intended for custom HUDs. I am not using NeoForge, and switching the project to NeoForge is currently not an option for me. I tried to look at the original minecraft source code to see how elements like hearts, hotbar etc are drawn on the screen but I am too new to Minecraft modding to understand. What I'm looking for: What is the correct way to add a custom HUD element (icon + text) in Forge 1.21, given that the previous overlay API is missing? Is there a new recommended event, callback, or method in Forge 1.21 for custom HUD overlays, or is everyone just using a workaround? Is there a minimal open-source example repo for Forge 1.21 that demonstrates a working HUD overlay without relying on NeoForge or deprecated Forge APIs? My ideal solution: Centered HUD element with an in-game item/block icon (from the base game's assets, e.g. a diamond or any ItemStack / Item) and its name as text, with a transparent background rectangle. It should be visible to the players when the mini game is running. Easy to update the item (e.g. static variable or other method), so it can change dynamically during the game. Any help, code snippets, or up-to-date references would be really appreciated! If this is simply not possible right now in Forge 1.21, it would also help to know that for sure. Thank you very much in advance!
    • The simple answer is there is not an easy way. You would need to know how to program in Java, as well as at least some familiarity with how Forge works so you could port the differences. You would also need the sourcecode for the original mod, and permission from the author to modify it, if they did not use some sort of open source license. So it's not impossible, but it would take some effort, but doing so would open up a whole new world of possibilities for you!
    • Does it still crash if you remove holdmyitems? Looks like that mod doesn't work on a server as far as I can tell from the error.  
  • Topics

×
×
  • Create New...

Important Information

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