Jump to content

[Solved][1.7.10]Creating a Custom Enchantment Table


Elrol_Arrowsend

Recommended Posts

well, the way i learn how to code is by using minecraft code and changing it to see what i can do, and when i do, i learn what certain codes do and how to code, so this code is almost the same as the vanilla enchantment table.

 

Here is the Block

 

 

package com.elrol_arrowsend.beingsofpower.blocks;

 

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

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

import java.util.Random;

 

import com.elrol_arrowsend.beingsofpower.items.ModItems;

import com.elrol_arrowsend.beingsofpower.lib.ModInfo;

import com.elrol_arrowsend.beingsofpower.tileentity.TileEntityHellAltar;

 

import net.minecraft.block.BlockContainer;

import net.minecraft.block.material.Material;

import net.minecraft.client.renderer.texture.IIconRegister;

import net.minecraft.command.ICommandSender;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.effect.EntityLightningBolt;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Blocks;

import net.minecraft.item.ItemStack;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.nbt.NBTTagList;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.tileentity.TileEntityEnchantmentTable;

import net.minecraft.util.ChunkCoordinates;

import net.minecraft.util.IChatComponent;

import net.minecraft.util.IIcon;

import net.minecraft.world.World;

 

public class TestET extends BlockContainer

{

    @SideOnly(Side.CLIENT)

    private IIcon field_149950_a;

    @SideOnly(Side.CLIENT)

    private IIcon field_149949_b;

    public NBTTagList enchants;

 

    protected TestET(String unlocalName)

    {

        super(Material.rock);

        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);

        this.setLightOpacity(0);

        this.setCreativeTab(CreativeTabs.tabDecorations);

        this.setBlockName(unlocalName);

        this.setBlockTextureName(ModInfo.Id + ":" + unlocalName);

        GameRegistry.registerBlock(this, unlocalName);

    }

 

    /**

    * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)

    */

    public boolean renderAsNormalBlock()

    {

        return false;

    }

 

   

    /**

    * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two

    * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.

    */

    public boolean isOpaqueCube()

    {

        return false;

    }

 

    /**

    * Gets the block's texture. Args: side, meta

    */

    @SideOnly(Side.CLIENT)

    public IIcon getIcon(int p_149691_1_, int p_149691_2_)

    {

        return p_149691_1_ == 0 ? this.field_149949_b : (p_149691_1_ == 1 ? this.field_149950_a : this.blockIcon);

    }

 

    /**

    * Returns a new instance of a block's tile entity class. Called on placing the block.

    */

    public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_)

    {

        return new TileEntityHellAltar();

    }

 

    /**

    * 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(world.canBlockSeeTheSky(x, y, z)){

    if(player.getCurrentEquippedItem() !=null && player.getCurrentEquippedItem().getItem() == ModItems.inertHellSword){

    player.setCurrentItemOrArmor(0, new ItemStack(ModItems.awakendHellSword, 1));

   

    for(int i = 0; i < 10; i++){

    world.spawnEntityInWorld(new EntityLightningBolt(world, x, y, z));

    }

   

    return true;

}else{

return true;

}

    }else{

   

    return true;

    }

    }

 

    /**

    * Called when the block is placed in the world.

    */

    public void onBlockPlacedBy(World p_149689_1_, int p_149689_2_, int p_149689_3_, int p_149689_4_, EntityLivingBase p_149689_5_, ItemStack p_149689_6_)

    {

        super.onBlockPlacedBy(p_149689_1_, p_149689_2_, p_149689_3_, p_149689_4_, p_149689_5_, p_149689_6_);

 

        if (p_149689_6_.hasDisplayName())

        {

            ((TileEntityHellAltar)p_149689_1_.getTileEntity(p_149689_2_, p_149689_3_, p_149689_4_)).func_145920_a(p_149689_6_.getDisplayName());

        }

    }

 

    @SideOnly(Side.CLIENT)

    public void registerBlockIcons(IIconRegister p_149651_1_)

    {

        this.blockIcon = p_149651_1_.registerIcon(this.getTextureName() + "_" + "side");

        this.field_149950_a = p_149651_1_.registerIcon(this.getTextureName() + "_" + "top");

        this.field_149949_b = p_149651_1_.registerIcon(this.getTextureName() + "_" + "bottom");

    }

 

 

}

 

 

 

