Jump to content

[1.7.10] Another FishingRod and FishingHook question, but I guess a simple one.


Recommended Posts

Posted

Hi guys,

 

I have created my own fishing rod and fish hook classes, that are in fact dumb copy of the vanilla classes. I do not want to extend from the vanilla classes for many reasons which I will not bother you with.

 

 

Here it is:

 

ItemReinforcedFishingRod, which is a copy of ItemFishingRod (vanilla)

 

 

package fantastic.items;

 

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

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import fantastic.FantasticIds;

import fantastic.FantasticInfo;

import fantastic.Names;

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityList;

import fantastic.entities.EntityReinforcedFishingHook;

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

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.Entity;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.projectile.EntityFishHook;

import net.minecraft.item.Item;

import net.minecraft.item.ItemFishingRod;

import net.minecraft.item.ItemStack;

import net.minecraft.util.IIcon;

import net.minecraft.world.World;

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

 

public class ItemReinforcedFishingRod extends Item

{

    @SideOnly(Side.CLIENT)

    private IIcon theIcon;

    private static final String __OBFID = "CL_00000034";

 

    public ItemReinforcedFishingRod()

    {

        super();

    this.setMaxDamage(64);

        this.setMaxStackSize(1);

        this.setCreativeTab(FantasticItems.tabFantastic);

    }

 

    /**

    * Returns True is the item is renderer in full 3D when hold.

    */

    @SideOnly(Side.CLIENT)

    public boolean isFull3D()

    {

        return true;

    }

 

    /**

    * Returns true if this item should be rotated by 180 degrees around the Y axis when being held in an entities

    * hands.

    */

    @SideOnly(Side.CLIENT)

    public boolean shouldRotateAroundWhenRendering()

    {

        return true;

    }

 

    /**

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

    */

    public ItemStack onItemRightClick(ItemStack anItemStack, World aWorld, EntityPlayer aPlayer)

    {

 

        //if (aPlayer.fishEntity != null)

        //{

        // int i = aPlayer.fishEntity.func_146034_e();

        // anItemStack.damageItem(i, aPlayer);

        // aPlayer.swingItem();

        //}

        //else

        //{

       

        if (!aWorld.isRemote)

        {

       

        if (EntityList.stringToClassMapping.containsKey(Names.ReinforcedFishingRod_UnlocalizedName))

        {

            EntityReinforcedFishingHook hook = new EntityReinforcedFishingHook(aWorld,aPlayer);

            aWorld.spawnEntityInWorld(hook);

        }

        else

        {

        System.out.println("Class not found.");

        }

       

       

        }

        aPlayer.swingItem();

        aWorld.playSoundAtEntity(aPlayer,"fantastic:throwLine",1.0F,1.0F);

        return anItemStack;

   

    }

   

   

 

    @SideOnly(Side.CLIENT)

    public void registerIcons(IIconRegister p_94581_1_)

    {

        this.itemIcon = p_94581_1_.registerIcon(FantasticInfo.ID.toLowerCase() + ":" + Names.ReinforcedFishingRod_UnlocalizedName+"_uncast");

        this.theIcon = p_94581_1_.registerIcon(FantasticInfo.ID.toLowerCase() + ":" + Names.ReinforcedFishingRod_UnlocalizedName+"_cast");

    }

 

    @SideOnly(Side.CLIENT)

    public IIcon func_94597_g()

    {

        return this.theIcon;

    }

 

    /**

    * Checks isDamagable and if it cannot be stacked

    */

    public boolean isItemTool(ItemStack p_77616_1_)

    {

        return super.isItemTool(p_77616_1_);

    }

 

    /**

    * Return the enchantability factor of the item, most of the time is based on material.

    */

    public int getItemEnchantability()

    {

        return 0;

    }

}

 

 

 

EntityReinforcedFishingHook, which is a copy of EntityFishHook (vanilla)

 

 

package fantastic.entities;

 

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

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import io.netty.buffer.ByteBuf;

 

import java.util.Arrays;

import java.util.List;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.enchantment.EnchantmentHelper;

import net.minecraft.entity.Entity;

import net.minecraft.entity.item.EntityItem;

import net.minecraft.entity.item.EntityXPOrb;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Blocks;

import net.minecraft.init.Items;

import net.minecraft.item.ItemFishFood;

import net.minecraft.item.ItemStack;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.stats.StatList;

import net.minecraft.util.AxisAlignedBB;

import net.minecraft.util.DamageSource;

import net.minecraft.util.MathHelper;

import net.minecraft.util.MovingObjectPosition;

import net.minecraft.util.Vec3;

import net.minecraft.util.WeightedRandom;

import net.minecraft.util.WeightedRandomFishable;

import net.minecraft.world.World;

import net.minecraft.world.WorldServer;

 

public class EntityReinforcedFishingHook extends Entity implements IEntityAdditionalSpawnData

{

    public static final List field_146039_d = Arrays.asList(new WeightedRandomFishable[] {(new WeightedRandomFishable(new ItemStack(Items.leather_boots), 10)).func_150709_a(0.9F), new WeightedRandomFishable(new ItemStack(Items.leather), 10), new WeightedRandomFishable(new ItemStack(Items.bone), 10), new WeightedRandomFishable(new ItemStack(Items.potionitem), 10), new WeightedRandomFishable(new ItemStack(Items.string), 5), (new WeightedRandomFishable(new ItemStack(Items.fishing_rod), 2)).func_150709_a(0.9F), new WeightedRandomFishable(new ItemStack(Items.bowl), 10), new WeightedRandomFishable(new ItemStack(Items.stick), 5), new WeightedRandomFishable(new ItemStack(Items.dye, 10, 0), 1), new WeightedRandomFishable(new ItemStack(Blocks.tripwire_hook), 10), new WeightedRandomFishable(new ItemStack(Items.rotten_flesh), 10)});

