Cleaned Up Code

Changed calls to canPlayerEdit() to pass hit.sideHit data with the
request. Also renamed several variables to make the code clearer.
Removed a custom implementation of the ray tracing call in BaseItemDoor
- we can use the built-in call from Minecraft there.
This commit is contained in:
SenseiKiwi 2013-09-05 11:36:59 -04:00
parent 22b7ed147a
commit 1138f6733e
5 changed files with 19 additions and 48 deletions

View file

@ -6,12 +6,10 @@ import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemDoor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.DDProperties;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
@ -41,12 +39,12 @@ public abstract class BaseItemDoor extends ItemDoor
public abstract void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4);
@Override
public abstract boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10);
public abstract boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ);
public static boolean tryItemUse(Block doorBlock, ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int par7, boolean requireLink, boolean reduceStack)
public static boolean tryItemUse(Block doorBlock, ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, boolean requireLink, boolean reduceStack)
{
//FIXME: Without any sort of this documentation, this condition is like magic -_- ~SenseiKiwi
if (par7 == 1 && !world.isRemote)
// Only place doors on top of blocks - check if we're targeting the top side
if (side == 1 && !world.isRemote)
{
int blockID = world.getBlockId(x, y, z);
if (blockID != 0)
@ -58,7 +56,7 @@ public abstract class BaseItemDoor extends ItemDoor
}
if (canPlace(world, x, y, z) && canPlace(world, x, y + 1, z) &&
player.canPlayerEdit(x, y, z, par7, stack) && player.canPlayerEdit(x, y + 1, z, par7, stack) &&
player.canPlayerEdit(x, y, z, side, stack) && player.canPlayerEdit(x, y + 1, z, side, stack) &&
(!requireLink || PocketManager.getLink(x, y + 1, z, world) != null))
{
int orientation = MathHelper.floor_double((double) ((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3;
@ -74,31 +72,6 @@ public abstract class BaseItemDoor extends ItemDoor
return false;
}
@Override
public final MovingObjectPosition getMovingObjectPositionFromPlayer(World par1World, EntityPlayer par2EntityPlayer, boolean par3)
{
float var4 = 1.0F;
float var5 = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * var4;
float var6 = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * var4;
double var7 = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * (double)var4;
double var9 = par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * (double)var4 + 1.62D - (double)par2EntityPlayer.yOffset;
double var11 = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * (double)var4;
Vec3 var13 = par1World.getWorldVec3Pool().getVecFromPool(var7, var9, var11);
float var14 = MathHelper.cos(-var6 * 0.017453292F - (float)Math.PI);
float var15 = MathHelper.sin(-var6 * 0.017453292F - (float)Math.PI);
float var16 = -MathHelper.cos(-var5 * 0.017453292F);
float var17 = MathHelper.sin(-var5 * 0.017453292F);
float var18 = var15 * var16;
float var20 = var14 * var16;
double var21 = 5.0D;
if (par2EntityPlayer instanceof EntityPlayerMP)
{
var21 = 4;
}
Vec3 var23 = var13.addVector((double) var18 * var21, (double)var17 * var21, (double)var20 * var21);
return par1World.rayTraceBlocks_do_do(var13, var23, true, false);
}
@Override
public abstract ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player);
@ -109,7 +82,7 @@ public abstract class BaseItemDoor extends ItemDoor
return false;
}
MovingObjectPosition hit = this.getMovingObjectPositionFromPlayer(player.worldObj, player, false);
MovingObjectPosition hit = this.getMovingObjectPositionFromPlayer(player.worldObj, player, true);
if (hit != null)
{
if (world.getBlockId(hit.blockX, hit.blockY, hit.blockZ) == properties.RiftBlockID)
@ -120,9 +93,8 @@ public abstract class BaseItemDoor extends ItemDoor
int x = hit.blockX;
int y = hit.blockY;
int z = hit.blockZ;
int par7 = 0;
if (player.canPlayerEdit(x, y, z, par7, item) && player.canPlayerEdit(x, y - 1, z, par7, item))
if (player.canPlayerEdit(x, y, z, hit.sideHit, item) && player.canPlayerEdit(x, y - 1, z, hit.sideHit, item))
{
if (canPlace(world, x, y, z) && canPlace(world, x, y - 1, z))
{

View file

@ -224,20 +224,19 @@ public class ItemRiftBlade extends ItemSword
{
if (PocketManager.getLink(hit.blockX, hit.blockY, hit.blockZ, world) != null)
{
Block var11 = mod_pocketDim.transientDoor;
int par4 = hit.blockX;
int par5 = hit.blockY;
int par6 = hit.blockZ;
int par7 = 0;
Block block = mod_pocketDim.transientDoor;
int x = hit.blockX;
int y = hit.blockY;
int z = hit.blockZ;
if (player.canPlayerEdit(par4, par5, par6, par7, stack) && player.canPlayerEdit(par4, par5 + 1, par6, par7, stack)&&!world.isRemote)
if (player.canPlayerEdit(x, y, z, hit.sideHit, stack) && player.canPlayerEdit(x, y + 1, z, hit.sideHit, stack) && !world.isRemote)
{
int var12 = MathHelper.floor_double((double)((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3;
int orientation = MathHelper.floor_double((double)((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3;
if (BaseItemDoor.canPlace(world, par4, par5, par6) &&
BaseItemDoor.canPlace(world, par4, par5 - 1, par6))
if (BaseItemDoor.canPlace(world, x, y, z) &&
BaseItemDoor.canPlace(world, x, y - 1, z))
{
ItemDimensionalDoor.placeDoorBlock(world, par4, par5 - 1, par6, var12, var11);
ItemDimensionalDoor.placeDoorBlock(world, x, y - 1, z, orientation, block);
player.worldObj.playSoundAtEntity(player,"mods.DimDoors.sfx.riftDoor", 0.6f, 1);
stack.damageItem(10, player);
}

View file

@ -60,7 +60,7 @@ public class ItemRiftSignature extends Item
//We don't check for replaceable blocks. The user can deal with that. <_<
y += 2; //Increase y by 2 to place the rift at head level
if (!player.canPlayerEdit(x, y, z, 0, stack))
if (!player.canPlayerEdit(x, y, z, side, stack))
{
return true;
}

View file

@ -40,7 +40,7 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature
// We don't check for replaceable blocks. The user can deal with that. <_<
y += 2; //Increase y by 2 to place the rift at head level
if (!player.canPlayerEdit(x, y, z, 0, stack))
if (!player.canPlayerEdit(x, y, z, side, stack))
{
return true;
}

View file

@ -56,7 +56,7 @@ public class itemRiftRemover extends Item
NewDimData dimension = PocketManager.getDimensionData(world);
DimLink link = dimension.getLink(hx, hy, hz);
if (world.getBlockId(hx, hy, hz) == mod_pocketDim.blockRift.blockID && link != null &&
player.canPlayerEdit(hx, hy, hz, 0, stack))
player.canPlayerEdit(hx, hy, hz, hit.sideHit, stack))
{
// Invoke onPlayerRightClick()
FMLClientHandler.instance().getClient().playerController.onPlayerRightClick(