lock tweaks

Changed how locks are modified so all modifications occur through
NewDimData
This commit is contained in:
StevenRS11 2014-05-29 19:04:23 -04:00
parent 77241e6f90
commit e8fa928c50
5 changed files with 55 additions and 41 deletions

View file

@ -40,7 +40,7 @@ public class DDLock
* otherwise returns true
* @param flag
*/
public void lock(boolean flag)
protected void lock(boolean flag)
{
this.isLocked = flag;
}
@ -157,7 +157,7 @@ public class DDLock
public static DDLock createLock(ItemStack itemStack, int lockKey2)
protected static DDLock createLock(ItemStack itemStack, int lockKey2)
{
itemStack.getTagCompound().setBoolean("HasCreatedLock", true);
DDLock.setKeys(itemStack, new int[]{lockKey2});

View file

@ -10,7 +10,7 @@ public abstract class DimLink
{
protected Point4D point;
protected int orientation;
private DDLock lock;
protected DDLock lock;
protected DimLink parent;
protected LinkTail tail;
protected List<DimLink> children;
@ -151,36 +151,9 @@ public abstract class DimLink
{
return this.hasLock()&&this.lock.isLocked();
}
public DDLock getLock()
{
PocketManager.getDimensionData(this.source().getDimension()).flagModified();
return this.lock;
}
/**
* only use this on the client to update errything
* @param lock
*/
public void setLock(DDLock lock)
{
PocketManager.getDimensionData(this.source().getDimension()).flagModified();
this.lock = lock;
}
/**
* create a lock from a key. Returns false if this door already has a lock, or if they has already locked a door
* @param itemStack
* @return
*/
public boolean createLock(ItemStack itemStack, int lockKey)
{
if(this.hasLock()||DDLock.hasCreatedLock(itemStack))
{
return false;
}
this.lock = DDLock.createLock(itemStack, lockKey);
PocketManager.getDimensionData(this.source().getDimension()).flagModified();
return true;
}
}

View file

@ -7,6 +7,7 @@ import java.util.Random;
import java.util.TreeMap;
import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.Point3D;
import StevenDimDoors.mod_pocketDim.config.DDProperties;
@ -98,6 +99,31 @@ public abstract class NewDimData implements IPackable<PackedDimData>
//Set new orientation
this.orientation=orientation;
}
/**
* only use this on the client to update errything
* @param lock
*/
public void setLock(DDLock lock)
{
this.lock = lock;
}
/**
* create a lock from a key. Returns false if this door already has a lock, or if they has already locked a door
* @param itemStack
* @return
*/
public boolean createLock(ItemStack itemStack, int lockKey)
{
if(this.hasLock()||DDLock.hasCreatedLock(itemStack))
{
return false;
}
this.lock = DDLock.createLock(itemStack, lockKey);
return true;
}
}
protected static Random random = new Random();
@ -561,6 +587,27 @@ public abstract class NewDimData implements IPackable<PackedDimData>
link.setDestination(x, y, z, this);
this.modified = true;
}
public void lock(DimLink link, boolean locked)
{
InnerDimLink innerLink = (InnerDimLink)link;
innerLink.lock.lock(locked);
modified = true;
}
public void setLock(DimLink link, DDLock lock)
{
InnerDimLink innerLink = (InnerDimLink)link;
innerLink.setLock(lock);
modified = true;
}
public void createLock(DimLink link, ItemStack item, int lockKey)
{
InnerDimLink innerLink = (InnerDimLink)link;
innerLink.createLock(item, lockKey);
modified = true;
}
public DimLink getRandomLink()
{
@ -583,11 +630,6 @@ public abstract class NewDimData implements IPackable<PackedDimData>
return modified;
}
public void flagModified()
{
modified = true;
}
public void clearModified()
{
this.modified = false;
@ -655,13 +697,12 @@ public abstract class NewDimData implements IPackable<PackedDimData>
children.add(childLink.source().toPoint3D());
}
PackedLinkTail tail = new PackedLinkTail(link.tail.getDestination(),link.tail.getLinkType());
Links.add(new PackedLinkData(link.point,parentPoint,tail,link.orientation,children,link.getLock()));
Links.add(new PackedLinkData(link.point,parentPoint,tail,link.orientation,children,link.lock));
PackedLinkTail tempTail = new PackedLinkTail(link.tail.getDestination(),link.tail.getLinkType());
if(Tails.contains(tempTail))
{
Tails.add(tempTail);
}

View file

@ -80,7 +80,7 @@ public class PocketManager
Point4D source = link.point;
NewDimData dimension = getDimensionData(source.getDimension());
DimLink dLink = dimension.getLink(source);
dLink.setLock(link.lock);
dLink.lock=link.lock;
}
}

View file

@ -102,7 +102,7 @@ public class ItemDDKey extends Item
{
world.playSoundAtEntity(player, mod_pocketDim.modid + ":keyLock", 1F, 1F);
}
link.getLock().lock(!link.isLocked());
PocketManager.getDimensionData(world).lock(link, !link.isLocked());
PocketManager.getLinkWatcher().update(new ClientLinkData(link.source(),link.getLock()));
}
else
@ -115,7 +115,7 @@ public class ItemDDKey extends Item
if(!DDLock.hasCreatedLock(itemStack))
{
world.playSoundAtEntity(player, mod_pocketDim.modid + ":keyLock", 1F, 1F);
link.createLock(itemStack, world.rand.nextInt(Integer.MAX_VALUE));
PocketManager.getDimensionData(world).createLock(link, itemStack, world.rand.nextInt(Integer.MAX_VALUE));
PocketManager.getLinkWatcher().update(new ClientLinkData(link.source(),link.getLock()));
}
}