Store owner information in the Tile

This commit is contained in:
CovertJaguar 2013-11-25 12:44:01 -08:00
parent 5c10517acb
commit 6b8ec69b37
12 changed files with 62 additions and 68 deletions

View file

@ -4,17 +4,30 @@ import buildcraft.core.utils.Utils;
import java.util.Random;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public abstract class BlockBuildCraft extends BlockContainer {
protected static boolean keepInventory = false;
protected Random rand;
protected final Random rand = new Random();
protected BlockBuildCraft(int id, Material material) {
super(id, material);
this.rand = new Random();
setCreativeTab(CreativeTabBuildCraft.MACHINES.get());
setHardness(5F);
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack) {
super.onBlockPlacedBy(world, x, y, z, entity, stack);
TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof TileBuildCraft) {
((TileBuildCraft) tile).onBlockPlacedBy(entity, stack);
}
}
@Override
@ -23,4 +36,11 @@ public abstract class BlockBuildCraft extends BlockContainer {
super.breakBlock(world, x, y, z, par5, par6);
}
@Override
public int getLightValue(IBlockAccess world, int x, int y, int z) {
TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof IMachine && ((IMachine) tile).isActive())
return super.getLightValue(world, x, y, z) + 8;
return super.getLightValue(world, x, y, z);
}
}

View file

