Jump to content

Recommended Posts

Posted

After two weeks of helping other people (but it seems like longer), I finally need some help myself. With an entity that is glitching horribly when I try to drive it.

 

I know it's just something stupid, some packet-related thing I forgot... but could someone point out to me what I did?

 

Here's my Entity code:

 

package sbfp.secret;

import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

import org.lwjgl.input.Keyboard;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class EntitySecret extends Entity{

public static final double speed = 0.25;

public EntitySecret(World w){
	super(w);
	this.preventEntitySpawning = true;
	this.entityCollisionReduction = 1;
	this.yOffset = this.height/2.0F;
}

@Override
protected boolean canTriggerWalking(){
	return true;
}

@Override
protected void entityInit(){
}

@Override
public AxisAlignedBB getCollisionBox(Entity e){
	return e.boundingBox;
}

@Override
public AxisAlignedBB getBoundingBox(){
	return this.boundingBox;
}

@Override
public void setPosition(double x, double y, double z){
	this.posX = x;
	this.posY = y;
	this.posZ = z;
	this.boundingBox.setBounds(x-0.375,y,z-0.75,x+0.375,y+1.125,z+0.75);
}

public EntitySecret(World w, double x, double y, double z){
	this(w);
	this.setPosition(x,y+this.yOffset,z);
	this.motionX = 0;
	this.motionY = 0;
	this.motionZ = 0;
	this.prevPosX = x;
	this.prevPosY = y;
	this.prevPosZ = z;
}

@Override
public double getMountedYOffset(){
	return 0.3;
}

@Override
public boolean attackEntityFrom(DamageSource ds, int damage){
	if(ds.damageType=="lava"||ds.damageType=="outOfWorld"||ds.damageType=="generic"){
		this.setDead();
		return true;
	}
	return false;
}

@Override
public boolean canBeCollidedWith(){
	return !this.isDead;
}

@Override
public void onUpdate(){
	super.onUpdate();
	if(this.riddenByEntity!=null){
		float dyaw = 0;
		if(Keyboard.isKeyDown(Keyboard.KEY_W)){
			this.motionX = Math.cos(this.rotationYaw*speed);
			this.motionZ = Math.sin(this.rotationYaw*speed);
		}else{
			this.motionX = 0;
			this.motionZ = 0;
		}
		if(Keyboard.isKeyDown(Keyboard.KEY_A)){
			dyaw = 5;
		}
		if(Keyboard.isKeyDown(Keyboard.KEY_D)){
			dyaw = -5;
		}
		this.setRotation(this.rotationPitch, this.rotationYaw+dyaw);
	}
	if(!this.onGround){
		this.motionY -= 0.098;
	}else{
		this.motionY = 0;
	}
	this.moveEntity(this.motionX,this.motionY,this.motionZ);
	if(!this.worldObj.isRemote){
		List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this,this.boundingBox.expand(0.2,0,0.2));
		if(list!=null&&!list.isEmpty()){
			for(int i = 0; i<list.size(); ++i){
				Entity entity = (Entity) list.get(i);
				if(entity!=this.riddenByEntity&&entity.canBePushed()&&!(entity instanceof EntitySecret)){
					entity.applyEntityCollision(this);
				}
			}
		}
		for(int i = 0; i<4; ++i){
			int blockX = MathHelper.floor_double(this.posX+(i%2-0.5D)*0.8D);
			int blockZ = MathHelper.floor_double(this.posZ+(i/2-0.5D)*0.8D);
			for(int j = 0; j<2; ++j){
				int blockY = MathHelper.floor_double(this.posY)+j;
				int id = this.worldObj.getBlockId(blockX,blockY,blockZ);
				if(id==Block.snow.blockID){
					this.worldObj.setBlockToAir(blockX,blockY,blockZ);
				}else if(id==Block.waterlily.blockID){
					this.worldObj.destroyBlock(blockX,blockY,blockZ,true);
				}
			}
		}
		if(this.riddenByEntity!=null&&this.riddenByEntity.isDead){
			this.riddenByEntity = null;
		}
	}
}

@Override
public void updateRiderPosition(){
	if(this.riddenByEntity!=null){
		double d0 = Math.cos(this.rotationYaw*Math.PI/180.0D)*0.4D;
		double d1 = Math.sin(this.rotationYaw*Math.PI/180.0D)*0.4D;
		this.riddenByEntity.setPosition(this.posX+d0,this.posY+this.getMountedYOffset()+this.riddenByEntity.getYOffset(),this.posZ+d1);
	}
}

/**
 * (abstract) Protected helper method to write subclass entity data to NBT.
 */
@Override
protected void writeEntityToNBT(NBTTagCompound par1NBTTagCompound){}

