Applied-Energistics-2-tiler.../src/main/java/appeng/block/misc/BlockCharger.java

196 lines
5.2 KiB
Java
Raw Normal View History

2014-11-14 12:02:52 +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>.
*/
2014-09-24 02:26:27 +02:00
package appeng.block.misc;
import java.util.Collections;
2014-09-24 02:26:27 +02:00
import java.util.EnumSet;
import java.util.List;
import java.util.Random;
import javax.annotation.Nullable;
2014-09-24 02:26:27 +02:00
import net.minecraft.block.material.Material;
2015-06-16 02:44:59 +02:00
import net.minecraft.block.state.IBlockState;
2014-09-24 02:26:27 +02:00
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
2015-06-16 02:44:59 +02:00
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
2014-09-24 02:26:27 +02:00
import net.minecraft.world.World;
2015-06-16 02:44:59 +02:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2015-12-24 02:07:03 +01:00
2014-09-24 02:26:27 +02:00
import appeng.api.AEApi;
2015-06-16 02:44:59 +02:00
import appeng.api.util.AEAxisAlignedBB;
import appeng.block.AEBaseTileBlock;
2014-09-24 02:26:27 +02:00
import appeng.client.render.BaseBlockRender;
import appeng.client.render.blocks.RenderBlockCharger;
import appeng.client.render.effects.LightningFX;
import appeng.core.AEConfig;
import appeng.core.CommonHelper;
import appeng.core.features.AEFeature;
import appeng.helpers.ICustomCollision;
import appeng.tile.AEBaseTile;
import appeng.tile.misc.TileCharger;
import appeng.util.Platform;
public class BlockCharger extends AEBaseTileBlock implements ICustomCollision
2014-09-24 02:26:27 +02:00
{
public BlockCharger()
{
super( Material.IRON );
2014-12-29 15:13:47 +01:00
this.setTileEntity( TileCharger.class );
this.setLightOpacity( 2 );
this.setFullSize( this.setOpaque( false ) );
this.setFeature( EnumSet.of( AEFeature.Core ) );
2014-09-24 02:26:27 +02:00
}
@Override
protected Class<? extends BaseBlockRender> getRenderer()
{
return RenderBlockCharger.class;
}
@Override
public boolean onActivated( final World w, final BlockPos pos, final EntityPlayer player, final EnumHand hand, final @Nullable ItemStack heldItem, final EnumFacing side, final float hitX, final float hitY, final float hitZ )
2014-09-24 02:26:27 +02:00
{
if( player.isSneaking() )
2015-04-29 02:30:53 +02:00
{
2014-09-24 02:26:27 +02:00
return false;
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
if( Platform.isServer() )
2014-09-24 02:26:27 +02:00
{
2015-09-30 14:24:40 +02:00
final TileCharger tc = this.getTileEntity( w, pos );
if( tc != null )
2014-09-24 02:26:27 +02:00
{
tc.activate( player );
}
}
return true;
}
2015-12-24 02:03:16 +01:00
@Override
@SideOnly( Side.CLIENT )
public void randomDisplayTick( final IBlockState state, final World w, final BlockPos pos, final Random r )
2014-09-24 02:26:27 +02:00
{
if( !AEConfig.instance.enableEffects )
2015-04-29 02:30:53 +02:00
{
2014-09-24 02:26:27 +02:00
return;
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
if( r.nextFloat() < 0.98 )
2015-04-29 02:30:53 +02:00
{
2014-09-24 02:26:27 +02:00
return;
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
2015-09-30 14:24:40 +02:00
final AEBaseTile tile = this.getTileEntity( w, pos );
if( tile instanceof TileCharger )
2014-09-24 02:26:27 +02:00
{
2015-09-30 14:24:40 +02:00
final TileCharger tc = (TileCharger) tile;
2014-09-24 02:26:27 +02:00
if( AEApi.instance().definitions().materials().certusQuartzCrystalCharged().isSameAs( tc.getStackInSlot( 0 ) ) )
{
2015-09-30 14:24:40 +02:00
final double xOff = 0.0;
final double yOff = 0.0;
final double zOff = 0.0;
2014-09-24 02:26:27 +02:00
for( int bolts = 0; bolts < 3; bolts++ )
2014-09-24 02:26:27 +02:00
{
if( CommonHelper.proxy.shouldAddParticles( r ) )
2014-09-24 02:26:27 +02:00
{
2015-09-30 14:24:40 +02:00
final LightningFX fx = new LightningFX( w, xOff + 0.5 + pos.getX(), yOff + 0.5 + pos.getY(), zOff + 0.5 + pos.getZ(), 0.0D, 0.0D, 0.0D );
2014-09-28 20:56:16 +02:00
Minecraft.getMinecraft().effectRenderer.addEffect( fx );
2014-09-24 02:26:27 +02:00
}
}
}
}
}
@Override
public Iterable<AxisAlignedBB> getSelectedBoundingBoxesFromPool( final World w, final BlockPos pos, final Entity thePlayer, final boolean b )
2014-09-24 02:26:27 +02:00
{
2015-09-30 14:24:40 +02:00
final TileCharger tile = this.getTileEntity( w, pos );
if( tile != null )
2014-09-24 02:26:27 +02:00
{
2015-09-30 14:24:40 +02:00
final double twoPixels = 2.0 / 16.0;
final EnumFacing up = tile.getUp();
final EnumFacing forward = tile.getForward();
final AEAxisAlignedBB bb = new AEAxisAlignedBB( twoPixels, twoPixels, twoPixels, 1.0 - twoPixels, 1.0 - twoPixels, 1.0 - twoPixels );
2014-09-24 02:26:27 +02:00
2015-06-16 02:44:59 +02:00
if( up.getFrontOffsetX() != 0 )
2014-09-24 02:26:27 +02:00
{
bb.minX = 0;
bb.maxX = 1;
}
2015-06-16 02:44:59 +02:00
if( up.getFrontOffsetY() != 0 )
2014-09-24 02:26:27 +02:00
{
bb.minY = 0;
bb.maxY = 1;
}
2015-06-16 02:44:59 +02:00
if( up.getFrontOffsetZ() != 0 )
2014-09-24 02:26:27 +02:00
{
bb.minZ = 0;
bb.maxZ = 1;
}
switch( forward )
2014-09-24 02:26:27 +02:00
{
case DOWN:
bb.maxY = 1;
break;
case UP:
bb.minY = 0;
break;
case NORTH:
bb.maxZ = 1;
break;
case SOUTH:
bb.minZ = 0;
break;
case EAST:
bb.minX = 0;
break;
case WEST:
bb.maxX = 1;
break;
default:
break;
2014-09-24 02:26:27 +02:00
}
2015-06-16 02:44:59 +02:00
return Collections.singletonList( bb.getBoundingBox() );
2014-09-24 02:26:27 +02:00
}
return Collections.singletonList( new AxisAlignedBB( 0.0, 0, 0.0, 1.0, 1.0, 1.0 ) );
2014-09-24 02:26:27 +02:00
}
@Override
public void addCollidingBlockToList( final World w, final BlockPos pos, final AxisAlignedBB bb, final List<AxisAlignedBB> out, final Entity e )
2014-09-24 02:26:27 +02:00
{
out.add( new AxisAlignedBB( 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 ) );
2014-09-24 02:26:27 +02:00
}
}