    public static final List field_146041_e = Arrays.asList(new WeightedRandomFishable[] {new WeightedRandomFishable(new ItemStack(Blocks.waterlily), 1), new WeightedRandomFishable(new ItemStack(Items.name_tag), 1), new WeightedRandomFishable(new ItemStack(Items.saddle), 1), (new WeightedRandomFishable(new ItemStack(Items.bow), 1)).func_150709_a(0.25F).func_150707_a(), (new WeightedRandomFishable(new ItemStack(Items.fishing_rod), 1)).func_150709_a(0.25F).func_150707_a(), (new WeightedRandomFishable(new ItemStack(Items.book), 1)).func_150707_a()});

    public static final List field_146036_f = Arrays.asList(new WeightedRandomFishable[] {new WeightedRandomFishable(new ItemStack(Items.fish, 1, ItemFishFood.FishType.COD.func_150976_a()), 60), new WeightedRandomFishable(new ItemStack(Items.fish, 1, ItemFishFood.FishType.SALMON.func_150976_a()), 25), new WeightedRandomFishable(new ItemStack(Items.fish, 1, ItemFishFood.FishType.CLOWNFISH.func_150976_a()), 2), new WeightedRandomFishable(new ItemStack(Items.fish, 1, ItemFishFood.FishType.PUFFERFISH.func_150976_a()), 13)});

    private int field_146037_g;

    private int field_146048_h;

    private int field_146050_i;

    private Block field_146046_j;

    private boolean field_146051_au;

    public int field_146044_a;

    public EntityPlayer field_146042_b;

    private int field_146049_av;

    private int field_146047_aw;

    private int field_146045_ax;

    private int field_146040_ay;

    private int field_146038_az;

    private float field_146054_aA;

    public Entity field_146043_c;

    private int field_146055_aB;

    private double field_146056_aC;

    private double field_146057_aD;

    private double field_146058_aE;

    private double field_146059_aF;

    private double field_146060_aG;

    @SideOnly(Side.CLIENT)

    private double field_146061_aH;

    @SideOnly(Side.CLIENT)

    private double field_146052_aI;

    @SideOnly(Side.CLIENT)

    private double field_146053_aJ;

    private static final String __OBFID = "CL_00001663";

 

    public EntityReinforcedFishingHook(World p_i1764_1_)

    {

        super(p_i1764_1_);

        this.field_146037_g = -1;

        this.field_146048_h = -1;

        this.field_146050_i = -1;

        this.setSize(0.25F, 0.25F);

        this.ignoreFrustumCheck = true;

    }

 

    @SideOnly(Side.CLIENT)

    public EntityReinforcedFishingHook(World p_i1765_1_, double p_i1765_2_, double p_i1765_4_, double p_i1765_6_, EntityPlayer p_i1765_8_)

    {

        this(p_i1765_1_);

        this.setPosition(p_i1765_2_, p_i1765_4_, p_i1765_6_);

        this.ignoreFrustumCheck = true;

        this.field_146042_b = p_i1765_8_;

        //p_i1765_8_.fishEntity = this;

    }

 

    public EntityReinforcedFishingHook(World p_i1766_1_, EntityPlayer p_i1766_2_)

    {

        super(p_i1766_1_);

        this.field_146037_g = -1;

        this.field_146048_h = -1;

        this.field_146050_i = -1;

        this.ignoreFrustumCheck = true;

        this.field_146042_b = p_i1766_2_;

        //this.field_146042_b.fishEntity = this;

        this.setSize(0.25F, 0.25F);

        this.setLocationAndAngles(p_i1766_2_.posX, p_i1766_2_.posY + 1.62D - (double)p_i1766_2_.yOffset, p_i1766_2_.posZ, p_i1766_2_.rotationYaw, p_i1766_2_.rotationPitch);

        this.posX -= (double)(MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * 0.16F);

        this.posY -= 0.10000000149011612D;

        this.posZ -= (double)(MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * 0.16F);

        this.setPosition(this.posX, this.posY, this.posZ);

        this.yOffset = 0.0F;

        float f = 0.4F;

        this.motionX = (double)(-MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI) * f);

