Switched linker to use VectorWorld

This commit is contained in:
Calclavia 2014-01-02 19:20:39 +08:00
parent 7427f5422e
commit 4ced4bec81
6 changed files with 15 additions and 100 deletions

@ -1 +1 @@
Subproject commit 0f31f415f1203883a1e4bed6570646b51ff5143d
Subproject commit 051bbef264186f28303b43eb7f71e523e56d72cc

@ -1 +1 @@
Subproject commit a33b93b4b5aa5a7049b3f4daa4a9c9650298d00b
Subproject commit c0d32e2507b3e5efc74dfede53e6c15743fa286e

View file

@ -1,5 +1,6 @@
package resonantinduction.levitator;
import calclavia.lib.prefab.item.ItemCoordLink;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;

View file

@ -1,88 +0,0 @@
/**
*
*/
package resonantinduction.levitator;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import resonantinduction.base.ItemBase;
import universalelectricity.api.vector.Vector3;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* @author Calclavia
*
*/
public abstract class ItemCoordLink extends ItemBase
{
public ItemCoordLink(String name, int id)
{
super(name, id);
this.setMaxStackSize(1);
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag)
{
super.addInformation(itemstack, entityplayer, list, flag);
if (hasLink(itemstack))
{
Vector3 vec = getLink(itemstack);
int dimID = getLinkDim(itemstack);
list.add("Bound to [" + (int) vec.x + ", " + (int) vec.y + ", " + (int) vec.z + "], dimension '" + dimID + "'");
}
else
{
list.add("No block bound");
}
}
public boolean hasLink(ItemStack itemStack)
{
return getLink(itemStack) != null;
}
public Vector3 getLink(ItemStack itemStack)
{
if (itemStack.stackTagCompound == null || !itemStack.getTagCompound().hasKey("position"))
{
return null;
}
return new Vector3(itemStack.getTagCompound().getCompoundTag("position"));
}
public void setLink(ItemStack itemStack, Vector3 vec, int dimID)
{
if (itemStack.getTagCompound() == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
itemStack.getTagCompound().setCompoundTag("position", vec.writeToNBT(new NBTTagCompound()));
itemStack.stackTagCompound.setInteger("dimID", dimID);
}
public int getLinkDim(ItemStack itemStack)
{
if (itemStack.stackTagCompound == null)
{
return 0;
}
return itemStack.stackTagCompound.getInteger("dimID");
}
public void clearLink(ItemStack itemStack)
{
itemStack.getTagCompound().removeTag("position");
itemStack.getTagCompound().removeTag("dimID");
}
}

View file

@ -6,7 +6,10 @@ package resonantinduction.levitator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import universalelectricity.api.vector.Vector3;
import resonantinduction.ResonantInduction;
import resonantinduction.TabRI;
import universalelectricity.api.vector.VectorWorld;
import calclavia.lib.prefab.item.ItemCoordLink;
/**
* @author Calclavia
@ -16,7 +19,7 @@ public class ItemLinker extends ItemCoordLink
{
public ItemLinker(int id)
{
super("linker", id);
super(id, "linker", ResonantInduction.CONFIGURATION, ResonantInduction.PREFIX, TabRI.INSTANCE);
}
@Override
@ -24,9 +27,8 @@ public class ItemLinker extends ItemCoordLink
{
if (!world.isRemote)
{
int dimID = world.provider.dimensionId;
player.addChatMessage("Set link to block [" + x + ", " + y + ", " + z + "], dimension '" + dimID + "'");
this.setLink(stack, new Vector3(x, y, z), dimID);
player.addChatMessage("Set link to block [" + x + ", " + y + ", " + z + "], Dimension: '" + world.getWorldInfo().getWorldName() + "'");
this.setLink(stack, new VectorWorld(world, x, y, z));
}
return true;

View file

@ -3,6 +3,7 @@
*/
package resonantinduction.tesla;
import calclavia.lib.prefab.item.ItemCoordLink;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
@ -11,9 +12,9 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import resonantinduction.ResonantInduction;
import resonantinduction.base.BlockBase;
import resonantinduction.levitator.ItemCoordLink;
import resonantinduction.render.BlockRenderingHandler;
import universalelectricity.api.vector.Vector3;
import universalelectricity.api.vector.VectorWorld;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -77,18 +78,17 @@ public class BlockTesla extends BlockBase implements ITileEntityProvider
if (tileEntity.linked == null)
{
ItemCoordLink link = ((ItemCoordLink) entityPlayer.getCurrentEquippedItem().getItem());
Vector3 linkVec = link.getLink(entityPlayer.getCurrentEquippedItem());
VectorWorld linkVec = link.getLink(entityPlayer.getCurrentEquippedItem());
if (linkVec != null)
{
if (!world.isRemote)
{
int dimID = link.getLinkDim(entityPlayer.getCurrentEquippedItem());
World otherWorld = MinecraftServer.getServer().worldServerForDimension(dimID);
World otherWorld = linkVec.world;
if (linkVec.getTileEntity(otherWorld) instanceof TileTesla)
{
tileEntity.setLink(new Vector3(((TileTesla) linkVec.getTileEntity(otherWorld)).getTopTelsa()), dimID, true);
tileEntity.setLink(new Vector3(((TileTesla) linkVec.getTileEntity(otherWorld)).getTopTelsa()), linkVec.world.provider.dimensionId, true);
entityPlayer.addChatMessage("Linked " + this.getLocalizedName() + " with " + " [" + (int) linkVec.x + ", " + (int) linkVec.y + ", " + (int) linkVec.z + "]");