Jump to content

Recommended Posts

Posted

Hello!

 

I'm currently porting an ancient Minecraft 1.2.5 mod to 1.4.6 for a private server. I've got everything to work perfectly except this one bug I can't seem to squash.

 

When I place the block down, it appears perfectly fine.

 

not-floating.png

 

Until, that is until I save and load the world again. The block is.. floating??

 

floating.png

 

Block code (Parts of this I didn't code, the original creator did):

 

package me.expertmac2.minecraft.gels.block;

import java.util.Random;

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

import me.expertmac2.minecraft.gels.mod_Portal2Gels;
import me.expertmac2.minecraft.gels.entity.EntityGelDrop;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.src.ModLoader;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockGel extends BlockContainer {

private int renderID;

public BlockGel(int var1, int var2, int var3) {
	super(var1, var2, Material.circuits);
	this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.125F, 1.0F);
	this.renderID = var3;
}

// start blocksnow

/**
 * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
 * cleared to be reused)
 */
public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
{
	//int var5 = par1World.getBlockMetadata(par2, par3, par4) & 7;
	//return var5 >= 3 ? AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)par2 + this.minX, (double)par3 + this.minY, (double)par4 + this.minZ, (double)par2 + this.maxX, (double)((float)par3 + 0.5F), (double)par4 + this.maxZ) : null;
	return null;
}

/**
 * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
 * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
 */
public boolean isOpaqueCube()
{
	return false;
}

/**
 * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
 */
public boolean renderAsNormalBlock()
{
	return false;
}

/**
 * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
 * their own) Args: x, y, z, neighbor blockID
 */
public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
{
	if (!canGelStay(par1World, par2, par3, par4)) {

	}
}

/**
 * Called when the player destroys a block with an item that can harvest it. (i, j, k) are the coordinates of the
 * block and l is the block's subtype/damage.
 */
public void harvestBlock(World par1World, EntityPlayer par2EntityPlayer, int par3, int par4, int par5, int par6)
{
	return;
}

/**
 * Returns the ID of the items to drop on destruction.
 */
public int idDropped(int par1, Random par2Random, int par3)
{
	return 0;
}

/**
 * Returns the quantity of items to drop on block destruction.
 */
public int quantityDropped(Random par1Random)
{
	return 0;
}

@SideOnly(Side.CLIENT)

/**
 * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given
 * coordinates.  Args: blockAccess, x, y, z, side
 */
public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
{
	return par5 == 1 ? true : super.shouldSideBeRendered(par1IBlockAccess, par2, par3, par4, par5);
}
// end blocksnow

/**
 * Called whenever the block is added into the world. Args: world, x, y, z
 */
public void onBlockAdded(World var1, int var2, int var3, int var4)
{
	super.onBlockAdded(var1, var2, var3, var4);
	var1.scheduleBlockUpdate(var2, var3, var4, this.blockID, 1);
}

/**
 * Updates the blocks bounds based on its current state. Args: world, x, y, z
 */
public void setBlockBoundsBasedOnState(IBlockAccess var1, int var2, int var3, int var4)
{
	TileEntityGel var5 = (TileEntityGel)var1.getBlockTileEntity(var2, var3, var4);

	if (var5 != null)
	{
		byte var6 = var5.Gelside;

		if (var6 == 1)
		{
			this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.125F, 1.0F);
		}

		if (var6 == 5)
		{
			this.setBlockBounds(0.0F, 0.0F, 0.0F, 0.125F, 1.0F, 1.0F);
		}

		if (var6 == 4)
		{
			this.setBlockBounds(0.875F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
		}

		if (var6 == 3)
		{
			this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.125F);
		}

		if (var6 == 2)
		{
			this.setBlockBounds(0.0F, 0.0F, 0.875F, 1.0F, 1.0F, 1.0F);
		}

		if (var6 == 0)
		{
			this.setBlockBounds(0.0F, 0.875F, 0.0F, 1.0F, 1.0F, 1.0F);
		}
	}
}

/**
 * Ticks the block if it's been scheduled
 */
public void updateTick(World var1, int var2, int var3, int var4, Random var5)
{
	this.canGelStay(var1, var2, var3, var4);
}

/**
 * Sets the block's bounds for rendering it as an item
 */
public void setBlockBoundsForItemRender()
{
	this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.125F, 1.0F);
}