        this.motionZ = (double)(MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI) * f);

        this.motionY = (double)(-MathHelper.sin(this.rotationPitch / 180.0F * (float)Math.PI) * f);

        this.func_146035_c(this.motionX, this.motionY, this.motionZ, 1.5F, 1.0F);

    }

 

    protected void entityInit() {}

 

    public void func_146035_c(double p_146035_1_, double p_146035_3_, double p_146035_5_, float p_146035_7_, float p_146035_8_)

    {

        float f2 = MathHelper.sqrt_double(p_146035_1_ * p_146035_1_ + p_146035_3_ * p_146035_3_ + p_146035_5_ * p_146035_5_);

        p_146035_1_ /= (double)f2;

        p_146035_3_ /= (double)f2;

        p_146035_5_ /= (double)f2;

        p_146035_1_ += this.rand.nextGaussian() * 0.007499999832361937D * (double)p_146035_8_;

        p_146035_3_ += this.rand.nextGaussian() * 0.007499999832361937D * (double)p_146035_8_;

        p_146035_5_ += this.rand.nextGaussian() * 0.007499999832361937D * (double)p_146035_8_;

        p_146035_1_ *= (double)p_146035_7_;

        p_146035_3_ *= (double)p_146035_7_;

        p_146035_5_ *= (double)p_146035_7_;

        this.motionX = p_146035_1_;

        this.motionY = p_146035_3_;

        this.motionZ = p_146035_5_;

        float f3 = MathHelper.sqrt_double(p_146035_1_ * p_146035_1_ + p_146035_5_ * p_146035_5_);

        this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(p_146035_1_, p_146035_5_) * 180.0D / Math.PI);

        this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(p_146035_3_, (double)f3) * 180.0D / Math.PI);

        this.field_146049_av = 0;

    }

 

    /**

    * Checks if the entity is in range to render by using the past in distance and comparing it to its average edge

    * length * 64 * renderDistanceWeight Args: distance

    */

    @SideOnly(Side.CLIENT)

    public boolean isInRangeToRenderDist(double p_70112_1_)

    {

        double d1 = this.boundingBox.getAverageEdgeLength() * 4.0D;

        d1 *= 64.0D;

        return p_70112_1_ < d1 * d1;

    }

 

    /**

    * Sets the position and rotation. Only difference from the other one is no bounding on the rotation. Args: posX,

    * posY, posZ, yaw, pitch

    */

    @SideOnly(Side.CLIENT)

    public void setPositionAndRotation2(double p_70056_1_, double p_70056_3_, double p_70056_5_, float p_70056_7_, float p_70056_8_, int p_70056_9_)

    {

        this.field_146056_aC = p_70056_1_;

        this.field_146057_aD = p_70056_3_;

        this.field_146058_aE = p_70056_5_;

        this.field_146059_aF = (double)p_70056_7_;

        this.field_146060_aG = (double)p_70056_8_;

        this.field_146055_aB = p_70056_9_;

        this.motionX = this.field_146061_aH;

        this.motionY = this.field_146052_aI;

        this.motionZ = this.field_146053_aJ;

    }

 

    /**

    * Sets the velocity to the args. Args: x, y, z

    */

    @SideOnly(Side.CLIENT)

    public void setVelocity(double p_70016_1_, double p_70016_3_, double p_70016_5_)

    {

        this.field_146061_aH = this.motionX = p_70016_1_;

        this.field_146052_aI = this.motionY = p_70016_3_;

        this.field_146053_aJ = this.motionZ = p_70016_5_;

    }

 

    /**

    * Called to update the entity's position/logic.

    */

    public void onUpdate()

    {

        super.onUpdate();

 

        if (this.field_146055_aB > 0)

        {

            double d7 = this.posX + (this.field_146056_aC - this.posX) / (double)this.field_146055_aB;

            double d8 = this.posY + (this.field_146057_aD - this.posY) / (double)this.field_146055_aB;

            double d9 = this.posZ + (this.field_146058_aE - this.posZ) / (double)this.field_146055_aB;

            double d1 = MathHelper.wrapAngleTo180_double(this.field_146059_aF - (double)this.rotationYaw);

            this.rotationYaw = (float)((double)this.rotationYaw + d1 / (double)this.field_146055_aB);

            this.rotationPitch = (float)((double)this.rotationPitch + (this.field_146060_aG - (double)this.rotationPitch) / (double)this.field_146055_aB);

            --this.field_146055_aB;

            this.setPosition(d7, d8, d9);

            this.setRotation(this.rotationYaw, this.rotationPitch);

        }

        else

        {

            if (!this.worldObj.isRemote)

            {

                ItemStack itemstack = this.field_146042_b.getCurrentEquippedItem();

 

                if (this.field_146042_b.isDead || !this.field_146042_b.isEntityAlive() || itemstack == null || itemstack.getItem() != Items.fishing_rod || this.getDistanceSqToEntity(this.field_146042_b) > 1024.0D)

                {

                    this.setDead();

                    this.field_146042_b.fishEntity = null;

                    return;

                }

 

                if (this.field_146043_c != null)

                {

                    if (!this.field_146043_c.isDead)

                    {

                        this.posX = this.field_146043_c.posX;

                        this.posY = this.field_146043_c.boundingBox.minY + (double)this.field_146043_c.height * 0.8D;

                        this.posZ = this.field_146043_c.posZ;

                        return;

                    }

 

                    this.field_146043_c = null;

                }

            }

 

            if (this.field_146044_a > 0)

            {

                --this.field_146044_a;

            }

 

            if (this.field_146051_au)

            {

                if (this.worldObj.getBlock(this.field_146037_g, this.field_146048_h, this.field_146050_i) == this.field_146046_j)

                {

                    ++this.field_146049_av;

 

                    if (this.field_146049_av == 1200)

                    {

                        this.setDead();

                    }

 

                    return;

                }

 

                this.field_146051_au = false;

                this.motionX *= (double)(this.rand.nextFloat() * 0.2F);

                this.motionY *= (double)(this.rand.nextFloat() * 0.2F);

                this.motionZ *= (double)(this.rand.nextFloat() * 0.2F);

                this.field_146049_av = 0;

                this.field_146047_aw = 0;

            }

            else

            {

                ++this.field_146047_aw;

            }

 

            Vec3 vec31 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);

            Vec3 vec3 = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);

            MovingObjectPosition movingobjectposition = this.worldObj.rayTraceBlocks(vec31, vec3);

            vec31 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);

            vec3 = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);

 

            if (movingobjectposition != null)

            {

                vec3 = Vec3.createVectorHelper(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);

            }

 

            Entity entity = null;

            List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D));

            double d0 = 0.0D;

            double d2;

 

            for (int i = 0; i < list.size(); ++i)

            {

                Entity entity1 = (Entity)list.get(i);

 

                if (entity1.canBeCollidedWith() && (entity1 != this.field_146042_b || this.field_146047_aw >= 5))

                {

                    float f = 0.3F;

                    AxisAlignedBB axisalignedbb = entity1.boundingBox.expand((double)f, (double)f, (double)f);

                    MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec31, vec3);

 

                    if (movingobjectposition1 != null)

                    {

                        d2 = vec31.distanceTo(movingobjectposition1.hitVec);

 

                        if (d2 < d0 || d0 == 0.0D)

                        {

                            entity = entity1;

                            d0 = d2;

                        }

                    }

                }

            }

 

            if (entity != null)

            {

                movingobjectposition = new MovingObjectPosition(entity);

            }

 

            if (movingobjectposition != null)

            {

                if (movingobjectposition.entityHit != null)

                {

                    if (movingobjectposition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.field_146042_b), 0.0F))

                    {

                        this.field_146043_c = movingobjectposition.entityHit;

                    }

                }

                else

                {

                    this.field_146051_au = true;

                }

            }

 

            if (!this.field_146051_au)

            {

                this.moveEntity(this.motionX, this.motionY, this.motionZ);

                float f5 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);

                this.rotationYaw = (float)(Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);

 

                for (this.rotationPitch = (float)(Math.atan2(this.motionY, (double)f5) * 180.0D / Math.PI); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)

                {

                    ;

                }

 

                while (this.rotationPitch - this.prevRotationPitch >= 180.0F)

                {

                    this.prevRotationPitch += 360.0F;

                }

 

                while (this.rotationYaw - this.prevRotationYaw < -180.0F)

                {

                    this.prevRotationYaw -= 360.0F;

                }

 

                while (this.rotationYaw - this.prevRotationYaw >= 180.0F)

                {

                    this.prevRotationYaw += 360.0F;

                }

 

                this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;

                this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;

                float f6 = 0.92F;

 

                if (this.onGround || this.isCollidedHorizontally)

                {

                    f6 = 0.5F;

                }

 

                byte b0 = 5;

                double d10 = 0.0D;

 

                for (int j = 0; j < b0; ++j)

                {

                    double d3 = this.boundingBox.minY + (this.boundingBox.maxY - this.boundingBox.minY) * (double)(j + 0) / (double)b0 - 0.125D + 0.125D;

                    double d4 = this.boundingBox.minY + (this.boundingBox.maxY - this.boundingBox.minY) * (double)(j + 1) / (double)b0 - 0.125D + 0.125D;

                    AxisAlignedBB axisalignedbb1 = AxisAlignedBB.getBoundingBox(this.boundingBox.minX, d3, this.boundingBox.minZ, this.boundingBox.maxX, d4, this.boundingBox.maxZ);

 

                    if (this.worldObj.isAABBInMaterial(axisalignedbb1, Material.water))

                    {

                        d10 += 1.0D / (double)b0;

                    }

                }

 

                if (!this.worldObj.isRemote && d10 > 0.0D)

                {

                    WorldServer worldserver = (WorldServer)this.worldObj;

                    int k = 1;

 

                    if (this.rand.nextFloat() < 0.25F && this.worldObj.canLightningStrikeAt(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY) + 1, MathHelper.floor_double(this.posZ)))

                    {

                        k = 2;

                    }

 

                    if (this.rand.nextFloat() < 0.5F && !this.worldObj.canBlockSeeTheSky(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY) + 1, MathHelper.floor_double(this.posZ)))

                    {

                        --k;

                    }

 

                    if (this.field_146045_ax > 0)

                    {

                        --this.field_146045_ax;

 

                        if (this.field_146045_ax <= 0)

                        {

                            this.field_146040_ay = 0;

                            this.field_146038_az = 0;

                        }

                    }

                    else

                    {

                        float f1;

                        float f2;

                        double d5;

                        double d6;

                        float f7;

                        double d11;

 

                        if (this.field_146038_az > 0)

                        {

                            this.field_146038_az -= k;

 

                            if (this.field_146038_az <= 0)

                            {

                                this.motionY -= 0.20000000298023224D;

                                this.playSound("random.splash", 0.25F, 1.0F + (this.rand.nextFloat() - this.rand.nextFloat()) * 0.4F);

                                f1 = (float)MathHelper.floor_double(this.boundingBox.minY);

                                worldserver.func_147487_a("bubble", this.posX, (double)(f1 + 1.0F), this.posZ, (int)(1.0F + this.width * 20.0F), (double)this.width, 0.0D, (double)this.width, 0.20000000298023224D);

                                worldserver.func_147487_a("wake", this.posX, (double)(f1 + 1.0F), this.posZ, (int)(1.0F + this.width * 20.0F), (double)this.width, 0.0D, (double)this.width, 0.20000000298023224D);

                                this.field_146045_ax = MathHelper.getRandomIntegerInRange(this.rand, 10, 30);

                            }

                            else

                            {

                                this.field_146054_aA = (float)((double)this.field_146054_aA + this.rand.nextGaussian() * 4.0D);

                                f1 = this.field_146054_aA * 0.017453292F;

                                f7 = MathHelper.sin(f1);

                                f2 = MathHelper.cos(f1);

                                d11 = this.posX + (double)(f7 * (float)this.field_146038_az * 0.1F);

                                d5 = (double)((float)MathHelper.floor_double(this.boundingBox.minY) + 1.0F);

                                d6 = this.posZ + (double)(f2 * (float)this.field_146038_az * 0.1F);

 

                                if (this.rand.nextFloat() < 0.15F)

                                {

                                    worldserver.func_147487_a("bubble", d11, d5 - 0.10000000149011612D, d6, 1, (double)f7, 0.1D, (double)f2, 0.0D);

                                }

 

                                float f3 = f7 * 0.04F;

                                float f4 = f2 * 0.04F;

                                worldserver.func_147487_a("wake", d11, d5, d6, 0, (double)f4, 0.01D, (double)(-f3), 1.0D);

                                worldserver.func_147487_a("wake", d11, d5, d6, 0, (double)(-f4), 0.01D, (double)f3, 1.0D);

                            }

                        }

                        else if (this.field_146040_ay > 0)

                        {

                            this.field_146040_ay -= k;

                            f1 = 0.15F;

 

                            if (this.field_146040_ay < 20)

                            {

                                f1 = (float)((double)f1 + (double)(20 - this.field_146040_ay) * 0.05D);

                            }

                            else if (this.field_146040_ay < 40)

                            {

                                f1 = (float)((double)f1 + (double)(40 - this.field_146040_ay) * 0.02D);

                            }

                            else if (this.field_146040_ay < 60)

                            {

                                f1 = (float)((double)f1 + (double)(60 - this.field_146040_ay) * 0.01D);

                            }

 

                            if (this.rand.nextFloat() < f1)

                            {

                                f7 = MathHelper.randomFloatClamp(this.rand, 0.0F, 360.0F) * 0.017453292F;

                                f2 = MathHelper.randomFloatClamp(this.rand, 25.0F, 60.0F);

                                d11 = this.posX + (double)(MathHelper.sin(f7) * f2 * 0.1F);

                                d5 = (double)((float)MathHelper.floor_double(this.boundingBox.minY) + 1.0F);

                                d6 = this.posZ + (double)(MathHelper.cos(f7) * f2 * 0.1F);

                                worldserver.func_147487_a("splash", d11, d5, d6, 2 + this.rand.nextInt(2), 0.10000000149011612D, 0.0D, 0.10000000149011612D, 0.0D);

                            }

 

                            if (this.field_146040_ay <= 0)

                            {

                                this.field_146054_aA = MathHelper.randomFloatClamp(this.rand, 0.0F, 360.0F);

                                this.field_146038_az = MathHelper.getRandomIntegerInRange(this.rand, 20, 80);

                            }

                        }

                        else

                        {

                            this.field_146040_ay = MathHelper.getRandomIntegerInRange(this.rand, 100, 900);

                            this.field_146040_ay -= EnchantmentHelper.func_151387_h(this.field_146042_b) * 20 * 5;

                        }

                    }

 

                    if (this.field_146045_ax > 0)

                    {

                        this.motionY -= (double)(this.rand.nextFloat() * this.rand.nextFloat() * this.rand.nextFloat()) * 0.2D;

                    }

                }

 

                d2 = d10 * 2.0D - 1.0D;

                this.motionY += 0.03999999910593033D * d2;

 

                if (d10 > 0.0D)

                {

                    f6 = (float)((double)f6 * 0.9D);

                    this.motionY *= 0.8D;

                }

 

                this.motionX *= (double)f6;

                this.motionY *= (double)f6;

                this.motionZ *= (double)f6;

                this.setPosition(this.posX, this.posY, this.posZ);

            }

        }

    }

 

    /**

    * (abstract) Protected helper method to write subclass entity data to NBT.

    */

    public void writeEntityToNBT(NBTTagCompound p_70014_1_)

    {

        p_70014_1_.setShort("xTile", (short)this.field_146037_g);

        p_70014_1_.setShort("yTile", (short)this.field_146048_h);

        p_70014_1_.setShort("zTile", (short)this.field_146050_i);

        p_70014_1_.setByte("inTile", (byte)Block.getIdFromBlock(this.field_146046_j));

        p_70014_1_.setByte("shake", (byte)this.field_146044_a);

        p_70014_1_.setByte("inGround", (byte)(this.field_146051_au ? 1 : 0));

    }

 

    /**

    * (abstract) Protected helper method to read subclass entity data from NBT.

    */

    public void readEntityFromNBT(NBTTagCompound p_70037_1_)

    {

        this.field_146037_g = p_70037_1_.getShort("xTile");

        this.field_146048_h = p_70037_1_.getShort("yTile");

        this.field_146050_i = p_70037_1_.getShort("zTile");

        this.field_146046_j = Block.getBlockById(p_70037_1_.getByte("inTile") & 255);

        this.field_146044_a = p_70037_1_.getByte("shake") & 255;

        this.field_146051_au = p_70037_1_.getByte("inGround") == 1;

    }

 

    @SideOnly(Side.CLIENT)

    public float getShadowSize()

    {

        return 0.0F;

    }

 

    public int func_146034_e()

    {

        if (this.worldObj.isRemote)

        {

            return 0;

        }

        else

        {

            byte b0 = 0;

 

            if (this.field_146043_c != null)

            {

                double d0 = this.field_146042_b.posX - this.posX;

                double d2 = this.field_146042_b.posY - this.posY;

                double d4 = this.field_146042_b.posZ - this.posZ;

                double d6 = (double)MathHelper.sqrt_double(d0 * d0 + d2 * d2 + d4 * d4);

                double d8 = 0.1D;

                this.field_146043_c.motionX += d0 * d8;

                this.field_146043_c.motionY += d2 * d8 + (double)MathHelper.sqrt_double(d6) * 0.08D;

                this.field_146043_c.motionZ += d4 * d8;

                b0 = 3;

            }

            else if (this.field_146045_ax > 0)

            {

                EntityItem entityitem = new EntityItem(this.worldObj, this.posX, this.posY, this.posZ, this.func_146033_f());

                double d1 = this.field_146042_b.posX - this.posX;

                double d3 = this.field_146042_b.posY - this.posY;

                double d5 = this.field_146042_b.posZ - this.posZ;

                double d7 = (double)MathHelper.sqrt_double(d1 * d1 + d3 * d3 + d5 * d5);

                double d9 = 0.1D;

                entityitem.motionX = d1 * d9;

                entityitem.motionY = d3 * d9 + (double)MathHelper.sqrt_double(d7) * 0.08D;

                entityitem.motionZ = d5 * d9;

                this.worldObj.spawnEntityInWorld(entityitem);

                this.field_146042_b.worldObj.spawnEntityInWorld(new EntityXPOrb(this.field_146042_b.worldObj, this.field_146042_b.posX, this.field_146042_b.posY + 0.5D, this.field_146042_b.posZ + 0.5D, this.rand.nextInt(6) + 1));

                b0 = 1;

            }

 

            if (this.field_146051_au)

            {

                b0 = 2;

            }

 

            this.setDead();

            this.field_146042_b.fishEntity = null;

            return b0;

        }

    }

 

    private ItemStack func_146033_f()

    {

        float f = this.worldObj.rand.nextFloat();

        int i = EnchantmentHelper.func_151386_g(this.field_146042_b);

        int j = EnchantmentHelper.func_151387_h(this.field_146042_b);

        if (true)

        {

            this.field_146042_b.addStat(net.minecraftforge.common.FishingHooks.getFishableCategory(f, i, j).stat, 1);

            return net.minecraftforge.common.FishingHooks.getRandomFishable(this.rand, f, i, j);

        }

 

        float f1 = 0.1F - (float)i * 0.025F - (float)j * 0.01F;

        float f2 = 0.05F + (float)i * 0.01F - (float)j * 0.01F;

        f1 = MathHelper.clamp_float(f1, 0.0F, 1.0F);

        f2 = MathHelper.clamp_float(f2, 0.0F, 1.0F);

 

        if (f < f1)

        {

            this.field_146042_b.addStat(StatList.field_151183_A, 1);

            return ((WeightedRandomFishable)WeightedRandom.getRandomItem(this.rand, field_146039_d)).func_150708_a(this.rand);

        }

        else

        {

            f -= f1;

 

            if (f < f2)

            {

                this.field_146042_b.addStat(StatList.field_151184_B, 1);

                return ((WeightedRandomFishable)WeightedRandom.getRandomItem(this.rand, field_146041_e)).func_150708_a(this.rand);

            }

            else

            {

                float f3 = f - f2;

                this.field_146042_b.addStat(StatList.fishCaughtStat, 1);

                return ((WeightedRandomFishable)WeightedRandom.getRandomItem(this.rand, field_146036_f)).func_150708_a(this.rand);

            }

        }

    }

 

    /**

    * Will get destroyed next tick.

    */

    public void setDead()

    {

        super.setDead();

 

        if (this.field_146042_b != null)

        {

            this.field_146042_b.fishEntity = null;

        }

    }

 