and the TileEntity:

 

 

package com.elrol_arrowsend.beingsofpower.tileentity;

 

import java.util.Random;

 

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.tileentity.TileEntity;

 

public class TileEntityHellAltar extends TileEntity

{

    public int field_145926_a;

    public float field_145933_i;

    public float field_145931_j;

    public float field_145932_k;

    public float field_145929_l;

    public float field_145930_m;

    public float field_145927_n;

    public float field_145928_o;

    public float field_145925_p;

    public float field_145924_q;

    private static Random field_145923_r = new Random();

    private String field_145922_s;

    //private static final String __OBFID = "CL_00000354";

 

    public void writeToNBT(NBTTagCompound p_145841_1_)

    {

        super.writeToNBT(p_145841_1_);

 

        if (this.func_145921_b())

        {

            p_145841_1_.setString("CustomName", this.field_145922_s);

        }

    }

 

    public void readFromNBT(NBTTagCompound p_145839_1_)

    {

        super.readFromNBT(p_145839_1_);

 

        if (p_145839_1_.hasKey("CustomName", 8))

        {

            this.field_145922_s = p_145839_1_.getString("CustomName");

        }

    }

 

    public void updateEntity()

    {

        super.updateEntity();

        this.field_145927_n = this.field_145930_m;

        this.field_145925_p = this.field_145928_o;

        EntityPlayer entityplayer = this.worldObj.getClosestPlayer((double)((float)this.xCoord + 0.5F), (double)((float)this.yCoord + 0.5F), (double)((float)this.zCoord + 0.5F), 3.0D);

 

        if (entityplayer != null)

        {

            double d0 = entityplayer.posX - (double)((float)this.xCoord + 0.5F);

            double d1 = entityplayer.posZ - (double)((float)this.zCoord + 0.5F);

            this.field_145924_q = (float)Math.atan2(d1, d0);

            this.field_145930_m += 0.1F;

 

            if (this.field_145930_m < 0.5F || field_145923_r.nextInt(40) == 0)

            {

                float f1 = this.field_145932_k;

 

                do

                {

                    this.field_145932_k += (float)(field_145923_r.nextInt(4) - field_145923_r.nextInt(4));

                }

                while (f1 == this.field_145932_k);

            }

        }

        else

        {

            this.field_145924_q += 0.02F;

            this.field_145930_m -= 0.1F;

        }

 

        while (this.field_145928_o >= (float)Math.PI)

        {

            this.field_145928_o -= ((float)Math.PI * 2F);

        }

 

        while (this.field_145928_o < -(float)Math.PI)

        {

            this.field_145928_o += ((float)Math.PI * 2F);

        }

 

        while (this.field_145924_q >= (float)Math.PI)

        {

            this.field_145924_q -= ((float)Math.PI * 2F);

        }

 

        while (this.field_145924_q < -(float)Math.PI)

        {

            this.field_145924_q += ((float)Math.PI * 2F);

        }

 

        float f2;

 

        for (f2 = this.field_145924_q - this.field_145928_o; f2 >= (float)Math.PI; f2 -= ((float)Math.PI * 2F))

        {

            ;

        }

 

        while (f2 < -(float)Math.PI)

        {

            f2 += ((float)Math.PI * 2F);

        }

 

        this.field_145928_o += f2 * 0.4F;

 

        if (this.field_145930_m < 0.0F)

        {

            this.field_145930_m = 0.0F;

        }

 

        if (this.field_145930_m > 1.0F)

        {

            this.field_145930_m = 1.0F;

        }

 

        ++this.field_145926_a;

        this.field_145931_j = this.field_145933_i;

        float f = (this.field_145932_k - this.field_145933_i) * 0.4F;

        float f3 = 0.2F;

 

        if (f < -f3)

        {

            f = -f3;

        }

 

        if (f > f3)

        {

            f = f3;

        }

 

        this.field_145929_l += (f - this.field_145929_l) * 0.9F;

        this.field_145933_i += this.field_145929_l;

    }

 