/**
 * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
 */
public boolean canPlaceBlockAt(World var1, int var2, int var3, int var4)
{
	TileEntityGel var5 = (TileEntityGel)var1.getBlockTileEntity(var2, var3, var4);

	if (var5 == null)
	{
		return false;
	}
	else
	{
		byte var6 = var5.Gelside;
		int var7;

		if (var6 == 1)
		{
			var7 = var1.getBlockId(var2, var3 - 1, var4);
			return var7 != 0 && (var7 == Block.leaves.blockID || Block.blocksList[var7].isOpaqueCube()) ? var1.getBlockMaterial(var2, var3 - 1, var4).isSolid() : false;
		}
		else if (var6 == 5)
		{
			var7 = var1.getBlockId(var2 - 1, var3, var4);
			return var7 != 0 && (var7 == Block.leaves.blockID || Block.blocksList[var7].isOpaqueCube()) ? var1.getBlockMaterial(var2 - 1, var3, var4).isSolid() : false;
		}
		else if (var6 == 4)
		{
			var7 = var1.getBlockId(var2 + 1, var3, var4);
			return var7 != 0 && (var7 == Block.leaves.blockID || Block.blocksList[var7].isOpaqueCube()) ? var1.getBlockMaterial(var2 + 1, var3, var4).isSolid() : false;
		}
		else if (var6 == 3)
		{
			var7 = var1.getBlockId(var2, var3, var4 - 1);
			return var7 != 0 && (var7 == Block.leaves.blockID || Block.blocksList[var7].isOpaqueCube()) ? var1.getBlockMaterial(var2, var3, var4 - 1).isSolid() : false;
		}
		else if (var6 == 2)
		{
			var7 = var1.getBlockId(var2, var3, var4 + 1);
			return var7 != 0 && (var7 == Block.leaves.blockID || Block.blocksList[var7].isOpaqueCube()) ? var1.getBlockMaterial(var2, var3, var4 + 1).isSolid() : false;
		}
		else if (var6 != 0)
		{
			return false;
		}
		else
		{
			var7 = var1.getBlockId(var2, var3 + 1, var4);
			return var7 != 0 && (var7 == Block.leaves.blockID || Block.blocksList[var7].isOpaqueCube()) ? var1.getBlockMaterial(var2, var3 + 1, var4).isSolid() : false;
		}
	}
}

private boolean canGelStay(World var1, int var2, int var3, int var4)
{
	if (!this.canPlaceBlockAt(var1, var2, var3, var4))
	{
		var1.setBlockWithNotify(var2, var3, var4, 0);
		return false;
	}
	else
	{
		return true;
	}
}

/**
 * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
 */
public int getBlockTextureFromSideAndMetadata(int var1, int var2)
{
	return var2;
}

/**
 * Triggered whenever an entity collides with this block (enters into the block). Args: world, x, y, z, entity
 */
