Worked on gas related objects
This commit is contained in:
parent
15fd2fdb30
commit
7fd258d8ae
7 changed files with 212 additions and 60 deletions
18
src/dark/api/IItemAirSupply.java
Normal file
18
src/dark/api/IItemAirSupply.java
Normal 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);
|
||||||
|
|
||||||
|
}
|
92
src/dark/core/common/EntityTickHandler.java
Normal file
92
src/dark/core/common/EntityTickHandler.java
Normal 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";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,16 +1,17 @@
|
||||||
package dark.core.common.blocks;
|
package dark.core.common.blocks;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.client.renderer.texture.IconRegister;
|
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.tileentity.TileEntity;
|
||||||
import net.minecraft.util.AxisAlignedBB;
|
import net.minecraft.util.AxisAlignedBB;
|
||||||
import net.minecraft.util.ChatMessageComponent;
|
import net.minecraft.util.Icon;
|
||||||
import net.minecraft.world.ColorizerGrass;
|
|
||||||
import net.minecraft.world.IBlockAccess;
|
import net.minecraft.world.IBlockAccess;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
@ -43,12 +44,15 @@ public class BlockGasOre extends Block implements IGasBlock
|
||||||
this.setTickRandomly(true);
|
this.setTickRandomly(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int tickRate(World par1World)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateTick(World world, int x, int y, int z, Random rand)
|
public void updateTick(World world, int x, int y, int z, Random rand)
|
||||||
{
|
{
|
||||||
if (!world.isRemote)
|
if (!world.isRemote)
|
||||||
{
|
|
||||||
if (rand.nextFloat() > 0.5f)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
final Vector3 vec = new Vector3(x, y, z);
|
final Vector3 vec = new Vector3(x, y, z);
|
||||||
|
@ -61,7 +65,7 @@ public class BlockGasOre extends Block implements IGasBlock
|
||||||
int blockID = sVec.getBlockID(world);
|
int blockID = sVec.getBlockID(world);
|
||||||
Block block = Block.blocksList[blockID];
|
Block block = Block.blocksList[blockID];
|
||||||
|
|
||||||
if (block != null && block.isAirBlock(world, x, y, z) && blockID != this.blockID)
|
if (blockID == 0 || block == null || block != null && block.isAirBlock(world, x, y, z) && blockID != this.blockID)
|
||||||
{
|
{
|
||||||
if (meta == 0)
|
if (meta == 0)
|
||||||
{
|
{
|
||||||
|
@ -85,7 +89,6 @@ public class BlockGasOre extends Block implements IGasBlock
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* IFluidBlock */
|
/* IFluidBlock */
|
||||||
@Override
|
@Override
|
||||||
|
@ -103,7 +106,7 @@ public class BlockGasOre extends Block implements IGasBlock
|
||||||
@Override
|
@Override
|
||||||
public boolean canDrain(World world, int x, int y, int z)
|
public boolean canDrain(World world, int x, int y, int z)
|
||||||
{
|
{
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -130,58 +133,66 @@ public class BlockGasOre extends Block implements IGasBlock
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isCollidable()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Icon getIcon(int par1, int par2)
|
||||||
|
{
|
||||||
|
return this.blockIcon;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerIcons(IconRegister par1IconRegister)
|
public void registerIcons(IconRegister par1IconRegister)
|
||||||
{
|
{
|
||||||
this.blockIcon = par1IconRegister.registerIcon(DarkMain.getInstance().PREFIX + "gas");
|
this.blockIcon = par1IconRegister.registerIcon(DarkMain.getInstance().PREFIX + "gas");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRenderBlockPass()
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOpaqueCube()
|
public boolean isOpaqueCube()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean renderAsNormalBlock()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public int getBlockColor()
|
public int getBlockColor()
|
||||||
{
|
{
|
||||||
return Color.GREEN.getRGB();
|
return Color.orange.getRGB();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public int getRenderColor(int par1)
|
public int getRenderColor(int par1)
|
||||||
{
|
{
|
||||||
|
//TODO make the color darker as the meta value goes higher
|
||||||
return this.getBlockColor();
|
return this.getBlockColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SideOnly(Side.CLIENT)
|
@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;
|
return this.getRenderColor(world.getBlockMetadata(x, y, z));
|
||||||
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;
|
@Override
|
||||||
|
public void getSubBlocks(int blockID, CreativeTabs tab, List creativeTabList)
|
||||||
|
{
|
||||||
|
creativeTabList.add(new ItemStack(blockID, 1, 15));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,8 @@ public class GasOreGenerator implements IWorldGenerator
|
||||||
|
|
||||||
public int minGenerateLevel = 6;
|
public int minGenerateLevel = 6;
|
||||||
public int maxGenerateLevel = 50;
|
public int maxGenerateLevel = 50;
|
||||||
public int amountPerChunk = 10;
|
public int amountPerChunk = 3;
|
||||||
public int amountPerBranch = 10;
|
public int amountPerBranch = 15;
|
||||||
public int replaceID = 1;
|
public int replaceID = 1;
|
||||||
|
|
||||||
public FluidStack stack;
|
public FluidStack stack;
|
||||||
|
|
25
src/dark/core/common/items/ItemFluidCan.java
Normal file
25
src/dark/core/common/items/ItemFluidCan.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
9
src/dark/core/common/items/ItemStorageCan.java
Normal file
9
src/dark/core/common/items/ItemStorageCan.java
Normal 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
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -20,8 +20,6 @@ public class BlockColored extends Block
|
||||||
{
|
{
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
private Icon[] icons;
|
private Icon[] icons;
|
||||||
@SideOnly(Side.CLIENT)
|
|
||||||
private Icon singleIcon;
|
|
||||||
|
|
||||||
/** Use a single icon to create all 16 colors */
|
/** Use a single icon to create all 16 colors */
|
||||||
boolean colorized = true;
|
boolean colorized = true;
|
||||||
|
@ -38,7 +36,7 @@ public class BlockColored extends Block
|
||||||
{
|
{
|
||||||
if (colorized)
|
if (colorized)
|
||||||
{
|
{
|
||||||
return this.singleIcon;
|
return this.blockIcon;
|
||||||
}
|
}
|
||||||
return this.icons[~meta & 15];
|
return this.icons[~meta & 15];
|
||||||
}
|
}
|
||||||
|
@ -65,7 +63,7 @@ public class BlockColored extends Block
|
||||||
{
|
{
|
||||||
if (colorized)
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@ -91,7 +89,6 @@ public class BlockColored extends Block
|
||||||
{
|
{
|
||||||
if (this.colorized)
|
if (this.colorized)
|
||||||
{
|
{
|
||||||
|
|
||||||
return DarkMain.dyeColors[meta & 15].getRGB();
|
return DarkMain.dyeColors[meta & 15].getRGB();
|
||||||
}
|
}
|
||||||
return super.getRenderColor(meta);
|
return super.getRenderColor(meta);
|
||||||
|
|
Loading…
Reference in a new issue