Untitled

 avatar
unknown
plain_text
17 days ago
4.4 kB
0
Indexable
package com.example.dococktentaclemod;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

public class EntityTentacle extends Entity {
    private EntityPlayer owner; // The player who controls the tentacle
    private float angle; // Tentacle's rotation angle
    private Vec3d targetPosition; // Target position the tentacle is aiming towards
    private float tentacleLength = 4.0F; // How long the tentacle should be
    private ModelTentacle modelTentacle; // Model used for rendering the tentacle

    public EntityTentacle(World world, EntityPlayer owner) {
        super(world);
        this.owner = owner;
        this.modelTentacle = new ModelTentacle(); // Initialize the tentacle model
        setSize(0.5F, 0.5F); // Define collision box
    }

    @Override
    public void onUpdate() {
        super.onUpdate();
        
        // Update the tentacle's position and rotation to follow the player
        if (owner != null) {
            // Get the player's position
            Vec3d playerPos = owner.getPositionVector();
            
            // Tentacle will follow the player with a little offset
            targetPosition = new Vec3d(playerPos.xCoord + 5, playerPos.yCoord, playerPos.zCoord);
            
            // Calculate the direction for movement
            moveToTarget(targetPosition);
        }
    }

    private void moveToTarget(Vec3d target) {
        double speed = 0.05;  // Tentacle's speed at moving
        Vec3d direction = target.subtract(this.posX, this.posY, this.posZ);
        direction = direction.normalize(); // Normalize to get direction
        this.motionX = direction.xCoord * speed;
        this.motionY = direction.yCoord * speed;
        this.motionZ = direction.zCoord * speed;
    }

    @Override
    public void onCollideWithPlayer(EntityPlayer player) {
        // Tentacle damage or other interactions with other entities
        if (this.owner != player) {
            player.attackEntityFrom(DamageSource.causeMobDamage(this), 2.0F); // Attack with 2 damage
        }
    }

    @Override
    public void readEntityFromNBT(NBTTagCompound compound) {
        super.readEntityFromNBT(compound);
        this.angle = compound.getFloat("Angle");
    }

    @Override
    public void writeEntityToNBT(NBTTagCompound compound) {
        super.writeEntityToNBT(compound);
        compound.setFloat("Angle", this.angle);
    }

    @Override
    protected void entityInit() {
        super.entityInit();
    }

    @Override
    public void onEntityUpdate() {
        super.onEntityUpdate();
    }

    // Rendering logic for drawing the tentacle using OpenGL (you might need a custom model)
    @Override
    public void render(Entity entity, float partialTicks, float scale) {
        GlStateManager.pushMatrix();
        
        // Rotate and move the tentacle to match the player
        GlStateManager.translate(this.posX, this.posY, this.posZ);
        GlStateManager.rotate(this.angle, 0.0F, 1.0F, 0.0F); // Rotate the tentacle around its base
        GlStateManager.scale(1.0F, tentacleLength, 1.0F); // Stretch the model
        
        modelTentacle.render(entity, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, scale); // Render the tentacle model
        GlStateManager.popMatrix();
    }
}

// Model for rendering a simple tentacle (can be a simple cylinder for a placeholder model)
class ModelTentacle extends ModelBase {
    private ModelRenderer tentacle;

    public ModelTentacle() {
        this.textureWidth = 64;
        this.textureHeight = 32;
        
        // Create a simple cylinder to represent the tentacle
        this.tentacle = new ModelRenderer(this);
        tentacle.addBox(-0.5F, 0.0F, -0.5F, 1, 12, 1); // Tentacle segment, essentially a vertical block

        this.tentacle.setRotationPoint(0.0F, 0.0F, 0.0F); // Origin of the tentacle
    }

    @Override
    public void render(Entity entity, float f1, float f2, float f3, float f4, float f5, float scale) {
        this.tentacle.render(scale); // Simple render call for the tentacle
    }
}
Leave a Comment