Added lock removal ability to keys
also fixed a network bug
This commit is contained in:
parent
96d84ed2fa
commit
eff8379325
3 changed files with 99 additions and 2 deletions
|
@ -124,6 +124,14 @@ public abstract class NewDimData implements IPackable<PackedDimData>
|
|||
return true;
|
||||
}
|
||||
|
||||
public void removeLock(ItemStack itemStack, InnerDimLink link)
|
||||
{
|
||||
if(link.doesKeyUnlock(itemStack))
|
||||
{
|
||||
link.lock = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
protected static Random random = new Random();
|
||||
|
||||
|
@ -601,6 +609,13 @@ public abstract class NewDimData implements IPackable<PackedDimData>
|
|||
innerLink.createLock(item, lockKey);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
public void removeLock(DimLink link, ItemStack item)
|
||||
{
|
||||
InnerDimLink innerLink = (InnerDimLink)link;
|
||||
innerLink.removeLock(item, innerLink);
|
||||
modified = true;
|
||||
}
|
||||
|
||||
public DimLink getRandomLink()
|
||||
{
|
||||
|
|
|
@ -8,11 +8,14 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.IconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumAction;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.EnumMovingObjectType;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.World;
|
||||
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
||||
|
@ -24,6 +27,7 @@ import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData;
|
|||
|
||||
public class ItemDDKey extends Item
|
||||
{
|
||||
public static final int TIME_TO_UNLOCK = 50;
|
||||
public ItemDDKey(int itemID)
|
||||
{
|
||||
super(itemID);
|
||||
|
@ -63,8 +67,10 @@ public class ItemDDKey extends Item
|
|||
}
|
||||
|
||||
|
||||
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
|
||||
public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
|
||||
{
|
||||
player.setItemInUse(itemStack, this.getMaxItemUseDuration(itemStack));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -75,6 +81,11 @@ public class ItemDDKey extends Item
|
|||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(player.getItemInUse() != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
int blockID = world.getBlockId(x, y, z);
|
||||
//make sure we are dealing with a door
|
||||
if (!(Block.blocksList[blockID] instanceof IDimDoor))
|
||||
|
@ -104,6 +115,7 @@ public class ItemDDKey extends Item
|
|||
}
|
||||
PocketManager.getDimensionData(world).lock(link, !link.getLockState());
|
||||
PocketManager.getLinkWatcher().update(new ClientLinkData(link));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -121,7 +133,77 @@ public class ItemDDKey extends Item
|
|||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Handle removal of locks here
|
||||
*/
|
||||
@Override
|
||||
public void onPlayerStoppedUsing(ItemStack itemStack, World world, EntityPlayer player, int heldTime)
|
||||
{
|
||||
int j = this.getMaxItemUseDuration(itemStack) - heldTime;
|
||||
if(j>= TIME_TO_UNLOCK)
|
||||
{
|
||||
MovingObjectPosition pos = getMovingObjectPositionFromPlayer(player.worldObj, player, true);
|
||||
if(pos!=null&&pos.typeOfHit == EnumMovingObjectType.TILE)
|
||||
{
|
||||
DimLink link = PocketManager.getLink(pos.blockX, pos.blockY, pos.blockZ, player.worldObj);
|
||||
if(link!=null && link.hasLock())
|
||||
{
|
||||
if (link.doesKeyUnlock(itemStack)&& !world.isRemote)
|
||||
{
|
||||
PocketManager.getDimensionData(world).removeLock(link, itemStack);
|
||||
world.playSoundAtEntity(player, mod_pocketDim.modid + ":keyUnlock", 1F, 1F);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
player.clearItemInUse();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Raytrace to make sure we are still looking at the right block
|
||||
*/
|
||||
@Override
|
||||
public void onUsingItemTick(ItemStack stack, EntityPlayer player, int count)
|
||||
{
|
||||
|
||||
//no need to check every tick
|
||||
if(count%10 == 0)
|
||||
{
|
||||
MovingObjectPosition pos = getMovingObjectPositionFromPlayer(player.worldObj, player, true);
|
||||
if(pos!=null&&pos.typeOfHit == EnumMovingObjectType.TILE)
|
||||
{
|
||||
DimLink link = PocketManager.getLink(pos.blockX, pos.blockY, pos.blockZ, player.worldObj);
|
||||
if(link!=null && link.hasLock())
|
||||
{
|
||||
if (link.doesKeyUnlock(stack))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
player.clearItemInUse();
|
||||
}
|
||||
}
|
||||
|
||||
public EnumAction getItemUseAction(ItemStack par1ItemStack)
|
||||
{
|
||||
return EnumAction.bow;
|
||||
}
|
||||
|
||||
public ItemStack onEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
|
||||
{
|
||||
return par1ItemStack;
|
||||
}
|
||||
|
||||
|
||||
public int getMaxItemUseDuration(ItemStack par1ItemStack)
|
||||
{
|
||||
return 72000;
|
||||
}
|
||||
|
||||
public String getItemStackDisplayName(ItemStack par1ItemStack)
|
||||
{
|
||||
|
|
|
@ -39,7 +39,7 @@ public class ClientLinkData
|
|||
public void write(DataOutputStream output) throws IOException
|
||||
{
|
||||
Point4D.write(point, output);
|
||||
output.write(this.type.index);
|
||||
output.writeInt(this.type.index);
|
||||
boolean hasLock = this.lock != null;
|
||||
output.writeBoolean(hasLock);
|
||||
|
||||
|
|
Loading…
Reference in a new issue