much closer to stable state

This commit is contained in:
Mohammad-Ali Minaie
2018-03-11 21:29:09 -04:00
parent 117b3fd0f3
commit 024360389e
3 changed files with 107 additions and 82 deletions

View File

@@ -3,10 +3,12 @@ package nmd.primal.forgecraft.blocks.Crucibles;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -37,7 +39,7 @@ import java.util.Random;
/**
* Created by mminaie on 11/11/17.
*/
public class NBTCrucible extends BlockContainer implements ITileEntityProvider, IPickup {
public class NBTCrucible extends BlockContainer implements ITileEntityProvider {
protected static final AxisAlignedBB boundBox = new AxisAlignedBB(4/16D, 0.0D, 4/16D, 12/16D, 7/16D, 12/16D);
@@ -49,7 +51,7 @@ public class NBTCrucible extends BlockContainer implements ITileEntityProvider,
setRegistryName(registryName);
setCreativeTab(ModInfo.TAB_FORGECRAFT);
setHardness(3.0f);
//setDefaultState(this.blockState.getBaseState().withProperty(PrimalAPI.States.ACTIVE, Boolean.valueOf(false)));
setDefaultState(this.blockState.getBaseState().withProperty(PrimalAPI.States.ACTIVE, Boolean.valueOf(false)));
}
@Override
@@ -59,30 +61,9 @@ public class NBTCrucible extends BlockContainer implements ITileEntityProvider,
TileNBTCrucible tile = (TileNBTCrucible) world.getTileEntity(pos);
ItemStack pItem = player.inventory.getCurrentItem();
ItemStack pItem1 = new ItemStack(pItem.getItem(), 1);
/**CLEARS THE INVENTORY**/
if(player.isSneaking()){
for(int i=0; i<tile.ingList.size(); i++){
//if(!tile.ingList.get(i).isEmpty()) {
PlayerHelper.spawnItemOnPlayer(world, player, tile.ingList.get(i));
tile.ingList.set(i, ItemStack.EMPTY);
//}
}
tile.update();
tile.markDirty();
return true;
}
/**PICKS UP THE CRUCIBLE**/
if(pItem.isEmpty()){
if(!player.isSneaking()) {
CrucibleCrafting recipe = CrucibleCrafting.getRecipe(tile.ingList.get(0), tile.ingList.get(1), tile.ingList.get(2), tile.ingList.get(3), tile.ingList.get(4));
if(recipe != null){
tile.setDrops(recipe.getDropsRaw());
}
return takeBlock(world, pos, state, face, player);
}
}
/**SET INGREDIENT ARRAY FOR THE CRUCIBLE NOW**/
if(!player.isSneaking()) {
if(player.isSneaking() == false) {
if(!pItem.isEmpty()) {
if(pItem.getItem() instanceof SlottedTongs) {
return false;
@@ -99,14 +80,46 @@ public class NBTCrucible extends BlockContainer implements ITileEntityProvider,
}
}
}
/**CLEARS THE INVENTORY**/
if (player.isSneaking() == true) {
if(pItem.isEmpty()) {
for (int i = 0; i < tile.ingList.size(); i++) {
if (!tile.ingList.get(i).isEmpty()) {
PlayerHelper.spawnItemOnPlayer(world, player, tile.ingList.get(i));
tile.ingList.set(i, ItemStack.EMPTY);
}
}
tile.update();
tile.markDirty();
return true;
}
}
/**PICKS UP THE CRUCIBLE**/
if(player.isSneaking() == false) {
if(pItem.isEmpty()){
CrucibleCrafting recipe = CrucibleCrafting.getRecipe(tile.ingList.get(0), tile.ingList.get(1), tile.ingList.get(2), tile.ingList.get(3), tile.ingList.get(4));
if(recipe != null){
tile.setDrops(recipe.getDropsRaw());
}
PlayerHelper.playerTakeItem(world, pos, EnumFacing.DOWN, player, player.getActiveHand(), this.getItem(world, pos, state));
world.setBlockState(pos, this.getReplacementBlock(world, pos, state));
return true;
}
}
}
return false;
}
private IBlockState getReplacementBlock(World world, BlockPos pos, IBlockState state)
{
return Blocks.AIR.getDefaultState();
}
@Override
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest)
{
System.out.println("Removed by player");
this.onBlockHarvested(world, pos, state, player);
return this.takeBlock(world, pos, state, EnumFacing.UP, player);
}
@@ -119,18 +132,13 @@ public class NBTCrucible extends BlockContainer implements ITileEntityProvider,
public boolean takeBlock(World world, BlockPos pos, IBlockState state, EnumFacing face, EntityPlayer player)
{
if (world.isRemote)
return true;
if (!world.isRemote) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileNBTCrucible) {
//World world, BlockPos pos, EnumFacing face, EntityPlayer player, EnumHand hand, ItemStack stack
PlayerHelper.playerTakeItem(world, pos, EnumFacing.DOWN, player, player.getActiveHand(), this.getItem(world, pos, state));
//world.updateComparatorOutputLevel(pos, state.getBlock());
return world.setBlockState(pos, this.getReplacementBlock(world, pos, state));
}
}
return false;
}
@@ -141,10 +149,8 @@ public class NBTCrucible extends BlockContainer implements ITileEntityProvider,
TileNBTCrucible tile = (TileNBTCrucible) world.getTileEntity(pos);
ItemStack pItem = player.inventory.getCurrentItem();
CrucibleCrafting recipe = CrucibleCrafting.getRecipe(tile.ingList.get(0), tile.ingList.get(1), tile.ingList.get(2), tile.ingList.get(3), tile.ingList.get(4));
System.out.println("Harvested" + tile.getStatus() + " | " + tile.getHot());
if(recipe != null && tile.getStatus() && !tile.getHot()){
PlayerHelper.spawnItemOnPlayer(world, player, tile.getDrops());
System.out.println("Drop stuff");
}
}
}
@@ -160,34 +166,53 @@ public class NBTCrucible extends BlockContainer implements ITileEntityProvider,
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
TileEntity tileentity = world.getTileEntity(pos);
if (tileentity instanceof TileNBTCrucible)
{
if (tileentity instanceof TileNBTCrucible) {
TileNBTCrucible tile = (TileNBTCrucible) world.getTileEntity(pos);
if(NBTHelper.hasNBT(stack)){
NBTTagCompound tag = stack.getSubCompound("BlockEntityTag").copy();
//tile.writeNBT(tag);
tile.setHot(tag.getBoolean("hot"));
tile.markDirty();
tile.updateBlock();
if(tag.getBoolean("hot")){
world.setBlockState(pos, state.withProperty(PrimalAPI.States.ACTIVE, true), 2);
}
}
}
}
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
{
TileNBTCrucible tile = (TileNBTCrucible) world.getTileEntity(pos);
if (tile != null && tile instanceof TileNBTCrucible) {
System.out.println("Hot:" + tile.getHot() + " Status: " + tile.getStatus());
if(tile.getHot()){
System.out.println("Should Be Red");
return state.withProperty(PrimalAPI.States.ACTIVE, true);
public int getMetaFromState(IBlockState state) {
int i = 0;
if( state.getValue(PrimalAPI.States.ACTIVE) == false){
i = 0;
return i;
}
if(!tile.getHot()){
System.out.println("Should Be Brown");
return state.withProperty(PrimalAPI.States.ACTIVE, false);
if( state.getValue(PrimalAPI.States.ACTIVE) == true) {
i = 1;
return i;
}
return i;
}
return state;
@Override
public IBlockState getStateFromMeta(int meta) {
IBlockState iblockstate = this.getDefaultState();
if (meta == 0){
iblockstate = iblockstate.withProperty(PrimalAPI.States.ACTIVE, false);
}
if (meta == 1){
iblockstate = iblockstate.withProperty(PrimalAPI.States.ACTIVE, true);
}
return iblockstate;
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, new IProperty[] {PrimalAPI.States.ACTIVE});
}
@Override
public int quantityDropped(Random random)

View File

@@ -7,7 +7,9 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ITickable;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import nmd.primal.core.api.PrimalAPI;
import nmd.primal.forgecraft.crafting.CrucibleCrafting;
/**
@@ -66,22 +68,20 @@ public class TileNBTCrucible extends BaseTile implements ITickable {
@Override
public void update () {
if (!world.isRemote) {
//World world = this.getWorld();
//IBlockState state = world.getBlockState(this.pos);
World world = this.getWorld();
IBlockState state = world.getBlockState(this.pos);
coolManager();
coolManager(this.pos, world, state);
}
}
private void coolManager() {
System.out.println(this.getHeat() + " " + this.getHot() + " " + this.getDrops());
private void coolManager(BlockPos pos, World world, IBlockState state) {
//System.out.println(this.getHeat() + " " + this.getHot() + " " + this.getDrops());
if(this.getHot()){
//System.out.println("Still Hot");
if(this.getHeat() > 0){
this.setHeat( this.getHeat() - 1);
System.out.println(this.getHeat());
//this.updateBlock();
//this.markDirty();
world.setBlockState(pos, state.withProperty(PrimalAPI.States.ACTIVE, true), 2);
}
if(this.getHeat() == 0){
this.setHot(false);
@@ -89,8 +89,10 @@ public class TileNBTCrucible extends BaseTile implements ITickable {
this.setDrops(recipe.getDropsCooked());
this.setStatus(false);
System.out.println("Ready to harvest: " + this.getDrops());
world.setBlockState(pos, state.withProperty(PrimalAPI.States.ACTIVE, false), 2);
this.updateBlock();
this.markDirty();
}
//CrucibleCrafting recipe = CrucibleCrafting.getRecipe(ingList.get(0), ingList.get(1), ingList.get(2), ingList.get(3), ingList.get(4));
}

View File

@@ -1,22 +1,20 @@
{
"forge_marker":1,
"variants": {
"normal": {
"active": {
"true": {
"textures": {
"particle": "forgecraft:blocks/stone_slab_hot",
"texture": "forgecraft:blocks/stone_slab_hot"
},
"model": "forgecraft:crucibleshut"
},
"false": {
"textures": {
"particle": "forgecraft:blocks/stone_slab",
"texture": "forgecraft:blocks/stone_slab"
},
"model": "forgecraft:crucibleshut"
}
},
"true": {
"textures": {
"particle": "forgecraft:blocks/stone_slab_hot",
"texture": "forgecraft:blocks/stone_slab_hot"
},
"model": "forgecraft:crucibleshut"
}
}
}