ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockSlabs.java

127 lines
4.3 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
* This file ("BlockSlabs.java") is part of the Actually Additions Mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-01-03 16:05:51 +01:00
* http://ellpeck.de/actaddlicense/
2015-08-29 14:33:25 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2016-01-03 16:05:51 +01:00
* © 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;
2016-01-08 13:31:58 +01:00
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
2015-06-28 03:12:32 +02:00
import net.minecraft.block.Block;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.IBlockState;
2015-06-28 03:12:32 +02:00
import net.minecraft.entity.Entity;
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;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
2015-06-28 03:12:32 +02:00
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import java.util.List;
public class BlockSlabs extends BlockBase{
2015-06-28 03:12:32 +02:00
private Block fullBlock;
2015-12-17 20:18:22 +01:00
private 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);
}
private static final PropertyInteger META = PropertyInteger.create("meta", 0, 1);
2015-12-17 20:18:22 +01:00
public BlockSlabs(String name, Block fullBlock, int meta){
super(fullBlock.getMaterial(), name);
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;
}
@Override
protected PropertyInteger getMetaProperty(){
return META;
}
2015-06-28 03:12:32 +02:00
@Override
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
public boolean isOpaqueCube(){
return false;
2015-06-28 03:12:32 +02:00
}
@Override
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
}
if(facing.ordinal() == 0 || hitY >= 0.5F){
return this.getStateFromMeta(meta+1);
2015-10-03 10:16:18 +02:00
}
return this.getStateFromMeta(meta);
2015-06-28 03:12:32 +02:00
}
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, BlockPos pos){
2016-01-08 13:31:58 +01:00
int meta = PosUtil.getMetadata(pos, world);
2015-10-03 10:19:40 +02:00
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);
2015-06-28 03:12:32 +02:00
}
@Override
2015-10-03 10:19:40 +02:00
public void setBlockBoundsForItemRender(){
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
2015-06-28 03:12:32 +02:00
}
@Override
2015-12-19 10:30:39 +01:00
public Class<? extends ItemBlockBase> getItemBlock(){
return TheItemBlock.class;
2015-06-28 03:12:32 +02:00
}
@Override
2015-12-19 10:30:39 +01:00
public EnumRarity getRarity(ItemStack stack){
return EnumRarity.COMMON;
2015-06-28 03:12:32 +02:00
}
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);
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ){
2016-01-08 13:31:58 +01:00
if(PosUtil.getBlock(pos, world) == this.block && ((side.ordinal() == 1 && PosUtil.getMetadata(pos, world) == 0) || (side.ordinal() == 0 && PosUtil.getMetadata(pos, world) == 1))){
if(PosUtil.setBlock(pos, world, ((BlockSlabs)this.block).fullBlock, ((BlockSlabs)this.block).meta, 3)){
world.playSoundEffect(pos.getX()+0.5F, pos.getY()+0.5F, pos.getZ()+0.5F, this.block.stepSound.getBreakSound(), (this.block.stepSound.getVolume()+1.0F)/2.0F, this.block.stepSound.frequency*0.8F);
2015-10-29 22:27:47 +01:00
stack.stackSize--;
return true;
}
}
return super.onItemUse(stack, player, world, pos, side, hitX, hitY, hitZ);
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
}