@Override

public void writeSpawnData(ByteBuf buffer) {

 

buffer.writeInt(this.field_146042_b != null ? this.field_146042_b.getEntityId() : 0);

}

 

@Override

public void readSpawnData(ByteBuf additionalData) {

field_146042_b = (EntityPlayer) worldObj.getEntityByID(additionalData.readInt());

 

}

}

 

 

And I also created my renderer, which is a copy of RenderFish

 

 

 

package fantastic.renders.entity;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.client.Minecraft;

import net.minecraft.client.renderer.Tessellator;

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

import net.minecraft.entity.Entity;

import net.minecraft.entity.projectile.EntityFishHook;

import net.minecraft.util.MathHelper;

import net.minecraft.util.ResourceLocation;

import net.minecraft.util.Vec3;

 

import org.lwjgl.opengl.GL11;

import org.lwjgl.opengl.GL12;

 

import fantastic.entities.EntityReinforcedFishingHook;

 

@SideOnly(Side.CLIENT)

public class RenderReinforcedFishingHook extends Render

{

    private static final ResourceLocation field_110792_a = new ResourceLocation("textures/particle/particles.png");

    private static final String __OBFID = "CL_00000996";

 

    /**

    * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then

    * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic

    * (Render<T extends Entity) and this method has signature public void func_76986_a(T entity, double d, double d1,

    * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.

    */

