001 002 /** 003 * Generic superclass for Chests and Furnaces, as they are really similar. 004 * @author lightweight 005 * 006 * @param <C> The type of container we wish to wrap. 007 */ 008 public abstract class BaseContainerBlock<C extends bm & mn & Container<jl>> extends ItemArray<C> implements Inventory { 009 private final String name; 010 011 /** 012 * Create a BaseContainerBlock to act as a wrapper for a given container. 013 * @param block The in-world block to 'envelop'. 014 * @param reference Shows in toString(). 015 */ 016 public BaseContainerBlock(C block, String reference) { 017 super(block); 018 this.name = reference; 019 } 020 021 public int getX() { 022 return container.b; 023 } 024 025 public int getY() { 026 return container.c; 027 } 028 029 public int getZ() { 030 return container.d; 031 } 032 033 public Block getBlock() { 034 return etc.getServer().getBlockAt(getX(), getY(), getZ()); 035 } 036 037 public void update() { 038 container.c(); 039 } 040 041 public String getName() { 042 return container.getName(); 043 } 044 045 public void setName(String value) { 046 container.setName(value); 047 } 048 049 /** 050 * Tests the given object to see if it equals this object 051 * 052 * @param obj the object to test 053 * @return true if the two objects match 054 */ 055 @Override 056 public boolean equals(Object obj) { 057 if (obj == null) { 058 return false; 059 } 060 if (getClass() != obj.getClass()) { 061 return false; 062 } 063 // Supress warning since we've already returned if class is wrong. 064 @SuppressWarnings("unchecked") 065 final BaseContainerBlock<C> other = (BaseContainerBlock<C>) obj; 066 if (this.getX() != other.getX()) { 067 return false; 068 } 069 if (this.getY() != other.getY()) { 070 return false; 071 } 072 if (this.getZ() != other.getZ()) { 073 return false; 074 } 075 return true; 076 } 077 078 /** 079 * Returns a semi-unique hashcode for this object 080 * 081 * @return hashcode 082 */ 083 @Override 084 public int hashCode() { 085 int hash = 7; 086 hash = 97 * hash + this.getX(); 087 hash = 97 * hash + this.getY(); 088 hash = 97 * hash + this.getZ(); 089 return hash; 090 } 091 092 @Override 093 public String toString() { 094 return String.format(name + " [x=%d, y=%d, z=%d]", getX(), getY(), getZ()); 095 } 096 }