Vydělávej až 160.000 Kč měsíčně! Akreditované rekvalifikační kurzy s garancí práce od 0 Kč. Více informací.
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.
Avatar
Dr.umělec
Člen
Avatar
Dr.umělec:5.8.2016 10:23

Ahoj,mám moba ,který dědí z tameable a má v AI(umělelé inteligenci) ,že má chodit za majitelem (followAIOwner) a že má stát na místě (AISit) jenže někde v mc je určeno,že když na toho moba kliknete pravym myšítkem ,tak tedy stojí na místě (sedí) a mě jde o to ,jak uměle vyvolám metodu ,aby si sednul ? :D
Skoušel jsem volat metodu setSitting (true) a bez uspěchu .
popřípadě dodám zdrojáky kdyby někdo chtěl.
Předem děkuji za rady :D

 
Odpovědět
5.8.2016 10:23
Avatar
Odpovídá na Dr.umělec
Luboš Běhounek Satik:5.8.2016 13:56

se koukni do obsluhy toho kliknutí pravým tlačítkem, co se tam děje :)

Nahoru Odpovědět
5.8.2016 13:56
https://www.facebook.com/peasantsandcastles/
Avatar
Maty Klug
Člen
Avatar
Maty Klug:5.8.2016 14:39

jde i na macu programovat mody pro mc s forge kdyby jo tak jak?

 
Nahoru Odpovědět
5.8.2016 14:39
Avatar
pocitac770
Tvůrce
Avatar
Odpovídá na Dr.umělec
pocitac770:5.8.2016 16:59

Trošku jsem hrabal v těch knihovnách Forge, zkus toto:

tvujObjektEntityTameable.getAISit().startExecuting();
//tohle tam píšu jenom kvůli jistotě, aby to AI fungovalo správně
tvujObjektEntityTameable.getAISit().setSitting(true);

A při zrušení sezení

tvujObjektEntityTameable.getAISit().resetTask();
tvujObjektEntityTameable.getAISit().setSitting(false);

Maty Klug, pročby ne? Zkus se normálně podívat na toto: http://www.itnetwork.cz/…raft-modding s tím, že při instalacích nástrojů zvolíš varianty pro Mac

Editováno 5.8.2016 17:00
 
Nahoru Odpovědět
5.8.2016 16:59
Avatar
Dr.umělec
Člen
Avatar
Odpovídá na pocitac770
Dr.umělec:6.8.2016 10:26

ok,skusím :)

 
Nahoru Odpovědět
6.8.2016 10:26
Avatar
Dr.umělec
Člen
Avatar
Odpovídá na pocitac770
Dr.umělec:7.8.2016 9:52

Ahoj,nwm bud jsem asi blbej já a nebo eclipse,protože mi tu tvojí syntaxi nechce uznat :(

 
Nahoru Odpovědět
7.8.2016 9:52
Avatar
pocitac770
Tvůrce
Avatar
Odpovídá na Dr.umělec
pocitac770:9.8.2016 0:00

Jakou máš verzi Forge? (jde z toho i vyčíst verzi MC, ale jsem línej, tak mi prosím řekni i tu :D). Je možné, že používáme každej jinou knihovnu...

 
Nahoru Odpovědět
9.8.2016 0:00
Avatar
pocitac770
Tvůrce
Avatar
pocitac770:9.8.2016 0:04

Případně se podívej, jestli u metod, kde ti to nebere, ti našeptávač neradí metody typu func18392(), to by jsi pak musel dohledat konkrétní metodu podle návratového typu (např. getAISit() logicky vrací AISit).

Editováno 9.8.2016 0:05
 
Nahoru Odpovědět
9.8.2016 0:04
Avatar
Dr.umělec
Člen
Avatar
Odpovídá na pocitac770
Dr.umělec:10.8.2016 10:15

Mám tu nejnovější pro 1.7.10 :)

 
Nahoru Odpovědět
10.8.2016 10:15
Avatar
pocitac770
Tvůrce
Avatar
Odpovídá na Dr.umělec
pocitac770:10.8.2016 15:58