public void onEntityCollidedWithBlock(World var1, int var2, int var3, int var4, Entity var5)
{
	TileEntityGel var6 = (TileEntityGel)var1.getBlockTileEntity(var2, var3, var4);
	int var7 = var1.getBlockMetadata(var2, var3, var4);

	if (var6 != null)
	{
		byte var8 = var6.Gelside;
		boolean var9;

		if (var7 == 1)
		{
			if (!var5.isSneaking())
			{
				if (var5 instanceof EntityPlayer)
				{
					if (ModLoader.getMinecraftInstance().gameSettings.keyBindForward.pressed)
					{
						var9 = false;

						if (var5.motionX < 1.5D & var5.motionX > -1.5D && var5.prevPosX < var5.posX - 0.2D | var5.prevPosX > var5.posX + 0.2D)
						{
							var5.motionX += var5.posX - var5.prevPosX;
							var9 = true;
						}

						if (var5.motionZ < 1.5D & var5.motionZ > -1.5D && var5.prevPosZ < var5.posZ - 0.2D | var5.prevPosZ > var5.posZ + 0.2D)
						{
							var5.motionZ += var5.posZ - var5.prevPosZ;
							var9 = true;
						}

						if (var9)
						{
							if (mod_Portal2Gels.alarm == 0)
							{
								var1.playSoundAtEntity(var5, "gels.enter_speed_gel_", 0.3F, 1.0F);
							}

							mod_Portal2Gels.alarm = 10;
						}
					}
				}
				else
				{
					if (var5.motionX < 1.5D & var5.motionX > -1.5D && var5.prevPosX < var5.posX - 0.2D | var5.prevPosX > var5.posX + 0.2D)
					{
						var5.motionX += var5.posX - var5.prevPosX;
					}

					if (var5.motionZ < 1.5D & var5.motionZ > -1.5D && var5.prevPosZ < var5.posZ - 0.2D | var5.prevPosZ > var5.posZ + 0.2D)
					{
						var5.motionZ += var5.posZ - var5.prevPosZ;
					}
				}
			}
		}
		else if (var7 == 0)
		{
			var9 = false;

			if (var8 == 1)
			{
				var5.fallDistance = 0.0F;

				if (var5 instanceof EntityPlayer)
				{
					if (ModLoader.getMinecraftInstance().gameSettings.keyBindJump.pressed)
					{
						var5.motionY = 1.0D;
						var9 = true;
					}
					else if (!var5.isSneaking() || !ModLoader.getMinecraftInstance().gameSettings.keyBindSneak.pressed)
					{
						if (var5.motionY < 0.0D)
						{
							var5.motionY = 0.0D - (var5.motionY - 0.30000001192092896D);
							var9 = true;
						}
						else
						{
							if (var5.motionX > 1.0D)
							{
								var5.motionY = 1.0D;
								var5.motionX = 2.0D;
								var9 = true;
							}

							if (var5.motionX < -1.0D)
							{
								var5.motionY = 1.0D;
								var5.motionX = -2.0D;
								var9 = true;
							}

							if (var5.motionZ > 1.0D)
							{
								var5.motionY = 1.0D;
								var5.motionZ = 2.0D;
								var9 = true;
							}

							if (var5.motionZ < -1.0D)
							{
								var5.motionY = 1.0D;
								var5.motionZ = -2.0D;
								var9 = true;
							}
						}
					}
				}
				else if (var5 instanceof EntityGelDrop)
				{
					if (((EntityGelDrop) var5).GelType != 3)
					{
						if (var5.motionY == 0.0D)
						{
							var5.motionY = 1.0D;
						}
						else if (var5.motionY < 0.0D)
						{
							var5.motionY = 0.0D - (var5.motionY - 0.20000000298023224D);
						}
					}
				}
				else if (var5.motionY == 0.0D)
				{
					var5.motionY = 1.0D;
				}
				else if (var5.motionY < 0.0D)
				{
					var5.motionY = 0.0D - (var5.motionY - 0.20000000298023224D);
				}
			}
			else if (var8 == 5)
			{
				if (var5 instanceof EntityPlayer)
				{
					if (ModLoader.getMinecraftInstance().gameSettings.keyBindJump.pressed)
					{
						var5.motionX = 1.0D;
						var5.motionY = 0.5D;
						var9 = true;
					}

					if (!var5.isSneaking() && !var5.onGround)
					{
						if (var5.motionX < 0.20000000298023224D)
						{
							var5.motionX = 0.0D - (var5.motionX - 0.30000001192092896D);
							var9 = true;
						}
						else
						{
							if (var5.motionZ > 1.0D)
							{
								var5.motionX = 1.0D;
								var5.motionZ = 1.5D;
								var5.motionY = 0.20000000298023224D;
								var9 = true;
							}

							if (var5.motionZ < -1.0D)
							{
								var5.motionX = 1.0D;
								var5.motionZ = -1.5D;
								var5.motionY = 0.20000000298023224D;
								var9 = true;
							}
						}
					}
				}
			}
			else if (var8 == 4)
			{
				if (var5 instanceof EntityPlayer)
				{
					if (ModLoader.getMinecraftInstance().gameSettings.keyBindJump.pressed)
					{
						var5.motionX = -1.0D;
						var5.motionY = 0.5D;
						var9 = true;
					}

					if (!var5.isSneaking() && !var5.onGround)
					{
						if (var5.motionX > 0.20000000298023224D)
						{
							var5.motionX = 0.0D - (var5.motionX - 0.30000001192092896D);
							var9 = true;
						}
						else
						{
							if (var5.motionZ > 1.0D)
							{
								var5.motionX = -1.0D;
								var5.motionZ = 1.5D;
								var5.motionY = 0.20000000298023224D;
								var9 = true;
							}

							if (var5.motionZ < -1.0D)
							{
								var5.motionX = -1.0D;
								var5.motionZ = -1.5D;
								var5.motionY = 0.20000000298023224D;
								var9 = true;
							}
						}
					}
				}
			}
			else if (var8 == 3)
			{
				if (var5 instanceof EntityPlayer)
				{
					if (ModLoader.getMinecraftInstance().gameSettings.keyBindJump.pressed)
					{
						var5.motionZ = 1.0D;
						var5.motionY = 0.5D;
						var9 = true;
					}

					if (!var5.isSneaking() && !var5.onGround)
					{
						if (var5.motionZ < 0.20000000298023224D)
						{
							var5.motionZ = 0.0D - (var5.motionZ - 0.30000001192092896D);
							var9 = true;
						}
						else
						{
							if (var5.motionX > 1.0D)
							{
								var5.motionZ = 1.0D;
								var5.motionX = 1.5D;
								var5.motionY = 0.20000000298023224D;
								var9 = true;
							}

							if (var5.motionX < -1.0D)
							{
								var5.motionZ = 1.0D;
								var5.motionX = -1.5D;
								var5.motionY = 0.20000000298023224D;
								var9 = true;
							}
						}
					}
				}
			}
			else if (var8 == 2 && var5 instanceof EntityPlayer)
			{
				if (ModLoader.getMinecraftInstance().gameSettings.keyBindJump.pressed)
				{
					var5.motionZ = -1.0D;
					var5.motionY = 0.5D;
					var9 = true;
				}

				if (!var5.isSneaking() && !var5.onGround)
				{
					if (var5.motionZ > 0.20000000298023224D)
					{
						var5.motionZ = 0.0D - (var5.motionZ - 0.30000001192092896D);
						var9 = true;
					}
					else
					{
						if (var5.motionX > 1.0D)
						{
							var5.motionZ = -1.0D;
							var5.motionX = 1.5D;
							var5.motionY = 0.20000000298023224D;
							var9 = true;
						}

						if (var5.motionX < -1.0D)
						{
							var5.motionZ = -1.0D;
							var5.motionX = -1.5D;
							var5.motionY = 0.20000000298023224D;
							var9 = true;
						}
					}
				}
			}

			if (var9)
			{
				var1.playSoundAtEntity(var5, "gels.bounce_jump_gel_", 0.3F, 1.0F);
			}
		}
	}
}

public String getTextureFile()
{
	return "/TheFLabs/FLabs.png";
}

/**
 * Returns the TileEntity used by this block.
 */
public TileEntity getBlockEntity()
{
	return new TileEntityGel();
}

@Override
public TileEntity createNewTileEntity(World var1) {
	return new TileEntityGel();
}
}

 

Thanks!

 

Edit: Sorry about the stretched post. I dunno what's happening with that...

Posted

Okay, I fixed that issue.. But I have another one. I fixed the rendering issue by blanking out setBlockBoundsBasedOnState().

Now, sometimes on save + reload, the gel doesn't work (e.g. Repulsion Gel doesn't make you bounce high when stepping on it/hitting the jump button) or it works improperly (Propulsion Gel only speeds the player up for a few moments)

 

Through debugging, stepping on repulsion gel seems to get all the way:

 

						
...
                                                else if (!var5.isSneaking())
					{
						if (var5.motionY < 0.0D)
						{
							var5.motionY = 0.0D - (var5.motionY - 0.30000001192092896D);
							var9 = true;
						}
						else
						{
                                                                // Here, but all of the if statements never pass and adds motion.
							if (var5.motionX > 1.0D)
							{
								var5.motionY = 1.0D;
								var5.motionX = 2.0D;
								var9 = true;
							}

							if (var5.motionX < -1.0D)
							{
...

 

Thanks!

 

Edit: The above information might not be correct...

Posted

I think I've found part of the problem: Entity.motionY. It gets set, but the player never ever ever EVER has motion on the y axis even if it's set to have it. Any ideas, anybody?

 

Thanks.

 

Also, the above is wrong: it runs into in the if statement (var5.motionY < 0.0D), and it passes, so it sets motionY.

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



×
×
  • Create New...

Important Information

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