Jump to content

My custom Entity is full of bugs :(


ItsAMysteriousYT

Recommended Posts

I have several strange problems with my custom car entity.The player and other entities won't collide with it I did isCollidable returns true and all that stuff, but the player simply goes through it and another problem is, that when i drive the entity(its a car) and collide with a wall, the boundingbox keeps there AND with the entity, but when i dismount, i am there where i collided. Hope you can help me. Here is the Code:

 

 

 

package de.ItsAMysterious.mods.reallifemod.core.entities.cars;

 

import net.minecraft.client.Minecraft;

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Items;

import net.minecraft.inventory.IInventory;

import net.minecraft.item.ItemStack;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.nbt.NBTTagDouble;

import net.minecraft.nbt.NBTTagList;

import net.minecraft.util.AxisAlignedBB;

import net.minecraft.util.ChatComponentText;

import net.minecraft.util.DamageSource;

import net.minecraft.util.MathHelper;

import net.minecraft.world.World;

 

import org.lwjgl.input.Keyboard;

import org.lwjgl.util.vector.Vector3f;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import de.ItsAMysterious.mods.reallifemod.RealLifeMod;

import de.ItsAMysterious.mods.reallifemod.api.entity.EntitySeat;

import de.ItsAMysterious.mods.reallifemod.api.util.LittleFunctions;

import de.ItsAMysterious.mods.reallifemod.client.ClientProxy;

import de.ItsAMysterious.mods.reallifemod.core.gui.GuiVehicleModification;

 

public class EntityJeep extends EntityVehicle implements IInventory {

 

private static final int inventorysize = 6;

private ItemStack jeepItems[] = new ItemStack[inventorysize];

 

public EntityJeep(World world) {

super(world);

this.setSize(3, 1.0F);

this.setSpeedMinMax(-0.25, 0.75);

this.setSpeedMinMax(-0.25, 1);

this.numPassengers = 5;

}

 

public EntityJeep(World world, double x, double y, double z,

float rotationYaw, double width, double length) {

this(world);

setLocationAndAngles(x, y, z, rotationYaw, 0);

}

 

public AxisAlignedBB getCollisionBox(Entity entity) {

return AxisAlignedBB.getBoundingBox(-1, 0, 0, 1, 1, 3);

}

 

public AxisAlignedBB getBoundingBox() {

return getCollisionBox(this);

}

 

public boolean canBeCollidedWith() {

return !this.isDead;

}

 

public void onUpdate() {

super.onUpdate();

checkInput();

move();

 

if (Keyboard.isKeyDown(Keyboard.KEY_RETURN)) {

if (worldObj.getClosestPlayer(posX, posY, posZ, 5.0F) != null) {

EntityPlayer entity = (EntityPlayer) worldObj.getClosestPlayer(

posX, posY, posZ, 5.0F);

interactFirst(entity);

// riddenByEntity = (EntityPlayer) entity;

playSound("reallifemod:door_close", 1.0F, 1.0F);

}

}

 

if (ClientProxy.Key_CarInv.isPressed()) {

EntityPlayer player = (EntityPlayer) riddenByEntity;

if (hasDriver()) {

player.openGui(RealLifeMod.instance, getEntityId(), worldObj,

(int) posX, (int) posY, (int) posZ);

}

}

}

 

@Override

public int getSizeInventory() {

return inventorysize;

}

 

@Override

public ItemStack getStackInSlot(int slotID) {

if (slotID < inventorysize) {

return jeepItems[slotID];

} else

return null;

}

 

public ItemStack decrStackSize(int slot, int amount) {

ItemStack stack = getStackInSlot(slot);

if (stack != null) {

if (stack.stackSize > amount) {

stack = stack.splitStack(amount);

if (stack.stackSize == 0) {

setInventorySlotContents(slot, null);

}

} else {

setInventorySlotContents(slot, null);

}

 

onInventoryChanged();

}

return stack;

}

 

public ItemStack getStackInSlotOnClosing(int slot) {

ItemStack stack = getStackInSlot(slot);

if (stack != null)

setInventorySlotContents(slot, null);

return stack;

}

 

public void onInventoryChanged() {

for (int i = 0; i < jeepItems.length; ++i) {

if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0)

setInventorySlotContents(i, null);

}

}

 

public void setInventorySlotContents(int slot, ItemStack stack) {

if (slot >= 0 && slot < inventorysize)

jeepItems[slot] = stack;

if (stack != null && stack.stackSize > getInventoryStackLimit()) {

stack.stackSize = getInventoryStackLimit();

}

markDirty();

}

 

@Override

public String getInventoryName() {

return "JeepTrunk";

}

 

@Override

public boolean hasCustomInventoryName() {

return true;

}

 

@Override

public int getInventoryStackLimit() {

return 64;

}

 

@Override

public void markDirty() {

}

 

@Override

public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {

return true;

}

 

@Override

public void openInventory() {

}

 

@Override

public void closeInventory() {

}

 

@Override

public boolean isItemValidForSlot(int slotID, ItemStack stack) {

return slotID < jeepItems.length;

}

 

@Override

public boolean interactFirst(EntityPlayer player) {

super.interactFirst(player);

player.mountEntity(this);

return true;

}

 

public void checkInput() {

if (hasDriver()) {

if (Keyboard.isKeyDown(Keyboard.KEY_W)) {

acceleration = 0.025;

} else if (Keyboard.isKeyDown(Keyboard.KEY_S)) {

acceleration = -0.025;

} else {

acceleration = 0;

}

 

if (Keyboard.isKeyDown(Keyboard.KEY_D)) {

if (deltasteer > -45) {

deltasteer--;

}

 

} else if (Keyboard.isKeyDown(Keyboard.KEY_A)) {

if (deltasteer < 45) {

deltasteer++;

}

} else {

if (deltasteer < 0) {

deltasteer++;

} else if (deltasteer > 0) {

deltasteer--;

}

}

 

if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {

brake();

}

 

if (Keyboard.isKeyDown(Keyboard.KEY_H)) {

worldObj.playSound(posX, posY, posZ, "reallifemod:horn", 10.5f,

1.0f, true);

}

 

 

if (Keyboard.isKeyDown(Keyboard.KEY_M)) {

((EntityPlayer)riddenByEntity).openGui(RealLifeMod.instance, this.getEntityId(), worldObj, (int)chunkCoordX,(int) chunkCoordY, (int)chunkCoordZ);

}

 

}

 

}

 

@Override

public void updateRiderPosition() {

super.updateRiderPosition();

double R = 0;

double k = 0;

if (deltasteer != 0) {

R = 5 / deltasteer;

k = 1 / R;

}

double z = Math.cos((rotationYaw + 16) * Math.PI / 180.0) * 2.2;// *5.0990195135927848300282241090228D;

double y = posY + Math.cos(rotationPitch * Math.PI / 180) * 3;

double x = Math.sin((rotationYaw + 16) * Math.PI / 180) * 2.2;

riddenByEntity.setPosition(posX + x, posY + 2, posZ + z);

riddenByEntity.rotationYaw-=currentspeed * k;

 

/*EntityPlayer p = (EntityPlayer) riddenByEntity;

    p.rotationYawHead -= currentspeed * k;

    p.rotationYawHead = -rotationYaw;*/

 

}

 

public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_) {

if (this.isEntityInvulnerable()) {

return false;

} else if (!this.worldObj.isRemote && !this.isDead) {

this.setForwardDirection(-this.getForwardDirection());

this.setTimeSinceHit(10);

this.setDamageTaken(this.getDamageTaken() + p_70097_2_ * 10.0F);

this.setBeenAttacked();

boolean flag = p_70097_1_.getEntity() instanceof EntityPlayer

&& ((EntityPlayer) p_70097_1_.getEntity()).capabilities.isCreativeMode;

 

if (flag || this.getDamageTaken() > 40.0F) {

if (this.riddenByEntity != null) {

this.riddenByEntity.mountEntity(this);

}

 

if (!flag) {

this.func_145778_a(Items.boat, 1, 0.0F);

}

 

this.setDead();

}

 

return true;

} else {

return true;

}

}

 

