Various Fixes #166

Merged
SenseiKiwi merged 19 commits from master into master 2014-06-26 23:17:34 +00:00
2 changed files with 71 additions and 52 deletions
Showing only changes of commit 4192270ef3 - Show all commits

View File

@@ -34,12 +34,13 @@ public class ItemRiftSignature extends Item
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
@Override @Override
public boolean hasEffect(ItemStack stack) public boolean hasEffect(ItemStack stack, int pass)
{ {
//Make the item glow if it has one endpoint stored //Make the item glow if it has one endpoint stored
return (stack.getItemDamage() != 0); return (stack.getItemDamage() != 0);
} }
@Override
public void registerIcons(IconRegister par1IconRegister) public void registerIcons(IconRegister par1IconRegister)
{ {
this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName().replace("item.", "")); this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName().replace("item.", ""));
@@ -60,14 +61,14 @@ public class ItemRiftSignature extends Item
return false; return false;
} }
y += 2; //Increase y by 2 to place the rift at head level //Increase y by 2 to place the rift at head level
if (!player.canPlayerEdit(x, y, z, side, stack)) int adjustedY = adjustYForSpecialBlocks(world, x, y + 2, z);
if (!player.canPlayerEdit(x, adjustedY, z, side, stack))
{ {
return true; return true;
} }
int adjustedY = adjustYForSpecialBlocks(world,x,y,z);
Point4DOrientation source = getSource(stack); Point4DOrientation source = getSource(stack);
int orientation = MathHelper.floor_double((double) ((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; int orientation = MathHelper.floor_double(((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3;
if (source != null) if (source != null)
{ {
//The link was used before and already has an endpoint stored. Create links connecting the two endpoints. //The link was used before and already has an endpoint stored. Create links connecting the two endpoints.
@@ -113,6 +114,7 @@ public class ItemRiftSignature extends Item
/** /**
* allows items to add custom lines of information to the mouseover description * allows items to add custom lines of information to the mouseover description
*/ */
@Override
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
@@ -140,26 +142,28 @@ public class ItemRiftSignature extends Item
*/ */
public static int adjustYForSpecialBlocks(World world, int x, int y, int z) public static int adjustYForSpecialBlocks(World world, int x, int y, int z)
{ {
y=y-2;//get the block the player actually clicked on int targetY = y - 2; // Get the block the player actually clicked on
Block block = Block.blocksList[world.getBlockId(x, y, z)]; Block block = Block.blocksList[world.getBlockId(x, targetY, z)];
if (block == null) if (block == null)
{ {
return y+2; return targetY + 2;
} }
if(block.isBlockReplaceable(world, x, y, z)) if (block.isBlockReplaceable(world, x, targetY, z))
{ {
return y+1;//move block placement down (-2+1) one so its directly over things like snow return targetY + 1; // Move block placement down (-2+1) one so its directly over things like snow
} }
if (block instanceof BaseDimDoor) if (block instanceof BaseDimDoor)
{ {
if(world.getBlockId(x, y-1, z)==block.blockID&&world.getBlockMetadata(x, y, z)==8) if (BaseDimDoor.isUpperDoorBlock(world.getBlockMetadata(x, targetY, z)))
{ {
return y;//move rift placement down two so its in the right place on the door. return targetY; // Move rift placement down two so its in the right place on the door.
} }
return y+1; // Move rift placement down one so its in the right place on the door.
return targetY + 1;
} }
return y+2; return targetY + 2;
} }
public static void setSource(ItemStack itemStack, int x, int y, int z, int orientation, NewDimData dimension) public static void setSource(ItemStack itemStack, int x, int y, int z, int orientation, NewDimData dimension)
{ {
NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound tag = new NBTTagCompound();
@@ -200,11 +204,12 @@ public class ItemRiftSignature extends Item
Integer orientation = tag.getInteger("orientation"); Integer orientation = tag.getInteger("orientation");
Integer dimID = tag.getInteger("linkDimID"); Integer dimID = tag.getInteger("linkDimID");
if (x != null && y != null && z != null && dimID != null) if (x != null && y != null && z != null && orientation != null && dimID != null)
{ {
return new Point4DOrientation(x, y, z, orientation, dimID); return new Point4DOrientation(x, y, z, orientation, dimID);
} }
} }
// Mark the item as uninitialized if its source couldn't be read
itemStack.setItemDamage(0); itemStack.setItemDamage(0);
} }
return null; return null;

View File

@@ -14,7 +14,6 @@ import StevenDimDoors.mod_pocketDim.core.DimLink;
import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.LinkTypes;
import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.NewDimData;
import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.core.PocketManager;
import StevenDimDoors.mod_pocketDim.util.Point4D;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@@ -40,22 +39,42 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature
return false; return false;
} }
// We don't check for replaceable blocks. The user can deal with that. <_< // Adjust Y so the rift is at head level, depending on the presence of certain blocks
y += 2; //Increase y by 2 to place the rift at head level int adjustedY = adjustYForSpecialBlocks(world, x, y + 2, z);
if (!player.canPlayerEdit(x, y, z, side, stack)) if (!player.canPlayerEdit(x, adjustedY, z, side, stack))
{ {
return true; return true;
} }
Point4DOrientation source = getSource(stack); Point4DOrientation source = getSource(stack);
int adjustedY = adjustYForSpecialBlocks(world,x,y,z);
// Check if the Stabilized Rift Signature has been initialized // Check if the Stabilized Rift Signature has been initialized
int orientation = MathHelper.floor_double((player.rotationYaw + 180.0F) * 4.0F / 360.0F - 0.5D) & 3; int orientation = MathHelper.floor_double((player.rotationYaw + 180.0F) * 4.0F / 360.0F - 0.5D) & 3;
if (source != null) if (source != null)
{ {
// Yes, it's initialized. Check if the player is in creative // Yes, it's initialized.
DimLink link;
DimLink reverse;
NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension());
NewDimData destinationDimension = PocketManager.getDimensionData(world);
// Check whether the SRS is being used to restore one of its previous
// link pairs. In other words, the SRS is being used on a location
// that already has a link pointing to the SRS's source, with the
// intention of overwriting the source-side link to point there.
// Those benign redirection operations will be handled for free.
if (false) //TODO Add proper check!
{
// Only the source-to-destination link is needed.
link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.NORMAL, source.getOrientation());
destinationDimension.setDestination(link, x, adjustedY, z);
}
else
{
// Check if the player is in creative mode,
// or if the player can pay with an Ender Pearl to create a rift. // or if the player can pay with an Ender Pearl to create a rift.
if (!player.capabilities.isCreativeMode && !player.inventory.hasItem(Item.enderPearl.itemID)) if (!player.capabilities.isCreativeMode &&
!player.inventory.consumeInventoryItem(Item.enderPearl.itemID))
{ {
mod_pocketDim.sendChat(player, "You don't have any Ender Pearls!"); mod_pocketDim.sendChat(player, "You don't have any Ender Pearls!");
// I won't do this, but this is the chance to localize chat // I won't do this, but this is the chance to localize chat
@@ -64,11 +83,9 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature
return true; return true;
} }
//The link was used before and already has an endpoint stored. Create links connecting the two endpoints. // Create links connecting the two endpoints.
NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension()); link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.NORMAL, source.getOrientation());
NewDimData destinationDimension = PocketManager.getDimensionData(world); reverse = destinationDimension.createLink(x, adjustedY, z, LinkTypes.NORMAL, orientation);
DimLink link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.NORMAL,source.getOrientation());
DimLink reverse = destinationDimension.createLink(x, adjustedY, z, LinkTypes.NORMAL,orientation);
destinationDimension.setDestination(link, x, adjustedY, z); destinationDimension.setDestination(link, x, adjustedY, z);
sourceDimension.setDestination(reverse, source.getX(), source.getY(), source.getZ()); sourceDimension.setDestination(reverse, source.getX(), source.getY(), source.getZ());
@@ -77,6 +94,7 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature
{ {
world.setBlock(x, adjustedY, z, mod_pocketDim.blockRift.blockID); world.setBlock(x, adjustedY, z, mod_pocketDim.blockRift.blockID);
} }
}
// Try placing a rift at the source point, but check if its world is loaded first // Try placing a rift at the source point, but check if its world is loaded first
World sourceWorld = DimensionManager.getWorld(sourceDimension.id()); World sourceWorld = DimensionManager.getWorld(sourceDimension.id());
@@ -86,10 +104,6 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature
sourceWorld.setBlock(source.getX(), source.getY(), source.getZ(), mod_pocketDim.blockRift.blockID); sourceWorld.setBlock(source.getX(), source.getY(), source.getZ(), mod_pocketDim.blockRift.blockID);
} }
if (!player.capabilities.isCreativeMode)
{
player.inventory.consumeInventoryItem(Item.enderPearl.itemID);
}
mod_pocketDim.sendChat(player, "Rift Created"); mod_pocketDim.sendChat(player, "Rift Created");
world.playSoundAtEntity(player, "mods.DimDoors.sfx.riftEnd", 0.6f, 1); world.playSoundAtEntity(player, "mods.DimDoors.sfx.riftEnd", 0.6f, 1);
} }