/**
 * (abstract) Protected helper method to read subclass entity data from NBT.
 */
@Override
protected void readEntityFromNBT(NBTTagCompound par1NBTTagCompound){}

@Override
@SideOnly(Side.CLIENT)
public float getShadowSize(){
	return 0.0F;
}

/**
 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
 */
@Override
public boolean interact(EntityPlayer par1EntityPlayer){
	if(this.riddenByEntity!=null&&this.riddenByEntity instanceof EntityPlayer&&this.riddenByEntity!=par1EntityPlayer){
		return true;
	}else{
		if(!this.worldObj.isRemote){
			par1EntityPlayer.mountEntity(this);
		}
		return true;
	}
}
}

 

My git repo, in case you need other files, is at https://github.com/Pentachoron-Labs/SBFP-Tech/tree/secretfeature—make sure you're on the "secretfeature" branch. Oh, and if the constant use of "secret" bothers you, just mentally replace it with "tractor".

Thanks!

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Posted

You can look at my code for the turrets. You can ride them, although you can't move with them:

https://github.com/SanAndreasP/TurretModv3/blob/master/sanandreasp/mods/TurretMod3/entity/turret/EntityTurret_Base.java

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

I'm honestly not sure how I found the solution, but I added tractorX/Y/Z/Yaw/Pitch and velocityX/Y/Z variables akin to the way they're used in EntityBoat and EntityMinecart, and it worked. Then I started fixing the bounding box and ran into... well, this.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

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

    • You would have better results asking a more specific question. What have you done? What exactly do you need help with? Please also read the FAQ regarding posting logs.
    • Hi, this is my second post with the same content as no one answered this and it's been a long time since I made the last post, I want to make a client-only mod, everything is ok, but when I use shaders, none of the textures rendered in RenderLevelStageEvent nor the crow entity model are rendered, I want them to be visible, because it's a horror themed mod I've already tried it with different shaders, but it didn't work with any of them and I really want to add support for shaders Here is how i render the crow model in the CrowEntityRenderer<CrowEntity>, by the time i use this method, i know is not the right method but i don't think this is the cause of the problem, the renderType i'm using is entityCutout @Override public void render(CrowEntity p_entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { super.render(p_entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); ClientEventHandler.getClient().crow.renderToBuffer(poseStack, bufferSource.getBuffer(ClientEventHandler.getClient().crow .renderType(TEXTURE)), packedLight, OverlayTexture.NO_OVERLAY, Utils.rgb(255, 255, 255)); } Here renderLevelStage @Override public void renderWorld(RenderLevelStageEvent e) { horrorEvents.draw(e); } Here is how i render every event public void draw(RenderLevelStageEvent e) { for (HorrorEvent event : currentHorrorEvents) { event.tick(e.getPartialTick()); event.draw(e); } } Here is how i render the crow model on the event @Override public void draw(RenderLevelStageEvent e) { if(e.getStage() == RenderLevelStageEvent.Stage.AFTER_ENTITIES) { float arcProgress = getArcProgress(0.25f); int alpha = (int) Mth.lerp(arcProgress, 0, 255); int packedLight = LevelRenderer.getLightColor(Minecraft.getInstance().level, blockPos); VertexConsumer builder = ClientEventHandler.bufferSource.getBuffer(crow); Crow<CreepyBirdHorrorEvent> model = ClientEventHandler .getClient().crow; model.setupAnim(this); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, packedLight, OverlayTexture.NO_OVERLAY, alpha); builder = ClientEventHandler.bufferSource.getBuffer(eyes); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, 15728880, OverlayTexture.NO_OVERLAY, alpha); } } How i render the model public static void renderModelInWorld(Model model, Vector3f pos, Vector3f offset, Camera camera, PoseStack matrix, VertexConsumer builder, int light, int overlay, int alpha) { matrix.pushPose(); Vec3 cameraPos = camera.getPosition(); double finalX = pos.x - cameraPos.x + offset.x; double finalY = pos.y - cameraPos.y + offset.y; double finalZ = pos.z - cameraPos.z + offset.z; matrix.pushPose(); matrix.translate(finalX, finalY, finalZ); matrix.mulPose(Axis.XP.rotationDegrees(180f)); model.renderToBuffer(matrix, builder, light, overlay, Utils .rgba(255, 255, 255, alpha)); matrix.popPose(); matrix.popPose(); } Thanks in advance
    • Same issue - I have no idea
    • I am trying to develop a modpack for me and my friends to use on our server. Does anyone know how to develop a modpack for a server or could they help take a look at my modpack to potentially help at all?
    • un server de armas realista.  
  • Topics

×
×
  • Create New...

Important Information

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