finished networking changes for locks

This commit is contained in:
StevenRS11 2014-05-22 00:15:27 -04:00
parent ef860e295e
commit 3fcc55b5e1
39 changed files with 566 additions and 350 deletions

View file

@ -1,11 +1,14 @@
package StevenDimDoors.mod_pocketDim;
import java.io.File;
import java.io.FileOutputStream;
import StevenDimDoors.mod_pocketDim.blocks.BaseDimDoor;
import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.IGuiHandler;
@ -130,6 +133,20 @@ public class CommonProxy implements IGuiHandler
{
}
public void updateDoorTE(BaseDimDoor door, World world, int x, int y, int z)
{
TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof TileEntityDimDoor)
{
int metadata = world.getBlockMetadata(x, y, z);
TileEntityDimDoor dimTile = (TileEntityDimDoor) tile;
dimTile.openOrClosed = door.isDoorOnRift(world, x, y, z)&&door.isUpperDoorBlock(metadata);
dimTile.orientation = door.getFullMetadata(world, x, y, z) & 7;
dimTile.lockStatus = door.getLockStatus(world, x, y, z);
}
}
}

View file

@ -1,6 +1,7 @@
package StevenDimDoors.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.config.DDProperties;
import StevenDimDoors.mod_pocketDim.core.DDLock;
import StevenDimDoors.mod_pocketDim.core.DimLink;
import StevenDimDoors.mod_pocketDim.items.ItemDDKey;
import net.minecraft.block.Block;
@ -129,7 +130,7 @@ public class CraftingManager implements ICraftingHandler
}
}
}
keyItem.addDoorToKey(topKey, bottomKey);
DDLock.addKeys(bottomKey, DDLock.getKeys(topKey));
item.setTagCompound(bottomKey.getTagCompound());
player.inventory.addItemStackToInventory(topKey);
}

View file

@ -59,6 +59,9 @@ public class EventHookContainer
@ForgeSubscribe
public void onSoundLoad(SoundLoadEvent event)
{
event.manager.addSound(mod_pocketDim.modid + ":doorLocked.ogg");
event.manager.addSound(mod_pocketDim.modid + ":keyLock.ogg");
event.manager.addSound(mod_pocketDim.modid + ":keyUnlock.ogg");
event.manager.addSound(mod_pocketDim.modid + ":monk.ogg");
event.manager.addSound(mod_pocketDim.modid + ":crack.ogg");
event.manager.addSound(mod_pocketDim.modid + ":tearing.ogg");

View file

@ -12,5 +12,6 @@ public class PacketConstants
public static final byte CREATE_LINK_PACKET_ID = 4;
public static final byte DELETE_LINK_PACKET_ID = 5;
public static final byte CLIENT_LOGIN_DIM_REGISTER = 6;
public static final byte UPDATE_LINK_PACKET_ID = 7;
}

View file

@ -38,6 +38,13 @@ public class ServerPacketHandler implements IPacketHandler
public void onDeleted(ClientDimData message)
{
sendDimPacket(PacketConstants.DELETE_DIM_PACKET_ID, message);
}
@Override
public void update(ClientDimData message)
{
// TODO Auto-generated method stub
}
}
@ -54,6 +61,12 @@ public class ServerPacketHandler implements IPacketHandler
{
sendLinkPacket(PacketConstants.DELETE_LINK_PACKET_ID, message);
}
@Override
public void update(ClientLinkData message)
{
sendLinkPacket(PacketConstants.UPDATE_LINK_PACKET_ID, message);
}
}
public static Packet250CustomPayload createLinkPacket(ClientLinkData data)

View file

