Worked on gas related objects

This commit is contained in:
Robert 2013-11-22 18:28:11 -05:00
parent 15fd2fdb30
commit 7fd258d8ae
7 changed files with 212 additions and 60 deletions

View file

@ -0,0 +1,18 @@
package dark.api;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
/** Item that supplies air to an entity and prevents them from dying when under water, in gas, or
* without air.
*
* @author DarkGuardsman */
public interface IItemAirSupply
{
/** Called when the entity is found to be in an area were the entity has no air. Does not work
* with vinalla blocks or blocks from other mods. To support other mods simply do a per tick
* update of the item and supply the entity with air. The reason for this method is to prevent
* potion effects from gas poisoning or potion effects from sucking in fluids */
public boolean canSupplyAir(Entity entity, ItemStack stack);
}

View file

@ -0,0 +1,92 @@
package dark.core.common;
import java.util.EnumSet;
import net.minecraft.block.material.Material;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.potion.Potion;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
import net.minecraft.world.WorldProvider;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;
/** Tick handler that takes care of things like decreasing air supply while in gas block
*
* @author DarkGuardsman */
public class EntityTickHandler implements ITickHandler
{
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
for (WorldServer world : DimensionManager.getWorlds())
{
for (Object o : world.loadedEntityList)
{
if (o instanceof EntityLivingBase)
{
EntityLivingBase entity = (EntityLivingBase) o;
boolean flag = entity instanceof EntityPlayer && ((EntityPlayer) entity).capabilities.disableDamage;
if (entity.isEntityAlive() && entity.isInsideOfMaterial(Material.water))
{
if (!entity.canBreatheUnderwater() && !entity.isPotionActive(Potion.waterBreathing.id) && !flag)
{
entity.setAir(this.decreaseAirSupply(entity, entity.getAir()));
if (entity.getAir() == -20)
{
entity.setAir(0);
for (int i = 0; i < 8; ++i)
{
float f = entity.worldObj.rand.nextFloat() - entity.worldObj.rand.nextFloat();
float f1 = entity.worldObj.rand.nextFloat() - entity.worldObj.rand.nextFloat();
float f2 = entity.worldObj.rand.nextFloat() - entity.worldObj.rand.nextFloat();
entity.worldObj.spawnParticle("bubble", entity.posX + (double) f, entity.posY + (double) f1, entity.posZ + (double) f2, entity.motionX, entity.motionY, entity.motionZ);
}
entity.attackEntityFrom(DamageSource.drown, 2.0F);
}
}
}
}
}
}
}
protected int decreaseAirSupply(EntityLivingBase entity, int par1)
{
int j = EnchantmentHelper.getRespiration(entity);
return j > 0 && entity.worldObj.rand.nextInt(j + 1) > 0 ? par1 : par1 - 1;
}
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{
// TODO Auto-generated method stub
}
@Override
public EnumSet<TickType> ticks()
{
return EnumSet.of(TickType.SERVER);
}
@Override
public String getLabel()
{
return "[CoreMachine]EntityTickHandler";
}
}

View file

