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

143 lines
4.5 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
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2015-11-02 20:55:19 +01:00
* © 2015 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2015-06-28 03:12:32 +02:00
package ellpeck.actuallyadditions.blocks;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
2015-10-29 22:27:47 +01:00
import ellpeck.actuallyadditions.items.ItemBlockBase;
import ellpeck.actuallyadditions.util.IActAddItemOrBlock;
2015-06-28 03:12:32 +02:00
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
2015-07-06 23:41:10 +02:00
import net.minecraft.client.renderer.texture.IIconRegister;
2015-06-28 03:12:32 +02:00
import net.minecraft.entity.Entity;
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.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import java.util.List;
public class BlockSlabs extends Block implements IActAddItemOrBlock{
2015-06-28 03:12:32 +02:00
private String name;
private Block fullBlock;
public BlockSlabs(String name, Block fullBlock){
super(Material.rock);
this.setHardness(1.5F);
this.setResistance(10.0F);
2015-06-28 03:12:32 +02:00
this.fullBlock = fullBlock;
this.name = name;
}
@Override
2015-10-03 10:19:40 +02:00
public boolean renderAsNormalBlock(){
return false;
2015-06-28 03:12:32 +02:00
}
@Override
2015-10-03 10:19:40 +02:00
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta){
return this.fullBlock.getIcon(0, 0);
2015-06-28 03:12:32 +02:00
}
@Override
2015-10-03 10:19:40 +02:00
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB axis, List list, Entity entity){
this.setBlockBoundsBasedOnState(world, x, y, z);
super.addCollisionBoxesToList(world, x, y, z, axis, list, entity);
}
@Override
public boolean isOpaqueCube(){
return false;
2015-06-28 03:12:32 +02:00
}
@Override
public int onBlockPlaced(World par1World, int blockX, int blockY, int blockZ, int side, float hitX, float hitY, float hitZ, int meta){
2015-10-03 10:16:18 +02:00
if(side == 1){
return meta;
}
if(side == 0 || hitY >= 0.5F){
return meta+1;
}
2015-06-28 03:12:32 +02:00
return meta;
}
@Override
2015-10-03 10:19:40 +02:00
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z){
int meta = world.getBlockMetadata(x, y, z);
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
}
2015-07-06 23:41:10 +02:00
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconReg){
}
2015-06-28 03:12:32 +02:00
@Override
public String getName(){
return this.name;
}
@Override
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 int getMetadata(int meta){
return meta;
}
@Override
public EnumRarity getRarity(ItemStack stack){
EnumRarity rarity = ((IActAddItemOrBlock)this.field_150939_a).getRarity(stack);
return rarity == null ? EnumRarity.common : rarity;
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ){
if(world.getBlock(x, y, z) == this.field_150939_a && ((side == 1 && world.getBlockMetadata(x, y, z) == 0) || (side == 0 && world.getBlockMetadata(x, y, z) == 1))){
if(world.setBlock(x, y, z, ((BlockSlabs)this.field_150939_a).fullBlock, 0, 3)){
world.playSoundEffect(x+0.5F, y+0.5F, z+0.5F, this.field_150939_a.stepSound.getBreakSound(), (this.field_150939_a.stepSound.getVolume()+1.0F)/2.0F, this.field_150939_a.stepSound.getPitch()*0.8F);
stack.stackSize--;
return true;
}
}
return super.onItemUse(stack, player, world, x, y, z, side, hitX, hitY, hitZ);
}
@Override
public String getUnlocalizedName(ItemStack stack){
return this.getUnlocalizedName();
}
}
2015-06-28 03:12:32 +02:00
}