• 0

    posted a message on How to set damage on bows/swords

    i think you may be misunderstanding .setDamage doesn't affect weapon damage its the durability you want. damageVsEntity which is determined by the toolMaterial that is what determines damage dealt. Correct me if I'm wrong.

    Posted in: Modification Development
  • 0

    posted a message on [SOLVED]Potion effects and held items.

    yeah i believe so? the rest of my code works and all my events are in the same class....


    here are my event handlers i apologize now for the huge wall of s#17 im sending your way lol!








    package com.bigdirty1985.hardcore.main;

    import ibxm.Player;

    import java.util.Random;

    import net.minecraft.block.BlockTorch;
    import net.minecraft.entity.passive.EntityCow;
    import net.minecraft.entity.passive.EntityPig;
    import net.minecraft.entity.passive.EntitySheep;
    import net.minecraft.init.Blocks;
    import net.minecraft.init.Items;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemAxe;
    import net.minecraft.item.ItemSpade;
    import net.minecraft.item.ItemStack;
    import net.minecraft.potion.Potion;
    import net.minecraft.potion.PotionEffect;
    import net.minecraftforge.event.entity.EntityEvent;
    import net.minecraftforge.event.entity.EntityJoinWorldEvent;
    import net.minecraftforge.event.entity.item.ItemEvent;
    import net.minecraftforge.event.entity.living.LivingDropsEvent;
    import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
    import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
    import net.minecraftforge.event.entity.player.PlayerEvent;
    import net.minecraftforge.event.entity.player.PlayerEvent.BreakSpeed;
    import net.minecraftforge.event.entity.player.PlayerInteractEvent;
    import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
    import net.minecraftforge.event.entity.player.PlayerUseItemEvent;
    import net.minecraftforge.event.world.BlockEvent;
    import net.minecraftforge.event.world.BlockEvent.BreakEvent;

    import com.bigdirty1985.hardcore.block.MBlock;
    import com.bigdirty1985.hardcore.item.MItem;

    import cpw.mods.fml.common.Mod.EventHandler;
    import cpw.mods.fml.common.eventhandler.SubscribeEvent;
    import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;

    public class MEventHandler {
    Random r = new Random();

    @SubscribeEvent
    public void onDrops(BlockEvent.HarvestDropsEvent event) {

    // if you break leaves
    if (event.block == Blocks.leaves || event.block == Blocks.leaves2)
    // 25% chance
    if (r.nextInt(3) == 0) {

    // to drop branches
    event.drops.add(new ItemStack(MBlock.branch));
    }
    }

    @SubscribeEvent
    public void onEntityDrop(LivingDropsEvent event) {

    if (event.entityLiving instanceof EntitySheep) {

    // delete vanilla drops
    // event.drops.clear();
    // drop bladder
    event.entity.entityDropItem(new ItemStack(MBlock.burntTorch), 1);
    // drop mutton
    event.entity.entityDropItem(new ItemStack(MBlock.branch), 1);
    // bones
    for (int i = r.nextInt(5); i > 0; i--) {
    event.entity.entityDropItem(new ItemStack(Items.bone), 1);
    }
    }

    }

    @SubscribeEvent
    // VV I KNOW THIS IS WRONG VV
    // when torch gets a random update
    // VV THIS VV
    public void onUpdate(BlockEvent event) {
    // if (event.block == Blocks.torch){
    // replace torch with burnt torch 10% of the time
    // if (r.nextInt(9)== 0){
    // event = MBlock.burntTorch;}

    // }

    }

    // @SubscribeEvent
    // public void EntityInteractEvent(Entity target) {

    // }

    // replaces vanilla torches with modded torches on placement
    @SubscribeEvent
    public void turnTorchIntofresh(BlockEvent.PlaceEvent event){
    if("tile.torch".equals(event.block.getUnlocalizedName())){
    System.out.println("Torch placed!");
    event.world.setBlock(event.x, event.y, event.z, MBlock.freshTorch);
    }
    }

    @SubscribeEvent // blocks that mine slower barehanded use a ?string array? maybe
    public void playerDigsSlow(BreakSpeed event){
    if("tile.dirt".equals(event.block.getUnlocalizedName()) || "tile.grass".equals(event.block.getUnlocalizedName())){
    if(event.entityPlayer.getHeldItem() == null){
    event.newSpeed = 0.1f;
    return;}
    if(!(event.entityPlayer.getHeldItem().getItem() instanceof ItemSpade || event.entityPlayer.getHeldItem().getItem() == MItem.diggingStick)){
    event.newSpeed = 0.1f;
    }
    }
    }

    @SubscribeEvent // make dirt drop sticky dirt and loose dirt
    public void dirtbreak(BlockEvent.HarvestDropsEvent event){
    if ("tile.dirt".equals(event.block.getUnlocalizedName())){
    if(event.harvester.getHeldItem() == null || event.harvester.getHeldItem().getItem() == MItem.diggingStick){
    //event.drops.clear();
    //event.drops.add(new ItemStack(MItem.diggingStick));//fix this
    }


    }
    }


    @SubscribeEvent // this makes my wood not break without an axe
    public void cantPunchWood(BreakSpeed event){
    if("tile.log".equals(event.block.getUnlocalizedName())){
    if(event.entityPlayer.getHeldItem() == null){
    event.newSpeed = 0;
    return;
    }
    if(!(event.entityPlayer.getHeldItem().getItem() instanceof ItemAxe)){
    event.newSpeed = 0;
    }
    }

    }
    /*@SubscribeEvent
    public void setPlayerMaxHealth(LivingUpdateEvent event){
    event.entityLiving.
    }*/

    @SubscribeEvent //makes breaking stone and cobble give gravel
    public void bustedCobble(BlockEvent.HarvestDropsEvent event){
    if ("tile.cobblestone".equals(event.block.getUnlocalizedName()) || "tile.stone".equals(event.block.getUnlocalizedName())){
    if(r.nextInt(3) != 0){
    event.drops.clear();
    event.drops.add(new ItemStack(Blocks.gravel));
    }
    }
    }
    // obsolete due to block methods
    /*@SubscribeEvent
    public void lightTorch(BlockEvent.PlaceEvent event){//lets you light a torch with flaming items
    if(event.placedAgainst instanceof BlockTorch && event.player.getHeldItem().getItem() == Item.getItemFromBlock(Blocks.torch) ){
    event.setCanceled(true);

    }

    }*/

    @SubscribeEvent //break iron with digging stick returns busted iron
    public void breakIron(BlockEvent.HarvestDropsEvent event){
    if ("tile.iron_ore".equals(event.block.getUnlocalizedName())){
    if(r.nextInt(3) == 0){
    event.drops.clear();
    event.drops.add(new ItemStack(Blocks.gravel));
    }
    }
    }

    @SubscribeEvent
    public void onEntitySpawn(EntityJoinWorldEvent event){
    if(event.entity instanceof EntityPig || event.entity instanceof EntityCow ){

    // if(event.world.PEANUTBUTTER.?chunksAreNewChunks?){
    // event.setCanceled(true);}
    }
    }
    //brokentools test not working
    /** @EventHandler
    public void onPlayerItemBreak(PlayerDestroyItemEvent event) {
    event.setCanceled(true);
    if( event.entityPlayer.getHeldItem().getItem() == Items.wooden_shovel){
    event.entityPlayer.dropItem(Items.potato, 3);
    event.entityPlayer.destroyCurrentEquippedItem();
    }
    } **/ // try replaceing with block break and reference durability zero

    //if using a rock you're slower
    @SubscribeEvent
    public void slowRocks(PlayerTickEvent event){
    if(event.player.getHeldItem() != null){
    if(event.player.getHeldItem().getItem() == MItem.bigRock || event.player.getHeldItem().getItem() == MItem.sharpRock){
    event.player.addPotionEffect(new PotionEffect(Potion.digSlowdown.getId(),1,1));
    }}
    }

    }

    Posted in: Modification Development
  • 0

    posted a message on [SOLVED]Potion effects and held items.

    Hi im working on an event to give the player mining fatigue only when holding a rock as a tool it looks to me that my code is correct but its not working any help is appreciated. Tanks in advance.



    @SubscribeEvent
    public void slowRocks(PlayerTickEvent event){

    //if item is not null
    if(event.player.getHeldItem() != null){

    //and is either rock tool
    if(event.player.getHeldItem().getItem() == MItem.bigRock || event.player.getHeldItem().getItem() == MItem.sharpRock){

    // then give mining fatigue
    event.player.addPotionEffect(new PotionEffect(Potion.digSlowdown.getId(),1,1));
    }}
    }

    Posted in: Modification Development
  • 0

    posted a message on Syntax error on token "else", delete this token

    }

    }
    }else{

    }

    world.setBlockToAir(x, y, z);
    }
    }



    taking out one of the brackets above the last else and adding it to the bottom fixes the errors but no promises on the function of the code



    fixed:


    }

    }else{


    }


    world.setBlockToAir(x,y,z);

    }

    }

    }

    Posted in: Modification Development
  • 0

    posted a message on Creating Biomes and Stairs

    if you can make a block then try Extending BlockStairs.



    I have no idea about the biome thing though.

    Posted in: Modification Development
  • 0

    posted a message on Getting animal mobs to spawn only on new chunks

    as the title says i'm trying to get animals to spawn fresh in new chunks but not respawn in old ones .


    my code;



    @SubscribeEvent
    public void onEntitySpawn(EntityJoinWorldEvent event){
    if(event.entity instanceof EntityPig || event.entity instanceof EntityCow ){

    //-------------------v v v something less sticky goes here im sure of it.
    if(event.world.PEANUTBUTTER.?!chunksAreNewChunks?){
    event.setCanceled(true);}
    }
    }

    i've dug through the code for 2 hours and cant find a method to return if the chunk is freshly generated.

    Posted in: Modification Development
  • 0

    posted a message on [SOLVED]Help with player.getHeldItem() need player.getHeldBlock??

    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_)
    {
    if(player.getHeldItem() != null){
    if(player.getHeldItem().getItem().getUnlocalizedName().equals("torch" ) || (player.getHeldItem().getItem() == Item.getItemFromBlock(Blocks.torch))){

    // gets the meta of the old block and replaces it
    world.setBlock(x, y, z, MBlock.freshTorch, world.getBlockMetadata(x, y, z),1)
    ;
    }}

    return true;



    This is my working code! marking as solved Azaka Leviathan you guys are awesome! I'm putting you in my credits.txt file for helping me learn events better at 2 am!I even figured out how to make them go out in the rain by stealing some code from BlockFire! Thanks alot!

    Posted in: Modification Development
  • 0

    posted a message on [SOLVED]Help with player.getHeldItem() need player.getHeldBlock??

    wow onBlockActivated would have been the way to go all along i kinda feel dumb now that fixes everything i CAN do away with the complicated event stuff. so thatproblems fixed . now the meta values are those in


    onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_)


    are they one of the obfuscated values i havent figured out yet or is there a this.getMeta or whatever method?

    Posted in: Modification Development
  • 0

    posted a message on [SOLVED]Help with player.getHeldItem() need player.getHeldBlock??

    yeah i fixed that one myself thanks though. (we must have been typing at the same time) it all works except for the fires and this issue:


    Before




    After


    Posted in: Modification Development
  • 0

    posted a message on [SOLVED]Help with player.getHeldItem() need player.getHeldBlock??

    ok i fixed it i changed event.block to event.placedAgainst


    now is there a similar way to stop the flint and steel from lighting the ground on fire when i light a torch with it?

    Posted in: Modification Development
  • 0

    posted a message on [SOLVED]Help with player.getHeldItem() need player.getHeldBlock??
    Quote from Azaka7»

    event.isCanceled() just returns if the event has been canceled. Use event.setCanceled(true); to cancel the event.


    ok i changed that but it still didnt fix it


    public void lightTorch(BlockEvent.PlaceEvent event){//lets you light a torch with flaming items
    if(event.block instanceof BlockTorch && event.player.getHeldItem().getItem() == Item.getItemFromBlock(Blocks.torch) ){
    event.setCanceled(true);

    }

    }


    EDIT: LMAO!! i'm sure @SubscribeEvent might help lol... wow..

    ok it is cancelling the event BUT i just noticed a huge oversight event,block is referencing the block placed not the target so all my code does is prevent me from placing torches anywhere at all......grrrrrr.

    Posted in: Modification Development
  • 0

    posted a message on [SOLVED]Help with player.getHeldItem() need player.getHeldBlock??
    Quote from Leviathan143»

    Is the lit torch from your mod?


    sort of.. at the time of use (while in my inventory )it is vanilla but when it is placed the eventhandler uses the freshtorch which is my ticking torch that goes out over time. other than randomly ticking and eventually changing to a burnt torch it is a copy paste of vanilla torches extending BlockTorch.

    Posted in: Modification Development
  • 0

    posted a message on [SOLVED]Help with player.getHeldItem() need player.getHeldBlock??
    Quote from Azaka7»

    Use Item.getItemFromBlock(block) when you want to compare an item to a block. You can also use Block.getBlockFromItem(item), but not all items have blocks, so I'm not sure how well it would work.


    yeah i was trying to reference the held item as a block and i should have been looking at how to use the block as an item. thanks .Azaka7


    and what im trying to do is after a torch is placed that is unlit i want to use a lit torch in hand to light it this is working now but sometimes i get weird floating torches that don't connect to the wall not sure how to fix...


    the other issue is i tried to stop the game from placing a torch next to the first torch when i click it to light it .



    public void lightTorch(BlockEvent.PlaceEvent event){
    if(event.block instanceof BlockTorch && event.player.getHeldItem().getItem() == Item.getItemFromBlock(Blocks.torch) ){
    event.isCanceled();

    }

    }


    i really have no idea why this doesn't work.

    Posted in: Modification Development
  • 0

    posted a message on [SOLVED]Help with player.getHeldItem() need player.getHeldBlock??

    im trying to make my unlit torches change to lit torches when i use various items on them. This works like i want but i cant get the torch item to light other torches it just places them next to it. I have spent the past five hours trying to figure this out myself so i could avoid a "Go Learn Java" response but i frickin give up lol. the flint and steel works fine and i know it is because a torch is a block not an item but i cant get it to check for held block.


    this is in my block class :



    @Override
    /**
    * Called upon block activation (right click on the block.)
    */
    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_)
    {
    if(player.getHeldItem() != null){
    if(player.getHeldItem().getItem().getUnlocalizedName().equals("tile.torch" ) || (player.getHeldItem().getItem() == Items.flint_and_steel)){
    world.setBlock(x, y, z,
    MBlock.freshTorch);
    }}

    return false;


    }


    to stop it from placing a torch when i click on it i tried this but again same problem : "Incompatible operand types Item and Block"


    public void lightTorch(BlockEvent.PlaceEvent event){ // ----------------------------v v this errors
    if(event.block instanceof BlockTorch && event.player.getHeldItem().getItem() == Blocks.torch ){
    event.isCanceled();

    }


    I know this is something small im overlooking surely.



    also my flint and steel is lighting the ground next to my torches as i figured it would

    I'm curious how to fix this as if i cancel playerInteract it wont do what I want it to either


    thanks for any feedback

    Posted in: Modification Development
  • 0

    posted a message on [redacted]

    I just had this problem. Override this method in your Block class



    @Override

    public void updateTick(World p_149674_1_, int p_149674_2_, int p_149674_3_, int p_149674_4_, Random p_149674_5_){


    the stuff you want it to do when it ticks


    }


    also in the constructor you'll need this.



    this.setTickRandomly(true);
    needsRandomTick = true;

    this may be redundant but i always put both in mine.


    that should be a big shove in the right direction.


    and if that doesn't help my question was here http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/2502382-solved-help-replacing-block-with-different-block

    Posted in: Modification Development
  • To post a comment, please .