Applied-Energistics-2-tiler.../src/main/java/appeng/block/solids/BlockSkyStone.java

126 lines
3.4 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 - 2015, AlgorithmX2, All rights reserved.
2014-11-14 12:02:52 +01:00
*
* 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-02-28 09:12:00 +01:00
package appeng.block.solids;
2014-02-28 09:12:00 +01:00
import java.util.EnumSet;
2014-02-28 20:13:43 +01:00
import com.google.common.base.Optional;
2014-02-28 09:12:00 +01:00
import net.minecraft.block.material.Material;
2015-06-16 02:44:59 +02:00
import net.minecraft.block.state.IBlockState;
2014-02-28 20:13:43 +01:00
import net.minecraft.item.ItemStack;
2015-06-16 02:44:59 +02:00
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerEvent;
2015-06-16 02:44:59 +02:00
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
2014-02-28 09:12:00 +01:00
import appeng.block.AEBaseBlock;
import appeng.core.features.AEFeature;
import appeng.core.worlddata.WorldData;
import appeng.util.Platform;
2014-02-28 09:12:00 +01:00
2015-06-16 02:44:59 +02:00
public class BlockSkyStone extends AEBaseBlock
2014-02-28 09:12:00 +01:00
{
private static final float BLOCK_RESISTANCE = 150.0f;
private static final double BREAK_SPEAK_SCALAR = 0.1;
private static final double BREAK_SPEAK_THRESHOLD = 7.0;
2014-02-28 09:12:00 +01:00
2015-06-16 02:44:59 +02:00
public static enum SkystoneType {
stone,block,brick,smallbrick
};
SkystoneType type;
public BlockSkyStone( SkystoneType type )
{
2015-06-16 02:44:59 +02:00
super( Material.rock, Optional.of( type.name()) );
this.setHardness( 50 );
this.hasSubtypes = true;
this.blockResistance = BLOCK_RESISTANCE;
2015-06-16 02:44:59 +02:00
if ( type == SkystoneType.stone )
this.setHarvestLevel( "pickaxe", 3 );
this.setFeature( EnumSet.of( AEFeature.Core ) );
2015-06-16 02:44:59 +02:00
this.type = type;
MinecraftForge.EVENT_BUS.register( this );
}
@SubscribeEvent
public void breakFaster( PlayerEvent.BreakSpeed event )
{
2015-06-16 02:44:59 +02:00
if( event.state.getBlock() == this && event.entityPlayer != null )
{
ItemStack is = event.entityPlayer.inventory.getCurrentItem();
int level = -1;
if( is != null && is.getItem() != null )
2015-04-29 02:30:53 +02:00
{
level = is.getItem().getHarvestLevel( is, "pickaxe" );
2015-04-29 02:30:53 +02:00
}
2015-06-16 02:44:59 +02:00
if( type != SkystoneType.stone || level >= 3 || event.originalSpeed > BREAK_SPEAK_THRESHOLD )
2015-04-29 02:30:53 +02:00
{
event.newSpeed /= BREAK_SPEAK_SCALAR;
2015-04-29 02:30:53 +02:00
}
}
}
@Override
2015-06-16 02:44:59 +02:00
public void onBlockAdded(
World w,
BlockPos pos,
IBlockState state )
{
2015-06-16 02:44:59 +02:00
super.onBlockAdded( w, pos, state );
if( Platform.isServer() )
2015-04-29 02:30:53 +02:00
{
WorldData.instance().compassData().service().updateArea( w, pos.getX(), pos.getY(), pos.getZ() );
2015-04-29 02:30:53 +02:00
}
2014-02-28 09:12:00 +01:00
}
2014-02-28 20:13:43 +01:00
@Override
public String getUnlocalizedName( ItemStack is )
{
2015-06-16 02:44:59 +02:00
switch(type)
2015-04-29 02:30:53 +02:00
{
2015-06-16 02:44:59 +02:00
case block: return this.getUnlocalizedName() + ".Block";
case brick: return this.getUnlocalizedName() + ".Brick";
case smallbrick: return this.getUnlocalizedName() + ".SmallBrick";
default: return this.getUnlocalizedName();
2015-04-29 02:30:53 +02:00
}
2014-02-28 20:13:43 +01:00
}
@Override
2015-06-16 02:44:59 +02:00
public void breakBlock(
World w,
BlockPos pos,
IBlockState state )
{
2015-06-16 02:44:59 +02:00
super.breakBlock( w, pos, state );
if( Platform.isServer() )
2015-04-29 02:30:53 +02:00
{
WorldData.instance().compassData().service().updateArea( w, pos.getX(), pos.getY(), pos.getZ() );
2015-04-29 02:30:53 +02:00
}
}
2014-02-28 09:12:00 +01:00
}