Mohl sis to urychlit, kdyby ses podíval sám, každopádně by mělo jít o metodu func_70907_r()

 
Nahoru Odpovědět
10.8.2016 15:58
Avatar
Dr.umělec
Člen
Avatar
Odpovídá na pocitac770
Dr.umělec:10.8.2016 17:20

jj,toto metodu jsem taky našel :) jsem koukal ,že to volá samo i startExecutin­g().Ještě něco skusím a pak napíšu.

 
Nahoru Odpovědět
10.8.2016 17:20
Avatar
Dr.umělec
Člen
Avatar
Odpovídá na pocitac770
Dr.umělec:11.8.2016 18:01

Ahoj,promin ,že tě takto obtěžuju,ale když vytvořim konstruktor třídy toho moba v jiné třídě ,tak se mi to Tameable červeně podtrhne ,a když klidnu na tu žárovičku ,tak mi to nabízí at udělám nějaky objekt třídy tameable v třídě toho moba

 
Nahoru Odpovědět
11.8.2016 18:01
Avatar
pocitac770
Tvůrce
Avatar
Odpovídá na Dr.umělec
pocitac770:11.8.2016 20:37

Vytvořil sis vlastní třídu vlastního moba, která z třídy EntityTameable dědí?

 
Nahoru Odpovědět
11.8.2016 20:37
Avatar
Dr.umělec
Člen
Avatar
 
Nahoru Odpovědět
11.8.2016 21:48
Avatar
pocitac770
Tvůrce
Avatar
Odpovídá na Dr.umělec
pocitac770:11.8.2016 22:15

Vyscreenuj to, co ti to píše (v té žárovičce), aby byl zároveň vidět tvůj kus kódu + sem pošli zdroják tý třídy moba

 
Nahoru Odpovědět
11.8.2016 22:15
Avatar
Dr.umělec
Člen
Avatar
Odpovídá na pocitac770
Dr.umělec:11.8.2016 23:14

Ok,ráno to tady máš ☺

 
Nahoru Odpovědět
11.8.2016 23:14
Avatar
Dr.umělec
Člen
Avatar
Odpovídá na Dr.umělec
Dr.umělec:12.8.2016 11:19
package net.uq.mod.entity;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockColored;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIFollowOwner;
import net.minecraft.entity.ai.EntityAILeapAtTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMate;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.monster.EntityGhast;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.passive.EntityHorse;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.passive.EntityWolf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.pathfinding.PathEntity;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.uq.mod.Uq;

public class Entity_Werca extends EntityTameable
{
        private float field_70926_e;
    private float field_70924_f;
    /** true is the wolf is wet else false */
    private  boolean isShaking;
    private boolean field_70928_h;
    /** This time increases while wolf is shaking and emitting water particles. */
    private float timeWolfIsShaking;
    private float prevTimeWolfIsShaking;
    private static final String __OBFID = "CL_00001654";
    //vajicko
    public int timeUntilNextEgg;
        private boolean field_152118_bv;
        public Object EntityTameable;


    public Entity_Werca(World p_i1696_1_)
    {
        super(p_i1696_1_);
        this.setSize(0.6F, 1.8F);
        this.timeUntilNextEgg = this.rand.nextInt(12000) + 12000;
        this.tasks.addTask(1, new EntityAISwimming(this));
        this.tasks.addTask(2, this.aiSit);
        this.tasks.addTask(3, new EntityAILeapAtTarget(this, 0.4F));
        this.tasks.addTask(4, new EntityAIAttackOnCollide(this, 1.0D, true));
        this.tasks.addTask(5, new EntityAIFollowOwner(this, 1.0D, 10.0F, 2.0F));
        this.tasks.addTask(6, new EntityAIMate(this, 1.0D));
        this.tasks.addTask(7, new EntityAIWander(this, 1.0D));
        this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
        this.tasks.addTask(9, new EntityAILookIdle(this));
        this.setTamed(false);


        }



