Various Fixes #166

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

View File

@@ -87,8 +87,6 @@ public class EventHookContainer
World world = event.entity.worldObj; World world = event.entity.worldObj;
ItemStack stack = event.entityPlayer.inventory.getCurrentItem(); ItemStack stack = event.entityPlayer.inventory.getCurrentItem();
if (stack != null && stack.getItem() instanceof ItemDoor) if (stack != null && stack.getItem() instanceof ItemDoor)
{
if (BaseItemDoor.getDoorToPlace(stack.getItem()) != null)
{ {
if (BaseItemDoor.tryToPlaceDoor(stack, event.entityPlayer, world, if (BaseItemDoor.tryToPlaceDoor(stack, event.entityPlayer, world,
event.x, event.y, event.z, event.face)) event.x, event.y, event.z, event.face))
@@ -98,7 +96,6 @@ public class EventHookContainer
} }
} }
} }
}
@ForgeSubscribe @ForgeSubscribe
public void onWorldLoad(WorldEvent.Load event) public void onWorldLoad(WorldEvent.Load event)

View File

@@ -24,9 +24,9 @@ import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor;
public abstract class BaseItemDoor extends ItemDoor public abstract class BaseItemDoor extends ItemDoor
{ {
// maps non-dimensional door items to their corresponding dimensional door // Maps non-dimensional door items to their corresponding dimensional door item
// item // Also maps dimensional door items to themselves for simplicity
private static HashMap<ItemDoor, BaseItemDoor> vanillaDoorMapping = new HashMap<ItemDoor, BaseItemDoor>(); private static HashMap<ItemDoor, BaseItemDoor> doorItemMapping = new HashMap<ItemDoor, BaseItemDoor>();
private static DDProperties properties = null; private static DDProperties properties = null;
/** /**
@@ -35,7 +35,7 @@ public abstract class BaseItemDoor extends ItemDoor
* @param material * @param material
* @param door * @param door
*/ */
public BaseItemDoor(int itemID, Material material, ItemDoor door) public BaseItemDoor(int itemID, Material material, ItemDoor vanillaDoor)
{ {
super(itemID, material); super(itemID, material);
this.setMaxStackSize(64); this.setMaxStackSize(64);
@@ -43,9 +43,10 @@ public abstract class BaseItemDoor extends ItemDoor
if (properties == null) if (properties == null)
properties = DDProperties.instance(); properties = DDProperties.instance();
if(door!=null) doorItemMapping.put(this, this);
if (vanillaDoor != null)
{ {
vanillaDoorMapping.put(door, this); doorItemMapping.put(vanillaDoor, this);
} }
} }
@@ -77,19 +78,6 @@ public abstract class BaseItemDoor extends ItemDoor
return false; return false;
} }
public static BaseDimDoor getDoorToPlace(Item item)
{
if (!(item instanceof BaseItemDoor))
{
item = BaseItemDoor.vanillaDoorMapping.get(item);
}
if(item == null)
{
return null;
}
return ((BaseItemDoor) item).getDoorBlock();
}
/** /**
* Tries to place a door block, called in EventHookContainer * Tries to place a door block, called in EventHookContainer
* *
@@ -111,15 +99,20 @@ public abstract class BaseItemDoor extends ItemDoor
{ {
return false; return false;
} }
if (!(stack.getItem() instanceof ItemDoor)) // Retrieve the actual door type that we want to use here.
// It's okay if stack isn't an ItemDoor. In that case, the lookup will
// return null, just as if the item was an unrecognized door type.
BaseItemDoor mappedItem = doorItemMapping.get(stack.getItem());
if (mappedItem == null)
{ {
throw new IllegalArgumentException("The itemstack must correspond to some type of door"); return false;
} }
if (BaseItemDoor.placeDoorOnBlock(getDoorToPlace(stack.getItem()), stack, player, world, x, y, z, side)) BaseDimDoor doorBlock = mappedItem.getDoorBlock();
if (BaseItemDoor.placeDoorOnBlock(doorBlock, stack, player, world, x, y, z, side))
{ {
return true; return true;
} }
return BaseItemDoor.placeDoorOnRift(getDoorToPlace(stack.getItem()), world, player, stack); return BaseItemDoor.placeDoorOnRift(doorBlock, world, player, stack);
} }
/** /**