    public void doRender(EntityReinforcedFishingHook p_76986_1_, double p_76986_2_, double p_76986_4_, double p_76986_6_, float p_76986_8_, float p_76986_9_)

    {

        GL11.glPushMatrix();

        GL11.glTranslatef((float)p_76986_2_, (float)p_76986_4_, (float)p_76986_6_);

        GL11.glEnable(GL12.GL_RESCALE_NORMAL);

        GL11.glScalef(0.5F, 0.5F, 0.5F);

        this.bindEntityTexture(p_76986_1_);

        Tessellator tessellator = Tessellator.instance;

        byte b0 = 1;

        byte b1 = 2;

        float f2 = (float)(b0 * 8 + 0) / 128.0F;

        float f3 = (float)(b0 * 8 + 8) / 128.0F;

        float f4 = (float)(b1 * 8 + 0) / 128.0F;

        float f5 = (float)(b1 * 8 + 8) / 128.0F;

        float f6 = 1.0F;

        float f7 = 0.5F;

        float f8 = 0.5F;

        GL11.glRotatef(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);

        GL11.glRotatef(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);

        tessellator.startDrawingQuads();

        tessellator.setNormal(0.0F, 1.0F, 0.0F);

        tessellator.addVertexWithUV((double)(0.0F - f7), (double)(0.0F - f8), 0.0D, (double)f2, (double)f5);

        tessellator.addVertexWithUV((double)(f6 - f7), (double)(0.0F - f8), 0.0D, (double)f3, (double)f5);

        tessellator.addVertexWithUV((double)(f6 - f7), (double)(1.0F - f8), 0.0D, (double)f3, (double)f4);

        tessellator.addVertexWithUV((double)(0.0F - f7), (double)(1.0F - f8), 0.0D, (double)f2, (double)f4);

        tessellator.draw();

        GL11.glDisable(GL12.GL_RESCALE_NORMAL);

        GL11.glPopMatrix();

 

        if (p_76986_1_.field_146042_b != null)

        {

            float f9 = p_76986_1_.field_146042_b.getSwingProgress(p_76986_9_);

            float f10 = MathHelper.sin(MathHelper.sqrt_float(f9) * (float)Math.PI);

            Vec3 vec3 = Vec3.createVectorHelper(-0.5D, 0.03D, 0.8D);

            vec3.rotateAroundX(-(p_76986_1_.field_146042_b.prevRotationPitch + (p_76986_1_.field_146042_b.rotationPitch - p_76986_1_.field_146042_b.prevRotationPitch) * p_76986_9_) * (float)Math.PI / 180.0F);

            vec3.rotateAroundY(-(p_76986_1_.field_146042_b.prevRotationYaw + (p_76986_1_.field_146042_b.rotationYaw - p_76986_1_.field_146042_b.prevRotationYaw) * p_76986_9_) * (float)Math.PI / 180.0F);

            vec3.rotateAroundY(f10 * 0.5F);

            vec3.rotateAroundX(-f10 * 0.7F);

            double d3 = p_76986_1_.field_146042_b.prevPosX + (p_76986_1_.field_146042_b.posX - p_76986_1_.field_146042_b.prevPosX) * (double)p_76986_9_ + vec3.xCoord;

            double d4 = p_76986_1_.field_146042_b.prevPosY + (p_76986_1_.field_146042_b.posY - p_76986_1_.field_146042_b.prevPosY) * (double)p_76986_9_ + vec3.yCoord;

            double d5 = p_76986_1_.field_146042_b.prevPosZ + (p_76986_1_.field_146042_b.posZ - p_76986_1_.field_146042_b.prevPosZ) * (double)p_76986_9_ + vec3.zCoord;

            double d6 = p_76986_1_.field_146042_b == Minecraft.getMinecraft().thePlayer ? 0.0D : (double)p_76986_1_.field_146042_b.getEyeHeight();

 

            if (this.renderManager.options.thirdPersonView > 0 || p_76986_1_.field_146042_b != Minecraft.getMinecraft().thePlayer)

            {

                float f11 = (p_76986_1_.field_146042_b.prevRenderYawOffset + (p_76986_1_.field_146042_b.renderYawOffset - p_76986_1_.field_146042_b.prevRenderYawOffset) * p_76986_9_) * (float)Math.PI / 180.0F;

                double d7 = (double)MathHelper.sin(f11);

                double d9 = (double)MathHelper.cos(f11);

                d3 = p_76986_1_.field_146042_b.prevPosX + (p_76986_1_.field_146042_b.posX - p_76986_1_.field_146042_b.prevPosX) * (double)p_76986_9_ - d9 * 0.35D - d7 * 0.85D;

                d4 = p_76986_1_.field_146042_b.prevPosY + d6 + (p_76986_1_.field_146042_b.posY - p_76986_1_.field_146042_b.prevPosY) * (double)p_76986_9_ - 0.45D;

                d5 = p_76986_1_.field_146042_b.prevPosZ + (p_76986_1_.field_146042_b.posZ - p_76986_1_.field_146042_b.prevPosZ) * (double)p_76986_9_ - d7 * 0.35D + d9 * 0.85D;

            }

 

            double d14 = p_76986_1_.prevPosX + (p_76986_1_.posX - p_76986_1_.prevPosX) * (double)p_76986_9_;

            double d8 = p_76986_1_.prevPosY + (p_76986_1_.posY - p_76986_1_.prevPosY) * (double)p_76986_9_ + 0.25D;

            double d10 = p_76986_1_.prevPosZ + (p_76986_1_.posZ - p_76986_1_.prevPosZ) * (double)p_76986_9_;

            double d11 = (double)((float)(d3 - d14));

            double d12 = (double)((float)(d4 - d8));

            double d13 = (double)((float)(d5 - d10));

            GL11.glDisable(GL11.GL_TEXTURE_2D);

            GL11.glDisable(GL11.GL_LIGHTING);

            tessellator.startDrawing(3);

            tessellator.setColorOpaque_I(0);

            byte b2 = 16;

 

            for (int i = 0; i <= b2; ++i)

            {

                float f12 = (float)i / (float)b2;

                tessellator.addVertex(p_76986_2_ + d11 * (double)f12, p_76986_4_ + d12 * (double)(f12 * f12 + f12) * 0.5D + 0.25D, p_76986_6_ + d13 * (double)f12);

            }

 

            tessellator.draw();

            GL11.glEnable(GL11.GL_LIGHTING);

            GL11.glEnable(GL11.GL_TEXTURE_2D);

        }

    }

 