        protected void applyEntityAttributes()
    {
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.30000001192092896D);

        if (this.isTamed())
        {
            this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D);
        }
        else
        {
            this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(8.0D);
        }
    }


    public boolean isAIEnabled()
    {
        return true ;
        }

    /**
     * Sets the active target the Task system uses for tracking
     */
    public void setAttackTarget(EntityLivingBase p_70624_1_)
    {
        super.setAttackTarget(p_70624_1_);

        if (p_70624_1_ == null)
        {
            this.setAngry(false);
        }
        else if (!this.isTamed())
        {
            this.setAngry(true);
        }
    }

    /**
     * main AI tick function, replaces updateEntityActionState
     */
    protected void updateAITick()
    {
        this.dataWatcher.updateObject(18, Float.valueOf(this.getHealth()));
    }

    protected void entityInit()
    {
        super.entityInit();
        this.dataWatcher.addObject(18, new Float(this.getHealth()));
        this.dataWatcher.addObject(19, new Byte((byte)0));
        this.dataWatcher.addObject(20, new Byte((byte)BlockColored.func_150032_b(1)));
    }

    protected void func_145780_a(int p_145780_1_, int p_145780_2_, int p_145780_3_, Block p_145780_4_)
    {
        this.playSound("mob.wolf.step", 0.15F, 1.0F);
    }

    /**
     * (abstract) Protected helper method to write subclass entity data to NBT.
     */
    public void writeEntityToNBT(NBTTagCompound p_70014_1_)
    {
        super.writeEntityToNBT(p_70014_1_);
        p_70014_1_.setBoolean("Angry", this.isAngry());

    }

    /**
     * (abstract) Protected helper method to read subclass entity data from NBT.
     */
    public void readEntityFromNBT(NBTTagCompound p_70037_1_)
    {
        super.readEntityFromNBT(p_70037_1_);
        this.setAngry(p_70037_1_.getBoolean("Angry"));


    }

    /**
     * Returns the sound this mob makes while it's alive.
     */
    protected String getLivingSound()
    {
        return this.isAngry() ? "mob.wolf.growl" : (this.rand.nextInt(3) == 0 ? (this.isTamed() && this.dataWatcher.getWatchableObjectFloat(18) < 10.0F ? "mob.wolf.whine" : "mob.wolf.panting") : "mob.wolf.bark");
    }

    /**
     * Returns the sound this mob makes when it is hurt.
     */
    protected String getHurtSound()
    {
        return "mob.wolf.hurt";
    }

    /**
     * Returns the sound this mob makes on death.
     */
    protected String getDeathSound()
    {
        return "mob.wolf.death";
    }

    /**
     * Returns the volume for the sounds this mob makes.
     */
    protected float getSoundVolume()
    {
        return 0.4F;
    }

    protected Item getDropItem()
    {
        return Item.getItemById(-1);
    }

    /**
     * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
     * use this to react to sunlight and start to burn.
     */
    public void onLivingUpdate()
    {
        //prdeni
        super.onLivingUpdate();
        if (!this.worldObj.isRemote && !this.isChild() && !this.func_152116_bZ() && --this.timeUntilNextEgg <= 0)
        {
            this.playSound("mob.chicken.plop", 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
            this.dropItem(Uq.itemBobek, 1);
            this.timeUntilNextEgg = this.rand.nextInt(12000) + 12000;
        }

        if (!this.worldObj.isRemote && this.isShaking && !this.field_70928_h && !this.hasPath() && this.onGround)
        {
            this.field_70928_h = true;
            this.timeWolfIsShaking = 0.0F;
            this.prevTimeWolfIsShaking = 0.0F;
            this.worldObj.setEntityState(this, (byte)8);
        }
    }
    public boolean func_152116_bZ()
    {
        return this.field_152118_bv;
    }

    /**
     * Called to update the entity's position/logic.
     */
    public void onUpdate()
    {
        super.onUpdate();
        this.field_70924_f = this.field_70926_e;

        if (this.func_70922_bv())
        {
            this.field_70926_e += (1.0F - this.field_70926_e) * 0.4F;
        }
        else
        {
            this.field_70926_e += (0.0F - this.field_70926_e) * 0.4F;
        }

        if (this.func_70922_bv())
        {
            this.numTicksToChaseTarget = 10;
        }

        if (this.isWet())
        {
            this.isShaking = true;
            this.field_70928_h = false;
            this.timeWolfIsShaking = 0.0F;
            this.prevTimeWolfIsShaking = 0.0F;
        }
        else if ((this.isShaking || this.field_70928_h) && this.field_70928_h)
        {
            if (this.timeWolfIsShaking == 0.0F)
            {
                this.playSound("mob.wolf.shake", this.getSoundVolume(), (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
            }

            this.prevTimeWolfIsShaking = this.timeWolfIsShaking;
            this.timeWolfIsShaking += 0.05F;

            if (this.prevTimeWolfIsShaking >= 2.0F)
            {
                this.isShaking = false;
                this.field_70928_h = false;
                this.prevTimeWolfIsShaking = 0.0F;
                this.timeWolfIsShaking = 0.0F;
            }

            if (this.timeWolfIsShaking > 0.4F)
            {
                float f = (float)this.boundingBox.minY;
                int i = (int)(MathHelper.sin((this.timeWolfIsShaking - 0.4F) * (float)Math.PI) * 7.0F);

                for (int j = 0; j < i; ++j)
                {
                    float f1 = (this.rand.nextFloat() * 2.0F - 1.0F) * this.width * 0.5F;
                    float f2 = (this.rand.nextFloat() * 2.0F - 1.0F) * this.width * 0.5F;
                    this.worldObj.spawnParticle("splash", this.posX + (double)f1, (double)(f + 0.8F), this.posZ + (double)f2, this.motionX, this.motionY, this.motionZ);
                }
            }
        }
    }

    @SideOnly(Side.CLIENT)
    public boolean getWolfShaking()
    {
        return this.isShaking;
    }

    /**
     * Used when calculating the amount of shading to apply while the wolf is shaking.
     */
    @SideOnly(Side.CLIENT)
    public float getShadingWhileShaking(float p_70915_1_)
    {
        return 0.75F + (this.prevTimeWolfIsShaking + (this.timeWolfIsShaking - this.prevTimeWolfIsShaking) * p_70915_1_) / 2.0F * 0.25F;
    }

    @SideOnly(Side.CLIENT)
    public float getShakeAngle(float p_70923_1_, float p_70923_2_)
    {
        float f2 = (this.prevTimeWolfIsShaking + (this.timeWolfIsShaking - this.prevTimeWolfIsShaking) * p_70923_1_ + p_70923_2_) / 1.8F;

        if (f2 < 0.0F)
        {
            f2 = 0.0F;
        }
        else if (f2 > 1.0F)
        {
            f2 = 1.0F;
        }

        return MathHelper.sin(f2 * (float)Math.PI) * MathHelper.sin(f2 * (float)Math.PI * 11.0F) * 0.15F * (float)Math.PI;
    }

    public float getEyeHeight()
    {
        return this.height * 0.8F;
    }

    @SideOnly(Side.CLIENT)
    public float getInterestedAngle(float p_70917_1_)
    {
        return (this.field_70924_f + (this.field_70926_e - this.field_70924_f) * p_70917_1_) * 0.15F * (float)Math.PI;
    }

    /**
     * The speed it takes to move the entityliving's rotationPitch through the faceEntity method. This is only currently
     * use in wolves.
     */
    public int getVerticalFaceSpeed()
    {
        return this.isSitting() ? 20 : super.getVerticalFaceSpeed();
    }

    /**
     * Called when the entity is attacked.
     */
    public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_)
    {
        if (this.isEntityInvulnerable())
        {
            return false;
        }
        else
        {
            Entity entity = p_70097_1_.getEntity();
            this.aiSit.setSitting(false);

            if (entity != null && !(entity instanceof EntityPlayer) && !(entity instanceof EntityArrow))
            {
                p_70097_2_ = (p_70097_2_ + 1.0F) / 2.0F;
            }

            return super.attackEntityFrom(p_70097_1_, p_70097_2_);
        }
    }

    public boolean attackEntityAsMob(Entity p_70652_1_)
    {
        int i = this.isTamed() ? 4 : 2;
        return p_70652_1_.attackEntityFrom(DamageSource.causeMobDamage(this), (float)i);
    }

    public void setTamed(boolean p_70903_1_)
    {
        super.setTamed(p_70903_1_);

        if (p_70903_1_)
        {
            this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D);
        }
        else
        {
            this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(8.0D);
        }
    }

    /**
     * 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 (this.isTamed())
        {
            if (itemstack != null)
            {
                if (itemstack.getItem() instanceof ItemFood)
                {
                    ItemFood itemfood = (ItemFood)itemstack.getItem();

                    if (itemfood.isWolfsFavoriteMeat() && this.dataWatcher.getWatchableObjectFloat(18) < 20.0F)
                    {
                        if (!p_70085_1_.capabilities.isCreativeMode)
                        {
                            --itemstack.stackSize;
                        }

                        this.heal((float)itemfood.func_150905_g(itemstack));

                        if (itemstack.stackSize <= 0)
                        {
                            p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, (ItemStack)null);
                        }

                        return true;
                    }
                }
                else if (itemstack.getItem() == Items.dye)
                {
                    int i = BlockColored.func_150032_b(itemstack.getItemDamage());


                        if (!p_70085_1_.capabilities.isCreativeMode && --itemstack.stackSize <= 0)
                        {
                            p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, (ItemStack)null);
                        }

                        return true;
                    }
                }
            }

            if (this.func_152114_e(p_70085_1_) && !this.worldObj.isRemote && !this.isBreedingItem(itemstack))
            {
                this.aiSit.setSitting(!this.isSitting());
                this.isJumping = false;
                this.setPathToEntity((PathEntity)null);
                this.setTarget((Entity)null);
                this.setAttackTarget((EntityLivingBase)null);
            }

        else if (itemstack != null && itemstack.getItem() == Items.nether_star && !this.isAngry())
        {
            if (!p_70085_1_.capabilities.isCreativeMode)
            {
                --itemstack.stackSize;
            }

            if (itemstack.stackSize <= 0)
            {
                p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, (ItemStack)null);
            }

            if (!this.worldObj.isRemote)
            {
                if (this.rand.nextInt(3) == 0)
                {
                    this.setTamed(true);
                    this.setPathToEntity((PathEntity)null);
                    this.setAttackTarget((EntityLivingBase)null);
                    this.aiSit.setSitting(true);
                    this.setHealth(20.0F);
                    this.func_152115_b(p_70085_1_.getUniqueID().toString());
                    this.playTameEffect(true);
                    this.worldObj.setEntityState(this, (byte)7);
                }
                else
                {
                    this.playTameEffect(false);
                    this.worldObj.setEntityState(this, (byte)6);
                }
            }

            return true;
        }

        return super.interact(p_70085_1_);
    }

    @SideOnly(Side.CLIENT)
    public void handleHealthUpdate(byte p_70103_1_)
    {
        if (p_70103_1_ == 8)
        {
            this.field_70928_h = true;
            this.timeWolfIsShaking = 0.0F;
            this.prevTimeWolfIsShaking = 0.0F;
        }
        else
        {
            super.handleHealthUpdate(p_70103_1_);
        }
    }

    @SideOnly(Side.CLIENT)
    public float getTailRotation()
    {
        return this.isAngry() ? 1.5393804F : (this.isTamed() ? (0.55F - (20.0F - this.dataWatcher.getWatchableObjectFloat(18)) * 0.02F) * (float)Math.PI : ((float)Math.PI / 5F));
    }

    /**
     * Checks if the parameter is an item which this animal can be fed to breed it (wheat, carrots or seeds depending on
     * the animal type)
     */
    public boolean isBreedingItem(ItemStack p_70877_1_)
    {
        return p_70877_1_ == null ? false : (!(p_70877_1_.getItem() instanceof ItemFood) ? false : ((ItemFood)p_70877_1_.getItem()).isWolfsFavoriteMeat());
    }

    /**
     * Will return how many at most can spawn in a chunk at once.
     */
    public int getMaxSpawnedInChunk()
    {
        return 0;
    }

    /**
     * Determines whether this wolf is angry or not.
     */
    public boolean isAngry()
    {
        return (this.dataWatcher.getWatchableObjectByte(16) & 2) != 0;
    }

    /**
     * Sets whether this wolf is angry or not.
     */
    public void setAngry(boolean p_70916_1_)
    {
        byte b0 = this.dataWatcher.getWatchableObjectByte(16);

        if (p_70916_1_)
        {
            this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 | 2)));
        }
        else
        {
            this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 & -3)));
        }
    }

    public EntityWolf createChild(EntityAgeable p_90011_1_)
    {
        EntityWolf entitywolf = new EntityWolf(this.worldObj);
        String s = this.func_152113_b();

        if (s != null && s.trim().length() > 0)
        {
            entitywolf.func_152115_b(s);
            entitywolf.setTamed(true);
        }

        return entitywolf;
    }

    public void func_70918_i(boolean p_70918_1_)
    {
        if (p_70918_1_)
        {
            this.dataWatcher.updateObject(19, Byte.valueOf((byte)1));
        }
        else
        {
            this.dataWatcher.updateObject(19, Byte.valueOf((byte)0));
        }
    }

    /**
     * Returns true if the mob is currently able to mate with the specified mob.
     */
    public boolean canMateWith(EntityAnimal p_70878_1_)
    {
        if (p_70878_1_ == this)
        {
            return false;
        }
        else if (!this.isTamed())
        {
            return false;
        }
        else if (!(p_70878_1_ instanceof EntityWolf))
        {
            return false;
        }
        else
        {
            EntityWolf entitywolf = (EntityWolf)p_70878_1_;
            return !entitywolf.isTamed() ? false : (entitywolf.isSitting() ? false : this.isInLove() && entitywolf.isInLove());
        }
    }

    public boolean func_70922_bv()
    {
        return this.dataWatcher.getWatchableObjectByte(19) == 1;
    }

    /**
     * Determines if an entity can be despawned, used on idle far away entities
     */
    protected boolean canDespawn()
    {
        return !this.isTamed() && this.ticksExisted > 2400;
    }

    public boolean func_142018_a(EntityLivingBase p_142018_1_, EntityLivingBase p_142018_2_)
    {
        if (!(p_142018_1_ instanceof EntityCreeper) && !(p_142018_1_ instanceof EntityGhast))
        {
            if (p_142018_1_ instanceof EntityWolf)
            {
                EntityWolf entitywolf = (EntityWolf)p_142018_1_;

                if (entitywolf.isTamed() && entitywolf.getOwner() == p_142018_2_)
                {
                    return false;
                }
            }

            return p_142018_1_ instanceof EntityPlayer && p_142018_2_ instanceof EntityPlayer && !((EntityPlayer)p_142018_2_).canAttackPlayer((EntityPlayer)p_142018_1_) ? false : !(p_142018_1_ instanceof EntityHorse) || !((EntityHorse)p_142018_1_).isTame();
        }
        else
        {
            return false;
        }
    }



        }
 
