2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("BlockSlabs.java") is part of the Actually Additions mod for Minecraft.
|
2015-08-29 14:33:25 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-2016 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.blocks;
|
2015-06-28 03:12:32 +02:00
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockBase;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.base.ItemBlockBase;
|
2015-06-28 03:12:32 +02:00
|
|
|
import net.minecraft.block.Block;
|
2016-05-01 22:26:26 +02:00
|
|
|
import net.minecraft.block.SoundType;
|
2016-01-08 15:21:05 +01:00
|
|
|
import net.minecraft.block.properties.PropertyInteger;
|
2016-01-07 19:47:53 +01:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
2015-10-29 22:27:47 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-06-28 03:12:32 +02:00
|
|
|
import net.minecraft.item.EnumRarity;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.EnumActionResult;
|
2016-01-07 19:47:53 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.EnumHand;
|
2016-05-01 22:26:26 +02:00
|
|
|
import net.minecraft.util.SoundCategory;
|
2016-05-02 16:56:27 +02:00
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2016-05-02 16:56:27 +02:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
2015-06-28 03:12:32 +02:00
|
|
|
import net.minecraft.world.World;
|
2016-05-02 16:56:27 +02:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2015-06-28 03:12:32 +02:00
|
|
|
|
2015-12-03 20:15:07 +01:00
|
|
|
public class BlockSlabs extends BlockBase{
|
2015-06-28 03:12:32 +02:00
|
|
|
|
2016-05-02 16:56:27 +02:00
|
|
|
private static final AxisAlignedBB AABB_BOTTOM_HALF = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.5D, 1.0D);
|
|
|
|
private static final AxisAlignedBB AABB_TOP_HALF = new AxisAlignedBB(0.0D, 0.5D, 0.0D, 1.0D, 1.0D, 1.0D);
|
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
private static final PropertyInteger META = PropertyInteger.create("meta", 0, 1);
|
2016-05-19 20:05:12 +02:00
|
|
|
private final Block fullBlock;
|
|
|
|
private final int meta;
|
2015-06-28 03:12:32 +02:00
|
|
|
|
2015-12-19 10:30:39 +01:00
|
|
|
public BlockSlabs(String name, Block fullBlock){
|
|
|
|
this(name, fullBlock, 0);
|
|
|
|
}
|
|
|
|
|
2015-12-17 20:18:22 +01:00
|
|
|
public BlockSlabs(String name, Block fullBlock, int meta){
|
2016-03-18 23:47:22 +01:00
|
|
|
super(fullBlock.getMaterial(fullBlock.getDefaultState()), name);
|
2015-07-07 01:13:39 +02:00
|
|
|
this.setHardness(1.5F);
|
|
|
|
this.setResistance(10.0F);
|
2015-06-28 03:12:32 +02:00
|
|
|
this.fullBlock = fullBlock;
|
2015-12-17 20:18:22 +01:00
|
|
|
this.meta = meta;
|
|
|
|
}
|
|
|
|
|
2016-03-18 23:47:22 +01:00
|
|
|
/*@Override
|
2016-01-07 19:47:53 +01:00
|
|
|
public void addCollisionBoxesToList(World world, BlockPos pos, IBlockState state, AxisAlignedBB axis, List list, Entity entity){
|
|
|
|
this.setBlockBoundsBasedOnState(world, pos);
|
|
|
|
super.addCollisionBoxesToList(world, pos, state, axis, list, entity);
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-18 23:47:22 +01:00
|
|
|
public void setBlockBoundsBasedOnState(IBlockAccess world, BlockPos pos){
|
|
|
|
int meta = PosUtil.getMetadata(pos, world);
|
|
|
|
float minY = meta == 1 ? 0.5F : 0.0F;
|
|
|
|
float maxY = meta == 1 ? 1.0F : 0.5F;
|
|
|
|
this.setBlockBounds(0.0F, minY, 0F, 1.0F, maxY, 1.0F);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setBlockBoundsForItemRender(){
|
|
|
|
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
|
|
|
|
}*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isOpaqueCube(IBlockState state){
|
2015-10-03 10:19:40 +02:00
|
|
|
return false;
|
2015-06-28 03:12:32 +02:00
|
|
|
}
|
|
|
|
|
2016-05-29 23:49:35 +02:00
|
|
|
|
2015-06-28 03:12:32 +02:00
|
|
|
@Override
|
2016-01-07 19:47:53 +01:00
|
|
|
public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer){
|
|
|
|
if(facing.ordinal() == 1){
|
|
|
|
return this.getStateFromMeta(meta);
|
2015-10-03 10:16:18 +02:00
|
|
|
}
|
2016-01-07 19:47:53 +01:00
|
|
|
if(facing.ordinal() == 0 || hitY >= 0.5F){
|
|
|
|
return this.getStateFromMeta(meta+1);
|
2015-10-03 10:16:18 +02:00
|
|
|
}
|
2016-01-07 19:47:53 +01:00
|
|
|
return this.getStateFromMeta(meta);
|
2015-06-28 03:12:32 +02:00
|
|
|
}
|
|
|
|
|
2016-05-02 17:09:23 +02:00
|
|
|
@Override
|
2016-05-02 16:56:27 +02:00
|
|
|
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos){
|
|
|
|
return state.getValue(META) == 1 ? AABB_TOP_HALF : AABB_BOTTOM_HALF;
|
|
|
|
}
|
|
|
|
|
2015-06-28 03:12:32 +02:00
|
|
|
@Override
|
2016-04-20 21:39:03 +02:00
|
|
|
protected ItemBlockBase getItemBlock(){
|
|
|
|
return new TheItemBlock(this);
|
2015-06-28 03:12:32 +02:00
|
|
|
}
|
|
|
|
|
2015-10-23 16:48:56 +02:00
|
|
|
@Override
|
2015-12-19 10:30:39 +01:00
|
|
|
public EnumRarity getRarity(ItemStack stack){
|
2016-01-07 19:47:53 +01:00
|
|
|
return EnumRarity.COMMON;
|
2015-06-28 03:12:32 +02:00
|
|
|
}
|
2015-10-29 22:27:47 +01:00
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@Override
|
|
|
|
protected PropertyInteger getMetaProperty(){
|
|
|
|
return META;
|
|
|
|
}
|
|
|
|
|
2015-10-29 22:27:47 +01:00
|
|
|
public static class TheItemBlock extends ItemBlockBase{
|
|
|
|
|
|
|
|
public TheItemBlock(Block block){
|
|
|
|
super(block);
|
|
|
|
this.setHasSubtypes(false);
|
|
|
|
this.setMaxDamage(0);
|
|
|
|
}
|
|
|
|
|
2016-05-02 17:09:23 +02:00
|
|
|
@Override
|
2016-05-29 23:49:35 +02:00
|
|
|
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ){
|
2016-05-02 16:56:27 +02:00
|
|
|
if(stack.stackSize != 0 && playerIn.canPlayerEdit(pos.offset(facing), facing, stack)){
|
|
|
|
IBlockState state = worldIn.getBlockState(pos);
|
|
|
|
|
|
|
|
if(state.getBlock() == this.block){
|
|
|
|
BlockSlabs theBlock = (BlockSlabs)this.block;
|
|
|
|
if((facing == EnumFacing.UP && state.getValue(META) == 0 || facing == EnumFacing.DOWN && state.getValue(META) == 1)){
|
|
|
|
IBlockState newState = theBlock.fullBlock.getStateFromMeta(theBlock.meta);
|
|
|
|
AxisAlignedBB bound = newState.getCollisionBoundingBox(worldIn, pos);
|
|
|
|
|
|
|
|
if(bound != Block.NULL_AABB && worldIn.checkNoEntityCollision(bound.offset(pos)) && worldIn.setBlockState(pos, newState, 11)){
|
|
|
|
SoundType soundtype = theBlock.fullBlock.getSoundType();
|
|
|
|
worldIn.playSound(playerIn, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume()+1.0F)/2.0F, soundtype.getPitch()*0.8F);
|
|
|
|
--stack.stackSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EnumActionResult.SUCCESS;
|
|
|
|
}
|
2015-10-29 22:27:47 +01:00
|
|
|
}
|
2016-05-02 16:56:27 +02:00
|
|
|
|
|
|
|
return this.tryPlace(playerIn, stack, worldIn, pos.offset(facing)) ? EnumActionResult.SUCCESS : super.onItemUse(stack, playerIn, worldIn, pos, hand, facing, hitX, hitY, hitZ);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
return EnumActionResult.FAIL;
|
2015-10-29 22:27:47 +01:00
|
|
|
}
|
2016-05-02 16:56:27 +02:00
|
|
|
}
|
|
|
|
|
2016-05-02 17:09:23 +02:00
|
|
|
@Override
|
2016-05-02 16:56:27 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2016-05-29 23:49:35 +02:00
|
|
|
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack){
|
2016-05-02 16:56:27 +02:00
|
|
|
IBlockState state = worldIn.getBlockState(pos);
|
|
|
|
|
|
|
|
if(state.getBlock() == this.block){
|
|
|
|
if((side == EnumFacing.UP && state.getValue(META) == 0 || side == EnumFacing.DOWN && state.getValue(META) == 1)){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return worldIn.getBlockState(pos.offset(side)).getBlock() == this.block || super.canPlaceBlockOnSide(worldIn, pos, side, player, stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean tryPlace(EntityPlayer player, ItemStack stack, World worldIn, BlockPos pos){
|
|
|
|
IBlockState iblockstate = worldIn.getBlockState(pos);
|
|
|
|
|
|
|
|
if(iblockstate.getBlock() == this.block){
|
|
|
|
BlockSlabs theBlock = (BlockSlabs)this.block;
|
|
|
|
IBlockState newState = theBlock.fullBlock.getStateFromMeta(theBlock.meta);
|
|
|
|
AxisAlignedBB bound = newState.getCollisionBoundingBox(worldIn, pos);
|
|
|
|
|
|
|
|
if(bound != Block.NULL_AABB && worldIn.checkNoEntityCollision(bound.offset(pos)) && worldIn.setBlockState(pos, newState, 11)){
|
|
|
|
SoundType soundtype = theBlock.fullBlock.getSoundType();
|
|
|
|
worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume()+1.0F)/2.0F, soundtype.getPitch()*0.8F);
|
|
|
|
--stack.stackSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-10-29 22:27:47 +01:00
|
|
|
}
|
|
|
|
|
2016-05-29 23:49:35 +02:00
|
|
|
|
2015-10-29 22:27:47 +01:00
|
|
|
@Override
|
|
|
|
public String getUnlocalizedName(ItemStack stack){
|
|
|
|
return this.getUnlocalizedName();
|
|
|
|
}
|
|
|
|
}
|
2015-06-28 03:12:32 +02:00
|
|
|
}
|