@ -181,14 +181,7 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
//but this works fine and is more versatile I think.
public BaseDimDoor updateAttachedTile(World world, int x, int y, int z)
{
TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof TileEntityDimDoor)
{
int metadata = world.getBlockMetadata(x, y, z);
TileEntityDimDoor dimTile = (TileEntityDimDoor) tile;
dimTile.openOrClosed = this.isDoorOnRift(world, x, y, z)&&this.isUpperDoorBlock(metadata);
dimTile.orientation = this.getFullMetadata(world, x, y, z) & 7;
}
mod_pocketDim.proxy.updateDoorTE(this, world, x, y, z);
return this;
}
@ -353,7 +346,7 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
this.dropBlockAsItem(world, x, y, z, metadata, 0);
}
}
else if(!this.hasLock(world, x, y, z))
else if(this.getLockStatus(world, x, y, z)<=1)
{
boolean powered = world.isBlockIndirectlyGettingPowered(x, y, z) || world.isBlockIndirectlyGettingPowered(x, y + 1, z);
if ((powered || neighborID > 0 && Block.blocksList[neighborID].canProvidePower()) && neighborID != this.blockID)
@ -457,17 +450,32 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
return (metadata & 4) != 0;
}
public boolean hasLock(World world, int x, int y, int z)
/**
* 0 if link is no lock;
* 1 if there is a lock;
* 2 if the lock is locked.
* @param world
* @param x
* @param y
* @param z
* @return
*/
public byte getLockStatus(World world, int x, int y, int z)
{
byte status = 0;
DimLink link = getLink(world, x, y, z);
if(link!=null&&link.isLocked())
if(link!=null&&link.hasLock())
{
return true;
status++;
if(link.isLocked())
{
status++;
}
}
return false;
return status;
}
public boolean checkCanOpen(World world, int x, int y, int z)
{
return this.checkCanOpen(world, x, y, z, null);
@ -475,30 +483,30 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
public boolean checkCanOpen(World world, int x, int y, int z, EntityPlayer player)
{
if(!hasLock(world, x, y, z))
DimLink link = getLink(world, x, y, z);
if(link==null||player==null)
{
return link==null;
}
if(!link.isLocked())
{
return true;
}
if(player == null)
{
return false;
}
DimLink link = getLink(world, x, y, z);
for(ItemStack item : player.inventory.mainInventory)
{
if(item != null)
{
if(item.getItem() instanceof ItemDDKey)
{
if(((ItemDDKey) item.getItem()).canKeyOpen(link, item))
if(link.open(item))
{
return true;
}
}
}
}
player.playSound(mod_pocketDim.modid + ":doorLocked", 1F, 1F);
return false;
}

View file

@ -8,6 +8,8 @@ import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
@ -16,6 +18,7 @@ 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.items.ItemDDKey;
import StevenDimDoors.mod_pocketDim.tileentities.TileEntityTransTrapdoor;
public class TransTrapdoor extends BlockTrapDoor implements IDimDoor, ITileEntityProvider
@ -40,6 +43,55 @@ public class TransTrapdoor extends BlockTrapDoor implements IDimDoor, ITileEntit
enterDimDoor(world, x, y, z, entity);
}
public boolean checkCanOpen(World world, int x, int y, int z)
{
return this.checkCanOpen(world, x, y, z, null);
}
public boolean checkCanOpen(World world, int x, int y, int z, EntityPlayer player)
{
DimLink link = PocketManager.getLink( x, y,z, world);
if(link==null||player==null)
{
return link==null;
}
if(!link.isLocked())
{
return true;
}
for(ItemStack item : player.inventory.mainInventory)
{
if(item != null)
{
if(item.getItem() instanceof ItemDDKey)
{
if(link.open(item))
{
return true;
}
}
}
}
return false;
}
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
if(this.checkCanOpen(par1World, par3, par3, par4, par5EntityPlayer))
{
return super.onBlockActivated(par1World, par2, par3, par4, par5EntityPlayer, par6, par7, par8, par9);
}
return false;
}
public void onPoweredBlockChange(World par1World, int par2, int par3, int par4, boolean par5)
{
if(this.checkCanOpen(par1World, par2, par3, par4))
{
super.onPoweredBlockChange(par1World, par2, par3, par4, par5);
}
}
@Override
public void enterDimDoor(World world, int x, int y, int z, Entity entity)
{

View file

@ -9,7 +9,6 @@ import StevenDimDoors.mod_pocketDim.core.LinkTypes;
import StevenDimDoors.mod_pocketDim.core.NewDimData;
import StevenDimDoors.mod_pocketDim.core.PocketManager;
@SuppressWarnings("deprecation")
public class WarpDoor extends BaseDimDoor
{
public WarpDoor(int blockID, Material material, DDProperties properties)

View file

@ -62,11 +62,11 @@ public class CommandResetDungeons extends DDCommandBase
{
if(link.linkType()==LinkTypes.REVERSE)
{
data.createLink(link.source(), LinkTypes.DUNGEON_EXIT, link.orientation(), false);
data.createLink(link.source(), LinkTypes.DUNGEON_EXIT, link.orientation(), null);
}
if(link.linkType()==LinkTypes.DUNGEON)
{
data.createLink(link.source(), LinkTypes.DUNGEON, link.orientation(), false);
data.createLink(link.source(), LinkTypes.DUNGEON, link.orientation(), null);
}
}
}

View file

@ -0,0 +1,169 @@
package StevenDimDoors.mod_pocketDim.core;
import java.io.IOException;
import com.google.gson.stream.JsonReader;
import StevenDimDoors.mod_pocketDim.items.ItemDDKey;
import StevenDimDoors.mod_pocketDim.saving.IPackable;
import StevenDimDoors.mod_pocketDim.saving.PackedDimData;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagIntArray;
import net.minecraft.nbt.NBTTagList;
public class DDLock
{
private boolean isLocked;
private final int lockKey;
public DDLock(boolean isLocked, int lockKey)
{
this.isLocked = isLocked;
this.lockKey = lockKey;
}
public int getLockKey()
{
return this.lockKey;
}
/**
* See if the lock is currently locked. False if there is no lock.
* @return
*/
public boolean isLocked()
{
return this.isLocked;
}
/**
* set the state of the lock. Returns false if there is no lock to set,
* otherwise returns true
* @param flag
*/
public void lock(boolean flag)
{
this.isLocked = flag;
}
/**
* see if we could unlock this door if it where locked.
* @param link
* @param itemStack
* @return
*/
public boolean canOpen(ItemStack itemStack)
{
for(int key :getKeys(itemStack))
{
if(this.lockKey == key)
{
return true;
}
}
return false;
}
/**
* Tries to open this lock
* @param item
* @return
*/
public boolean open(ItemStack itemStack)
{
return (!this.isLocked)||this.canOpen(itemStack);
}
/**
* sets the key/s to the given key/s
* @return
* @return
*/
/**
* gets all the keys stored on a single key item
* @return
*/
public static int[] getKeys(ItemStack itemStack)
{
if (!itemStack.hasTagCompound())
{
initNBTTags(itemStack);
}
return itemStack.getTagCompound().getIntArray("DDKeys");
}
/**
* adds the key/s to the given key
* @return
* @return
*/
public static void addKeys(ItemStack itemStack, int[] keysToAdd)
{
int[] oldKeys = DDLock.getKeys(itemStack);
int[] newKeys = new int[keysToAdd.length+oldKeys.length];
System.arraycopy(oldKeys, 0, newKeys, 0, oldKeys.length);
System.arraycopy(keysToAdd, 0, newKeys, oldKeys.length, keysToAdd.length);
setKeys(itemStack,newKeys);
}
/**
* sets the key/s to the given key/s
* @return
* @return
*/
public static void setKeys(ItemStack itemStack, int[] keys)
{
if (!itemStack.hasTagCompound())
{
initNBTTags(itemStack);
}
NBTTagCompound tag = itemStack.getTagCompound();
tag.setIntArray("DDKeys", keys);
itemStack.setTagCompound(tag);
}
/**
* Gives the key a new NBTTag
* @param itemStack
*/
public static void initNBTTags(ItemStack itemStack)
{
itemStack.setTagCompound(new NBTTagCompound());
NBTTagCompound tag = itemStack.getTagCompound();
tag.setIntArray("DDKeys", new int[0]);
tag.setBoolean("HasCreatedLock", false);
itemStack.setTagCompound(tag);
}
public static boolean hasCreatedLock(ItemStack key)
{
if(isKey(key))
{
if(key.hasTagCompound())
{
return key.getTagCompound().getBoolean("HasCreatedLock");
}
initNBTTags(key);
}
return false;
}
public static boolean isKey(ItemStack key)
{
return key.getItem() instanceof ItemDDKey;
}
public static DDLock createLock(ItemStack itemStack, int lockKey2)
{
itemStack.getTagCompound().setBoolean("HasCreatedLock", true);
DDLock.setKeys(itemStack, new int[]{lockKey2});
return new DDLock(true, lockKey2);
}
}

View file

@ -485,7 +485,7 @@ public class DDTeleporter
{
if(PocketManager.isBlackListed(link.destination().getDimension()))
{
link=PocketManager.getDimensionData(link.source().getDimension()).createLink(link.point,LinkTypes.SAFE_EXIT,link.orientation, false);
link=PocketManager.getDimensionData(link.source().getDimension()).createLink(link.point,LinkTypes.SAFE_EXIT,link.orientation, null);
}
else
{

View file

@ -2,20 +2,20 @@ package StevenDimDoors.mod_pocketDim.core;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.item.ItemStack;
import StevenDimDoors.mod_pocketDim.items.ItemDDKey;
import StevenDimDoors.mod_pocketDim.util.Point4D;
import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData;
public abstract class DimLink
{
protected Point4D point;
protected int orientation;
protected boolean isLocked;
private DDLock lock;
protected DimLink parent;
protected LinkTail tail;
protected List<DimLink> children;
protected DimLink(Point4D point, int orientation, boolean locked, DimLink parent)
protected DimLink(Point4D point, int orientation, DDLock lock, DimLink parent)
{
if (parent.point.getDimension() != point.getDimension())
@ -23,26 +23,25 @@ public abstract class DimLink
// Ban having children in other dimensions to avoid serialization issues with cross-dimensional tails
throw new IllegalArgumentException("source and parent.source must have the same dimension.");
}
this.lock = lock;
this.parent = parent;
this.point = point;
this.tail = parent.tail;
this.orientation = orientation;
this.isLocked = locked;
this.children = new LinkedList<DimLink>();
parent.children.add(this);
}
protected DimLink(Point4D point, int orientation, boolean locked, int linkType)
protected DimLink(Point4D point, int orientation, DDLock lock, int linkType)
{
if ((linkType < LinkTypes.ENUM_MIN || linkType > LinkTypes.ENUM_MAX) && linkType != LinkTypes.CLIENT_SIDE)
{
throw new IllegalArgumentException("The specified link type is invalid.");
}
this.lock = lock;
this.parent = null;
this.point = point;
this.orientation = orientation;
this.isLocked = locked;
this.tail = new LinkTail(linkType, null);
this.children = new LinkedList<DimLink>();
}
@ -115,18 +114,63 @@ public abstract class DimLink
return tail.getLinkType();
}
public boolean isLocked()
{
return isLocked;
}
public void setLocked(boolean bol)
{
isLocked = bol;
}
public String toString()
{
return point + " -> " + (hasDestination() ? destination() : "");
}
/**
* Tries to open this lock. Returns true if the lock is open or if the key can open it
* @return
*/
public boolean open(ItemStack item)
{
return lock.open(item);
}
/**
* test if there is a lock, regardless if it is locked or not.
* @return
*/
public boolean hasLock()
{
return this.lock!=null;
}
public boolean isLocked()
{
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)
{
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

@ -24,14 +24,14 @@ public abstract class NewDimData implements IPackable<PackedDimData>
{
private static class InnerDimLink extends DimLink
{
public InnerDimLink(Point4D source, DimLink parent, int orientation, boolean isLocked)
public InnerDimLink(Point4D source, DimLink parent, int orientation, DDLock lock)
{
super(source, orientation, isLocked, parent);
super(source, orientation, lock, parent);
}
public InnerDimLink(Point4D source, int linkType, int orientation, boolean isLocked)
public InnerDimLink(Point4D source, int linkType, int orientation, DDLock lock)
{
super(source, orientation, isLocked, linkType);
super(source, orientation, lock, linkType);
}
public void setDestination(int x, int y, int z, NewDimData dimension)
@ -99,7 +99,6 @@ public abstract class NewDimData implements IPackable<PackedDimData>
this.orientation=orientation;
}
}
protected static Random random = new Random();
protected int id;
@ -279,10 +278,10 @@ public abstract class NewDimData implements IPackable<PackedDimData>
public DimLink createLink(int x, int y, int z, int linkType, int orientation)
{
return createLink(new Point4D(x, y, z, id), linkType, orientation, false);
return createLink(new Point4D(x, y, z, id), linkType, orientation, null);
}
public DimLink createLink(Point4D source, int linkType, int orientation, boolean locked)
public DimLink createLink(Point4D source, int linkType, int orientation, DDLock locked)
{
//Return an existing link if there is one to avoid creating multiple links starting at the same point.
InnerDimLink link = linkMapping.get(source);
@ -308,10 +307,10 @@ public abstract class NewDimData implements IPackable<PackedDimData>
public DimLink createChildLink(int x, int y, int z, DimLink parent)
{
return createChildLink(new Point4D(x, y, z, id), (InnerDimLink) parent, false);
return createChildLink(new Point4D(x, y, z, id), (InnerDimLink) parent, null);
}
public DimLink createChildLink(Point4D source, DimLink parent, boolean locked)
public DimLink createChildLink(Point4D source, DimLink parent, DDLock locked)
{
//To avoid having multiple links at a single point, if we find an existing link then we overwrite
//its destination data instead of creating a new instance.
@ -584,6 +583,11 @@ public abstract class NewDimData implements IPackable<PackedDimData>
return modified;
}
public void flagModified()
{
modified = true;
}
public void clearModified()
{
this.modified = false;
@ -651,7 +655,7 @@ 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.isLocked()));
Links.add(new PackedLinkData(link.point,parentPoint,tail,link.orientation,children,link.getLock()));
PackedLinkTail tempTail = new PackedLinkTail(link.tail.getDestination(),link.tail.getLinkType());
if(Tails.contains(tempTail))

View file

@ -7,32 +7,25 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
import StevenDimDoors.mod_pocketDim.Point3D;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.config.DDProperties;
import StevenDimDoors.mod_pocketDim.helpers.Compactor;
import StevenDimDoors.mod_pocketDim.helpers.DeleteFolder;
import StevenDimDoors.mod_pocketDim.saving.DDSaveHandler;
import StevenDimDoors.mod_pocketDim.saving.IPackable;
import StevenDimDoors.mod_pocketDim.saving.OldSaveImporter;
import StevenDimDoors.mod_pocketDim.saving.PackedDimData;
import StevenDimDoors.mod_pocketDim.saving.PackedDungeonData;
import StevenDimDoors.mod_pocketDim.saving.PackedLinkData;
import StevenDimDoors.mod_pocketDim.saving.PackedLinkTail;
import StevenDimDoors.mod_pocketDim.util.Point4D;
import StevenDimDoors.mod_pocketDim.watcher.ClientDimData;
import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData;
import StevenDimDoors.mod_pocketDim.watcher.IUpdateSource;
import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher;
import StevenDimDoors.mod_pocketDim.watcher.UpdateWatcherProxy;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* This class regulates all the operations involving the storage and manipulation of dimensions.
@ -40,7 +33,7 @@ import StevenDimDoors.mod_pocketDim.watcher.UpdateWatcherProxy;
* well as loading old dimensions on startup
*/
public class PocketManager
{
{
private static class InnerDimData extends NewDimData
{
// This class allows us to instantiate NewDimData indirectly without exposing
@ -69,7 +62,7 @@ public class PocketManager
{
Point4D source = link.point;
NewDimData dimension = getDimensionData(source.getDimension());
dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.CLIENT_SIDE,link.orientation);
dimension.createLink(source, LinkTypes.CLIENT_SIDE, 0, link.lock);
}
@Override
@ -78,7 +71,17 @@ public class PocketManager
Point4D source = link.point;
NewDimData dimension = getDimensionData(source.getDimension());
dimension.deleteLink(source.getX(), source.getY(), source.getZ());
}
}
@Override
public void update(ClientLinkData link)
{
Point4D source = link.point;
NewDimData dimension = getDimensionData(source.getDimension());
DimLink dLink = dimension.getLink(source);
dLink.setLock(link.lock);
}
}
private static class ClientDimWatcher implements IUpdateWatcher<ClientDimData>
@ -94,6 +97,12 @@ public class PocketManager
{
deletePocket(getDimensionData(data.ID), false);
}
@Override
public void update(ClientDimData message)
{
// TODO Auto-generated method stub
}
}
private static class DimRegistrationCallback implements IDimRegistrationCallback
@ -633,4 +642,9 @@ public class PocketManager
{
return dimWatcher;
}
public static UpdateWatcherProxy<ClientLinkData> getLinkWatcher()
{
return linkWatcher;
}
}

