2014-11-06 19:34:01 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
|
|
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-11-06 19:34:01 +01:00
|
|
|
package appeng.entity;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-12-29 21:59:05 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
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;
|
2014-11-06 19:34:01 +01:00
|
|
|
|
2014-12-29 21:59:05 +01:00
|
|
|
import appeng.api.AEApi;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.api.definitions.IMaterials;
|
2014-12-29 21:59:05 +01:00
|
|
|
import appeng.client.EffectType;
|
|
|
|
import appeng.core.AEConfig;
|
|
|
|
import appeng.core.CommonHelper;
|
|
|
|
import appeng.core.features.AEFeature;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.helpers.Reflected;
|
2014-12-29 21:59:05 +01:00
|
|
|
import appeng.util.Platform;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-11-04 02:18:37 +01:00
|
|
|
final public class EntityChargedQuartz extends AEBaseEntityItem
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
int delay = 0;
|
|
|
|
int transformTime = 0;
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
@Reflected
|
2014-11-06 19:34:01 +01:00
|
|
|
public EntityChargedQuartz(World w)
|
|
|
|
{
|
|
|
|
super( w );
|
|
|
|
}
|
|
|
|
|
|
|
|
public EntityChargedQuartz(World w, double x, double y, double z, ItemStack is)
|
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
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;
|
|
|
|
|
2015-03-26 11:07:26 +01:00
|
|
|
if ( Platform.isClient() && this.delay > 30 && AEConfig.instance.enableEffects )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
CommonHelper.proxy.spawnEffect( EffectType.Lightning, this.worldObj, this.posX, this.posY, this.posZ, null );
|
|
|
|
this.delay = 0;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2015-03-26 11:07:26 +01:00
|
|
|
this.delay++;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
int j = MathHelper.floor_double( this.posX );
|
|
|
|
int i = MathHelper.floor_double( this.posY );
|
|
|
|
int k = MathHelper.floor_double( this.posZ );
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
Material mat = this.worldObj.getBlock( j, i, k ).getMaterial();
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( Platform.isServer() && mat.isLiquid() )
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.transformTime++;
|
|
|
|
if ( this.transformTime > 60 )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
if ( !this.transform() )
|
|
|
|
this.transformTime = 0;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2014-12-29 15:13:47 +01:00
|
|
|
this.transformTime = 0;
|
2014-09-28 00:50:06 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
public boolean transform()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
ItemStack item = this.getEntityItem();
|
2015-01-03 02:53:14 +01:00
|
|
|
final IMaterials materials = AEApi.instance().definitions().materials();
|
|
|
|
|
|
|
|
if ( materials.certusQuartzCrystalCharged().isSameAs( item ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
AxisAlignedBB region = AxisAlignedBB.getBoundingBox( this.posX - 1, this.posY - 1, this.posZ - 1, this.posX + 1, this.posY + 1, this.posZ + 1 );
|
2014-11-04 02:18:37 +01:00
|
|
|
List<Entity> l = this.getCheckedEntitiesWithinAABBExcludingEntity( region );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.getEntityItem().stackSize--;
|
2013-12-27 23:59:59 +01:00
|
|
|
redstone.getEntityItem().stackSize--;
|
|
|
|
netherQuartz.getEntityItem().stackSize--;
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
if ( this.getEntityItem().stackSize <= 0 )
|
|
|
|
this.setDead();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
if ( redstone.getEntityItem().stackSize <= 0 )
|
|
|
|
redstone.setDead();
|
|
|
|
|
|
|
|
if ( netherQuartz.getEntityItem().stackSize <= 0 )
|
|
|
|
netherQuartz.setDead();
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
for ( ItemStack fluixCrystalStack : materials.fluixCrystal().maybeStack( 2 ).asSet() )
|
|
|
|
{
|
|
|
|
final EntityItem entity = new EntityItem( this.worldObj, this.posX, this.posY, this.posZ, fluixCrystalStack );
|
|
|
|
|
|
|
|
this.worldObj.spawnEntityInWorld( entity );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|