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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
  • Topics

×
×
  • Create New...

Important Information

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