View file

@ -80,7 +80,7 @@ public class Compactor
{
ClientLinkData link = ClientLinkData.read(input);
Point4D source = link.point;
dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.CLIENT_SIDE,link.orientation);
dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.CLIENT_SIDE,0);
}
}
}

View file

@ -17,8 +17,10 @@ import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.blocks.IDimDoor;
import StevenDimDoors.mod_pocketDim.core.DDLock;
import StevenDimDoors.mod_pocketDim.core.DimLink;
import StevenDimDoors.mod_pocketDim.core.PocketManager;
import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData;
public class ItemDDKey extends Item
{
@ -32,8 +34,14 @@ public class ItemDDKey extends Item
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
{
boolean check = (this.isBound(par1ItemStack) ? par3List.add("Bound") : par3List.add("Unbound"));
return;
if(DDLock.hasCreatedLock(par1ItemStack))
{
par3List.add("Bound");
}
else
{
par3List.add("Unbound");
}
}
@ -47,7 +55,7 @@ public class ItemDDKey extends Item
@SideOnly(Side.CLIENT)
public boolean hasEffect(ItemStack par1ItemStack)
{
return !this.isBound(par1ItemStack);
return !DDLock.hasCreatedLock(par1ItemStack);
}
public boolean onItemUseFirst(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float playerX, float playerY,
@ -70,162 +78,40 @@ public class ItemDDKey extends Item
{
return false;
}
//make sure we are not trying to mess with a door thats already locked by someone else
if(!this.canKeyOpen(link, itemStack)&&link.isLocked())
{
return false;
}
//see if we can bind this key to this door and lock it
if(setBoundDoor(itemStack, link))
{
link.setLocked(true);
return false;
}
//lastly, just see if we can toggle the door's lock state if its locked.
if(this.canKeyOpen(link, itemStack))
{
link.setLocked(!link.isLocked());
return false;
}
return false;
}
public boolean setBoundDoor(ItemStack itemStack, DimLink link)
{
//dont bind to a door if we already are bound, or if we dont have permission to lock that door
if(this.isBound(itemStack)|| (!this.canKeyOpen(link, itemStack)&&link.isLocked()))
//what to do if the door has a lock already
if(link.hasLock())
{
return false;
}
//dont bind if the door has a lock already on it, but we can still open it. That would waste the key.
if(link.isLocked())
{
return false;
}
//init tags
if(!itemStack.hasTagCompound())
{
this.initNBTTags(itemStack);
}
//consume this keys ability to create a lock
itemStack.getTagCompound().setBoolean("HasLockedDoor", true);
//create the tag that binds this door to this key
NBTTagCompound tag = new NBTTagCompound();
int x = link.source().getX();
int y = link.source().getY();
int z = link.source().getZ();
tag.setInteger("x", x);
tag.setInteger("y", y);
tag.setInteger("z", z);
tag.setInteger("dim", link.source().getDimension());
//add this door's tag to this keys keyring
NBTTagList keyRing = itemStack.getTagCompound().getTagList("DDKeys");
keyRing.appendTag(tag);
itemStack.getTagCompound().setTag("DDKeys", keyRing);
return true;
}
/**
* copies all the tags from the first key onto the second key
* @param givingKey
* @param receivingKey
*/
public void addDoorToKey(ItemStack givingKey, ItemStack receivingKey)
{
//cant copy tags from a key with no tags
if(!givingKey.hasTagCompound())
{
return;
}
//initialize the receiving key
if(!receivingKey.hasTagCompound())
{
this.initNBTTags(receivingKey);
}
//get the tags
NBTTagCompound recevingTags = receivingKey.getTagCompound();
NBTTagCompound sendingTags = (NBTTagCompound) givingKey.getTagCompound().copy();
//copy over the actual tags
for(int i = 0; i<sendingTags.getTagList("DDKeys").tagCount();i++)
{
recevingTags.getTagList("DDKeys").appendTag(sendingTags.getTagList("DDKeys").tagAt(i));
}
}
/**
* see if we could unlock this door if it where locked.
* @param link
* @param itemStack
* @return
*/
public boolean canKeyOpen(DimLink link, ItemStack itemStack)
{
//make sure we have a tag
if (itemStack.hasTagCompound())
{
NBTTagList tags = itemStack.getTagCompound().getTagList("DDKeys");
for(int i = 0; i < tags.tagCount(); i++)
if(link.getLock().canOpen(itemStack))
{
NBTTagCompound tag = (NBTTagCompound) tags.tagAt(i);
Integer x = tag.getInteger("x");
Integer y = tag.getInteger("y");
Integer z = tag.getInteger("z");
Integer dimID = tag.getInteger("dim");
if (x != null && y != null && z != null && dimID != null)
if(link.isLocked())
{
if (x == link.source().getX() &&
y == link.source().getY() &&
z == link.source().getZ() &&
dimID == link.source().getDimension())
{
return true;
}
world.playSoundAtEntity(player, mod_pocketDim.modid + ":keyUnlock", 1F, 1F);
}
else
{
world.playSoundAtEntity(player, mod_pocketDim.modid + ":keyLock", 1F, 1F);
}
link.getLock().lock(!link.isLocked());
PocketManager.getLinkWatcher().update(new ClientLinkData(link.source(),link.getLock()));
}
}
else
{
if(!DDLock.hasCreatedLock(itemStack))
{
world.playSoundAtEntity(player, mod_pocketDim.modid + ":keyLock", 1F, 1F);
link.createLock(itemStack, world.rand.nextInt(Integer.MAX_VALUE));
PocketManager.getLinkWatcher().update(new ClientLinkData(link.source(),link.getLock()));
}
}
return false;
}
public String getItemStackDisplayName(ItemStack par1ItemStack)
{
return StatCollector.translateToLocal(this.getUnlocalizedName(par1ItemStack) + ".name");
}
public boolean isBound(ItemStack item)
{
if(item.hasTagCompound())
{
if(item.getTagCompound().getBoolean("HasLockedDoor"))
{
return true;
}
}
return false;
}
public void initNBTTags(ItemStack itemStack)
{
itemStack.setTagCompound(new NBTTagCompound());
NBTTagCompound tag = itemStack.getTagCompound();
tag.setTag("DDKeys", new NBTTagList());
itemStack.setTagCompound(tag);
}
}