    public String func_145919_a()

    {

        return this.func_145921_b() ? this.field_145922_s : "container.enchant";

    }

 

    public boolean func_145921_b()

    {

        return this.field_145922_s != null && this.field_145922_s.length() > 0;

    }

 

    public void func_145920_a(String p_145920_1_)

    {

        this.field_145922_s = p_145920_1_;

    }

}

 

 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • It all began with a chance encounter with a testimonial shared by Olivia, a fellow traveler on the winding road of cryptocurrency. Her words spoke of a miraculous recovery orchestrated by Wizard Web Recovery, a beacon of hope in the murky waters of online fraud. Intrigued by her story, I reached out to Wizard Web Recovery, hoping they could work their magic on my blocked crypto recovery. With bated breath, I shared my plight, providing evidence of my dilemma and praying for a solution. To my astonishment, a prompt response came, swift and reassuring. Wizard Web Recovery wasted no time in assessing my situation, guiding me through the process with patience and expertise. and then like a ray of sunshine breaking through the clouds, came the news I had longed for – a new private key had been generated, restoring my precious bitcoins. It was a moment of jubilation, a triumph over adversity that filled me with newfound hope. At that moment, I realized the true power of Wizard Web Recovery, not just as skilled technicians, but as guardians of trust in the digital realm. With their assistance, I reclaimed what was rightfully mine, turning despair into determination and paving the way for a brighter future. But their capabilities did not end there. Delving deeper into their expertise, I discovered that Wizard Web Recovery possessed a wealth of knowledge in reclaiming lost stolen cryptocurrency, and even exposing fraudulent investment schemes. So to all those who find themselves entangled in the web of online fraud, take heart. With the guidance of Wizard Web Recovery, there is a path to redemption.     Write Mail; ( Wizard webrecovery AT  vprogrammer. net ) 
    • It all began with a chance encounter with a testimonial shared by Olivia, a fellow traveler on the winding road of cryptocurrency. Her words spoke of a miraculous recovery orchestrated by Wizard Web Recovery, a beacon of hope in the murky waters of online fraud. Intrigued by her story, I reached out to Wizard Web Recovery, hoping they could work their magic on my blocked crypto recovery. With bated breath, I shared my plight, providing evidence of my dilemma and praying for a solution. To my astonishment, a prompt response came, swift and reassuring. Wizard Web Recovery wasted no time in assessing my situation, guiding me through the process with patience and expertise. and then like a ray of sunshine breaking through the clouds, came the news I had longed for – a new private key had been generated, restoring my precious bitcoins. It was a moment of jubilation, a triumph over adversity that filled me with newfound hope. At that moment, I realized the true power of Wizard Web Recovery, not just as skilled technicians, but as guardians of trust in the digital realm. With their assistance, I reclaimed what was rightfully mine, turning despair into determination and paving the way for a brighter future. But their capabilities did not end there. Delving deeper into their expertise, I discovered that Wizard Web Recovery possessed a wealth of knowledge in reclaiming lost stolen cryptocurrency, and even exposing fraudulent investment schemes. So to all those who find themselves entangled in the web of online fraud, take heart. With the guidance of Wizard Web Recovery, there is a path to redemption.    
    • How can I add drops when killing an entity? Now there are no drops. How can I add an @override to change the attack speed to 1.6 and show "when in main hand...attack damage,...attack speed"? also, how can I make the item enchantable? 
    • Ok. Thanks. by the way, will this crash in any circumstances? public boolean onLeftClickEntity(ItemStack stack, Player player, Entity entity) { if (entity instanceof LivingEntity){ LivingEntity victim = (LivingEntity) entity; if(!victim.isDeadOrDying() && victim.getHealth()>0){ victim.setHealth(0); return true; } } return false; }  
    • You shouldn't be extracting the mod .jar, just place it in your mods folder.
  • Topics

×
×
  • Create New...

Important Information

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