    /**

    * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.

    */

    protected ResourceLocation getEntityTexture(EntityReinforcedFishingHook p_110775_1_)

    {

        return field_110792_a;

    }

 

    /**

    * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.

    */

    protected ResourceLocation getEntityTexture(Entity p_110775_1_)

    {

        return this.getEntityTexture((EntityReinforcedFishingHook)p_110775_1_);

    }

 

    /**

    * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then

    * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic

    * (Render<T extends Entity) and this method has signature public void func_76986_a(T entity, double d, double d1,

    * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.

    */

    public void doRender(Entity p_76986_1_, double p_76986_2_, double p_76986_4_, double p_76986_6_, float p_76986_8_, float p_76986_9_)

    {

        this.doRender((EntityReinforcedFishingHook)p_76986_1_, p_76986_2_, p_76986_4_, p_76986_6_, p_76986_8_, p_76986_9_);

    }

}

 

 

 

 

RenderReinforcedFishingHook, which is a copy of RenderFish (vanilla)

 

I registered the item:

 

 

reinforcedFishingRod = new ItemReinforcedFishingRod().setUnlocalizedName(Names.ReinforcedFishingRod_UnlocalizedName).setTextureName("fantastic:reinforced_fishing_rod_uncast");

 

 

I registered the Entity:

 

 