Nahoru Odpovědět
12.8.2016 11:19
Avatar
pocitac770
Tvůrce
Avatar
Odpovídá na Dr.umělec
pocitac770:12.8.2016 13:22

Jo, teď to chápu "Add cast to method reciever"..
method reciever, tím je myšleno to .func_70907_r()­.setSitting(tru­e), normálně je ta metoda na objektu typu EntityTameable, ale překladač dostal typ Object, tak chce mít jistotu, že ten objekt je opravdu EntityTameable, protože to byl původně tento objekt, ale máš uloženého pouze jeho předka, tak ho můžeš "odmaskovat" (navenek to je Object, ale vnitřně se to chová jako EntityTameable). Toto odmaskování se dělá přes tzn. "cast" (nevím, jak to přeložit do čestiny), který vypadá takto:

(TridaA)instanceTridyB

kde A dědí z B. Pokud chceš využít metodu třídy A, tak ji musíš opět "obalit" závorkami

((TridaA)instanceTridyB).nejakaMetodaTridyA()

A pokud tu instanci nezískáváš přímo, tak jsou víceméně taktéž povinné, aby se vědělo, na které části toho statementu chceš cast provést (již tvůj konkrétní příklad)

((EntityTameable)werca.EntityTameable).func_70907_r().setSitting(true);