View file

@ -197,7 +197,7 @@ public class DDSaveHandler
linkType = LinkTypes.NORMAL;
}
DimLink link = data.createLink(packedLink.source, linkType, packedLink.orientation, packedLink.locked);
DimLink link = data.createLink(packedLink.source, linkType, packedLink.orientation, packedLink.lock);
Point4D destination = packedLink.tail.destination;
if(destination!=null)
{
@ -216,7 +216,7 @@ public class DDSaveHandler
NewDimData data = PocketManager.getDimensionData(packedLink.source.getDimension());
if(data.getLink(packedLink.parent)!=null)
{
data.createChildLink(packedLink.source, data.getLink(packedLink.parent), packedLink.locked);
data.createChildLink(packedLink.source, data.getLink(packedLink.parent), packedLink.lock);
}
unpackedLinks.add(packedLink);
}
@ -224,7 +224,7 @@ public class DDSaveHandler
}
return true;
}
private static PackedDimData readDimension(File dataFile, DimDataProcessor reader)
{

View file

@ -13,6 +13,7 @@ import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import StevenDimDoors.mod_pocketDim.Point3D;
import StevenDimDoors.mod_pocketDim.core.DDLock;
import StevenDimDoors.mod_pocketDim.util.BaseConfigurationProcessor;
import StevenDimDoors.mod_pocketDim.util.ConfigurationProcessingException;
import StevenDimDoors.mod_pocketDim.util.Point4D;
@ -202,7 +203,7 @@ public class DimDataProcessor extends BaseConfigurationProcessor<PackedDimData>
private PackedLinkData createLinkDataFromJson(JsonReader reader) throws IOException
{
boolean locked = false;
DDLock lock = null;
Point4D source;
Point3D parent;
@ -235,13 +236,11 @@ public class DimDataProcessor extends BaseConfigurationProcessor<PackedDimData>
if(reader.peek()== JsonToken.NAME)
{
reader.nextName();
locked = reader.nextBoolean();
lock = this.createLockFromJson(reader);
}
reader.endObject();
return new PackedLinkData(source, parent, tail, orientation, children, locked);
return new PackedLinkData(source, parent, tail, orientation, children, lock);
}
private PackedDungeonData createDungeonDataFromJson(JsonReader reader) throws IOException
{
@ -307,4 +306,21 @@ public class DimDataProcessor extends BaseConfigurationProcessor<PackedDimData>
return new PackedLinkTail(destination, linkType);
}
private DDLock createLockFromJson(JsonReader reader) throws IOException
{
reader.nextName();
reader.beginObject();
reader.nextName();
boolean locked = reader.nextBoolean();
reader.nextName();
int key = reader.nextInt();
reader.endObject();
return new DDLock(locked, key);
}
}

