Skip to content

Commit

Permalink
redone TileEntity Metadata getter, address #76
Browse files Browse the repository at this point in the history
may or may not correct the issue
  • Loading branch information
darkdiplomat committed Oct 23, 2013
1 parent bb18173 commit 07debc0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 53 deletions.
66 changes: 19 additions & 47 deletions src/main/java/net/canarymod/api/world/blocks/CanaryTileEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/**
* TileEntity implementation
*
*
* @author Jason (darkdiplomat)
*/
public abstract class CanaryTileEntity implements TileEntity {
Expand All @@ -18,9 +18,9 @@ public abstract class CanaryTileEntity implements TileEntity {

/**
* Constructs a new wrapper for TileEntityChest
*
*
* @param tileentity
* the TileEntityChest to be wrapped
* the TileEntityChest to be wrapped
*/
public CanaryTileEntity(net.minecraft.server.TileEntity tileentity) {
this.tileentity = tileentity;
Expand All @@ -35,62 +35,48 @@ public CanaryTileEntity(IInventory inventory) {

/**
* Gets the TileEntity being wrapped
*
*
* @return the TileEntity
*/
public abstract net.minecraft.server.TileEntity getTileEntity();

/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
@Override
public Block getBlock() {
return getWorld().getBlockAt(getX(), getY(), getZ());
}

/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
@Override
public int getX() {
return tileentity.l;
}

/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
@Override
public int getY() {
return tileentity.m;
}

/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
@Override
public int getZ() {
return tileentity.n;
}

/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
@Override
public World getWorld() {
return tileentity.az().getCanaryWorld();
}

/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
@Override
public void update() {
tileentity.az().j(getX(), getY(), getZ());
}

/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
@Override
public CompoundTag getDataTag() {
if (tileentity != null) {
Expand All @@ -101,29 +87,16 @@ public CompoundTag getDataTag() {
return null;
}

/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
@Override
public CompoundTag getMetaTag() {
if (tileentity != null) {
CompoundTag dataTag = getDataTag();

if (dataTag == null) {
dataTag = new CanaryCompoundTag("tag");
writeToTag(dataTag);
}
if (!dataTag.containsKey("Canary")) {
dataTag.put("Canary", new CanaryCompoundTag("Canary"));
}
return dataTag.getCompoundTag("Canary");
return tileentity.getMetaTag();
}
return null;
}

/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
@Override
public CompoundTag writeToTag(CompoundTag tag) {
if (tileentity != null) {
Expand All @@ -133,9 +106,7 @@ public CompoundTag writeToTag(CompoundTag tag) {
return null;
}

/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
@Override
public void readFromTag(CompoundTag tag) {
if (tileentity != null) {
Expand All @@ -145,7 +116,7 @@ public void readFromTag(CompoundTag tag) {

/**
* Returns a semi-unique hashcode for this block
*
*
* @return hashcode
*/
@Override
Expand All @@ -160,9 +131,10 @@ public int hashCode() {

/**
* Tests the given object to see if it equals this object
*
*
* @param obj
* the object to test
* the object to test
*
* @return true if the two objects match
*/
@Override
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/net/minecraft/server/TileEntity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.minecraft.server;

import net.canarymod.api.nbt.CanaryCompoundTag;
import net.canarymod.api.nbt.CompoundTag;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -59,7 +60,7 @@ public void a(NBTTagCompound nbttagcompound) {
}

public void b(NBTTagCompound nbttagcompound) {
String s0 = (String)b.get(this.getClass());
String s0 = (String) b.get(this.getClass());

if (s0 == null) {
throw new RuntimeException(this.getClass() + " is missing a mapping! This is a bug!");
Expand All @@ -82,10 +83,10 @@ public static TileEntity c(NBTTagCompound nbttagcompound) {
TileEntity tileentity = null;

try {
Class oclass0 = (Class)a.get(nbttagcompound.i("id"));
Class oclass0 = (Class) a.get(nbttagcompound.i("id"));

if (oclass0 != null) {
tileentity = (TileEntity)oclass0.newInstance();
tileentity = (TileEntity) oclass0.newInstance();
}
}
catch (Exception exception) {
Expand Down Expand Up @@ -154,12 +155,18 @@ public void i() {
}

public void a(CrashReportCategory crashreportcategory) {
crashreportcategory.a("Name", (Callable)(new CallableTileEntityName(this)));
crashreportcategory.a("Name", (Callable) (new CallableTileEntityName(this)));
CrashReportCategory.a(crashreportcategory, this.l, this.m, this.n, this.q().cF, this.p());
crashreportcategory.a("Actual block type", (Callable)(new CallableTileEntityID(this)));
crashreportcategory.a("Actual block data value", (Callable)(new CallableTileEntityData(this)));
crashreportcategory.a("Actual block type", (Callable) (new CallableTileEntityID(this)));
crashreportcategory.a("Actual block data value", (Callable) (new CallableTileEntityData(this)));
}

// CanaryMod:
public CompoundTag getMetaTag() {
return meta;
}
//

static Map t() {
return b;
}
Expand Down

0 comments on commit 07debc0

Please sign in to comment.