@ -19,6 +19,10 @@ import buildcraft.core.utils.Utils;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
@ -32,6 +36,7 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
private final TilePacketWrapper descriptionPacket;
private final TilePacketWrapper updatePacket;
private boolean init = false;
private String owner = "[BuildCraft]";
public TileBuildCraft() {
if (!updateWrappers.containsKey(this.getClass())) {
@ -47,6 +52,10 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
}
public String getOwner() {
return owner;
}
@Override
public void updateEntity() {
if (!init && !isInvalid()) {
@ -70,6 +79,11 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
Utils.handleBufferedDescription(this);
}
public void onBlockPlacedBy(EntityLivingBase entity, ItemStack stack) {
if (entity instanceof EntityPlayer)
owner = ((EntityPlayer) entity).username;
}
public void destroy() {
}
@ -110,6 +124,19 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
public void postPacketHandling(PacketUpdate packet) {
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
nbt.setString("owner", owner);
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
if (nbt.hasKey("owner"))
owner = nbt.getString("owner");
}
public boolean isInvNameLocalized() {
// TODO Auto-generated method stub
return false;

View file

@ -8,13 +8,12 @@
package buildcraft.energy;
import buildcraft.BuildCraftCore;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.IItemPipe;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import java.util.Random;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
@ -25,7 +24,7 @@ import net.minecraft.util.Icon;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
public class BlockEngine extends BlockContainer {
public class BlockEngine extends BlockBuildCraft {
private static Icon woodTexture;
private static Icon stoneTexture;
@ -33,9 +32,6 @@ public class BlockEngine extends BlockContainer {
public BlockEngine(int i) {
super(i, Material.iron);
setHardness(5F);
setCreativeTab(CreativeTabBuildCraft.MACHINES.get());
setUnlocalizedName("engineBlock");
}

View file

@ -8,12 +8,12 @@
package buildcraft.factory;
import buildcraft.api.tools.IToolWrench;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.utils.Utils;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.ArrayList;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
@ -23,7 +23,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
public class BlockFloodGate extends BlockContainer {
public class BlockFloodGate extends BlockBuildCraft {
private Icon textureTop;
private Icon textureBottom;
@ -31,8 +31,6 @@ public class BlockFloodGate extends BlockContainer {
public BlockFloodGate(int i) {
super(i, Material.iron);
setHardness(5F);
setCreativeTab(CreativeTabBuildCraft.MACHINES.get());
}
@Override

View file

@ -23,7 +23,6 @@ public class BlockHopper extends BlockBuildCraft {
public BlockHopper(int blockId) {
super(blockId, Material.iron);
setHardness(5F);
}
@Override

View file

@ -1,43 +0,0 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.factory;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.IMachine;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
public abstract class BlockMachineRoot extends BlockContainer {
protected BlockMachineRoot(int i, Material material) {
super(i, material);
setCreativeTab(CreativeTabBuildCraft.MACHINES.get());
setHardness(5F);
}
@Override
public float getBlockBrightness(IBlockAccess iblockaccess, int i, int j, int k) {
for (int x = i - 1; x <= i + 1; ++x) {
for (int y = j - 1; y <= j + 1; ++y) {
for (int z = k - 1; z <= k + 1; ++z) {
TileEntity tile = iblockaccess.getBlockTileEntity(x, y, z);
if (tile instanceof IMachine && ((IMachine) tile).isActive())
return super.getBlockBrightness(iblockaccess, i, j, k) + 0.5F;
}
}
}
return super.getBlockBrightness(iblockaccess, i, j, k);
}
}

View file

@ -11,6 +11,7 @@ package buildcraft.factory;
import buildcraft.BuildCraftFactory;
import buildcraft.api.core.Position;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.utils.Utils;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -24,7 +25,7 @@ import net.minecraft.util.Icon;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
public class BlockMiningWell extends BlockMachineRoot {
public class BlockMiningWell extends BlockBuildCraft {
Icon textureFront, textureSides, textureBack, textureTop;

View file

@ -11,7 +11,6 @@ import buildcraft.core.CoreConstants;
import buildcraft.core.IFramePipeConnection;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;

View file

@ -8,12 +8,12 @@
package buildcraft.factory;
import buildcraft.api.tools.IToolWrench;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.utils.Utils;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.ArrayList;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
@ -23,7 +23,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
public class BlockPump extends BlockContainer {
public class BlockPump extends BlockBuildCraft {
private Icon textureTop;
private Icon textureBottom;
@ -31,8 +31,6 @@ public class BlockPump extends BlockContainer {
public BlockPump(int i) {
super(i, Material.iron);
setHardness(5F);
setCreativeTab(CreativeTabBuildCraft.MACHINES.get());
}
@Override

View file

@ -10,6 +10,7 @@ package buildcraft.factory;
import buildcraft.BuildCraftFactory;
import buildcraft.api.core.Position;
import buildcraft.api.tools.IToolWrench;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.Box;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;
@ -27,7 +28,7 @@ import net.minecraft.util.Icon;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
public class BlockQuarry extends BlockMachineRoot {
public class BlockQuarry extends BlockBuildCraft {
Icon textureTop;
Icon textureFront;
@ -38,7 +39,7 @@ public class BlockQuarry extends BlockMachineRoot {
setHardness(10F);
setResistance(10F);
setStepSound(soundStoneFootstep);
setStepSound(soundAnvilFootstep);
}
@Override

View file

@ -19,7 +19,6 @@ import buildcraft.api.recipes.RefineryRecipes.Recipe;
import buildcraft.core.IMachine;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.fluids.SingleUseTank;
import buildcraft.core.fluids.Tank;
import buildcraft.core.fluids.TankManager;
import buildcraft.core.network.PacketPayload;
import buildcraft.core.network.PacketPayloadStream;

View file

@ -15,7 +15,6 @@ import java.util.Map;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.client.particle.EntityDiggingFX;
@ -38,6 +37,7 @@ import buildcraft.BuildCraftTransport;
import buildcraft.api.tools.IToolWrench;
import buildcraft.api.transport.IPipe;
import buildcraft.api.transport.ISolidSideTile;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.BlockIndex;
import buildcraft.core.CoreConstants;
import buildcraft.core.proxy.CoreProxy;
@ -50,7 +50,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import java.util.Arrays;
import net.minecraft.client.Minecraft;
public class BlockGenericPipe extends BlockContainer {
public class BlockGenericPipe extends BlockBuildCraft {
static enum Part {
@ -79,7 +79,6 @@ public class BlockGenericPipe extends BlockContainer {
}
}
private static final ForgeDirection[] DIR_VALUES = ForgeDirection.values();
private static Random rand = new Random();
private boolean skippedFirstIconRegister;
private int renderMask = 0;