Zároveň tě chci upozornit na to, že toto:

public Object EntityTameable;

je jako artibut absolutní hloupost, když použiješ jako datový typ základní Object, protože nemůžeš dosledovat, co tam bude uloženo, protože tam chceš mít EntityTameable, tak bys ho měl mít taktéž nadefinovaný jako datový typ. (Což by řešilo náš problém s castem, ale...) Navíc, pokud jde o toto vnější volání, tak nemusíš mít přímo onen typ, stačí pouze třída, co z něj dědí, protože získává všechny původní metody (je divné získávat přes atribut instance instanci samotnou, jenom v jiné podobě). Jak se na to koukám, vypadá to, že "programuješ" bez větších znalostí OOP podle rádoby tutoriálů z internetu, ano, jsou dobré, ale pouze ve chvíli, když chápeš, co se tam píše, a jak to funguje, protože bez toho skončíš na výsledcích tutoriálu a nebudeš umět udělat něco kreativního. Pokud jsi zatím neudělal, tak si nejprve přečti zdejší tutoriály o OOP, dozvíš se tam toho hodně a alespoň nebudeš tápat při programování.

Editováno 12.8.2016 13:24
 
Nahoru Odpovědět
12.8.2016 13:22
Avatar
Dr.umělec
Člen
Avatar
Odpovídá na pocitac770
Dr.umělec:12.8.2016 14:07

Děkuji mockrát za vysvětlení toho cast :) kdybys chtěl tak ti za odměnu dám nějaký random key na steam . Ale ted to hází error v konzoli a když ho rozkliknu ,tak to poukazuje na ten tvůj příklad :( Ano OOP trochu znám ,ale né moc.

 
Nahoru Odpovědět
12.8.2016 14:07
Avatar
Atrament
Tvůrce
Avatar
Odpovídá na pocitac770
Atrament:12.8.2016 16:05

Casting se obvykle překládá jako přetypování.

 
Nahoru Odpovědět
12.8.2016 16:05
Avatar
pocitac770
Tvůrce
Avatar
Odpovídá na Dr.umělec
pocitac770:12.8.2016 17:45

Víš co? Už se to tu moc rozrůstá, soukromka...
Atrament, díky, jednoduché, ale zrovna to mě nenapadlo :D

Akceptované řešení
+20 Zkušeností
+2,50 Kč
Řešení problému
 
Nahoru Odpovědět
12.8.2016 17:45
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 21 zpráv z 21.