Some more work on the tree farm
This commit is contained in:
parent
ef5d81d8e2
commit
5d574e0540
2 changed files with 103 additions and 37 deletions
|
@ -1,6 +1,9 @@
|
||||||
package techreborn.farm;
|
package techreborn.farm;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.BlockLeavesBase;
|
||||||
|
import net.minecraft.block.BlockSapling;
|
||||||
|
import net.minecraft.block.IGrowable;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import techreborn.api.farm.IFarmLogicDevice;
|
import techreborn.api.farm.IFarmLogicDevice;
|
||||||
|
@ -12,36 +15,39 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
public class FarmTree implements IFarmLogicDevice {
|
public class FarmTree implements IFarmLogicDevice {
|
||||||
|
|
||||||
|
public static ArrayList<Block> harvestableLogs = new ArrayList<Block>();
|
||||||
|
ArrayList<Location> farmlandToPlace = new ArrayList<Location>();
|
||||||
|
Block farmlandType = Blocks.dirt;
|
||||||
|
int harvestx = 0;
|
||||||
|
int harvesty = 0;
|
||||||
|
int harvestz = 0;
|
||||||
|
boolean isHavrvesting = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick(TileFarm tileFarm) {
|
public void tick(TileFarm tileFarm) {
|
||||||
if(tileFarm.getWorldObj().isRemote){
|
if (tileFarm.getWorldObj().isRemote) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(tileFarm.getWorldObj().getTotalWorldTime() %100 == 0 || tileFarm.inventory.hasChanged){
|
if (tileFarm.getWorldObj().getTotalWorldTime() % 20 == 0 || tileFarm.inventory.hasChanged) {
|
||||||
calculateFarmLand(tileFarm);
|
calculateFarmLand(tileFarm);
|
||||||
}
|
}
|
||||||
if(tileFarm.getWorldObj().getTotalWorldTime() %5 == 0){
|
if (tileFarm.getWorldObj().getTotalWorldTime() % 10 == 0) {
|
||||||
farmLandTick(tileFarm);
|
farmLandTick(tileFarm);
|
||||||
saplinTick(tileFarm);
|
saplinTick(tileFarm);
|
||||||
}
|
}
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
harvestTick(tileFarm);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<Location> farmlandToPlace = new ArrayList<Location>();
|
public void calculateFarmLand(TileFarm tileFarm) {
|
||||||
Block farmlandType = Blocks.dirt;
|
if (farmlandToPlace.isEmpty()) {
|
||||||
boolean needsToPlaceWater = false;
|
|
||||||
|
|
||||||
public void calculateFarmLand(TileFarm tileFarm){
|
|
||||||
if(farmlandToPlace.isEmpty()){
|
|
||||||
for (int x = -tileFarm.size + 1; x < tileFarm.size; x++) {
|
for (int x = -tileFarm.size + 1; x < tileFarm.size; x++) {
|
||||||
for (int z = -tileFarm.size + 1; z < tileFarm.size; z++) {
|
for (int z = -tileFarm.size + 1; z < tileFarm.size; z++) {
|
||||||
int xpos = x + tileFarm.xCoord;
|
int xpos = x + tileFarm.xCoord;
|
||||||
int ypos = tileFarm.yCoord + 1;
|
int ypos = tileFarm.yCoord + 1;
|
||||||
int zpos = z + tileFarm.zCoord;
|
int zpos = z + tileFarm.zCoord;
|
||||||
if(xpos == tileFarm.xCoord && zpos == tileFarm.zCoord){
|
if (tileFarm.getWorldObj().getBlock(xpos, ypos, zpos) != farmlandType) {
|
||||||
if(tileFarm.getWorldObj().getBlock(xpos,ypos, zpos) != Blocks.water){
|
|
||||||
needsToPlaceWater = true;
|
|
||||||
}
|
|
||||||
} else if(tileFarm.getWorldObj().getBlock(xpos,ypos, zpos) != farmlandType) {
|
|
||||||
farmlandToPlace.add(new Location(xpos, ypos, zpos));
|
farmlandToPlace.add(new Location(xpos, ypos, zpos));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,43 +55,87 @@ public class FarmTree implements IFarmLogicDevice {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void farmLandTick(TileFarm tileFarm) {
|
||||||
public void farmLandTick(TileFarm tileFarm){
|
if (!farmlandToPlace.isEmpty()) {
|
||||||
if(!farmlandToPlace.isEmpty()){
|
|
||||||
Location location = farmlandToPlace.get(0);
|
Location location = farmlandToPlace.get(0);
|
||||||
if(tileFarm.getWorldObj().getBlock(location.getX(),location.getY(), location.getZ()) != farmlandType){
|
if (tileFarm.getWorldObj().getBlock(location.getX(), location.getY(), location.getZ()) != farmlandType) {
|
||||||
if(removeInputStack(new ItemStack(Blocks.dirt), tileFarm)){
|
if (removeInputStack(new ItemStack(Blocks.dirt), tileFarm)) {
|
||||||
tileFarm.getWorldObj().setBlock(location.getX(),location.getY(), location.getZ(), farmlandType);
|
tileFarm.getWorldObj().setBlock(location.getX(), location.getY(), location.getZ(), farmlandType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
farmlandToPlace.remove(location);
|
farmlandToPlace.remove(location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int sapx = 0;
|
||||||
|
int sapz = 0;
|
||||||
|
boolean isplanting;
|
||||||
|
|
||||||
|
//TODO use saplins from inv
|
||||||
|
public void saplinTick(TileFarm tileFarm) {
|
||||||
|
if(!isplanting){
|
||||||
|
sapx = - tileFarm.size;
|
||||||
|
sapz = -tileFarm.size;
|
||||||
|
isplanting = true;
|
||||||
} else {
|
} else {
|
||||||
if(needsToPlaceWater){
|
int xpos = sapx + tileFarm.xCoord;
|
||||||
//TODO use water out of tank
|
int ypos = tileFarm.yCoord + 2;
|
||||||
tileFarm.getWorldObj().setBlock(tileFarm.xCoord, tileFarm.yCoord + 1, tileFarm.zCoord, Blocks.water);
|
int zpos = sapz + tileFarm.zCoord;
|
||||||
needsToPlaceWater = false;
|
if(getSaplinStack(tileFarm) != null){
|
||||||
|
Block saplin = Block.getBlockFromItem(getSaplinStack(tileFarm).getItem());
|
||||||
|
int meta = getSaplinStack(tileFarm).getItemDamage();
|
||||||
|
if (saplin != null && tileFarm.getWorldObj().getBlock(xpos, ypos, zpos) == Blocks.air && saplin.canBlockStay(tileFarm.getWorldObj(), xpos, ypos, zpos) && saplin.canPlaceBlockAt(tileFarm.getWorldObj(), xpos, ypos, zpos)) {
|
||||||
|
tileFarm.getWorldObj().setBlock(xpos, ypos, zpos, saplin, meta, 2);
|
||||||
|
}
|
||||||
|
sapx ++;
|
||||||
|
if(sapx == tileFarm.size){
|
||||||
|
sapx = - tileFarm.size;
|
||||||
|
sapz ++;
|
||||||
|
}
|
||||||
|
if(sapz >= tileFarm.size){
|
||||||
|
sapz = -tileFarm.size;
|
||||||
|
sapx = -tileFarm.size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saplinTick(TileFarm tileFarm){
|
public void harvestTick(TileFarm tileFarm) {
|
||||||
for (int x = -tileFarm.size + 1; x < tileFarm.size; x++) {
|
int overlap = 2;
|
||||||
for (int z = -tileFarm.size + 1; z < tileFarm.size; z++) {
|
if (farmlandToPlace.isEmpty()) {
|
||||||
int xpos = x + tileFarm.xCoord;
|
if (!isHavrvesting) {
|
||||||
int ypos = tileFarm.yCoord + 2;
|
harvestx = -tileFarm.size - overlap;
|
||||||
int zpos = z + tileFarm.zCoord;
|
harvesty = + 2;
|
||||||
//if(tileFarm.getWorldObj().getBlock(xpos,ypos -1, zpos) == farmlandType) {
|
harvestz = -tileFarm.size - overlap;
|
||||||
if(tileFarm.getWorldObj().getBlock(xpos,ypos , zpos) == Blocks.air){
|
isHavrvesting = true;
|
||||||
tileFarm.getWorldObj().setBlock(xpos,ypos , zpos, Blocks.sapling);
|
} else {
|
||||||
}
|
Block block = tileFarm.getWorldObj().getBlock(harvestx + tileFarm.xCoord, harvesty + tileFarm.yCoord, harvestz + tileFarm.zCoord);
|
||||||
// }
|
if(block instanceof BlockLeavesBase){
|
||||||
|
tileFarm.getWorldObj().setBlockToAir(harvestx + tileFarm.xCoord, harvesty + tileFarm.yCoord, harvestz + tileFarm.zCoord);
|
||||||
|
} else if(harvestableLogs.contains(block)){
|
||||||
|
tileFarm.getWorldObj().setBlockToAir(harvestx + tileFarm.xCoord, harvesty + tileFarm.yCoord, harvestz + tileFarm.zCoord);
|
||||||
|
}
|
||||||
|
harvestx ++;
|
||||||
|
if(harvestx >= tileFarm.size + overlap){
|
||||||
|
harvestx = -tileFarm.size - overlap;
|
||||||
|
harvestz ++;
|
||||||
|
} else if(harvestz >= tileFarm.size + overlap){
|
||||||
|
harvestx = -tileFarm.size - overlap;
|
||||||
|
harvestz = -tileFarm.size - overlap;
|
||||||
|
harvesty ++;
|
||||||
|
} else if(harvesty > 12){
|
||||||
|
harvestx = 0;
|
||||||
|
harvesty = 2;
|
||||||
|
harvestz = 0;
|
||||||
|
isHavrvesting = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeInputStack(ItemStack stack, TileFarm tileFarm){
|
public boolean removeInputStack(ItemStack stack, TileFarm tileFarm) {
|
||||||
for (int i = 1; i < 3; i++) {
|
for (int i = 1; i < 3; i++) {
|
||||||
if(ItemUtils.isItemEqual(stack, tileFarm.getStackInSlot(i), true, true)){
|
if (ItemUtils.isItemEqual(stack, tileFarm.getStackInSlot(i), true, true)) {
|
||||||
tileFarm.decrStackSize(i, 1);
|
tileFarm.decrStackSize(i, 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -94,4 +144,13 @@ public class FarmTree implements IFarmLogicDevice {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ItemStack getSaplinStack(TileFarm tileFarm) {
|
||||||
|
for (int i = 1; i < 14; i++) {
|
||||||
|
if(tileFarm.getStackInSlot(i) != null && Block.getBlockFromItem(tileFarm.getStackInSlot(i).getItem()) instanceof BlockSapling){
|
||||||
|
return tileFarm.getStackInSlot(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import techreborn.blocks.BlockOre;
|
||||||
import techreborn.blocks.BlockStorage;
|
import techreborn.blocks.BlockStorage;
|
||||||
import techreborn.blocks.BlockStorage2;
|
import techreborn.blocks.BlockStorage2;
|
||||||
import techreborn.config.ConfigTechReborn;
|
import techreborn.config.ConfigTechReborn;
|
||||||
|
import techreborn.farm.FarmTree;
|
||||||
import techreborn.items.ItemCells;
|
import techreborn.items.ItemCells;
|
||||||
import techreborn.items.ItemDusts;
|
import techreborn.items.ItemDusts;
|
||||||
import techreborn.items.ItemDustsSmall;
|
import techreborn.items.ItemDustsSmall;
|
||||||
|
@ -62,6 +63,7 @@ public class ModRecipes {
|
||||||
addBlastFurnaceRecipes();
|
addBlastFurnaceRecipes();
|
||||||
addIndustrialGrinderRecipes();
|
addIndustrialGrinderRecipes();
|
||||||
addImplosionCompressorRecipes();
|
addImplosionCompressorRecipes();
|
||||||
|
addLogs();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addGeneralShapedRecipes() {
|
static void addGeneralShapedRecipes() {
|
||||||
|
@ -2194,4 +2196,9 @@ public class ModRecipes {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void addLogs(){
|
||||||
|
FarmTree.harvestableLogs.add(Blocks.log);
|
||||||
|
FarmTree.harvestableLogs.add(Blocks.log2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue