Jump to content

[1.7.10] Something to add interaction to a mob without editing it.


Recommended Posts

Posted

To remove all edit base class of my mod following the advice of diesieben07 I do resouvir the bucket with water or lava enable my two portals to the sky and hell hard, but new problems appeared:

To achieve my objective I recreated the bucket of minecraft and removed the original recipe.

The new Class:

 

 

package mod.mcreator;//based on master condiguration

 

import cpw.mods.fml.client.*;

import cpw.mods.fml.client.registry.*;

import cpw.mods.fml.common.*;

import cpw.mods.fml.common.asm.*;

import cpw.mods.fml.common.asm.transformers.*;

import cpw.mods.fml.common.discovery.*;

import cpw.mods.fml.common.discovery.asm.*;

import cpw.mods.fml.common.event.*;

import cpw.mods.fml.common.eventhandler.Event;

import cpw.mods.fml.common.functions.*;

import cpw.mods.fml.common.network.*;

import cpw.mods.fml.common.registry.*;

import cpw.mods.fml.common.toposort.*;

import cpw.mods.fml.common.versioning.*;

import cpw.mods.fml.relauncher.*;

import cpw.mods.fml.server.*;

import net.minecraft.block.*;

import net.minecraft.block.material.*;

import net.minecraft.client.*;

import net.minecraft.client.audio.*;

import net.minecraft.client.entity.*;

import net.minecraft.client.gui.*;

import net.minecraft.client.gui.achievement.*;

import net.minecraft.client.gui.inventory.*;

import net.minecraft.client.model.*;

import net.minecraft.client.multiplayer.*;

import net.minecraft.client.particle.*;

import net.minecraft.client.renderer.*;

import net.minecraft.client.renderer.culling.*;

import net.minecraft.client.renderer.entity.*;

import net.minecraft.client.renderer.tileentity.*;

import net.minecraft.client.settings.*;

import net.minecraft.command.*;

import net.minecraft.crash.*;

import net.minecraft.creativetab.*;

import net.minecraft.dispenser.*;

import net.minecraft.enchantment.*;

import net.minecraft.entity.*;

import net.minecraft.entity.ai.*;

import net.minecraft.entity.boss.*;

import net.minecraft.entity.effect.*;

import net.minecraft.entity.item.*;

import net.minecraft.entity.monster.*;

import net.minecraft.entity.passive.*;

import net.minecraft.entity.player.*;

import net.minecraft.entity.projectile.*;

import net.minecraft.inventory.*;

import net.minecraft.item.*;

import net.minecraft.item.crafting.*;

import net.minecraft.nbt.*;

import net.minecraft.network.*;

import net.minecraft.network.rcon.*;

import net.minecraft.pathfinding.*;

import net.minecraft.potion.*;

import net.minecraft.profiler.*;

import net.minecraft.server.*;

import net.minecraft.server.dedicated.*;

import net.minecraft.server.gui.*;

import net.minecraft.server.integrated.*;

import net.minecraft.server.management.*;

import net.minecraft.src.*;

import net.minecraft.stats.*;

import net.minecraft.tileentity.*;

import net.minecraft.util.*;

import net.minecraft.village.*;

import net.minecraft.world.*;

import net.minecraft.world.biome.*;

import net.minecraft.world.chunk.*;

import net.minecraft.world.chunk.storage.*;

import net.minecraft.world.demo.*;

import net.minecraft.world.gen.*;

import net.minecraft.world.gen.feature.*;

import net.minecraft.world.gen.layer.*;

import net.minecraft.world.gen.structure.*;

import net.minecraft.world.storage.*;

import net.minecraftforge.classloading.*;

import net.minecraftforge.client.*;

import net.minecraftforge.client.event.*;

import net.minecraftforge.client.event.sound.*;

import net.minecraftforge.common.*;

import net.minecraftforge.event.*;

import net.minecraftforge.event.entity.*;

import net.minecraftforge.event.entity.item.*;

import net.minecraftforge.event.entity.living.*;

import net.minecraftforge.event.entity.minecart.*;

import net.minecraftforge.event.entity.player.*;

import net.minecraftforge.event.terraingen.*;

import net.minecraftforge.event.world.*;

import net.minecraftforge.oredict.*;

import net.minecraftforge.transformers.*;

import net.minecraft.init.*;

 

import java.util.*;

 

import net.minecraftforge.common.util.*;

 

import org.lwjgl.opengl.GL11;

 

 

 

@SuppressWarnings("unchecked")

public class mcreator_bucket{

 

public mcreator_bucket(){}

 

public static Item block;public static Item blockWater;public static Item blockLava;public static Object instance;public void load(){

 

GameRegistry.addRecipe(new ItemStack(block, 1), new Object[]{

"XXX", "3X5", "X7X", Character.valueOf('3'), new ItemStack(Items.iron_ingot, 1), Character.valueOf('5'), new ItemStack(Items.iron_ingot, 1), Character.valueOf('7'), new ItemStack(Items.iron_ingot, 1),

});new ChestGenHooks("bonusChest").addItem(new WeightedRandomChestContent(new ItemStack(block), 1, 5, 10));}

public void generateNether(World world, Random random, int chunkX, int chunkZ){}

public void generateSurface(World world, Random random, int chunkX, int chunkZ){}

public int addFuel(ItemStack fuel){return 0;}

public void serverLoad(FMLServerStartingEvent event){}

public void preInit(FMLPreInitializationEvent event){}

public void registerRenderers(){

}

 

 

static{

block = (new ItemBucket(Blocks.air)).setUnlocalizedName("bucket").setMaxStackSize(16).setTextureName("bucket_empty");

Item.itemRegistry.addObject(533, "Bucket", block);

blockWater = (new ItemBucket(Blocks.flowing_water)).setUnlocalizedName("bucketWater").setContainerItem(block).setTextureName("bucket_water");

Item.itemRegistry.addObject(534, "water_bucket", blockWater);

blockLava = (new ItemBucket(Blocks.flowing_lava)).setUnlocalizedName("bucketLava").setContainerItem(block).setTextureName("bucket_lava");

Item.itemRegistry.addObject(535, "lava_bucket", blockLava);

}

 

static class ItemBucket extends Item

{

    /** field for checking if the bucket has been filled. */

    private Block isFull;

    private static final String __OBFID = "CL_00000000";

 

    public ItemBucket(Block p_i45331_1_)

    {

        this.maxStackSize = 1;

        this.isFull = p_i45331_1_;

        this.setCreativeTab(CreativeTabs.tabMisc);

    }

 

    /**

    * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer

    */

    public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_)

    {

        boolean flag = this.isFull == Blocks.air;

        MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(p_77659_2_, p_77659_3_, flag);

 

        if (movingobjectposition == null)

        {

            return p_77659_1_;

        }

        else

        {

            FillBucketEvent event = new FillBucketEvent(p_77659_3_, p_77659_1_, p_77659_2_, movingobjectposition);

            if (MinecraftForge.EVENT_BUS.post(event))

            {

                return p_77659_1_;

            }

 

            if (event.getResult() == Event.Result.ALLOW)

            {

                if (p_77659_3_.capabilities.isCreativeMode)

                {

                    return p_77659_1_;

                }

 

                if (--p_77659_1_.stackSize <= 0)

                {

                    return event.result;

                }

 

                if (!p_77659_3_.inventory.addItemStackToInventory(event.result))

                {

                    p_77659_3_.dropPlayerItemWithRandomChoice(event.result, false);

                }

 

                return p_77659_1_;

            }

            if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)

            {

                int i = movingobjectposition.blockX;

                int j = movingobjectposition.blockY;

                int k = movingobjectposition.blockZ;

 

                if (!p_77659_2_.canMineBlock(p_77659_3_, i, j, k))

                {

                    return p_77659_1_;

                }

 

                if (flag)

                {

                    if (!p_77659_3_.canPlayerEdit(i, j, k, movingobjectposition.sideHit, p_77659_1_))

                    {

                        return p_77659_1_;

                    }

 

                    Material material = p_77659_2_.getBlock(i, j, k).getMaterial();

                    int l = p_77659_2_.getBlockMetadata(i, j, k);

 

                    if (material == Material.water && l == 0)

                    {

                        p_77659_2_.setBlockToAir(i, j, k);

                        return this.func_150910_a(p_77659_1_, p_77659_3_, mcreator_bucket.blockWater);

                    }

 

                    if (material == Material.lava && l == 0)

                    {

                        p_77659_2_.setBlockToAir(i, j, k);

                        return this.func_150910_a(p_77659_1_, p_77659_3_, mcreator_bucket.blockLava);

                    }

                }

                else

                {

                    if (this.isFull == Blocks.air)

                    {

                        return new ItemStack(mcreator_bucket.block);

                    }

 

                    if (movingobjectposition.sideHit == 0)

                    {

                        --j;

                    }

 

                    if (movingobjectposition.sideHit == 1)

                    {

                        ++j;

                    }

 

                    if (movingobjectposition.sideHit == 2)

                    {

                        --k;

                    }

 

                    if (movingobjectposition.sideHit == 3)

                    {

                        ++k;

                    }

 

                    if (movingobjectposition.sideHit == 4)

                    {

                        --i;

                    }

 

                    if (movingobjectposition.sideHit == 5)

                    {

                        ++i;

                    }

 

                    if (!p_77659_3_.canPlayerEdit(i, j, k, movingobjectposition.sideHit, p_77659_1_))

                    {

                        return p_77659_1_;

                    }

 

                    if (this.tryPlaceContainedLiquid(p_77659_2_, i, j, k) && !p_77659_3_.capabilities.isCreativeMode)

                    {

                        return new ItemStack(mcreator_bucket.block);

                    }

                }

            }

 

            return p_77659_1_;

        }

    }

 

    private ItemStack func_150910_a(ItemStack p_150910_1_, EntityPlayer p_150910_2_, Item p_150910_3_)

    {

        if (p_150910_2_.capabilities.isCreativeMode)

        {

            return p_150910_1_;

        }

        else if (--p_150910_1_.stackSize <= 0)

        {

            return new ItemStack(p_150910_3_);

        }

        else

        {

            if (!p_150910_2_.inventory.addItemStackToInventory(new ItemStack(p_150910_3_)))

            {

                p_150910_2_.dropPlayerItemWithRandomChoice(new ItemStack(p_150910_3_, 1, 0), false);

            }

 

            return p_150910_1_;

        }

    }

 

    /**

    * Attempts to place the liquid contained inside the bucket.

    */

    public boolean tryPlaceContainedLiquid(World p_77875_1_, int p_77875_2_, int p_77875_3_, int p_77875_4_)

    {

        if (this.isFull == Blocks.air)

        {

            return false;

        }

        else

        {

            Material material = p_77875_1_.getBlock(p_77875_2_, p_77875_3_, p_77875_4_).getMaterial();

            boolean flag = !material.isSolid();

 

            if (!p_77875_1_.isAirBlock(p_77875_2_, p_77875_3_, p_77875_4_) && !flag)

            {

                return false;

            }

            else

            {

                if (p_77875_1_.provider.isHellWorld && this.isFull == Blocks.flowing_water)

                {

                    p_77875_1_.playSoundEffect((double)((float)p_77875_2_ + 0.5F), (double)((float)p_77875_3_ + 0.5F), (double)((float)p_77875_4_ + 0.5F), "random.fizz", 0.5F, 2.6F + (p_77875_1_.rand.nextFloat() - p_77875_1_.rand.nextFloat()) * 0.8F);

 

                    for (int l = 0; l < 8; ++l)

                    {

                        p_77875_1_.spawnParticle("largesmoke", (double)p_77875_2_ + Math.random(), (double)p_77875_3_ + Math.random(), (double)p_77875_4_ + Math.random(), 0.0D, 0.0D, 0.0D);

                    }

                }

                else

                {

                Block i1 = p_77875_1_.getBlock(p_77875_2_, p_77875_3_, p_77875_4_);

                if (i1 == Blocks.air && this.isFull == Blocks.flowing_water)

                {

                p_77875_1_.setBlock(p_77875_2_, p_77875_3_, p_77875_4_, Blocks.flowing_water);

                p_77875_1_.notifyBlockOfNeighborChange(p_77875_2_, p_77875_3_, p_77875_4_, Blocks.flowing_water);

                mcreator_sky.portal.tryToCreatePortal(p_77875_1_, p_77875_2_, p_77875_3_, p_77875_4_);

                }

                    else

                    {

                    i1 = p_77875_1_.getBlock(p_77875_2_, p_77875_3_, p_77875_4_);

                    if (i1 == Blocks.air && this.isFull == Blocks.flowing_lava)

                    {

                    p_77875_1_.setBlock(p_77875_2_, p_77875_3_, p_77875_4_, Blocks.flowing_lava);

                    p_77875_1_.notifyBlockOfNeighborChange(p_77875_2_, p_77875_3_, p_77875_4_, Blocks.flowing_lava);

                    mcreator_hell.portal.tryToCreatePortal(p_77875_1_, p_77875_2_, p_77875_3_, p_77875_4_);

                    }

                else

                {

                    if (!p_77875_1_.isRemote && flag && !material.isLiquid())

                    {

                        p_77875_1_.func_147480_a(p_77875_2_, p_77875_3_, p_77875_4_, true);

                    }

 

                    p_77875_1_.setBlock(p_77875_2_, p_77875_3_, p_77875_4_, this.isFull, 0, 3);

                }

 

                    return true;

                    }

                }

            }

            return true;

}

}

}

}

 

 

But the bucket of milk depends on the cow:

 

    /**

    * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.

    */

    public boolean interact(EntityPlayer p_70085_1_)

    {

        ItemStack itemstack = p_70085_1_.inventory.getCurrentItem();

 

        if (itemstack != null && itemstack.getItem() == Items.bucket && !p_70085_1_.capabilities.isCreativeMode)

        {

            if (itemstack.stackSize-- == 1)

            {

                p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, new ItemStack(Items.milk_bucket));

            }

            else if (!p_70085_1_.inventory.addItemStackToInventory(new ItemStack(Items.milk_bucket)))

            {

                p_70085_1_.dropPlayerItemWithRandomChoice(new ItemStack(Items.milk_bucket, 1, 0), false);

            }

 

            return true;

        }

        else

        {

            return super.interact(p_70085_1_);

        }

    }

 

I want my new bucket has the same function as minecraft bucket, but do not know how.

 

Please anyone who can help make the class ready, because I never had a lesson of java in life.

 

This is very important for my mod.

Translated by google translator.

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.