2013-12-27 23:59:59 +01:00
|
|
|
package appeng.entity;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.item.EntityItem;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.init.Items;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.MathHelper;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import appeng.api.AEApi;
|
2014-02-23 23:50:53 +01:00
|
|
|
import appeng.client.EffectType;
|
2014-02-09 06:08:27 +01:00
|
|
|
import appeng.core.AEConfig;
|
2014-02-23 23:50:53 +01:00
|
|
|
import appeng.core.CommonHelper;
|
|
|
|
import appeng.core.features.AEFeature;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.util.Platform;
|
|
|
|
|
|
|
|
final public class EntityChargedQuartz extends EntityItem
|
|
|
|
{
|
|
|
|
|
|
|
|
int delay = 0;
|
|
|
|
int transformTime = 0;
|
|
|
|
|
|
|
|
public EntityChargedQuartz(World w) {
|
|
|
|
super( w );
|
|
|
|
}
|
|
|
|
|
|
|
|
public EntityChargedQuartz(World w, double x, double y, double z, ItemStack is) {
|
|
|
|
super( w, x, y, z, is );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdate()
|
|
|
|
{
|
|
|
|
super.onUpdate();
|
|
|
|
|
2014-02-23 23:50:53 +01:00
|
|
|
if ( !AEConfig.instance.isFeatureEnabled( AEFeature.inWorldFluix ) )
|
|
|
|
return;
|
|
|
|
|
2014-02-09 06:08:27 +01:00
|
|
|
if ( Platform.isClient() && delay++ > 30 && AEConfig.instance.enableEffects )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-23 23:50:53 +01:00
|
|
|
CommonHelper.proxy.spawnEffect( EffectType.Lightning, worldObj, posX, posY, posZ );
|
2013-12-27 23:59:59 +01:00
|
|
|
delay = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int j = MathHelper.floor_double( this.posX );
|
|
|
|
int i = MathHelper.floor_double( this.posY );
|
|
|
|
int k = MathHelper.floor_double( this.posZ );
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
Material mat = worldObj.getBlock( j, i, k ).getMaterial();
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( Platform.isServer() && mat.isLiquid() )
|
|
|
|
{
|
|
|
|
transformTime++;
|
|
|
|
if ( transformTime > 60 )
|
|
|
|
{
|
|
|
|
if ( !transform() )
|
|
|
|
transformTime = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
transformTime = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
public boolean transform()
|
|
|
|
{
|
|
|
|
ItemStack item = getEntityItem();
|
2014-05-10 07:00:02 +02:00
|
|
|
if ( AEApi.instance().materials().materialCertusQuartzCrystalCharged.sameAsStack( item ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
AxisAlignedBB region = AxisAlignedBB.getBoundingBox( posX - 1, posY - 1, posZ - 1, posX + 1, posY + 1, posZ + 1 );
|
|
|
|
List<Entity> l = worldObj.getEntitiesWithinAABBExcludingEntity( this, region );
|
|
|
|
|
|
|
|
EntityItem redstone = null;
|
|
|
|
EntityItem netherQuartz = null;
|
|
|
|
|
|
|
|
for (Entity e : l)
|
|
|
|
{
|
|
|
|
if ( e instanceof EntityItem && !e.isDead )
|
|
|
|
{
|
|
|
|
ItemStack other = ((EntityItem) e).getEntityItem();
|
|
|
|
if ( other != null && other.stackSize > 0 )
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
if ( Platform.isSameItem( other, new ItemStack( Items.redstone ) ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
redstone = (EntityItem) e;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
if ( Platform.isSameItem( other, new ItemStack( Items.quartz ) ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
netherQuartz = (EntityItem) e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( redstone != null && netherQuartz != null )
|
|
|
|
{
|
|
|
|
getEntityItem().stackSize--;
|
|
|
|
redstone.getEntityItem().stackSize--;
|
|
|
|
netherQuartz.getEntityItem().stackSize--;
|
|
|
|
|
|
|
|
if ( getEntityItem().stackSize <= 0 )
|
|
|
|
setDead();
|
|
|
|
|
|
|
|
if ( redstone.getEntityItem().stackSize <= 0 )
|
|
|
|
redstone.setDead();
|
|
|
|
|
|
|
|
if ( netherQuartz.getEntityItem().stackSize <= 0 )
|
|
|
|
netherQuartz.setDead();
|
|
|
|
|
|
|
|
List<ItemStack> i = new ArrayList();
|
|
|
|
i.add( AEApi.instance().materials().materialFluixCrystal.stack( 1 ) );
|
|
|
|
|
|
|
|
ItemStack Output = AEApi.instance().materials().materialFluixCrystal.stack( 2 );
|
|
|
|
worldObj.spawnEntityInWorld( new EntityItem( worldObj, posX, posY, posZ, Output ) );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|