Adding new active state
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package nmd.primal.forgecraft.blocks;
|
||||
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.MapColor;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.PropertyDirection;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
/**
|
||||
* Created by kitsu on 12/3/2016.
|
||||
*/
|
||||
public abstract class CustomContainerFacing extends BlockContainer {
|
||||
|
||||
public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
|
||||
|
||||
protected CustomContainerFacing(Material material)
|
||||
{
|
||||
super(material);
|
||||
}
|
||||
|
||||
protected CustomContainerFacing(Material material, MapColor color)
|
||||
{
|
||||
super(material, color);
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,17 @@ import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.BlockHorizontal;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityFurnace;
|
||||
@@ -30,14 +35,16 @@ import javax.annotation.Nullable;
|
||||
/**
|
||||
* Created by kitsu on 11/26/2016.
|
||||
*/
|
||||
public class Firebox extends BlockHorizontal implements ITileEntityProvider {
|
||||
//public class Firebox extends Block {
|
||||
public class Firebox extends CustomContainerFacing implements ITileEntityProvider {
|
||||
|
||||
public static final PropertyBool ACTIVE = PropertyBool.create("active");
|
||||
|
||||
public Firebox(Material material) {
|
||||
super(material);
|
||||
setUnlocalizedName(ModInfo.ForgecraftBlocks.FIREBOX.getUnlocalizedName());
|
||||
setRegistryName(ModInfo.ForgecraftBlocks.FIREBOX.getRegistryName());
|
||||
setCreativeTab(ModInfo.TAB_FORGECRAFT);
|
||||
setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
|
||||
setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(ACTIVE, Boolean.valueOf(false)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,9 +63,37 @@ public class Firebox extends BlockHorizontal implements ITileEntityProvider {
|
||||
{
|
||||
|
||||
ItemStack playerStack = player.getHeldItemMainhand();
|
||||
Item playerItem;
|
||||
|
||||
ItemStack tileStack = tile.getStackInSlot(0);
|
||||
|
||||
System.out.println(playerStack + " : " + tileStack);
|
||||
//System.out.println("Player Stack = " + playerStack);
|
||||
//System.out.println("TileStack = " + tileStack);
|
||||
if(playerStack != null){
|
||||
playerItem = playerStack.getItem();
|
||||
if (playerItem.equals(Items.FLINT_AND_STEEL)) {
|
||||
world.setBlockState(pos, state.withProperty(ACTIVE, Boolean.valueOf(true)), 2);
|
||||
BlockPos tempPos = new BlockPos(pos.getX(), pos.getY()+1, pos.getZ());
|
||||
if(world.getBlockState(tempPos).getBlock().equals(Blocks.AIR)){
|
||||
world.setBlockState(tempPos, Blocks.FIRE.getDefaultState(), 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(tileStack == null && playerStack != null){
|
||||
tile.setInventorySlotContents(0, playerStack);
|
||||
player.setHeldItem(EnumHand.MAIN_HAND, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(tileStack != null && playerStack == null && player.isSneaking()){
|
||||
tile.setInventorySlotContents(0, null);
|
||||
player.setHeldItem(EnumHand.MAIN_HAND, tileStack);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
if (tile.getStackInSlot(0) == null){
|
||||
@@ -76,6 +111,7 @@ public class Firebox extends BlockHorizontal implements ITileEntityProvider {
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +163,7 @@ public class Firebox extends BlockHorizontal implements ITileEntityProvider {
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
return new BlockStateContainer(this, FACING);
|
||||
return new BlockStateContainer(this, new IProperty[] {FACING, ACTIVE});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
{
|
||||
"variants": {
|
||||
"facing=north": { "model": "forgecraft:firebox" },
|
||||
"facing=east": { "model": "forgecraft:firebox", "y": 90 },
|
||||
"facing=south": { "model": "forgecraft:firebox", "y": 180 },
|
||||
"facing=west": { "model": "forgecraft:firebox", "y": 270 }
|
||||
"facing=north,active=false": { "model": "forgecraft:firebox" },
|
||||
"facing=east,active=false": { "model": "forgecraft:firebox", "y": 90 },
|
||||
"facing=south,active=false": { "model": "forgecraft:firebox", "y": 180 },
|
||||
"facing=west,active=false": { "model": "forgecraft:firebox", "y": 270 },
|
||||
"facing=north,active=true": { "model": "forgecraft:firebox" },
|
||||
"facing=east,active=true": { "model": "forgecraft:firebox", "y": 90 },
|
||||
"facing=south,active=true": { "model": "forgecraft:firebox", "y": 180 },
|
||||
"facing=west,active=true": { "model": "forgecraft:firebox", "y": 270 }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user