View file

@ -80,7 +80,7 @@ public class OldSaveImporter
PackedLinkTail tail = new PackedLinkTail(destintion, link.linkOrientation);
List<Point3D> children = new ArrayList<Point3D>();
PackedLinkData newPackedLink = new PackedLinkData(source, new Point3D(-1,-1,-1), tail, link.linkOrientation,children, false);
PackedLinkData newPackedLink = new PackedLinkData(source, new Point3D(-1,-1,-1), tail, link.linkOrientation,children, null);
newPackedLinkData.add(newPackedLink);
allPackedLinks.add(newPackedLink);

View file

@ -49,4 +49,6 @@ public class PackedDimData
{
return "ID= "+this.ID;
}
}

View file

@ -3,6 +3,7 @@ package StevenDimDoors.mod_pocketDim.saving;
import java.util.List;
import StevenDimDoors.mod_pocketDim.Point3D;
import StevenDimDoors.mod_pocketDim.core.DDLock;
import StevenDimDoors.mod_pocketDim.util.Point4D;
public class PackedLinkData
@ -12,15 +13,15 @@ public class PackedLinkData
public final PackedLinkTail tail;
public final int orientation;
public final List<Point3D> children;
public final boolean locked;
public final DDLock lock;
public PackedLinkData(Point4D source, Point3D parent, PackedLinkTail tail, int orientation, List<Point3D> children, boolean locked)
public PackedLinkData(Point4D source, Point3D parent, PackedLinkTail tail, int orientation, List<Point3D> children, DDLock lock)
{
this.source=source;
this.parent=parent;
this.tail=tail;
this.orientation=orientation;
this.children=children;
this.locked = locked;
this.lock = lock;
}
}

