Skip to content

Commit

Permalink
Rebalance electron tubes and add ender farm
Browse files Browse the repository at this point in the history
  • Loading branch information
Nedelosk committed Jan 20, 2018
1 parent 10fec50 commit 287cb8c
Show file tree
Hide file tree
Showing 36 changed files with 617 additions and 115 deletions.
2 changes: 2 additions & 0 deletions src/main/java/forestry/api/farming/IFarmInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ default void registerSoil(ItemStack resource, IBlockState soilState){
registerSoil(resource, soilState, false);
}

void registerFarmables(String identifier);

void registerSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData);

boolean isAcceptedSoil(IBlockState blockState);
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/forestry/api/farming/IFarmable.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@ public interface IFarmable {

/**
* @return true if the block at the given location is a "sapling" for this type, i.e. a non-harvestable immature version of the crop.
* @deprecated Since Forestry 5.8. Use the version below. TODO Remove this method in 1.13
*/
boolean isSaplingAt(World world, BlockPos pos);
@Deprecated
default boolean isSaplingAt(World world, BlockPos pos){
return false;
}

/**
* @return true if the block at the given location is a "sapling" for this type, i.e. a non-harvestable immature version of the crop.
*/
default boolean isSaplingAt(World world, BlockPos pos, IBlockState blockState){
return isSaplingAt(world, pos);
}

/**
* @return {@link ICrop} if the block at the given location is a harvestable and mature crop, null otherwise.
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/forestry/core/circuits/Circuits.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ public class Circuits {
public static ICircuit farmCropsManaged;
public static ICircuit farmPeatManaged;
public static ICircuit farmSucculentManaged;
public static ICircuit farmPoaleManaged;
public static ICircuit farmPoalesManaged;
public static ICircuit farmInfernalManaged;
public static ICircuit farmEnderManaged;
public static ICircuit farmOrchidManaged;
public static ICircuit farmGourdManaged;
public static ICircuit farmCocoaManaged;


public static ICircuit farmArborealManual;
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/forestry/core/render/ParticleRender.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package forestry.core.render;

import java.util.List;
import java.util.Random;

import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.Particle;
Expand Down Expand Up @@ -157,6 +158,26 @@ public static void addEntityPotionFX(World world, double x, double y, double z,
effectRenderer.addEffect(particle);
}
}

public static void addPortalFx(World world, BlockPos pos, Random rand){
if (!shouldSpawnParticle(world)) {
return;
}

int j = rand.nextInt(2) * 2 - 1;
int k = rand.nextInt(2) * 2 - 1;
double xPos = (double)pos.getX() + 0.5D + 0.25D * (double)j;
double yPos = (double)((float)pos.getY() + rand.nextFloat());
double zPos = (double)pos.getZ() + 0.5D + 0.25D * (double)k;
double xSpeed = (double)(rand.nextFloat() * (float)j);
double ySpeed = ((double)rand.nextFloat() - 0.5D) * 0.125D;
double zSpeed = (double)(rand.nextFloat() * (float)k);
ParticleManager effectRenderer = Minecraft.getMinecraft().effectRenderer;
Particle particle = effectRenderer.spawnEffectParticle(EnumParticleTypes.PORTAL.getParticleID(), xPos, yPos, zPos, xSpeed, ySpeed, zSpeed);
if(particle != null){
effectRenderer.addEffect(particle);
}
}

public static void addEntityBiodustFX(World world, double x, double y, double z){
if (!shouldSpawnParticle(world)) {
Expand Down
53 changes: 31 additions & 22 deletions src/main/java/forestry/cultivation/ModuleCultivation.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import javax.annotation.Nullable;
import java.util.Set;

import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.util.ResourceLocation;

import forestry.api.modules.ForestryModule;
Expand Down Expand Up @@ -53,6 +51,7 @@ public void doInit() {
blocks.farmMushroom.init();
blocks.farmNether.init();
blocks.farmGourd.init();
blocks.farmEnder.init();
//blocks.plantation.init();
blocks.peatBog.init();
}
Expand Down Expand Up @@ -85,39 +84,49 @@ public void registerRecipes() {
"TCT",
"GBG",
'G', OreDictUtil.BLOCK_GLASS,
'T', coreItems.tubes.get(EnumElectronTube.COPPER, 1),
'T', coreItems.tubes.get(EnumElectronTube.OBSIDIAN, 1),
'C', coreItems.sturdyCasing,
'B', coreItems.circuitboards.get(EnumCircuitBoardType.BASIC));

RecipeUtil.addRecipe("farm_mushroom", blocks.farmMushroom,
"BGR",
"GAG",
"RGB",
"GTG",
"TCT",
"GBG",
'G', OreDictUtil.BLOCK_GLASS,
'B', Blocks.BROWN_MUSHROOM,
'R', Blocks.RED_MUSHROOM,
'A', blocks.arboretum);
'T', coreItems.tubes.get(EnumElectronTube.APATITE, 1),
'C', coreItems.sturdyCasing,
'B', coreItems.circuitboards.get(EnumCircuitBoardType.BASIC));

RecipeUtil.addRecipe("farm_gourd", blocks.farmGourd,
"MGP",
"GAG",
"PGM",
"GTG",
"TCT",
"GBG",
'G', OreDictUtil.BLOCK_GLASS,
'M', Blocks.MELON_BLOCK,
'P', Blocks.PUMPKIN,
'A', blocks.arboretum);
'T', coreItems.tubes.get(EnumElectronTube.LAPIS, 1),
'C', coreItems.sturdyCasing,
'B', coreItems.circuitboards.get(EnumCircuitBoardType.BASIC));

RecipeUtil.addRecipe("farm_nether", blocks.farmNether,
"WGW",
"GAG",
"WGW",
"GTG",
"TCT",
"GBG",
'G', OreDictUtil.BLOCK_GLASS,
'W', Items.NETHER_WART,
'A', blocks.arboretum);
'T', coreItems.tubes.get(EnumElectronTube.BLAZE, 1),
'C', coreItems.sturdyCasing,
'B', coreItems.circuitboards.get(EnumCircuitBoardType.BASIC));

RecipeUtil.addRecipe("farm_ender", blocks.farmEnder,
"GTG",
"TCT",
"GBG",
'G', OreDictUtil.BLOCK_GLASS,
'T', coreItems.tubes.get(EnumElectronTube.ENDER, 1),
'C', coreItems.sturdyCasing,
'B', coreItems.circuitboards.get(EnumCircuitBoardType.BASIC));

for(BlockPlanter planter : getBlocks().getPlanters()){
RecipeUtil.addRecipe(planter.blockType.getName() + "_manual_managed", planter.get(true), "# ", " ", " ", '#', planter.get(false));
RecipeUtil.addRecipe(planter.blockType.getName() + "_managed_manual", planter.get(false), "# ", " ", " ", '#', planter.get(true));
RecipeUtil.addShapelessRecipe(planter.blockType.getName() + "_manual_managed", planter.get(true), planter.get(false));
RecipeUtil.addShapelessRecipe(planter.blockType.getName() + "_managed_manual", planter.get(false), planter.get(true));
}
}
}
30 changes: 20 additions & 10 deletions src/main/java/forestry/cultivation/blocks/BlockPlanter.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package forestry.cultivation.blocks;

import java.util.Random;

import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
Expand All @@ -23,6 +23,7 @@
import net.minecraftforge.fml.relauncher.SideOnly;

import forestry.core.blocks.BlockBase;
import forestry.core.render.ParticleRender;
import forestry.cultivation.tiles.TilePlanter;

public class BlockPlanter extends BlockBase<BlockTypePlanter> {
Expand All @@ -38,6 +39,16 @@ protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, FACING, MANUAL);
}

@SideOnly(Side.CLIENT)
@Override
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
if(blockType == BlockTypePlanter.FARM_ENDER){
for (int i = 0; i < 3; ++i) {
ParticleRender.addPortalFx(worldIn, pos, rand);
}
}
}

@Override
public IBlockState getStateFromMeta(int meta) {
int facing = meta & 7;
Expand All @@ -62,6 +73,11 @@ public TileEntity createTileEntity(World world, IBlockState state) {
return tile;
}

@Override
public int damageDropped(IBlockState state) {
return state.getValue(MANUAL) ? 1 : 0;
}

@Override
@SideOnly(Side.CLIENT)
public void registerStateMapper() {
Expand All @@ -87,16 +103,10 @@ public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items) {
}

public static boolean isManual(ItemStack stack){
NBTTagCompound tagCompound = stack.getTagCompound();
if(tagCompound != null){
return tagCompound.getBoolean("Manual");
}
return false;
return stack.getMetadata() == 1;
}

public ItemStack get(boolean isManual){
ItemStack stack = new ItemStack(this);
stack.setTagInfo("Manual", new NBTTagByte((byte) (isManual ? 1 : 0)));
return stack;
return new ItemStack(this, 1, isManual ? 1 : 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class BlockRegistryCultivation extends BlockRegistry {
public final BlockPlanter farmMushroom;
public final BlockPlanter farmGourd;
public final BlockPlanter farmNether;
public final BlockPlanter farmEnder;
public final BlockPlanter peatBog;
/*public final BlockPlanter plantation;*/

Expand All @@ -38,6 +39,10 @@ public BlockRegistryCultivation() {
registerBlock(farmNether, new ItemBlockPlanter(farmNether), "farm_nether");
planters.add(farmNether);

farmEnder = new BlockPlanter(BlockTypePlanter.FARM_ENDER);
registerBlock(farmEnder, new ItemBlockPlanter(farmEnder), "farm_ender");
planters.add(farmEnder);

peatBog = new BlockPlanter(BlockTypePlanter.PEAT_POG);
registerBlock(peatBog, new ItemBlockPlanter(peatBog), "peat_bog");
planters.add(peatBog);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,31 @@

import forestry.core.blocks.IBlockTypeCustom;
import forestry.core.blocks.IMachineProperties;
import forestry.core.blocks.MachineProperties;
import forestry.core.tiles.TileForestry;
import forestry.cultivation.tiles.TileArboretum;
import forestry.cultivation.tiles.TileBog;
import forestry.cultivation.tiles.TileFarmCrops;
import forestry.cultivation.tiles.TileFarmEnder;
import forestry.cultivation.tiles.TileFarmGourd;
import forestry.cultivation.tiles.TileFarmMushroom;
import forestry.cultivation.tiles.TileFarmNether;
import forestry.cultivation.tiles.TilePlanter;

public enum BlockTypePlanter implements IBlockTypeCustom {
ARBORETUM(TileArboretum.class, "arboretum"),
FARM_CROPS(TileFarmCrops.class, "farm_crop"),
FARM_MUSHROOM(TileFarmMushroom.class, "farm_mushroom"),
FARM_GOURD(TileFarmGourd.class, "farm_gourd"),
FARM_NETHER(TileFarmNether.class, "farm_nether"),
FARM_ENDER(TileFarmEnder.class, "farm_ender"),
PEAT_POG(TileBog.class, "peat_bog"),

//TODO Add ic2 integration
/*PLANTATION(TilePlantation.class, "plantation")*/;

private final IMachineProperties machineProperties;

<T extends TileForestry> BlockTypePlanter(Class<T> teClass, String name) {
this.machineProperties = new MachineProperties<>(teClass, name);
BlockTypePlanter(Class<? extends TilePlanter> teClass, String name) {
this.machineProperties = new PlanterProperties<>(teClass, name);
}

@Override
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/forestry/cultivation/blocks/PlanterProperties.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package forestry.cultivation.blocks;

import com.google.common.base.Preconditions;

import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;

import forestry.api.core.IModelManager;
import forestry.core.blocks.MachineProperties;
import forestry.core.utils.ItemStackUtil;
import forestry.cultivation.tiles.TilePlanter;

public class PlanterProperties<T extends TilePlanter> extends MachineProperties<T> {

PlanterProperties(Class<T> teClass, String name) {
super(teClass, name);
}

@Override
public void registerModel(Item item, IModelManager manager) {
ResourceLocation itemNameFromRegistry = ItemStackUtil.getItemNameFromRegistry(item);
Preconditions.checkNotNull(itemNameFromRegistry, "No registry name for item");
String identifier = itemNameFromRegistry.getResourcePath();
manager.registerItemModel(item, 0, identifier);
manager.registerItemModel(item, 1, identifier);
}
}
41 changes: 41 additions & 0 deletions src/main/java/forestry/cultivation/tiles/TileFarmEnder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package forestry.cultivation.tiles;

import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;

public class TileFarmEnder extends TilePlanter {
public TileFarmEnder() {
super("farmEnder");
}

@Override
public ItemStack[] createGermlingStacks() {
return new ItemStack[]{
new ItemStack(Blocks.CHORUS_FLOWER),
new ItemStack(Blocks.CHORUS_FLOWER),
new ItemStack(Blocks.CHORUS_FLOWER),
new ItemStack(Blocks.CHORUS_FLOWER)
};
}

@Override
public ItemStack[] createResourceStacks() {
return new ItemStack[]{
new ItemStack(Blocks.END_STONE),
new ItemStack(Blocks.END_STONE),
new ItemStack(Blocks.END_STONE),
new ItemStack(Blocks.END_STONE)
};
}

@Override
public ItemStack[] createProductionStacks() {
return new ItemStack[]{
new ItemStack(Blocks.CHORUS_FLOWER),
new ItemStack(Items.CHORUS_FRUIT),
new ItemStack(Items.CHORUS_FRUIT),
new ItemStack(Blocks.CHORUS_FLOWER)
};
}
}
6 changes: 1 addition & 5 deletions src/main/java/forestry/farming/FarmRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.Map.Entry;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.stream.Collectors;

import net.minecraft.item.ItemStack;

Expand All @@ -41,7 +40,6 @@ public final class FarmRegistry implements IFarmRegistry {
private static final FarmRegistry INSTANCE = new FarmRegistry();
private final Multimap<String, IFarmable> farmables = HashMultimap.create();
private final Map<ItemStack, Integer> fertilizers = new LinkedHashMap<>();
private final Map<String, IFarmLogic> logics = new HashMap<>();
private final Map<String, IFarmInstance> farmInstances = new HashMap<>();

public static FarmRegistry getInstance() {
Expand All @@ -51,7 +49,6 @@ public static FarmRegistry getInstance() {
@Override
@Deprecated
public void registerLogic(String identifier, IFarmLogic logic) {
logics.put(identifier, logic);
}

@Override
Expand Down Expand Up @@ -103,8 +100,7 @@ public IFarmInstance registerLogic(IFarmInstance farmInstance) {
public IFarmInstance registerLogic(String identifier, BiFunction<IFarmInstance, Boolean, IFarmLogic> logicFactory, String... farmablesIdentifiers) {
Set<String> fIdentifiers = new HashSet<>(Arrays.asList(farmablesIdentifiers));
fIdentifiers.add(identifier);
Collection<IFarmable> farmablesSet = fIdentifiers.stream().map(farmables::get).flatMap(Collection::stream).collect(Collectors.toSet());
IFarmInstance instance = new FarmInstance(identifier, logicFactory, farmablesSet);
IFarmInstance instance = new FarmInstance(identifier, logicFactory, fIdentifiers);
farmInstances.put(identifier, instance);
return instance;
}
Expand Down
Loading

0 comments on commit 287cb8c

Please sign in to comment.