Jump to content

[Update Last Message] About AddSmelting


xwerswoodx

Recommended Posts

Hi everyone,

 

I want to know how can I check close items, or blocks. For example, if I have fire 1 square around me I want to give ench. to my sword. How can I check and change itemicon?

 

Secondly, when I eat custom foods with BOWL I want to give bowl back to me.  Like water when you use it, it gives bucket back. How can I do this?

 

Thanks

Link to comment
Share on other sites

The food is easy, add something like this to you class;

 


    @Override
public ItemStack onEaten(params)
    {
        super#onEaten(params);
        return new ItemStack(Whateveryouwantinreturn);
    }

 

The enchantment thing took me a while, but I finally got it to work in a clean manner.

 


if (player#worldObj#getBlockId((int)player#posX, (int)player#posY - 1, (int)player#posZ) == Blockwhateveryouwant)

        {
            	ItemStack sword = player#getCurrentEquippedItem();
            	
            	if(sword#isItemEnchantable())
            	{
            	
            		if(!sword#isItemEnchanted());
            		{
            			sword#addEnchantment(whateverenchantment you want);
            		}
            	}
            }

 

The above code goes in your TickHandler, if you don't have one of those, go make one(I'll wait).

 

First it looks at the block below you; if it matches the block you specify, it will go to the first "if statement". Next, it will look at the player is currently holding and asks if it is enchantable, if it is, proceed to the next "if statement". If you are at this stage, it means that you are standing on your specified block, and the item that you are holding is enchantable. The next "if statement' checks to see if the enchantable item you are holding is already enchanted, if it is, nothing happens, if it isn't the enchantment(s) that you specify will be applied to the weapon.

 

i don't have time to check right now, but as far as the itemIcon goes, you may want to look into "getItemDamageForDisplay".

 

 

(Just for fun)

Try and take out one of the "if statements' and see what is does.

 

 

 

If you remove "!player.isItemEnchanted" for instance, the same enchantment(s) will be applied every tick,(20 times every second, I believe) and your game will more than likely crash.

 

 

 

 

 

I hope I helped, and you learned something that you can apply to your future modding endeavors!

 

--Tenyar97

Link to comment
Share on other sites

For item.bowlempty is working now thank you.

 

However, I working eclipse for 3 days and I don't know what is TickHandler, could you explain me little bit more, please? I looked to internet but couldn't find, or if I can, I didn't know :P And also how can I check distance between item

Link to comment
Share on other sites

A Tickhandler basically checks something on an event. For example, I am using my Tickhandler to check if a player falls in my custom dimension, and if they do, then I want the fall damage to be reduced significantly. Here is the outline of a basic Tickhandler:

 

 

 

public class YOURTICKHANDLER implements ITickHandler {

 

@Override

public void tickStart(EnumSet<TickType> type, Object... tickData) {

}

//This is an example of an event, you need to put @ForgeSubscribe in front of it so Forge knows It is an event. Then you need to specify an event type in the same way I did the Living fall event.

@ForgeSubscribe

public void livingFall(LivingFallEvent event)

{

}

 

 

@Override

public void tickEnd(EnumSet<TickType> type, Object... tickData) {

 

}

 

@Override

public EnumSet<TickType> ticks() {

 

        return EnumSet.of(TickType.PLAYER, TickType.SERVER);

 

}

 

@Override

public String getLabel() {

 

return null;

}

 

}

 

And that is your basic Tickhandler. :)

 

Hope that helps.

 

EDIT: To register your TH, you need to put this in your main class:

 

TickRegistry.registerTickHandler(new NAMETickHandler(), What ever side your tickhandler needs to be on, probably Side.SERVER, but it could be Side.CLIENT, I'd recommend Side.SERVER though.);

Link to comment
Share on other sites

The tick handler will allow you to "focus" on the player(CJ said it better), allowing you to do neat things like potion effects.

 

Here is a video showing how to set one up,

 

 

...and one showing potion effects

 

 

Locating blocks can be a bit...tricky.

 

You have three ways to move, "X", "Y", and "Z"

 

The "Y" axis is the easiest, it is up/down. Up is represented by positive numbers, down by negative. From the example I gave you,

(int)player#posY - 1

you can see that the game is looking one block below the player's feet. (Represented by cobblestone)

 

 

 

 

I believe "X" is the East direction, and "Z" is South. Unfortunately, my project is acting up at the moment, so I can't get screenshots of those two.  I did, however find a "compass" that may help.

 

 

 

Coordinates.png

 

 

 

Play around with them yourself, though! Anyone can tell you how to do it forever, but you are never going to learn unless you actually do something. ;P

Link to comment
Share on other sites

A Tickhandler basically checks something on an event. For example, I am using my Tickhandler to check if a player falls in my custom dimension, and if they do, then I want the fall damage to be reduced significantly. Here is the outline of a basic Tickhandler:

 

 

 

public class YOURTICKHANDLER implements ITickHandler {

 

@Override

public void tickStart(EnumSet<TickType> type, Object... tickData) {

}

//This is an example of an event, you need to put @ForgeSubscribe in front of it so Forge knows It is an event. Then you need to specify an event type in the same way I did the Living fall event.

@ForgeSubscribe

public void livingFall(LivingFallEvent event)

{

}

 

 

@Override

public void tickEnd(EnumSet<TickType> type, Object... tickData) {

 

}

 

@Override

public EnumSet<TickType> ticks() {

 

        return EnumSet.of(TickType.PLAYER, TickType.SERVER);

 

}

 

@Override

public String getLabel() {

 

return null;

}

 

}

 

And that is your basic Tickhandler. :)

 

Hope that helps.

 

EDIT: To register your TH, you need to put this in your main class:

 

TickRegistry.registerTickHandler(new NAMETickHandler(), What ever side your tickhandler needs to be on, probably Side.SERVER, but it could be Side.CLIENT, I'd recommend Side.SERVER though.);

 

The tick handler will allow you to "focus" on the player(CJ said it better), allowing you to do neat things like potion effects.

 

Here is a video showing how to set one up,

 

 

...and one showing potion effects

 

 

Locating blocks can be a bit...tricky.

 

You have three ways to move, "X", "Y", and "Z"

 

The "Y" axis is the easiest, it is up/down. Up is represented by positive numbers, down by negative. From the example I gave you,

(int)player#posY - 1

you can see that the game is looking one block below the player's feet. (Represented by cobblestone)

 

 

 

 

I believe "X" is the East direction, and "Z" is South. Unfortunately, my project is acting up at the moment, so I can't get screenshots of those two.  I did, however find a "compass" that may help.

 

 

 

Coordinates.png

 

 

 

Play around with them yourself, though! Anyone can tell you how to do it forever, but you are never going to learn unless you actually do something. ;P

 

Thank you so much, these messages are helpful for me. I check and test something like this;

 

package acidmod.proxy;

import java.util.EnumSet;

import acidmod.blockref;
import acidmod.configref;
import acidmod.itemref;
import acidmod.functions.writeline;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class ServerTickHandler implements ITickHandler {

private void onPlayerTick(EntityPlayer player) {
	if (player.getCurrentItemOrArmor(4) != null) {
		ItemStack helmet = player.getCurrentItemOrArmor(4);			
		if (helmet.getItem() == itemref.blackDiamondHelmet) {
			player.addPotionEffect((new PotionEffect(Potion.confusion.getId(), 200, 0)));
		}
	}

	int blockItem;
	blockItem = configref.blackDiamondBlockID;
	if (player.worldObj.getBlockId((int)player.posX, (int)player.posY - 2, (int)player.posZ) == blockItem) {
		ItemStack sword = player.getCurrentEquippedItem();
            sword.setItemName("Y");
	} else if (player.worldObj.getBlockId((int)player.posX -2, (int)player.posY, (int)player.posZ) == blockItem) {
		ItemStack sword = player.getCurrentEquippedItem();
            sword.setItemName("X");
	} else if (player.worldObj.getBlockId((int)player.posX, (int)player.posY, (int)player.posZ -2) == blockItem) {
		ItemStack sword = player.getCurrentEquippedItem();
            sword.setItemName("Z");
	}

}

@Override
public void tickStart(EnumSet<TickType> type, Object... tickData) {
	if (type.equals(EnumSet.of(TickType.PLAYER))) {
		onPlayerTick((EntityPlayer) tickData [0]);
	}

}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData) {

}

@Override
public EnumSet<TickType> ticks() {
	return EnumSet.of(TickType.PLAYER, TickType.SERVER);
}

@Override
public String getLabel() {
	return null;
}

}

 

I understand how it works, but I only stuck when I try to change icon, for example I want to change my blackDiamondSword to blackDiamondBow, but I couldn't find registericon, seticon, or something like this. Is it possible to do? And also I don't want only equiped item change, I want if I have in my bag, it change, if its possible :P

 

If you explain how can I, I can try :)