View file

@ -19,6 +19,7 @@ public class TileEntityDimDoor extends DDTileEntityBase
public boolean openOrClosed;
public int orientation;
public boolean hasExit;
public byte lockStatus;
public boolean isDungeonChainLink;
public boolean hasGennedPair=false;

View file

@ -3,43 +3,53 @@ package StevenDimDoors.mod_pocketDim.watcher;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import StevenDimDoors.mod_pocketDim.core.DDLock;
import StevenDimDoors.mod_pocketDim.core.DimLink;
import StevenDimDoors.mod_pocketDim.util.Point4D;
public class ClientLinkData
{
public Point4D point;
public int orientation;
public boolean isLocked;
public ClientLinkData(DimLink link)
{
this.point= link.source();
this.orientation=link.orientation();
this.isLocked = link.isLocked();
}
public ClientLinkData(Point4D point, int orientation, boolean isLocked)
{
this.point = point;
this.orientation=orientation;
this.isLocked = isLocked;
}
public void write(DataOutputStream output) throws IOException
{
Point4D.write(point, output);
output.writeInt(orientation);
output.writeBoolean(isLocked);
}
public static ClientLinkData read(DataInputStream input) throws IOException
{
Point4D point = Point4D.read(input);
int orientation = input.readInt();
boolean isLocked = input.readBoolean();
return new ClientLinkData(point, orientation, isLocked);
}
public Point4D point;
public DDLock lock;
public ClientLinkData(DimLink link)
{
this.point = link.source();
if (link.hasLock())
{
lock = link.getLock();
}
}
public ClientLinkData(Point4D point, DDLock lock)
{
this.point = point;
this.lock = lock;
}
public void write(DataOutputStream output) throws IOException
{
Point4D.write(point, output);
boolean hasLock = this.lock != null;
output.writeBoolean(hasLock);
if (hasLock)
{
output.writeBoolean(lock.isLocked());
output.writeInt(lock.getLockKey());
}
}
public static ClientLinkData read(DataInputStream input) throws IOException
{
Point4D point = Point4D.read(input);
DDLock lock = null;
if (input.readBoolean())
{
lock = new DDLock(input.readBoolean(), input.readInt());
}
return new ClientLinkData(point, lock);
}
}

