Setup a registration system for sentry guns

This commit is contained in:
Robert 2013-11-12 15:12:44 -05:00
parent 75ede59759
commit 41aa838510
5 changed files with 200 additions and 0 deletions

View file

@ -0,0 +1,9 @@
package dark.api;
/** Applied to tile entities that are sentry guns
*
* @author DarkGuardsman */
public interface ISentryGun
{
}

View file

@ -0,0 +1,115 @@
package dark.core.prefab.sentry;
import java.util.Set;
import com.builtbroken.common.Pair;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import dark.core.common.DarkMain;
import dark.core.prefab.machine.BlockMachine;
import dark.core.registration.ModObjectRegistry;
/** Actual block that is the sentry gun. Mainly a place holder as the sentry guns need something to
* exist threw that is not an entity.
*
* @author DarkGuardsman */
public class BlockSentryGun extends BlockMachine
{
static TileEntitySentry[] sentryGuns = new TileEntitySentry[16];
static String[] sentryGunNames = new String[16];
static int registeredGuns = 0;
static int[] sentryBlockIds = new int[1];
public BlockSentryGun(int v)
{
super(DarkMain.CONFIGURATION, "DMSentryGun" + v, Material.iron);
this.setResistance(100);
this.setHardness(100);
}
/** Make sure to let others know your claimed IDs or add configs so we don't run into issues. As
* well the slot is the meta data value the gun will be created with. Any number over 15 will
* create another block then use its 16 meta values. */
public static void registerSentry(int slot, String name, Class<? extends TileEntitySentry> clazz)
{
try
{
//Expands the sentry gun list as needed;
if (slot > sentryGuns.length)
{
int b = (slot / 16) + 1;
sentryBlockIds = new int[b];
TileEntitySentry[] guns = new TileEntitySentry[b * 16];
for (int s = 0; s < sentryGuns.length; s++)
{
guns[s] = sentryGuns[s];
}
sentryGuns = guns;
}
if (clazz != null && sentryGuns[slot] == null)
{
int b = (slot / 16);
sentryBlockIds[b] = -1;
sentryGuns[slot] = clazz.newInstance();
sentryGunNames[slot] = name;
registeredGuns++;
}
else if (sentryGuns[slot] != null)
{
throw new IllegalArgumentException("Sentry gun slot " + slot + " is already occupied by " + sentryGuns[slot] + " when adding " + clazz);
}
}
catch (InstantiationException e)
{
e.printStackTrace();
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
catch (IllegalArgumentException e)
{
throw e;
}
catch (Exception e)
{
e.printStackTrace();
}
}
/** Called by the core when this block is about to be created. If there are no registered sentry
* guns then this block doesn't exist. */
public static void createAndRegister()
{
if (registeredGuns > 0)
{
for (int b = 0; b < sentryBlockIds.length; b++)
{
if (sentryBlockIds[b] == -1)
{
Block block = ModObjectRegistry.createNewBlock("DMSentryGun" + b, DarkMain.MOD_ID, BlockSentryGun.class);
sentryBlockIds[b] = block.blockID;
}
}
for (int t = 0; t < sentryGuns.length; t++)
{
}
}
}
@Override
public void getTileEntities(int blockID, Set<Pair<String, Class<? extends TileEntity>>> list)
{
for (int t = 0; t < sentryGuns.length; t++)
{
if (sentryGuns[t] != null)
{
list.add(new Pair("DMSentry_" + sentryGunNames[t], sentryGuns[t].getClass()));
}
}
}
}

View file

@ -0,0 +1,40 @@
package dark.core.prefab.sentry;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
/** Since we are going to need an entity for the sentries to take damage with we are actually going
* to do more with the entity than redirect damage.
*
* @author DarkGuardsman */
public class EntitySentryGun extends Entity
{
public EntitySentryGun(World par1World)
{
super(par1World);
}
@Override
protected void entityInit()
{
// TODO Auto-generated method stub
}
@Override
protected void readEntityFromNBT(NBTTagCompound nbttagcompound)
{
// TODO Auto-generated method stub
}
@Override
protected void writeEntityToNBT(NBTTagCompound nbttagcompound)
{
// TODO Auto-generated method stub
}
}

View file

@ -0,0 +1,30 @@
package dark.core.prefab.sentry;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import dark.core.prefab.ItemBlockHolder;
/** Item block that is the unplaced sentry gun. All sentry gun data is held by NBT to allow the sentry
* gun to exist without metadata limits.
*
* @author DarkGuardsman */
public class ItemBlockSentry extends ItemBlockHolder
{
public ItemBlockSentry(int id)
{
super(id);
}
@Override
public int getMetadata(int damage)
{
return 0;
}
@Override
public String getUnlocalizedName(ItemStack itemStack)
{
return Block.blocksList[this.getBlockID()].getUnlocalizedName() + "." + itemStack.getItemDamage();
}
}

View file

@ -0,0 +1,6 @@
package dark.core.prefab.sentry;
public class TileEntityTerminal
{
}