Implemented block saving with their content
Added tooltip to item blocks to show their content
This commit is contained in:
parent
3e72a2f23f
commit
d8639613ee
5 changed files with 153 additions and 5 deletions
|
@ -411,12 +411,12 @@ public class WarpDrive implements LoadingCallback {
|
||||||
|
|
||||||
// FORCE FIELD PROJECTOR
|
// FORCE FIELD PROJECTOR
|
||||||
blockForceFieldProjectors[index] = new BlockForceFieldProjector(tier);
|
blockForceFieldProjectors[index] = new BlockForceFieldProjector(tier);
|
||||||
GameRegistry.registerBlock(blockForceFieldProjectors[index], "blockProjector" + tier);
|
GameRegistry.registerBlock(blockForceFieldProjectors[index], ItemBlockForceFieldProjector.class, "blockProjector" + tier);
|
||||||
GameRegistry.registerTileEntity(TileEntityForceFieldProjector.class, MODID + ":blockProjector" + tier);
|
GameRegistry.registerTileEntity(TileEntityForceFieldProjector.class, MODID + ":blockProjector" + tier);
|
||||||
|
|
||||||
// FORCE FIELD RELAY
|
// FORCE FIELD RELAY
|
||||||
blockForceFieldRelays[index] = new BlockForceFieldRelay(tier);
|
blockForceFieldRelays[index] = new BlockForceFieldRelay(tier);
|
||||||
GameRegistry.registerBlock(blockForceFieldRelays[index], "blockForceFieldRelay" + tier);
|
GameRegistry.registerBlock(blockForceFieldRelays[index], ItemBlockForceFieldRelay.class, "blockForceFieldRelay" + tier);
|
||||||
GameRegistry.registerTileEntity(TileEntityForceFieldRelay.class, MODID + ":blockForceFieldRelay" + tier);
|
GameRegistry.registerTileEntity(TileEntityForceFieldRelay.class, MODID + ":blockForceFieldRelay" + tier);
|
||||||
}
|
}
|
||||||
/* TODO
|
/* TODO
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
package cr0s.warpdrive.block;
|
package cr0s.warpdrive.block;
|
||||||
|
|
||||||
|
import cr0s.warpdrive.block.forcefield.TileEntityForceFieldProjector;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockContainer;
|
import net.minecraft.block.BlockContainer;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.MovingObjectPosition;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import cr0s.warpdrive.WarpDrive;
|
import cr0s.warpdrive.WarpDrive;
|
||||||
import cr0s.warpdrive.api.IBlockUpdateDetector;
|
import cr0s.warpdrive.api.IBlockUpdateDetector;
|
||||||
|
@ -32,8 +36,8 @@ public abstract class BlockAbstractContainer extends BlockContainer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemstack) {
|
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack) {
|
||||||
super.onBlockPlacedBy(world, x, y, z, entityLiving, itemstack);
|
super.onBlockPlacedBy(world, x, y, z, entityLiving, itemStack);
|
||||||
if (isRotating) {
|
if (isRotating) {
|
||||||
if (entityLiving != null) {
|
if (entityLiving != null) {
|
||||||
int metadata;
|
int metadata;
|
||||||
|
@ -64,6 +68,50 @@ public abstract class BlockAbstractContainer extends BlockContainer {
|
||||||
world.setBlockMetadataWithNotify(x, y, z, metadata, 3);
|
world.setBlockMetadataWithNotify(x, y, z, metadata, 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TileEntity tileEntity = world.getTileEntity(x, y, z);
|
||||||
|
if (itemStack.hasTagCompound()) {
|
||||||
|
NBTTagCompound nbtTagCompound = (NBTTagCompound)itemStack.getTagCompound().copy();
|
||||||
|
nbtTagCompound.setInteger("x", x);
|
||||||
|
nbtTagCompound.setInteger("y", y);
|
||||||
|
nbtTagCompound.setInteger("z", z);
|
||||||
|
tileEntity.readFromNBT(nbtTagCompound);
|
||||||
|
world.markBlockForUpdate(x, y, z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) {
|
||||||
|
return willHarvest || super.removedByPlayer(world, player, x, y, z, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void dropBlockAsItem(World world, int x, int y, int z, ItemStack itemStack) {
|
||||||
|
TileEntity tileEntity = world.getTileEntity(x, y, z);
|
||||||
|
if (tileEntity == null) {
|
||||||
|
WarpDrive.logger.error("Missing tile entity for " + this + " at " + world + " " + x + " " + y + " " + z);
|
||||||
|
} else {
|
||||||
|
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
||||||
|
tileEntity.writeToNBT(nbtTagCompound);
|
||||||
|
nbtTagCompound.removeTag("x");
|
||||||
|
nbtTagCompound.removeTag("y");
|
||||||
|
nbtTagCompound.removeTag("z");
|
||||||
|
itemStack.setTagCompound(nbtTagCompound);
|
||||||
|
}
|
||||||
|
world.setBlockToAir(x, y, z);
|
||||||
|
super.dropBlockAsItem(world, x, y, z, itemStack);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z, EntityPlayer entityPlayer) {
|
||||||
|
ItemStack itemStack = super.getPickBlock(target, world, x, y, z, entityPlayer);
|
||||||
|
TileEntity tileEntity = world.getTileEntity(x, y, z);
|
||||||
|
NBTTagCompound nbtTagCompound = new NBTTagCompound();
|
||||||
|
tileEntity.writeToNBT(nbtTagCompound);
|
||||||
|
nbtTagCompound.removeTag("x");
|
||||||
|
nbtTagCompound.removeTag("y");
|
||||||
|
nbtTagCompound.removeTag("z");
|
||||||
|
itemStack.setTagCompound(nbtTagCompound);
|
||||||
|
return itemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
package cr0s.warpdrive.block;
|
||||||
|
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
import cr0s.warpdrive.WarpDrive;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.ItemBlock;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.IIcon;
|
||||||
|
import net.minecraft.util.StatCollector;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ItemBlockAbstractBase extends ItemBlock {
|
||||||
|
|
||||||
|
public ItemBlockAbstractBase(Block block) {
|
||||||
|
super(block); // sets field_150939_a to block
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public IIcon getIconFromDamage(int p_77617_1_) {
|
||||||
|
return field_150939_a.getIcon(2, p_77617_1_);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetadata(int damage) {
|
||||||
|
return damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus(final NBTTagCompound nbtTagCompound) {
|
||||||
|
TileEntity tileEntity = field_150939_a.createTileEntity(null, 0);
|
||||||
|
if (tileEntity instanceof TileEntityAbstractEnergy) {
|
||||||
|
if (nbtTagCompound != null) {
|
||||||
|
tileEntity.readFromNBT(nbtTagCompound);
|
||||||
|
}
|
||||||
|
return ((TileEntityAbstractEnergy)tileEntity).getStatus();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addInformation(ItemStack itemStack, EntityPlayer entityPlayer, List list, boolean advancedItemTooltips) {
|
||||||
|
super.addInformation(itemStack, entityPlayer, list, advancedItemTooltips);
|
||||||
|
|
||||||
|
String tooltipName1 = getUnlocalizedName(itemStack) + ".tooltip";
|
||||||
|
if (StatCollector.canTranslate(tooltipName1)) {
|
||||||
|
WarpDrive.addTooltip(list, StatCollector.translateToLocalFormatted(tooltipName1));
|
||||||
|
}
|
||||||
|
|
||||||
|
String tooltipName2 = getUnlocalizedName() + ".tooltip";
|
||||||
|
if ((!tooltipName1.equals(tooltipName2)) && StatCollector.canTranslate(tooltipName2)) {
|
||||||
|
WarpDrive.addTooltip(list, StatCollector.translateToLocalFormatted(tooltipName2));
|
||||||
|
}
|
||||||
|
|
||||||
|
WarpDrive.addTooltip(list, StatCollector.translateToLocalFormatted(getStatus(itemStack.getTagCompound())));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package cr0s.warpdrive.block.forcefield;
|
||||||
|
|
||||||
|
import cr0s.warpdrive.block.ItemBlockAbstractBase;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
|
public class ItemBlockForceFieldProjector extends ItemBlockAbstractBase {
|
||||||
|
|
||||||
|
public ItemBlockForceFieldProjector(Block block) {
|
||||||
|
super(block);
|
||||||
|
setMaxDamage(0);
|
||||||
|
setHasSubtypes(true);
|
||||||
|
setUnlocalizedName("warpdrive.forcefield.projector");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUnlocalizedName(ItemStack itemstack) {
|
||||||
|
if (itemstack == null) {
|
||||||
|
return getUnlocalizedName();
|
||||||
|
}
|
||||||
|
return getUnlocalizedName() + (itemstack.getItemDamage() == 1 ? ".double" : ".single");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package cr0s.warpdrive.block.forcefield;
|
||||||
|
|
||||||
|
import cr0s.warpdrive.block.ItemBlockAbstractBase;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
|
||||||
|
public class ItemBlockForceFieldRelay extends ItemBlockAbstractBase {
|
||||||
|
|
||||||
|
public ItemBlockForceFieldRelay(Block block) {
|
||||||
|
super(block);
|
||||||
|
setMaxDamage(0);
|
||||||
|
setHasSubtypes(false);
|
||||||
|
setUnlocalizedName("warpdrive.forcefield.relay");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue