diff --git a/src/minecraft/dark/library/DarkMain.java b/src/minecraft/dark/library/DarkMain.java index a6da8eca..971c9bb9 100644 --- a/src/minecraft/dark/library/DarkMain.java +++ b/src/minecraft/dark/library/DarkMain.java @@ -42,8 +42,7 @@ public class DarkMain if (!loadedItems) { LOGGER.fine("Loaded Basic Components Items"); - - // UniversalElectricity.CONFIGURATION.load(); + BasicComponents.requestItem("ingotCopper", 0); BasicComponents.requestItem("ingotTin", 0); @@ -69,7 +68,8 @@ public class DarkMain BasicComponents.requestItem("infiniteBattery", 0); loadedItems = true; + BasicComponents.register(mod, channel); } - BasicComponents.register(mod, channel); + } } diff --git a/src/minecraft/dark/library/damage/EntityTileDamage.java b/src/minecraft/dark/library/damage/EntityTileDamage.java new file mode 100644 index 00000000..b5ee6168 --- /dev/null +++ b/src/minecraft/dark/library/damage/EntityTileDamage.java @@ -0,0 +1,143 @@ +package dark.library.damage; + +import universalelectricity.core.vector.Vector3; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.DamageSource; +import net.minecraft.world.World; + +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteArrayDataOutput; + +import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData; + +/** + * Entity designed to take damage and apply it to the tile from an Entity. Simulates the tile is + * alive and can be harmed by normal AIs without additional code. + * + * @author DarkGuardsman + * + */ +public class EntityTileDamage extends Entity implements IEntityAdditionalSpawnData +{ + + private TileEntity host; + int hp = 100; + + public EntityTileDamage(World par1World) + { + super(par1World); + this.setSize(1F, 1F); + } + + public EntityTileDamage(World par1World, TileEntity c) + { + this(par1World); + this.isImmuneToFire = true; + this.setPosition(c.xCoord + 0.5, c.yCoord + 0.5, c.zCoord + 0.5); + this.host = c; + } + + @Override + protected void entityInit() + { + // TODO Auto-generated method stub + + } + + @Override + public boolean attackEntityFrom(DamageSource source, int ammount) + { + if (this.isEntityInvulnerable()) + { + return false; + } + else if (this.host instanceof IHpTile) + { + return ((IHpTile) this.host).onDamageTaken(source, ammount); + } + else + { + this.hp -= ammount; + if (hp <= 0) + { + if (this.host != null) + { + Vector3 vec = new Vector3(this.host.xCoord, this.host.yCoord, this.host.zCoord); + int id = vec.getBlockID(this.worldObj); + int meta = vec.getBlockID(this.worldObj); + Block block = Block.blocksList[id]; + if (block != null) + { + block.breakBlock(this.worldObj, this.host.xCoord, this.host.yCoord, this.host.zCoord, id, meta); + } + vec.setBlock(this.worldObj, 0); + } + this.setDead(); + + } + return false; + } + } + + @Override + public String getEntityName() + { + return "EntityTileTarget"; + } + + @Override + public void writeSpawnData(ByteArrayDataOutput data) + { + if (this.host != null) + { + data.writeInt(this.host.xCoord); + data.writeInt(this.host.yCoord); + data.writeInt(this.host.zCoord); + } + } + + @Override + public void readSpawnData(ByteArrayDataInput data) + { + this.host = this.worldObj.getBlockTileEntity(data.readInt(), data.readInt(), data.readInt()); + } + + @Override + public void onUpdate() + { + if (this.host == null || this.host.isInvalid()) + { + this.setDead(); + return; + } + if (this.host instanceof IHpTile && !((IHpTile) this.host).isAlive()) + { + this.setDead(); + return; + } + } + + @Override + protected void readEntityFromNBT(NBTTagCompound nbttagcompound) + { + // TODO Auto-generated method stub + + } + + @Override + protected void writeEntityToNBT(NBTTagCompound nbttagcompound) + { + // TODO Auto-generated method stub + + } + + @Override + protected boolean canTriggerWalking() + { + return false; + } + +} diff --git a/src/minecraft/dark/library/damage/IHpTile.java b/src/minecraft/dark/library/damage/IHpTile.java new file mode 100644 index 00000000..4dc5151d --- /dev/null +++ b/src/minecraft/dark/library/damage/IHpTile.java @@ -0,0 +1,21 @@ +package dark.library.damage; + +import net.minecraft.util.DamageSource; + +public interface IHpTile +{ + /** + * Same as attackEntityFrom in Entity.class + * + * @param source - DamageSource/DamageType + * @param ammount - amount of damage + * @return + */ + public boolean onDamageTaken(DamageSource source, int ammount); + + /** + * Is this tile considered too still be alive. Allows for the tile to remain while being + * considered dead + */ + public boolean isAlive(); +} diff --git a/src/minecraft/dark/library/damage/TileDamageSource.java b/src/minecraft/dark/library/damage/TileDamageSource.java new file mode 100644 index 00000000..d4031729 --- /dev/null +++ b/src/minecraft/dark/library/damage/TileDamageSource.java @@ -0,0 +1,36 @@ +package dark.library.damage; + +import universalelectricity.prefab.CustomDamageSource; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EntityDamageSourceIndirect; +import cpw.mods.fml.common.registry.LanguageRegistry; + +public class TileDamageSource extends CustomDamageSource +{ + protected Object damageSource; + + public static final CustomDamageSource bullets = ((CustomDamageSource) new CustomDamageSource("Bullets")).setDeathMessage("%1$s was filled with holes!"); + public static final CustomDamageSource laser = ((CustomDamageSource) new CustomDamageSource("Laser")).setDeathMessage("%1$s was vaporized!"); + + public TileDamageSource(String damageName, Object attacker) + { + super(damageName); + this.damageSource = attacker; + } + + @Override + public Entity getEntity() + { + return damageSource instanceof Entity ? (Entity) damageSource : null; + } + + @Override + public boolean isDifficultyScaled() + { + return this.damageSource != null && this.damageSource instanceof EntityLiving && !(this.damageSource instanceof EntityPlayer); + } +} diff --git a/src/minecraft/dark/library/orbit/NetworkOrbit.java b/src/minecraft/dark/library/orbit/NetworkOrbit.java index bd8a4f06..6f27f81f 100644 --- a/src/minecraft/dark/library/orbit/NetworkOrbit.java +++ b/src/minecraft/dark/library/orbit/NetworkOrbit.java @@ -159,6 +159,6 @@ public class NetworkOrbit quat.FromEuler((float) t.x, ((float) (t.y)), (float) t.z); ya.FromAxis(new Vector3(0, 1f, 0), (float) o); - return ya.multi(quat).multi(new Vector3(0, 0, r)); + return quat.multi(ya).multi(new Vector3(0, 0, r)); } }