EntityRegistry.registerGlobalEntityID(EntityReinforcedFishingHook.class, Names.ReinforcedFishingRod_UnlocalizedName, EntityRegistry.findGlobalUniqueEntityId());

 

 

I registered the render:

 

 

RenderingRegistry.registerEntityRenderingHandler(EntityReinforcedFishingHook.class, new RenderReinforcedFishingHook());

 

 

So everything works fine from the client side perspective. When I right click on my fishing rod, my new ReinforcedFishingHook entity spawned and the fishing line appears. But I noticed that if I try to spawn the ReinforcedFishingHook server side, the hook do not spawn.

 

I am pretty sure this is something about registering the entity server side. I miss something but I can't figure out what.

 

Briefly, in the following code, if I want to spawn server side by adding the bold part ... server refuse to spawn it (or it is spawned but I do not see it client side).

 

 

 

    public ItemStack onItemRightClick(ItemStack anItemStack, World aWorld, EntityPlayer aPlayer)

    {

 

        //if (aPlayer.fishEntity != null)

        //{

        // int i = aPlayer.fishEntity.func_146034_e();

        // anItemStack.damageItem(i, aPlayer);

        // aPlayer.swingItem();

        //}

        //else

        //{

       

        if (!aWorld.isRemote)

        {

       

        if (EntityList.stringToClassMapping.containsKey(Names.ReinforcedFishingRod_UnlocalizedName))

        {

            EntityReinforcedFishingHook hook = new EntityReinforcedFishingHook(aWorld,aPlayer);

            aWorld.spawnEntityInWorld(hook);

        }

        else

        {

        System.out.println("Class not found.");

        }

       

       

        }

        aPlayer.swingItem();

        aWorld.playSoundAtEntity(aPlayer,"fantastic:throwLine",1.0F,1.0F);

        return anItemStack;

   

    }

 

 

 

