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)
@Override
public boolean hasEffect(ItemStack stack)
public boolean hasEffect(ItemStack stack, int pass)
{
//Make the item glow if it has one endpoint stored
return (stack.getItemDamage() != 0);
}
@Override
public void registerIcons(IconRegister par1IconRegister)
{
this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName().replace("item.", ""));
@@ -60,14 +61,14 @@ public class ItemRiftSignature extends Item
return false;
}
y += 2; //Increase y by 2 to place the rift at head level
if (!player.canPlayerEdit(x, y, z, side, stack))
//Increase y by 2 to place the rift at head level
int adjustedY = adjustYForSpecialBlocks(world, x, y + 2, z);
if (!player.canPlayerEdit(x, adjustedY, z, side, stack))
{
return true;
}
int adjustedY = adjustYForSpecialBlocks(world,x,y,z);
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)
{
//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
*/
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
@SideOnly(Side.CLIENT)
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)
{
y=y-2;//get the block the player actually clicked on
Block block = Block.blocksList[world.getBlockId(x, y, z)];
if(block==null)
int targetY = y - 2; // Get the block the player actually clicked on
Block block = Block.blocksList[world.getBlockId(x, targetY, z)];
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)
{
NBTTagCompound tag = new NBTTagCompound();
@@ -200,11 +204,12 @@ public class ItemRiftSignature extends Item
Integer orientation = tag.getInteger("orientation");
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);
}
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.NewDimData;
import StevenDimDoors.mod_pocketDim.core.PocketManager;
import StevenDimDoors.mod_pocketDim.util.Point4D;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -40,62 +39,77 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature
return false;
}
// 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, side, stack))
// Adjust Y so the rift is at head level, depending on the presence of certain blocks
int adjustedY = adjustYForSpecialBlocks(world, x, y + 2, z);
if (!player.canPlayerEdit(x, adjustedY, z, side, stack))
{
return true;
}
Point4DOrientation source = getSource(stack);
int adjustedY = adjustYForSpecialBlocks(world,x,y,z);
// 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;
if (source != null)
{
// Yes, it's initialized. Check if the player is in creative
// or if the player can pay with an Ender Pearl to create a rift.
if (!player.capabilities.isCreativeMode && !player.inventory.hasItem(Item.enderPearl.itemID))
{
mod_pocketDim.sendChat(player, "You don't have any Ender Pearls!");
// I won't do this, but this is the chance to localize chat
// messages sent to the player; look at ChatMessageComponent
// and how MFR does it with items like the safari net launcher
return true;
}
//The link was used before and already has an endpoint stored. Create links connecting the two endpoints.
// Yes, it's initialized.
DimLink link;
DimLink reverse;
NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension());
NewDimData destinationDimension = PocketManager.getDimensionData(world);
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);
sourceDimension.setDestination(reverse, source.getX(), source.getY(), source.getZ());
//Try placing a rift at the destination point
if (!mod_pocketDim.blockRift.isBlockImmune(world, x, adjustedY, z))
// 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!
{
world.setBlock(x, adjustedY, z, mod_pocketDim.blockRift.blockID);
// 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.
if (!player.capabilities.isCreativeMode &&
!player.inventory.consumeInventoryItem(Item.enderPearl.itemID))
{
mod_pocketDim.sendChat(player, "You don't have any Ender Pearls!");
// I won't do this, but this is the chance to localize chat
// messages sent to the player; look at ChatMessageComponent
// and how MFR does it with items like the safari net launcher
return true;
}
// Create links connecting the two endpoints.
link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.NORMAL, source.getOrientation());
reverse = destinationDimension.createLink(x, adjustedY, z, LinkTypes.NORMAL, orientation);
destinationDimension.setDestination(link, x, adjustedY, z);
sourceDimension.setDestination(reverse, source.getX(), source.getY(), source.getZ());
// Try placing a rift at the destination point
if (!mod_pocketDim.blockRift.isBlockImmune(world, x, adjustedY, z))
{
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());
if (sourceWorld != null &&
!mod_pocketDim.blockRift.isBlockImmune(sourceWorld, source.getX(), source.getY(), source.getZ()))
{
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");
world.playSoundAtEntity(player,"mods.DimDoors.sfx.riftEnd", 0.6f, 1);
mod_pocketDim.sendChat(player, "Rift Created");
world.playSoundAtEntity(player, "mods.DimDoors.sfx.riftEnd", 0.6f, 1);
}
else
{
//The link signature has not been used. Store its current target as the first location.
// The link signature has not been used. Store its current target as the first location.
setSource(stack, x, adjustedY, z, orientation, PocketManager.getDimensionData(world));
mod_pocketDim.sendChat(player,"Location Stored in Stabilized Rift Signature");
world.playSoundAtEntity(player,"mods.DimDoors.sfx.riftStart", 0.6f, 1);