View file

@ -3,5 +3,6 @@ package StevenDimDoors.mod_pocketDim.watcher;
public interface IUpdateWatcher<T>
{
public void onCreated(T message);
public void update(T message);
public void onDeleted(T message);
}

View file

@ -39,4 +39,13 @@ public class UpdateWatcherProxy<T> implements IUpdateWatcher<T>
{
return watchers.remove(receiver);
}
@Override
public void update(T message)
{
for (IUpdateWatcher<T> receiver : watchers)
{
receiver.update(message);
}
}
}

View file

@ -40,87 +40,6 @@ public class PocketBuilder
private PocketBuilder() { }
/**
* Method that takes an arbitrary link into a dungeon pocket and tries to regenerate it. First uses the origin to find that link,
* then uses that link to find the link that originally created the dungeon. If it cant find any of these, it
* instead makes the link that lead to this point into an exit door style link, sending the player to the overworld.
* @param dimension The dungeon to be regenerated
* @param linkIn The link leading somewhere into the dungeon.
* @param properties
* @return
*/
public static boolean regenerateDungeonPocket(NewDimData dimension, DimLink linkIn, DDProperties properties)
{
if (linkIn == null)
{
throw new IllegalArgumentException("link cannot be null.");
}
if (properties == null)
{
throw new IllegalArgumentException("properties cannot be null.");
}
//The link that is at the origin of the dungeon
DimLink originLink = dimension.getLink(dimension.origin());
Point4D oldLinkPos = linkIn.source();
if(originLink==null)
{
int orientation = linkIn.orientation();
originLink=dimension.createLink(oldLinkPos, LinkTypes.SAFE_EXIT, (orientation+2)%4, false);
return false;
}
//The link that originally created the dungeon on the way in
DimLink incomingLink = PocketManager.getLink(originLink.destination());
if(incomingLink==null||incomingLink.linkType()!=LinkTypes.DUNGEON||!(originLink.linkType()==LinkTypes.REVERSE))
{
int orientation = linkIn.orientation();
dimension.deleteLink(originLink);
dimension.createLink(oldLinkPos, LinkTypes.SAFE_EXIT, (orientation+2)%4, false);
return false;
}
NewDimData parent = PocketManager.getDimensionData(incomingLink.source().getDimension());
if (!dimension.isDungeon())
{
throw new IllegalArgumentException("destination must be dungeon");
}
if (dimension.isFilled())
{
throw new IllegalArgumentException("destination must be empty");
}
if (!dimension.isInitialized())
{
throw new IllegalArgumentException("destination must already exist");
}
try
{
//Load a world
World world = PocketManager.loadDimension(dimension.id());
if (world == null || world.provider == null)
{
System.err.println("Could not initialize dimension for a dungeon!");
return false;
}
DungeonSchematic schematic = loadAndValidateDungeon(dimension.dungeon(), properties);
if (schematic == null)
{
return false;
}
Point3D destination = new Point3D(incomingLink.destination());
schematic.copyToWorld(world, destination, originLink.orientation(), incomingLink, random, properties, false);
dimension.setFilled(true);
return true;
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
}
private static boolean buildDungeonPocket(DungeonData dungeon, NewDimData dimension, DimLink link, DungeonSchematic schematic, World world, DDProperties properties)
{
//Calculate the destination point

View file

@ -68,6 +68,9 @@ public class ClientPacketHandler implements IPacketHandler, IUpdateSource
case PacketConstants.DELETE_LINK_PACKET_ID:
linkWatcher.onDeleted( ClientLinkData.read(input) );
break;
case PacketConstants.UPDATE_LINK_PACKET_ID:
linkWatcher.update( ClientLinkData.read(input) );
break;
}
}
catch (Exception e)