Any idea what the heck I am missing here?

 

 

 

 

 

Posted

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

 

Hi SanAndreasP,

 

thanks for the answer. I tried that one and the result was the same. But someone could explain me what is the difference between registerModEntity and RegisterGlobalEntity? A lot of mods use both, but I did not figure out what is the difference yet.

 

 

Posted

There are only so many global IDs and if everyone is registering their entity using registerGlobalEntityId, there won't be enough to go around.

 

So instead, you use registerModEntity, which gives you 256 IDs that you, and you alone, can use.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

There are only so many global IDs and if everyone is registering their entity using registerGlobalEntityId, there won't be enough to go around.

 

So instead, you use registerModEntity, which gives you 256 IDs that you, and you alone, can use.

 

It also seems that we have more control over the spawn (refresh ... distance seen ... etc).

 

Ok I will make more testing tonight to see if I can fix my issue by playing around with this.

Posted

I was able to generate my own rod and hook by extending those from the vanilla classes, but it limits me a lot. I would still like to understand why I cannot spawn that custom fishing hook like explained in the first post :(

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

    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
    • Do you use features of inventory profiles next (ipnext) or is there a change without it?
    • Remove rubidium - you are already using embeddium, which is a fork of rubidium
  • Topics

×
×
  • Create New...

Important Information

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