Link to comment
Share on other sites

I have registerIcon setting under my item class, but I'm not really understand how can I add getIcon settings under this,

 

package acidmod.functions;

import acidmod.ref;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

public class additem extends Item {

//additem(UID, STACK-SIZE, IMAGE-NAME)
public additem(int uid, int stack, String name, CreativeTabs tab) {
	super(uid);

	this.setMaxStackSize(stack);
	this.setCreativeTab(tab);
	this.setUnlocalizedName(name);
	GameRegistry.registerItem(this, name);
}

@SideOnly(Side.CLIENT)
@Override
public void registerIcons(IconRegister reg) {
	this.itemIcon = reg.registerIcon(ref.uid + ":" + (this.getUnlocalizedName().substring(5)));
}

}

Link to comment
Share on other sites

I added some items but I have a problem because I add addsmelting but not working on foods.

 

My drink;

Configref;

        cupOfMilkyChocolateID = config.get("Drink IDs", "Cup Of Milky Chocolate ID", 3386).getInt();
        cupOfHotMilkyChocolateID = config.get("Drink IDs", "Cup Of Hot Milky Chocolate ID", 3387).getInt();

 

Foodref;

	this.cupOfMilkyChocolate = new addcanfood(configref.cupOfMilkyChocolateID, "cupofmilkychocolate", 6, 0.5F, false, 0, itemref.cup);
	this.cupOfHotMilkyChocolate = new addcanfood(configref.cupOfHotMilkyChocolateID, "cupofhotmilkychocolate", 6, 0.8F, false, 1, itemref.cup);	

 