@Override

protected void readEntityFromNBT(NBTTagCompound compound) {

super.readEntityFromNBT(compound);

}

 

@Override

protected void writeEntityToNBT(NBTTagCompound compound) {

super.writeEntityToNBT(compound);

}

 

}

 

 

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Wow this looks a lot simpler than I thought it would be. Especially compared to the setup I had to do for capabilities. I'll look at all this and update if I have any issues ty
    • Me and a group of friends were trying to get a modpack to work so we can play together. It works for everyone else, except me. At first when I tried to import the modpack, it said "invalid file" but it didn't with anyone else's. The owner of the modpack resent it several times and I still kept getting the same issue, so I opened the modlist and downloaded every single mod by hand. I thought that it would resolve the issue, but instead, it started saying "Forge Modloader Installation Failed" after I created a new installation, so I tried to use a pre-existing modpack, made sure it was the same version "1.20.1, forge version 47.3.0" and swap the mods there, but it still had the same issue, and now none of my modpacks are working at all. They all keep saying that the modloader installation failed. None of us have any idea what to do as we aren't the techiest people. Any help is appreciated. Thank you!
    • I don't think there's any documentation on them yet, I mainly just looked at the Vanilla code when implementing mine. You can see a fairly simple example here: Registration: https://github.com/Choonster-Minecraft-Mods/TestMod3/blob/f3bea10d5f455fa0904056caafd8c844b6fd13ae/src/main/java/choonster/testmod3/init/ModDataComponents.java#L50-L58 Item Registration: https://github.com/Choonster-Minecraft-Mods/TestMod3/blob/f3bea10d5f455fa0904056caafd8c844b6fd13ae/src/main/java/choonster/testmod3/init/ModItems.java#L264-L266 Usage: https://github.com/Choonster-Minecraft-Mods/TestMod3/blob/f3bea10d5f455fa0904056caafd8c844b6fd13ae/src/main/java/choonster/testmod3/world/item/EntityCheckerItem.java
    • Okay, I'm glad I made a backup then. I'm confused as to where there is any information on how to work with Data Components. I don't see anything about it on the Forge docs or any tutorials on this in general unless I'm missing it somehow. I can see the DataComponents decompiled class file but I'm not sure how to work with it. Maybe it's beyond my technical expertise?
    • The situation is the same in 1.20.6. Data Components were introduced in 1.20.5/1.20.6 and Item Capabilities haven't been re-implemented since then.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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