View file

@ -1,8 +1,14 @@
package StevenDimDoors.mod_pocketDimClient;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.CommonProxy;
import StevenDimDoors.mod_pocketDim.blocks.BaseDimDoor;
import StevenDimDoors.mod_pocketDim.core.DimLink;
import StevenDimDoors.mod_pocketDim.core.PocketManager;
import StevenDimDoors.mod_pocketDim.ticking.MobMonolith;
import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor;
import StevenDimDoors.mod_pocketDim.tileentities.TileEntityTransTrapdoor;
import StevenDimDoors.mod_pocketDim.watcher.ClientLinkData;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry;
@ -24,9 +30,18 @@ public class ClientProxy extends CommonProxy
}
@Override
public void loadTextures()
public void updateDoorTE(BaseDimDoor door, World world, int x, int y, int z)
{
TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof TileEntityDimDoor)
{
DimLink link = PocketManager.getLink(x, y, z, world);
int metadata = world.getBlockMetadata(x, y, z);
TileEntityDimDoor dimTile = (TileEntityDimDoor) tile;
dimTile.openOrClosed = door.isDoorOnRift(world, x, y, z)&&door.isUpperDoorBlock(metadata);
dimTile.orientation = door.getFullMetadata(world, x, y, z) & 7;
dimTile.lockStatus = door.getLockStatus(world, x, y, z);
}
}
@Override

View file

@ -315,15 +315,13 @@ public class RenderDimDoor extends TileEntitySpecialRenderer
if(i==1)
{
bindTexture(KeyholeLight);
GL11.glColor4d(1, 1, 1, .6);
GL11.glColor4d(1, 1, 1, .7);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_DST_COLOR);
}
else
else
{
bindTexture(keyPath);
GL11.glColor4d(.0, .7, .1, 1);
glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
}
@ -365,12 +363,17 @@ public class RenderDimDoor extends TileEntitySpecialRenderer
if (tile.openOrClosed)
{
renderDimDoorTileEntity((TileEntityDimDoor) par1TileEntity, par2, par4, par6);
for(int i = 0; i<2; i++ )
if(tile.lockStatus>=1)
{
this.renderKeyHole(tile, par2, par4, par6, i);
for(int i = 0; i<1+tile.lockStatus; i++ )
{
this.renderKeyHole(tile, par2, par4, par6, i);
}
}
}
}

View file

@ -0,0 +1,25 @@
package StevenDimDoors.mod_pocketDimClient;
public class TESyncHandler
{
public void onServerChanges()
{
}
public void onClientChanges()
{
}
public void onClientData()
{
}
public void onServerData()
{
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB