Nearly finished BaseItemDoor, need to find placeDoorBlock method.

This commit is contained in:
Michael Zanga 2016-07-29 16:44:30 -04:00
parent cecdc7c12c
commit 0756e94e01

View file

@ -9,14 +9,11 @@ import com.zixiken.dimdoors.config.DDProperties;
import com.zixiken.dimdoors.core.DimLink; import com.zixiken.dimdoors.core.DimLink;
import com.zixiken.dimdoors.core.PocketManager; import com.zixiken.dimdoors.core.PocketManager;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemDoor; import net.minecraft.item.ItemDoor;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper; import net.minecraft.util.*;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World; import net.minecraft.world.World;
import com.zixiken.dimdoors.tileentities.TileEntityDimDoor; import com.zixiken.dimdoors.tileentities.TileEntityDimDoor;
@ -24,7 +21,7 @@ public abstract class BaseItemDoor extends ItemDoor {
// Maps non-dimensional door items to their corresponding dimensional door item // Maps non-dimensional door items to their corresponding dimensional door item
// Also maps dimensional door items to themselves for simplicity // Also maps dimensional door items to themselves for simplicity
private static HashMap<ItemDoor, BaseItemDoor> doorItemMapping = new HashMap<ItemDoor, BaseItemDoor>(); private static HashMap<ItemDoor, BaseItemDoor> doorItemMapping = new HashMap<ItemDoor, BaseItemDoor>();
private static DDProperties properties = null; private static DDProperties properties;
/** /**
* door represents the non-dimensional door this item is associated with. Leave null for none. * door represents the non-dimensional door this item is associated with. Leave null for none.
@ -40,20 +37,11 @@ public abstract class BaseItemDoor extends ItemDoor {
doorItemMapping.put(this, this); doorItemMapping.put(this, this);
if (vanillaDoor != null) if (vanillaDoor != null)
{
doorItemMapping.put(vanillaDoor, this); doorItemMapping.put(vanillaDoor, this);
} }
}
@Override @Override
public void registerIcons(IIconRegister par1IconRegister) public abstract void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced);
{
this.itemIcon = par1IconRegister.registerIcon(DimDoors.modid + ":" + this.getUnlocalizedName().replace("item.", ""));
}
@SuppressWarnings({ "rawtypes" })
@Override
public abstract void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4);
/** /**
* Overriden in subclasses to specify which door block that door item will * Overriden in subclasses to specify which door block that door item will
@ -68,10 +56,8 @@ public abstract class BaseItemDoor extends ItemDoor {
* dimensional doors, we handle this in the EventHookContainer * dimensional doors, we handle this in the EventHookContainer
*/ */
@Override @Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos,
{ EnumFacing side, float hitX, float hitY, float hitZ) {return false;}
return false;
}
/** /**
* Tries to place a door as a dimensional door * Tries to place a door as a dimensional door
@ -85,25 +71,18 @@ public abstract class BaseItemDoor extends ItemDoor {
* @param side * @param side
* @return * @return
*/ */
public static boolean tryToPlaceDoor(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side) public static boolean tryToPlaceDoor(ItemStack stack, EntityPlayer player, World world,
{ BlockPos pos, EnumFacing side) {
if (world.isRemote) if (world.isRemote) return false;
{
return false;
}
// Retrieve the actual door type that we want to use here. // Retrieve the actual door type that we want to use here.
// It's okay if stack isn't an ItemDoor. In that case, the lookup will // It's okay if stack isn't an ItemDoor. In that case, the lookup will
// return null, just as if the item was an unrecognized door type. // return null, just as if the item was an unrecognized door type.
BaseItemDoor mappedItem = doorItemMapping.get(stack.getItem()); BaseItemDoor mappedItem = doorItemMapping.get(stack.getItem());
if (mappedItem == null) if (mappedItem == null) return false;
{
return false;
}
BaseDimDoor doorBlock = mappedItem.getDoorBlock(); BaseDimDoor doorBlock = mappedItem.getDoorBlock();
if (BaseItemDoor.placeDoorOnBlock(doorBlock, stack, player, world, x, y, z, side)) if (BaseItemDoor.placeDoorOnBlock(doorBlock, stack, player, world, pos, side)) return true;
{
return true;
}
return BaseItemDoor.placeDoorOnRift(doorBlock, world, player, stack); return BaseItemDoor.placeDoorOnRift(doorBlock, world, player, stack);
} }
@ -119,36 +98,22 @@ public abstract class BaseItemDoor extends ItemDoor {
* @param side * @param side
* @return * @return
*/ */
public static boolean placeDoorOnBlock(Block doorBlock, ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side) public static boolean placeDoorOnBlock(Block doorBlock, ItemStack stack, EntityPlayer player,
{ World world, BlockPos pos, EnumFacing side) {
if (world.isRemote) if (world.isRemote) return false;
{
return false;
}
// Only place doors on top of blocks - check if we're targeting the top // Only place doors on top of blocks - check if we're targeting the top
// side // side
if (side == 1 && !world.isRemote) if (side == EnumFacing.UP) {
{ Block block = world.getBlockState(pos).getBlock();
Block block = world.getBlock(x, y, z); if (!block.isAir(world, pos) && !block.isReplaceable(world, pos)) pos = pos.up();
if (!block.isAir(world, x, y, z))
{
if (!block.isReplaceable(world, x, y, z))
{
y++;
}
}
if (canPlace(world, x, y, z) && canPlace(world, x, y + 1, z) && player.canPlayerEdit(x, y, z, side, stack) BlockPos upPos = pos.up();
&& (player.canPlayerEdit(x, y + 1, z, side, stack) && stack.stackSize > 0) if (canPlace(world, pos) && canPlace(world, upPos) && player.canPlayerEdit(pos, side, stack)
&&((stack.getItem() instanceof BaseItemDoor) || PocketManager.getLink(x, y + 1, z, world) != null)) && (player.canPlayerEdit(upPos, side, stack) && stack.stackSize > 0)
{ && ((stack.getItem() instanceof BaseItemDoor) || PocketManager.getLink(upPos, world) != null)) {
int orientation = MathHelper.floor_double((player.rotationYaw + 180.0F) * 4.0F / 360.0F - 0.5D) & 3; placeDoorBlock(world, pos, EnumFacing.fromAngle(player.rotationYaw), doorBlock);
placeDoorBlock(world, x, y, z, orientation, doorBlock); if (!player.capabilities.isCreativeMode) stack.stackSize--;
if (!player.capabilities.isCreativeMode)
{
stack.stackSize--;
}
return true; return true;
} }
} }
@ -164,53 +129,35 @@ public abstract class BaseItemDoor extends ItemDoor {
* @param stack * @param stack
* @return * @return
*/ */
public static boolean placeDoorOnRift(Block doorBlock, World world, EntityPlayer player, ItemStack stack) public static boolean placeDoorOnRift(Block doorBlock, World world, EntityPlayer player, ItemStack stack) {
{ if (world.isRemote) return false;
if (world.isRemote)
{
return false;
}
MovingObjectPosition hit = BaseItemDoor.doRayTrace(player.worldObj, player, true); MovingObjectPosition hit = BaseItemDoor.doRayTrace(world, player, true);
if (hit != null) if (hit != null) {
{ BlockPos pos = hit.getBlockPos();
if (world.getBlock(hit.blockX, hit.blockY, hit.blockZ) == DimDoors.blockRift) if (world.getBlockState(pos).getBlock() == DimDoors.blockRift) {
{ DimLink link = PocketManager.getLink(pos, world.provider.getDimensionId());
DimLink link = PocketManager.getLink(hit.blockX, hit.blockY, hit.blockZ, world.provider.dimensionId); if (link != null) {
if (link != null) BlockPos downPos = pos.down();
{ if (player.canPlayerEdit(pos, hit.sideHit, stack) &&
int x = hit.blockX; player.canPlayerEdit(downPos, hit.sideHit, stack) &&
int y = hit.blockY; canPlace(world, pos) && canPlace(world, downPos)) {
int z = hit.blockZ; placeDoorBlock(world, downPos, EnumFacing.fromAngle(player.rotationYaw), doorBlock);
if (player.canPlayerEdit(x, y, z, hit.sideHit, stack) && player.canPlayerEdit(x, y - 1, z, hit.sideHit, stack))
{
if (canPlace(world, x, y, z) && canPlace(world, x, y - 1, z))
{
int orientation = MathHelper.floor_double(((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3;
placeDoorBlock(world, x, y - 1, z, orientation, doorBlock);
if (!(stack.getItem() instanceof BaseItemDoor)) if (!(stack.getItem() instanceof BaseItemDoor))
{ ((TileEntityDimDoor) world.getTileEntity(pos)).hasGennedPair = true;
((TileEntityDimDoor) world.getTileEntity(x, y, z)).hasGennedPair = true; if (!player.capabilities.isCreativeMode) stack.stackSize--;
}
if (!player.capabilities.isCreativeMode)
{
stack.stackSize--;
}
return true; return true;
} }
} }
} }
} }
}
return false; return false;
} }
public static boolean canPlace(World world, int x, int y, int z) public static boolean canPlace(World world, BlockPos pos) {
{ Block block = world.getBlockState(pos).getBlock();
Block block = world.getBlock(x, y, z);
return (block == DimDoors.blockRift || block.isAir(world, x, y, z) || block.getMaterial().isReplaceable()); return (block == DimDoors.blockRift || block.isAir(world, pos) || block.getMaterial().isReplaceable());
} }
/** /**
@ -222,28 +169,23 @@ public abstract class BaseItemDoor extends ItemDoor {
* @param par3 * @param par3
* @return * @return
*/ */
protected static MovingObjectPosition doRayTrace(World par1World, EntityPlayer par2EntityPlayer, boolean par3) protected static MovingObjectPosition doRayTrace(World worldIn, EntityPlayer playerIn, boolean useLiquids) {
{ float f = playerIn.rotationPitch;
float f = 1.0F; float f1 = playerIn.rotationYaw;
float f1 = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * f; double d0 = playerIn.posX;
float f2 = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * f; double d1 = playerIn.posY + (double)playerIn.getEyeHeight();
double d0 = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * (double) f; double d2 = playerIn.posZ;
double d1 = par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * (double) f Vec3 vec3 = new Vec3(d0, d1, d2);
+ (double) (par1World.isRemote ? par2EntityPlayer.getEyeHeight() - par2EntityPlayer.getDefaultEyeHeight() : par2EntityPlayer.getEyeHeight()); float f2 = MathHelper.cos(-f1 * 0.017453292F - (float)Math.PI);
double d2 = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * (double) f; float f3 = MathHelper.sin(-f1 * 0.017453292F - (float)Math.PI);
Vec3 vec3 = Vec3.createVectorHelper (d0, d1, d2); float f4 = -MathHelper.cos(-f * 0.017453292F);
float f3 = MathHelper.cos(-f2 * 0.017453292F - (float) Math.PI); float f5 = MathHelper.sin(-f * 0.017453292F);
float f4 = MathHelper.sin(-f2 * 0.017453292F - (float) Math.PI); float f6 = f3 * f4;
float f5 = -MathHelper.cos(-f1 * 0.017453292F); float f7 = f2 * f4;
float f6 = MathHelper.sin(-f1 * 0.017453292F);
float f7 = f4 * f5;
float f8 = f3 * f5;
double d3 = 5.0D; double d3 = 5.0D;
if (par2EntityPlayer instanceof EntityPlayerMP) if (playerIn instanceof EntityPlayerMP)
{ d3 = ((EntityPlayerMP)playerIn).theItemInWorldManager.getBlockReachDistance();
d3 = ((EntityPlayerMP) par2EntityPlayer).theItemInWorldManager.getBlockReachDistance(); Vec3 vec31 = vec3.addVector((double)f6 * d3, (double)f5 * d3, (double)f7 * d3);
} return worldIn.rayTraceBlocks(vec3, vec31, useLiquids, !useLiquids, false);
Vec3 vec31 = vec3.addVector((double) f7 * d3, (double) f6 * d3, (double) f8 * d3);
return par1World.rayTraceBlocks(vec3, vec31, par3);
} }
} }