Smelting;

        GameRegistry.addSmelting(smelt_ore_diamond_black_id, craft_ingot_diamond_black, 0.9f);
        GameRegistry.addSmelting(smelt_ore_night_id, craft_ingot_night, 1.0f);

        GameRegistry.addSmelting(smelt_cup_chocolate_id, craft_cup_chocolate_hot, 0.8f);
        GameRegistry.addSmelting(smelt_cup_milk_id, craft_cup_milk_hot, 0.8f);
        GameRegistry.addSmelting(configref.cupOfMilkyChocolateID, new ItemStack(foodref.cupOfHotMilkyChocolate), 0.8f);        

 

And addcanfood;

package acidmod.functions;

import acidmod.AcidMod;
import acidmod.ref;
import cpw.mods.fml.common.network.Player;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.util.Icon;
import net.minecraft.world.World;

public class addcanfood extends ItemFood {
private Item returnItem;
private int foodHeal;
private float foodSaturation;
private static final int[] potionType = new int[] {Potion.poison.getId(), Potion.regeneration.getId(), Potion.heal.getId(), Potion.harm.getId()};

//addfood(UID, STACK, IMAGE-NAME, HEAL*2, GOOD?, TRUE?|FALSE?, 1|2|3, noRETURN|RETURN)
public addcanfood(int uid, String name, int heal, float saturation, boolean what, int potion, Item item) {
	super(uid, heal, saturation, what);

	//Max Stack = 1, because of returns!
	this.setMaxStackSize(64);
	this.setCreativeTab(CreativeTabs.tabFood);
	this.setUnlocalizedName(name);
		if (potion > 0) {
			this.setPotionEffect(potionType[potion], 5, 0, 0.6F);
		}
	this.foodHeal = heal;
	this.foodSaturation = saturation;
	this.returnItem = item;
	GameRegistry.registerItem(this, name);
}

@SideOnly(Side.CLIENT)
@Override
public void registerIcons(IconRegister reg) {
	this.itemIcon = reg.registerIcon(ref.uid + ":" + (this.getUnlocalizedName().substring(5)));
}

public ItemStack onEaten(ItemStack itemstack, World world, EntityPlayer player) {
	if (!player.capabilities.isCreativeMode) {
		itemstack.stackSize -=1;
		if (itemstack.stackSize > 0) {
			player.inventory.addItemStackToInventory(new ItemStack(this.returnItem));
		}
	}
	if (!world.isRemote) {
		player.getFoodStats().addStats(this.foodHeal, this.foodSaturation);
		world.playSoundAtEntity(player, "random.burp", 0.5F, world.rand.nextFloat() * 0.1F + 0.9F);
	}
        
        return itemstack.stackSize > 0 ? itemstack : new ItemStack(this.returnItem);
}
}

 

The problem is, smelting, the first 2 item which are ores, working but when I try to cook my drinks it isn't possible, I tried to fix it 3 hours but I couldn't because I don't understand where is the mistake.

 

Can anyone help my about this please, thanks.

Link to comment
Share on other sites

Join the conversation

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

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

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

×   Your previous content has been restored.   Clear editor

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

Announcements



×
×
  • Create New...

Important Information

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