mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-28 07:55:41 +00:00
#192 Transceivers remember their channel when broken.
This commit is contained in:
1 parent
0d075c158d
commit
ebfde0a3da
1 file changed
+55
-16
@@ -13,6 +13,7 @@ import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
@@ -107,7 +108,7 @@ public class BlockHyperCube extends Block implements ITileEntityProvider, IGuiHa
|
||||
|
||||
@Override
|
||||
public void onBlockAdded(World world, int x, int y, int z) {
|
||||
if(world.isRemote) {
|
||||
if (world.isRemote) {
|
||||
return;
|
||||
}
|
||||
TileHyperCube tr = (TileHyperCube) world.getBlockTileEntity(x, y, z);
|
||||
@@ -116,7 +117,7 @@ public class BlockHyperCube extends Block implements ITileEntityProvider, IGuiHa
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, int blockId) {
|
||||
if(world.isRemote) {
|
||||
if (world.isRemote) {
|
||||
return;
|
||||
}
|
||||
TileHyperCube te = (TileHyperCube) world.getBlockTileEntity(x, y, z);
|
||||
@@ -126,28 +127,65 @@ public class BlockHyperCube extends Block implements ITileEntityProvider, IGuiHa
|
||||
@Override
|
||||
public ArrayList<ItemStack> getBlockDropped(World world, int x, int y, int z, int metadata, int fortune) {
|
||||
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
|
||||
if(!world.isRemote) {
|
||||
if (!world.isRemote) {
|
||||
TileEntity te = world.getBlockTileEntity(x, y, z);
|
||||
if(te instanceof TileHyperCube) {
|
||||
if (te instanceof TileHyperCube) {
|
||||
TileHyperCube hc = (TileHyperCube) te;
|
||||
hc.onBreakBlock();
|
||||
ItemStack itemStack = new ItemStack(this);
|
||||
PowerHandlerUtil.setStoredEnergyForItem(itemStack, hc.getInternalPowerHandler().getEnergyStored());
|
||||
setChannelOnItem(hc, itemStack);
|
||||
ret.add(itemStack);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private void setChannelOnItem(TileHyperCube hc, ItemStack itemStack) {
|
||||
Channel chan = hc.getChannel();
|
||||
if (chan != null) {
|
||||
NBTTagCompound tag = itemStack.getTagCompound();
|
||||
if (tag == null) {
|
||||
tag = new NBTTagCompound();
|
||||
itemStack.setTagCompound(tag);
|
||||
}
|
||||
tag.setString("channelName", chan.name);
|
||||
tag.setBoolean("channelIsPublic", chan.isPublic());
|
||||
if(!chan.isPublic()) {
|
||||
tag.setString("channelUser", chan.user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Channel getChannelFromItem(ItemStack itemStack) {
|
||||
NBTTagCompound tag = itemStack.getTagCompound();
|
||||
if(tag == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String channelName = tag.getString("channelName");
|
||||
if(channelName == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String user = null;
|
||||
if(!tag.getBoolean("channelIsPublic")) {
|
||||
user = tag.getString("channelUser");
|
||||
}
|
||||
return new Channel(channelName, user);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeBlockByPlayer(World world, EntityPlayer player, int x, int y, int z) {
|
||||
if(!world.isRemote) {
|
||||
if (!world.isRemote) {
|
||||
TileEntity te = world.getBlockTileEntity(x, y, z);
|
||||
if(te instanceof TileHyperCube) {
|
||||
if (te instanceof TileHyperCube) {
|
||||
TileHyperCube hc = (TileHyperCube) te;
|
||||
hc.onBreakBlock();
|
||||
ItemStack itemStack = new ItemStack(this);
|
||||
PowerHandlerUtil.setStoredEnergyForItem(itemStack, hc.getInternalPowerHandler().getEnergyStored());
|
||||
setChannelOnItem(hc, itemStack);
|
||||
float f = 0.7F;
|
||||
double d0 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
double d1 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
@@ -162,16 +200,17 @@ public class BlockHyperCube extends Block implements ITileEntityProvider, IGuiHa
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) {
|
||||
if(world.isRemote) {
|
||||
if (world.isRemote) {
|
||||
return;
|
||||
}
|
||||
TileEntity te = world.getBlockTileEntity(x, y, z);
|
||||
if(te instanceof TileHyperCube) {
|
||||
if (te instanceof TileHyperCube) {
|
||||
TileHyperCube cb = (TileHyperCube) te;
|
||||
cb.getInternalPowerHandler().setEnergy(PowerHandlerUtil.getStoredEnergyForItem(stack));
|
||||
if(player instanceof EntityPlayerMP) {
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
cb.setOwner(((EntityPlayerMP) player).username);
|
||||
}
|
||||
cb.setChannel(getChannelFromItem(stack));
|
||||
}
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
@@ -189,23 +228,23 @@ public class BlockHyperCube extends Block implements ITileEntityProvider, IGuiHa
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) {
|
||||
|
||||
if(ConduitUtil.isToolEquipped(entityPlayer) && entityPlayer.isSneaking()) {
|
||||
if(entityPlayer.getCurrentEquippedItem().getItem() instanceof IToolWrench) {
|
||||
if (ConduitUtil.isToolEquipped(entityPlayer) && entityPlayer.isSneaking()) {
|
||||
if (entityPlayer.getCurrentEquippedItem().getItem() instanceof IToolWrench) {
|
||||
IToolWrench wrench = (IToolWrench) entityPlayer.getCurrentEquippedItem().getItem();
|
||||
if(wrench.canWrench(entityPlayer, x, y, z)) {
|
||||
if (wrench.canWrench(entityPlayer, x, y, z)) {
|
||||
removeBlockByPlayer(world, entityPlayer, x, y, z);
|
||||
if(entityPlayer.getCurrentEquippedItem().getItem() instanceof IToolWrench) {
|
||||
if (entityPlayer.getCurrentEquippedItem().getItem() instanceof IToolWrench) {
|
||||
((IToolWrench) entityPlayer.getCurrentEquippedItem().getItem()).wrenchUsed(entityPlayer, x, y, z);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(entityPlayer.isSneaking()) {
|
||||
if (entityPlayer.isSneaking()) {
|
||||
return false;
|
||||
}
|
||||
TileEntity te = world.getBlockTileEntity(x, y, z);
|
||||
if(!(te instanceof TileHyperCube)) {
|
||||
if (!(te instanceof TileHyperCube)) {
|
||||
return false;
|
||||
}
|
||||
entityPlayer.openGui(EnderIO.instance, GuiHandler.GUI_ID_HYPER_CUBE, world, x, y, z);
|
||||
@@ -220,7 +259,7 @@ public class BlockHyperCube extends Block implements ITileEntityProvider, IGuiHa
|
||||
@Override
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
TileEntity te = world.getBlockTileEntity(x, y, z);
|
||||
if(te instanceof TileHyperCube) {
|
||||
if (te instanceof TileHyperCube) {
|
||||
TileHyperCube hc = (TileHyperCube) te;
|
||||
return new GuiHyperCube(hc);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user