@ -1,16 +1,17 @@
package dark.core.common.blocks;
import java.awt.Color;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatMessageComponent;
import net.minecraft.world.ColorizerGrass;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
@ -42,47 +43,49 @@ public class BlockGasOre extends Block implements IGasBlock
this.setCreativeTab(DMCreativeTab.tabIndustrial);
this.setTickRandomly(true);
}
public int tickRate(World par1World)
{
return 1;
}
@Override
public void updateTick(World world, int x, int y, int z, Random rand)
{
if (!world.isRemote)
{
if (rand.nextFloat() > 0.5f)
final Vector3 vec = new Vector3(x, y, z);
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
int meta = world.getBlockMetadata(x, y, z);
final Vector3 vec = new Vector3(x, y, z);
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
Vector3 sVec = vec.clone().modifyPositionFromSide(dir);
int sMeta = sVec.getBlockMetadata(world);
int blockID = sVec.getBlockID(world);
Block block = Block.blocksList[blockID];
if (blockID == 0 || block == null || block != null && block.isAirBlock(world, x, y, z) && blockID != this.blockID)
{
int meta = world.getBlockMetadata(x, y, z);
Vector3 sVec = vec.clone().modifyPositionFromSide(dir);
int sMeta = sVec.getBlockMetadata(world);
int blockID = sVec.getBlockID(world);
Block block = Block.blocksList[blockID];
if (block != null && block.isAirBlock(world, x, y, z) && blockID != this.blockID)
if (meta == 0)
{
if (meta == 0)
{
world.setBlockToAir(x, y, z);
break;
}
else
{
world.setBlock(x, y, z, this.blockID, meta / 2, 2);
sVec.setBlock(world, this.blockID, meta / 2, 2);
break;
}
world.setBlockToAir(x, y, z);
break;
}
else if (blockID == this.blockID && meta > sMeta)
else
{
meta += sMeta;
world.setBlock(x, y, z, this.blockID, meta / 2, 2);
sVec.setBlock(world, this.blockID, meta / 2, 2);
break;
}
}
else if (blockID == this.blockID && meta > sMeta)
{
meta += sMeta;
world.setBlock(x, y, z, this.blockID, meta / 2, 2);
sVec.setBlock(world, this.blockID, meta / 2, 2);
break;
}
}
}
}
@ -103,7 +106,7 @@ public class BlockGasOre extends Block implements IGasBlock
@Override
public boolean canDrain(World world, int x, int y, int z)
{
return true;
return false;
}
@Override
@ -129,6 +132,17 @@ public class BlockGasOre extends Block implements IGasBlock
{
return null;
}
public boolean isCollidable()
{
return false;
}
@Override
public Icon getIcon(int par1, int par2)
{
return this.blockIcon;
}
@Override
public void registerIcons(IconRegister par1IconRegister)
@ -136,52 +150,49 @@ public class BlockGasOre extends Block implements IGasBlock
this.blockIcon = par1IconRegister.registerIcon(DarkMain.getInstance().PREFIX + "gas");
}
@Override
public int getRenderBlockPass()
{
return 1;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
@SideOnly(Side.CLIENT)
public int getBlockColor()
{
return Color.GREEN.getRGB();
return Color.orange.getRGB();
}
@Override
@SideOnly(Side.CLIENT)
public int getRenderColor(int par1)
{
//TODO make the color darker as the meta value goes higher
return this.getBlockColor();
}
@Override
public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
{
return true;
}
@Override
@SideOnly(Side.CLIENT)
public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
@Override
public int colorMultiplier(IBlockAccess world, int x, int y, int z)
{
int l = 0;
int i1 = 0;
int j1 = 0;
for (int k1 = -1; k1 <= 1; ++k1)
{
for (int l1 = -1; l1 <= 1; ++l1)
{
int i2 = par1IBlockAccess.getBiomeGenForCoords(par2 + l1, par4 + k1).getBiomeGrassColor();
l += (i2 & 16711680) >> 16;
i1 += (i2 & 65280) >> 8;
j1 += i2 & 255;
}
}
return (l / 9 & 255) << 16 | (i1 / 9 & 255) << 8 | j1 / 9 & 255;
return this.getRenderColor(world.getBlockMetadata(x, y, z));
}
@Override
public void getSubBlocks(int blockID, CreativeTabs tab, List creativeTabList)
{
creativeTabList.add(new ItemStack(blockID, 1, 15));
}
}

View file

@ -23,8 +23,8 @@ public class GasOreGenerator implements IWorldGenerator
public int minGenerateLevel = 6;
public int maxGenerateLevel = 50;
public int amountPerChunk = 10;
public int amountPerBranch = 10;
public int amountPerChunk = 3;
public int amountPerBranch = 15;
public int replaceID = 1;
public FluidStack stack;

View file

@ -0,0 +1,25 @@
package dark.core.common.items;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.core.common.DMCreativeTab;
import dark.core.common.DarkMain;
import net.minecraft.item.Item;
import net.minecraft.util.Icon;
/** Small fluid can that is designed to store up to one bucket of fluid.
*
* @author DarkGuardsman */
public class ItemFluidCan extends Item
{
public static final String FLUID_NBT = "FluidStack";
@SideOnly(Side.CLIENT)
public Icon[] icons;
public ItemFluidCan()
{
super(DarkMain.CONFIGURATION.getItem("FluidCan", DarkMain.getNextItemId()).getInt());
this.setCreativeTab(DMCreativeTab.tabIndustrial);
}
}

View file

@ -0,0 +1,9 @@
package dark.core.common.items;
/** Can that is used to store items such as food, parts, or solid fuels.
*
* @author DarkGuardsman */
public class ItemStorageCan
{
}

View file

@ -20,8 +20,6 @@ public class BlockColored extends Block
{
@SideOnly(Side.CLIENT)
private Icon[] icons;
@SideOnly(Side.CLIENT)
private Icon singleIcon;
/** Use a single icon to create all 16 colors */
boolean colorized = true;
@ -38,7 +36,7 @@ public class BlockColored extends Block
{
if (colorized)
{
return this.singleIcon;
return this.blockIcon;
}
return this.icons[~meta & 15];
}
@ -65,7 +63,7 @@ public class BlockColored extends Block
{
if (colorized)
{
this.singleIcon = iconReg.registerIcon(DarkMain.getInstance().PREFIX + this.getUnlocalizedName().replace("tile.", ""));
this.blockIcon = iconReg.registerIcon(DarkMain.getInstance().PREFIX + this.getUnlocalizedName().replace("tile.", ""));
}
else
{
@ -91,7 +89,6 @@ public class BlockColored extends Block
{
if (this.colorized)
{
return DarkMain.dyeColors[meta & 15].getRGB();
}
return super.getRenderColor(meta);