• 0

    posted a message on How to make a portable light source?
    Quote from Dudemister1999

    It is! Instead of creating an invisible block every tick, having it emit light, and die, only to be repeated, you can just have it give the player the effect. I had made code for something like that, but it was for 1.4, and now I can't remember where I put it. I'll make an example and have it up soon!

    See look:
    public void onArmorTickUpdate(World world, EntityPlayer player, ItemStack itemStack)
    {
    player.addPotionEffect((new PotionEffect(Potion.nightVision.getId(), 1, 1)));
    }

    Have that every tick, and you, my friend, have night vision while your armor is on :)



    Actually, somehow I did not remember there being a nightvision potion in Minecraft. After checking it's effect, this is exactly what I am looking for! Thanks!

    Quote from coolAlias

    Night vision is simpler, but not quite the same effect. :)

    To destroy the block, in the block's updateTick method, check if the metadata == 0 and if so, world.setBlockToAir(x, y, z). World and coordinates are passed in to the method, metadata you get from world.getBlockMetadata(x, y, z).

    I used metadata to store its lifespan.


    I'm not seeing any way to pass the coords into the method. I can pass the world through my main class file, but because the coords change quicker than the block destroys itself, the wouldn't be correct when the block actually tried to destroy itself. The block itself has a minX maxX type of system you can get coords from, but they don't seem to work for destroying the block...

    I'm going to go with the nightvision, but for future reference, I'd REALLY like to know why this code here only destroys the second and later blocks, but leaves the first one placed.

      private int prevX = 0;
    private int prevY = 0;
    private int prevZ = 0;
    private long lastTime = 0;
    public void onArmorTickUpdate(World world, EntityPlayer player, ItemStack itemStack)
    {
      long time = world.getTotalWorldTime();
      if(lastTime == 0 || lastTime + 80 < time)
      {
       lastTime = time;
       if(prevX != (int)player.posX || prevY != (int)player.posY || prevZ != (int)player.posZ)
       {
        world.setBlock((int)player.posX, (int)player.posY, (int)player.posZ, Progress.lightBlock.blockID, -1, 3);
        if(world.getBlockId(prevX, prevY, prevZ) == Progress.lightBlock.blockID)
        {
    	 world.destroyBlock(prevX, prevY, prevZ, false);
        }
        prevX = (int)player.posX;
        prevY = (int)player.posY;
        prevZ = (int)player.posZ;
       }
      }
      else
      {
       return;
      }
    }
    Posted in: Modification Development
  • 0

    posted a message on How to make a portable light source?
    Cause that sounds SO much simpler :steve_eyeroll:
    Posted in: Modification Development
  • 0

    posted a message on How to make a portable light source?
    Can anyone tell me how to make a block destroy itself from it's tick function? I am having zero luck.
    Posted in: Modification Development
  • 0

    posted a message on How to make a portable light source?
    I looked and could not find the method which would let me destroy the block from inside it's own tick function. The one function I found that might have worked required me to pass it the world, which I currently have no method of doing from that class. My solution was to use the onArmorTickUpdate to do everything for me. This seems to work much better due to immediate access to world functions and better control of when the light disappears.
    The issue I now face is that the very first light block that gets placed down never gets removed. The code follows.

    private int prevX = 0;
    private int prevY = 0;
    private int prevZ = 0;
    private long lastTime = 0;
    
    public void onArmorTickUpdate(World world, EntityPlayer player, ItemStack itemStack)
    {
    long time = world.getTotalWorldTime();
    if(lastTime == 0 || lastTime + 80 < time)
    {
    lastTime = time;
    if(prevX != (int)player.posX || prevY != (int)player.posY || prevZ != (int)player.posZ)
    {
    world.setBlock((int)player.posX, (int)player.posY, (int)player.posZ, Progress.lightBlock.blockID, -1, 3);
    if(world.getBlockId(prevX, prevY, prevZ) == Progress.lightBlock.blockID)
    {
    	 world.destroyBlock(prevX, prevY, prevZ, false);
    }
    prevX = (int)player.posX;
    prevY = (int)player.posY;
    prevZ = (int)player.posZ;
    }
    }
    else
    {
    return;
    }
    }


    EDIT 2: Maybe I'm just not on top of it today, but I cannot figure out how to get my block to destroy itself after a set amount of time.
    Posted in: Modification Development
  • 0

    posted a message on How to make a portable light source?
    Ah, gotcha coolAlias. Thanks for the help I'm pretty sure I know how to do the rest.

    I might try that if I can't get this to work DrunkMafia, but it sounds like a lot more hassle.
    Posted in: Modification Development
  • 0

    posted a message on How to make a portable light source?
    I don't see a reference to the blockTick for destroying it at a later time. Are you destroying the block from the place you created it?
    Posted in: Modification Development
  • 0

    posted a message on How to make a portable light source?
    I tried this code to get it to work, and it does not work properly at all:

        private int oldLight;
        private int prevX = 0;
        private int prevY = 0;
        private int prevZ = 0;
        private boolean ranOnce = false;
        public void onArmorTickUpdate(World world, EntityPlayer player, ItemStack itemStack)
        {	   
    	    if(prevX != (int)player.posX || prevY != (int)player.posY || prevZ != (int)player.posZ)
    	    {
    		    oldLight = (int) world.getLightBrightness((int)player.posX, (int)player.posY, (int)player.posZ);
    		    world.setLightValue(EnumSkyBlock.Block, (int)player.posX, (int)player.posY, (int)player.posZ, 15);
    		    if(ranOnce)
    		    {
    			    world.setLightValue(EnumSkyBlock.Block, prevX, prevY, prevZ, oldLight);
    		    }
    		    else
    		    {
    			    ranOnce = true;
    		    }
    	    }
    	    prevX = (int)player.posX;
    	    prevY = (int)player.posY;
    	    prevZ = (int)player.posZ;
        }


    I'm going to try the light emitting block trick. Did you have to mark the block as Material.portal so it was walkable?
    Posted in: Modification Development
  • 0

    posted a message on Trouble with Item Use
    I am attempting to make a charging sword that stores damage every time a creature is hit. The sword itself does 1 damage, but if it hits 9 times, you should be able to right click and deal a single hit of 9 damage. After that the sword goes back to 1 damage until you right click again and release any charged damage.

    Unfortunately, it is not working. I am modding in Forge for Minecraft 1.52. The following is my class:

    package mods.progress.weapon;
    import java.util.Random;
    import mods.progress.Progress;
    import net.minecraft.client.renderer.texture.IconRegister;
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.EnumRarity;
    import net.minecraft.item.EnumToolMaterial;
    import net.minecraft.item.ItemStack;
    import net.minecraft.item.ItemSword;
    import net.minecraft.world.World;
    public class ItemChargeSword extends ItemSword {
    public ItemChargeSword(int par1, EnumToolMaterial par2EnumToolMaterial) {
    super(par1, par2EnumToolMaterial);
    // TODO Auto-generated constructor stub
    }
    private EnumToolMaterial material;
    private boolean doDamage = false;
    private boolean wasUsed = false;
    private int currentDamage = 0;
    
    public void registerIcons(IconRegister iconRegister) {
    itemIcon = iconRegister.registerIcon("progress:chargeSword");
    }
    public boolean hasEffect(ItemStack par1ItemStack) {
    return true;
    }
    
    public EnumRarity getRarity(ItemStack par1ItemStack) {
    return EnumRarity.uncommon;
    }
    
    public boolean getIsRepairable(ItemStack stack, ItemStack stack2) {
    return false;
    }
    
    public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
    {
    	 return true;
    }
    
    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    {
    	 if (doDamage){
    	 doDamage = false;
    	 }
    	 else if (!doDamage) {
    	 doDamage = true;
    	 }
    	 par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
    	 return par1ItemStack;
    }
    
    public int getDamageVsEntity(Entity par1Entity) {
    if (wasUsed) {
    currentDamage = 0;
    wasUsed = false;
    }
    if (doDamage) {
    wasUsed = true;
    doDamage = false;
    return currentDamage;
    }
    else {
    currentDamage++;
    return 1;
    }
    }
    }
    Posted in: Modification Development
  • 0

    posted a message on Crafting Event
    Awesome, looking at that I can see it's exactly what I need. I am a little confused on where I implement this interface though. It doesn't seem like this would work if implemented in the armor class itself.
    Posted in: Modification Development
  • 0

    posted a message on Crafting Event
    Where is the event called during crafting? I see one for brewing but I cannot find an event to hook into to change the result of a crafting recipe. Does this exist?
    Posted in: Modification Development
  • 0

    posted a message on Using if(EntityPlayer) in main mod file? [FORGE]
    I would check for an event that fires when the player levels(or maybe when they gain/lose XP). That would allow you to set a variable when a player hit thirty, and take it away when they drop below thirty. A little round about but if the event is there you're golden.
    Posted in: Modification Development
  • 0

    posted a message on Replacing a vanilla item
    If you're referring to the CraftingManager base class, I'm trying NOT to edit base classes.

    Other than that, I've searched minecraft code, forge forums, this forum, and Google for tutorials on the RecipeManager class, to no avail.

    Could you give me something more specific?
    Posted in: Modification Development
  • 0

    posted a message on Replacing a vanilla item
    Is there any way to change the result of a recipe so that it gives a custom item instead of a vanilla item? I want to change the stats of Iron Armor, but I want to avoid the trouble of recreating a new Iron from the ground up(which would cause problems with compatibility).
    Posted in: Modification Development
  • 0

    posted a message on [FORGE][1.52]Progress Mod

    From right to left: Copper, Malachite, Aluminum, Amethyst, Ruby, Diamond Fragments.

    Let's make Progress...

    This is light mod which will soon be in Alpha version(it has not had a compiled test version...yet). My desire was to make a mod that preserved the Minecraft experience while making it longer played and more challenging. To that end, I have made numerous small changes.
    First, diamonds no longer spawn in the regular world. In order to get basics like a pickaxe and enchanting table, you must find diamond fragments ore, and combine the fragments into diamonds. This ore is very rare; unless you spend an inordinate amount of time mining, you won't be getting any armor out of it.
    Iron has also been made to spawn at much lower levels and in lower quantities. To fill in these gaps, other materials have been added.

    Copper - Basic material, easy to find and usable in low quality swords and armor, as well as tools.

    Aluminum - Almost as strong as iron, but without the durability. Better used for adornment(below).

    Malachite - The lowest level gem used for adornment.

    Amethyst - Moderately rare gem used for adornment.

    Ruby - Extremely rare gem used for adornment.

    The adornment system is currently using the crafting table until I learn how to create my own table/smelter. To adorn an item, you put the item in with gold, lapis, and the gem of your choice(malachite requires no gold/lapis), and the item is adorned. Adornment increases stats and will eventually give a very small ability/bonus depending on the gem used.

    This is most DEFINITELY still very much a WIP, but I will be adding more by the week. Figured I would put it up and see if there is interest in the community. I am making this mod for myself and my friends to play on our dedicated server.

    More pictures here.






    Posted in: WIP Mods
  • 0

    posted a message on Spawn ore in the Nether
    You rock, I got it. For anyone else wondering, you have to make a copy of the WorldGenMinable and change the part in it that says stone to say netherrack. Then in your world generator use WorldGenNether(or whatever you named the copied class) instead of WorldGenMinable in the generateNether method.
    Posted in: Modification Development
  • To post a comment, please or register a new account.