Posted June 6, 201510 yr 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); } }
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.