Compare commits

...
27 Commits
Author SHA1 Message Date
mezz 438883bb8e Change IAllele.getName to IAllele.getAlleleName to fix obfuscation bugs 2017-05-10 00:06:30 -07:00
mezz 828dd63acd Fix #1681 Worldgen leaves are not decaying 2017-05-07 17:40:31 -07:00
mezz f7cc35d949 Add new default leaf block without tile entity for worldgen trees #1661 2017-05-03 17:15:58 -07:00
AlexIIL ec9004b50b Fix names in BC|Transport compat
As with the update to 1.11 BC|Transport now has a modid of "buildcrafttransport", and the pipeWaterproof has been renamed to "waterproof".

You *might* want to rename this plugin from "BuildCraft 6 Transport" to "BuildCraft 8 Transport" - but that's minor.

The api for getting BC items is [here](https://github.com/BuildCraft/BuildCraftAPI/blob/8.0.x/api/buildcraft/api/BCItems.java#L123), so thet's where the registry names came from (and they won't be changed in 8.0.x or 7.99.x) in case I've made a mistake.
2017-04-29 13:19:25 -07:00
Nedelosk 8b4c1a5dab Fix #1667 Unable to open Electrical Engine GUI 2017-04-22 00:18:02 +02:00
Nedelosk 853355062e Fix #1666 Crash 1.11.2 2017-04-21 22:34:00 +02:00
Nedelosk 834e3ed55a Readd Ic2 Integration 2017-04-21 22:30:37 +02:00
Nedelosk 5b2b0bfc95 Fix #1657 Charcoal Pit - Silk Touch 2017-04-11 21:35:02 +02:00
Nedelosk 4fae8c26d9 Allow other mods to register fruit blocks 2017-04-10 01:19:49 +02:00
Nedelosk 0aa4a0f794 Add AlleleRegisterEvent 2017-04-10 00:23:39 +02:00
Nedelosk ac0864303c Clean Up Climate Region 2017-04-08 20:46:57 +02:00
Nedelosk 8811b24811 Merge branch 'mc-1.11' of https://github.com/ForestryMC/ForestryMC into mc-1.11 2017-04-08 19:37:15 +02:00
Nedelosk 904293f407 Move go home to get getBlockPathWeight 2017-04-08 19:37:07 +02:00
mezz 3e175aa8e6 Use improved Forge LootTableLoadEvent, remove hacky LootTableLoader 2017-04-07 22:09:44 -07:00
Nedelosk c4ecdde110 Fix #1426 A way to change how much sand an tree multifarm gives when a tree grows 2017-04-07 21:44:20 +02:00
Nedelosk 4aa978023d Fix #1539 Immersive engineering Ethanol doesn’t work with Bio Generator 2017-04-07 19:46:46 +02:00
Nedelosk 50009786d8 Fix #1546 Electric Engine via MFSU 2017-04-07 19:10:19 +02:00
Nedelosk 032d706fc4 Fix #1594 EnderLillySeeds not accept for farm 2017-04-07 18:37:52 +02:00
Nedelosk dcd9e90898 Fix butterfly pollen 2017-04-07 18:29:03 +02:00
Nedelosk bab3479cde Add Cache to greenhouse nursery and clean up 2017-04-07 17:45:45 +02:00
Nedelosk a5b79c97d2 Improve greenhouse recipes 2017-04-07 14:12:42 +02:00
Nedelosk 05d6dc3d4a Fix greenhouse door model 2017-04-07 13:29:25 +02:00
Nedelosk 6e2ed37e80 Fix #1652 A way to make Cobwebs out of Silk Wisps and fix greenhouse item models 2017-04-07 13:21:39 +02:00
Nedelosk c840945706 Add missing changes 2017-04-07 13:10:28 +02:00
Nedelosk ca7d6dbc66 Add honey comb blocks and improve greenhouse nursery 2017-04-07 12:55:34 +02:00
Nedelosk 81ef5d536f Add missing changes 2017-04-06 01:11:27 +02:00
Nedelosk f911100c3d Clean Up and update version 2017-04-06 00:17:41 +02:00
137 changed files with 3335 additions and 2215 deletions

No files matched your search

+1 -1
View File
@@ -63,7 +63,7 @@ dependencies {
deobfCompile "net.darkhax.tesla:Tesla:${tesla_version}"
deobfCompile "mezz.jei:jei_${mcversion}:${jei_version}:api"
runtime "mezz.jei:jei_${mcversion}:${jei_version}"
// deobfCompile "net.industrial-craft:industrialcraft-2:${ic2_version}:api"
deobfCompile "net.industrial-craft:industrialcraft-2:${ic2_version}:api"
}
configurations {
+3 -3
View File
@@ -1,11 +1,11 @@
mcversion=1.11.2
forgeversion=13.20.0.2262
forgeversion=13.20.0.2279
mcp_mappings=snapshot_20161220
tesla_version=1.11-1.3.0.51
jei_version=4.3.0.252
#ic2_version=2.6.76-ex110
ic2_version=2.7.7-ex111
version_major=5
version_minor=3
version_patch=2
version_patch=4
+1 -1
Submodule lang updated: addea45c4f...f5300f059b.
+4 -3
View File
@@ -29,6 +29,7 @@ import forestry.core.proxy.Proxies;
import forestry.core.utils.MigrationHelper;
import forestry.core.worldgen.WorldGenerator;
import forestry.plugins.PluginManager;
import forestry.plugins.compat.PluginIC2;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.common.Mod;
@@ -54,9 +55,9 @@ import net.minecraftforge.fml.common.registry.GameRegistry;
version = Constants.VERSION,
guiFactory = "forestry.core.config.ForestryGuiConfigFactory",
acceptedMinecraftVersions = "[1.11]",
dependencies = "required-after:forge@[13.20.0.2230,);"
+ "after:JEI@[4.3.0,);")
// + "after:" + PluginIC2.modId + ";")
dependencies = "required-after:forge@[13.20.0.2270,);"
+ "after:JEI@[4.3.0,);"
+ "after:" + PluginIC2.modId + ";")
public class Forestry {
@SuppressWarnings("NullableProblems")
@@ -44,4 +44,9 @@ public interface ITreeGenome extends IGenome {
* @return A ItemStack that is used in getPickBlock of the leave block.
*/
ItemStack getDecorativeLeaves();
/**
* @return true if this genome matches one of the default template genomes
*/
boolean matchesTemplateGenome();
}
@@ -11,7 +11,6 @@ import java.util.Map;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import forestry.api.core.ForestryAPI;
import net.minecraft.item.ItemStack;
public class Farmables {
@@ -1,3 +1,8 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.farming;
import net.minecraft.item.ItemStack;
@@ -5,7 +5,7 @@
******************************************************************************/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@API(apiVersion = "2.1.0", owner = "ForestryAPI|core", provides = "ForestryAPI|farming")
@API(apiVersion = "2.2.0", owner = "ForestryAPI|core", provides = "ForestryAPI|farming")
package forestry.api.farming;
import javax.annotation.ParametersAreNonnullByDefault;
@@ -0,0 +1,22 @@
package forestry.api.genetics;
import forestry.api.arboriculture.IAlleleFruit;
import net.minecraftforge.fml.common.eventhandler.Event;
/**
* Called after Forestry has registered all his alleles of an specific type. Like IAlleleFruit or IAlleleSpecies
* @since 5.3.3
*/
public class AlleleRegisterEvent<A extends IAllele> extends Event {
private final Class<? extends A> alleleClass;
public AlleleRegisterEvent(Class<? extends A> alleleClass) {
this.alleleClass = alleleClass;
}
public Class<? extends A> getAlleleClass() {
return alleleClass;
}
}
@@ -5,11 +5,12 @@ import net.minecraftforge.fml.common.eventhandler.Event;
/**
* Called after Forestry has registered all his species alleles of a individual.
*/
public class AlleleSpeciesRegisterEvent extends Event {
public class AlleleSpeciesRegisterEvent<A extends IAlleleSpecies> extends AlleleRegisterEvent<A> {
private final ISpeciesRoot root;
public AlleleSpeciesRegisterEvent(ISpeciesRoot root) {
public AlleleSpeciesRegisterEvent(ISpeciesRoot root, Class<? extends A> alleleClass) {
super(alleleClass);
this.root = root;
}
@@ -28,9 +28,20 @@ public interface IAllele {
/**
* @return Localized short, human-readable identifier used in tooltips and beealyzer.
* @deprecated since Forestry 5.3.4. Use {@link #getAlleleName()}.
*/
@Deprecated
String getName();
/**
* @return Localized short, human-readable identifier used in tooltips and beealyzer.
* @since Forestry 5.3.4
* @apiNote This can't be named "getName" or it can conflict during obfuscation. https://github.com/md-5/SpecialSource/issues/12
*/
default String getAlleleName() {
return getName();
}
/**
* @return The unlocalized identifier
*/
@@ -5,8 +5,11 @@
******************************************************************************/
package forestry.api.lepidopterology;
import java.util.Set;
import javax.annotation.Nullable;
import forestry.api.core.IErrorState;
import forestry.api.genetics.IIndividualLiving;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
@@ -48,6 +51,27 @@ public interface IButterfly extends IIndividualLiving {
*/
@Nullable
IButterfly spawnCaterpillar(World world, IButterflyNursery nursery);
/**
* Determines whether the caterpillar can grow.
*
* @param cocoon the {@link IButterflyCocoon} the caterpillar resides in.
* @param nursery the {@link IButterflyNursery} of the caterpillar.
* @return an empty set if the caterpillar can grow, a set of error states if the caterpillar can not grow
* @since 5.3.3
*/
Set<IErrorState> getCanGrow(IButterflyNursery nursery, @Nullable IButterflyCocoon cocoon);
/**
* Determines whether the caterpillar can spawn. (Used to auto-spawn butterflies out of a cocoon.)
*
* @param cocoon the {@link IButterflyCocoon} the caterpillar resides in.
* @param nursery the {@link IButterflyNursery} of the caterpillar.
* @return an empty set if the caterpillar can spawn, a set of error states if the caterpillar can not spawn
* @since 5.3.3
*/
Set<IErrorState> getCanSpawn(IButterflyNursery nursery, @Nullable IButterflyCocoon cocoon);
/**
* @param playerKill Whether or not the butterfly was killed by a player.
@@ -13,7 +13,7 @@ package forestry.api.lepidopterology;
import forestry.api.genetics.IHousing;
public interface IButterflyCocoon extends IHousing {
IButterfly getCaterpillar();
void setCaterpillar(IButterfly butterfly);
@@ -10,15 +10,19 @@ import javax.annotation.Nullable;
import forestry.api.climate.IClimateProvider;
import forestry.api.genetics.IHousing;
import forestry.api.genetics.IIndividual;
import net.minecraft.world.World;
public interface IButterflyNursery extends IHousing, IClimateProvider {
@Nullable
IButterfly getCaterpillar();
@Nullable
IIndividual getNanny();
void setCaterpillar(@Nullable IButterfly caterpillar);
boolean canNurse(IButterfly caterpillar);
World getWorldObj();
}
@@ -5,7 +5,7 @@
******************************************************************************/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@API(apiVersion = "1.3.0", owner = "ForestryAPI|core", provides = "ForestryAPI|lepidopterology")
@API(apiVersion = "1.4.0", owner = "ForestryAPI|core", provides = "ForestryAPI|lepidopterology")
package forestry.api.lepidopterology;
import javax.annotation.ParametersAreNonnullByDefault;
@@ -10,6 +10,7 @@ import forestry.api.climate.IClimateSourceProvider;
import forestry.api.climate.IClimatiserDefinition;
import forestry.api.greenhouse.IGreenhouseListener;
import forestry.api.lepidopterology.IButterflyCocoon;
import forestry.api.lepidopterology.IButterflyNursery;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
@@ -32,7 +33,7 @@ public interface IGreenhouseComponent<T extends IMultiblockLogicGreenhouse> exte
IClimatiserDefinition getDefinition();
}
interface Nursery extends IGreenhouseComponent {
interface Nursery extends IGreenhouseComponent, IButterflyNursery {
void addCocoonLoot(IButterflyCocoon cocoon, NonNullList<ItemStack> loot);
}
@@ -13,6 +13,7 @@ import forestry.api.core.ICamouflageHandler;
import forestry.api.greenhouse.IGreenhouseHousing;
import forestry.api.greenhouse.IInternalBlock;
import forestry.api.lepidopterology.IButterfly;
import forestry.api.lepidopterology.IButterflyCocoon;
public interface IGreenhouseController extends IMultiblockController, IGreenhouseHousing, ICamouflageHandler, IClimateControlProvider {
@@ -21,6 +22,16 @@ public interface IGreenhouseController extends IMultiblockController, IGreenhous
*/
Set<IInternalBlock> getInternalBlocks();
/**
* spawns a butterfly in a greenhouse
* @return true if it has spawned it, and false if it has not
*/
boolean spawnButterfly(IGreenhouseComponent.Nursery nursery);
/**
* @deprecated use {@link #spawnButterfly(IButterflyCocoon)}
*/
@Deprecated
boolean spawnButterfly(IButterfly butterfly);
IClimateRegion getRegion();
@@ -38,6 +38,7 @@ import forestry.api.storage.ICrateRegistry;
import forestry.api.storage.StorageManager;
import forestry.apiculture.blocks.BlockAlvearyType;
import forestry.apiculture.blocks.BlockCandle;
import forestry.apiculture.blocks.BlockHoneyComb;
import forestry.apiculture.blocks.BlockRegistryApiculture;
import forestry.apiculture.capabilities.ArmorApiarist;
import forestry.apiculture.commands.CommandBee;
@@ -103,7 +104,6 @@ import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.init.PotionTypes;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionType;
import net.minecraft.potion.PotionUtils;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
@@ -488,6 +488,15 @@ public class PluginApiculture extends BlankForestryPlugin {
"C",
'B', new ItemStack(blocks.apiary),
'C', Items.MINECART);
for(int i = 0;i < blocks.beeCombs.length;i++){
BlockHoneyComb block = blocks.beeCombs[i];
for(int m = 0;m < EnumHoneyComb.VALUES.length - i * 16;m++){
RecipeUtil.addRecipe(new ItemStack(block, 1, m),
"###",
"###",
"###", '#', items.beeComb.get(EnumHoneyComb.get(i * 16 + m), 1));
}
}
// FOOD STUFF
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FOOD)) {
@@ -0,0 +1,22 @@
package forestry.apiculture.blocks;
import java.util.Locale;
import net.minecraft.util.IStringSerializable;
public enum BlockBeeProductType implements IStringSerializable {
BEE_COMBS,
BEESWAX;
public static final BlockBeeProductType[] VALUES = values();
@Override
public String getName() {
return name().toLowerCase(Locale.ENGLISH);
}
public int getMeta() {
return ordinal();
}
}
@@ -332,6 +332,7 @@ public class BlockCandle extends BlockTorch implements IItemModelRegister, ITile
return new ItemStack(this, amount, 1);
}
@SideOnly(Side.CLIENT)
@Override
public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex) {
if (worldIn != null && pos != null) {
@@ -0,0 +1,162 @@
package forestry.apiculture.blocks;
import javax.annotation.Nullable;
import com.google.common.base.Predicate;
import forestry.api.core.IItemModelRegister;
import forestry.api.core.IModelManager;
import forestry.api.core.IStateMapperRegister;
import forestry.api.core.Tabs;
import forestry.apiculture.items.EnumHoneyComb;
import forestry.core.blocks.IBlockWithMeta;
import forestry.core.blocks.IColoredBlock;
import forestry.core.config.Config;
import forestry.core.config.Constants;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public abstract class BlockHoneyComb extends Block implements IItemModelRegister, IBlockWithMeta, IColoredBlock, IStateMapperRegister {
public final int minMeta;
public static final BlockHoneyComb[] create(){
BlockHoneyComb[] blocks = new BlockHoneyComb[2];
for(int i = 0;i < blocks.length;i++){
HoneyCombPredicate filter = new HoneyCombPredicate(i, 16);
PropertyEnum<EnumHoneyComb> variant = PropertyEnum.create("type", EnumHoneyComb.class, filter);
blocks[i] = new BlockHoneyComb(filter.minMeta) {
@Override
protected PropertyEnum<EnumHoneyComb> getVariant() {
return variant;
}
};
}
return blocks;
}
public BlockHoneyComb(int minMeta) {
super(Material.CLOTH);
setHardness(1F);
setCreativeTab(Tabs.tabApiculture);
setDefaultState(this.blockState.getBaseState().withProperty(getVariant(), getVariant().getAllowedValues().iterator().next()));
this.minMeta = minMeta;
}
protected abstract PropertyEnum<EnumHoneyComb> getVariant();
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, getVariant());
}
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(getVariant()).ordinal()-minMeta;
}
@Override
public IBlockState getStateFromMeta(int meta) {
return getDefaultState().withProperty(getVariant(), EnumHoneyComb.get(minMeta + meta));
}
@Override
public void getSubBlocks(Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list) {
for (EnumHoneyComb honeyComb : getVariant().getAllowedValues()) {
if(!honeyComb.isSecret() || Config.isDebug){
list.add(get(honeyComb));
}
}
}
@Override
public String getUnlocalizedName() {
return "tile.for.bee_combs";
}
@SideOnly(Side.CLIENT)
@Override
public BlockRenderLayer getBlockLayer() {
return BlockRenderLayer.CUTOUT;
}
@Override
public int damageDropped(IBlockState state) {
return getMetaFromState(state);
}
@SideOnly(Side.CLIENT)
@Override
public void registerModel(Item item, IModelManager manager) {
for (EnumHoneyComb comb : getVariant().getAllowedValues()) {
manager.registerItemModel(item, comb.ordinal()-minMeta, "block_bee_combs");
}
}
public ItemStack get(EnumHoneyComb honeyComb) {
return new ItemStack(this, 1, honeyComb.ordinal() - minMeta);
}
@Override
public String getNameFromMeta(int meta) {
EnumHoneyComb honeyComb = EnumHoneyComb.get(minMeta + meta);
return honeyComb.name;
}
@SideOnly(Side.CLIENT)
@Override
public int colorMultiplier(IBlockState state, IBlockAccess worldIn, BlockPos pos, int tintIndex) {
int meta = getMetaFromState(state);
EnumHoneyComb honeyComb = EnumHoneyComb.get(minMeta + meta);
if (tintIndex == 1) {
return honeyComb.primaryColor;
} else {
return honeyComb.secondaryColor;
}
}
@SideOnly(Side.CLIENT)
@Override
public void registerStateMapper() {
ModelLoader.setCustomStateMapper(this, new HoneyCombStateMapper());
}
private static class HoneyCombPredicate implements Predicate<EnumHoneyComb> {
private final int minMeta;
private final int maxMeta;
public HoneyCombPredicate(int blockNumber, int variantsPerBlock) {
this.minMeta = blockNumber * variantsPerBlock;
this.maxMeta = minMeta + variantsPerBlock - 1;
}
@Override
public boolean apply(@Nullable EnumHoneyComb honeyComb) {
return honeyComb != null && honeyComb.ordinal() >= minMeta && honeyComb.ordinal() <= maxMeta;
}
}
@SideOnly(Side.CLIENT)
private static class HoneyCombStateMapper extends StateMapperBase {
@Override
protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
return new ModelResourceLocation(Constants.MOD_ID + ":bee_combs", "normal");
}
}
}
@@ -13,6 +13,7 @@ package forestry.apiculture.blocks;
import java.util.Map;
import forestry.api.core.Tabs;
import forestry.apiculture.items.ItemBlockHoneyComb;
import forestry.apiculture.items.ItemBlockCandle;
import forestry.core.blocks.BlockBase;
import forestry.core.blocks.BlockRegistry;
@@ -27,6 +28,7 @@ public class BlockRegistryApiculture extends BlockRegistry {
public final BlockBeeHives beehives;
public final BlockCandle candle;
public final BlockStump stump;
public final BlockHoneyComb[] beeCombs;
private final Map<BlockAlvearyType, BlockAlveary> alvearyBlockMap;
public BlockRegistryApiculture() {
@@ -48,6 +50,12 @@ public class BlockRegistryApiculture extends BlockRegistry {
registerBlock(candle, new ItemBlockCandle(candle), "candle");
stump = new BlockStump();
registerBlock(stump, new ItemBlockForestry(stump), "stump");
beeCombs = BlockHoneyComb.create();
for(int i = 0;i < beeCombs.length;i++){
BlockHoneyComb block = beeCombs[i];
registerBlock(block, new ItemBlockHoneyComb(block), "bee_combs_" + i);
}
alvearyBlockMap = BlockAlveary.create();
for (BlockAlveary block : alvearyBlockMap.values()) {
@@ -94,7 +94,7 @@ public class CommandBeeGive extends SubCommand {
ItemStack beeStack = BeeManager.beeRoot.getMemberStack(bee, beeType);
player.dropItem(beeStack, false, true);
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.bee.give.given", player.getName(), bee.getGenome().getPrimary().getName(), beeType.getName());
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.bee.give.given", player.getName(), bee.getGenome().getPrimary().getAlleleName(), beeType.getName());
}
private static IBeeGenome getBeeGenome(String speciesName) throws SpeciesNotFoundException, TemplateNotFoundException {
@@ -115,7 +115,7 @@ public class CommandBeeGive extends SubCommand {
if (species == null) {
for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) {
if (allele instanceof IAlleleBeeSpecies && allele.getName().equals(speciesName)) {
if (allele instanceof IAlleleBeeSpecies && allele.getAlleleName().equals(speciesName)) {
species = (IAlleleBeeSpecies) allele;
break;
}
@@ -150,7 +150,7 @@ public class CommandBeeGive extends SubCommand {
for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) {
if (allele instanceof IAlleleBeeSpecies) {
species.add(allele.getName());
species.add(allele.getAlleleName());
}
}
@@ -361,7 +361,7 @@ public class Bee extends IndividualLiving implements IBee {
IAlleleBeeSpecies primary = genome.getPrimary();
IAlleleBeeSpecies secondary = genome.getSecondary();
if (!isPureBred(EnumBeeChromosome.SPECIES)) {
list.add(TextFormatting.BLUE + Translator.translateToLocal("for.bees.hybrid").replaceAll("%PRIMARY", primary.getName()).replaceAll("%SECONDARY", secondary.getName()));
list.add(TextFormatting.BLUE + Translator.translateToLocal("for.bees.hybrid").replaceAll("%PRIMARY", primary.getAlleleName()).replaceAll("%SECONDARY", secondary.getAlleleName()));
}
if (generation > 0) {
@@ -389,12 +389,12 @@ public class Bee extends IndividualLiving implements IBee {
if (Translator.canTranslateToLocal(unlocalizedCustomSpeed)) {
speed = Translator.translateToLocal(unlocalizedCustomSpeed);
} else {
speed = speedAllele.getName() + ' ' + Translator.translateToLocal("for.gui.worker");
speed = speedAllele.getAlleleName() + ' ' + Translator.translateToLocal("for.gui.worker");
}
String lifespan = genome.getActiveAllele(EnumBeeChromosome.LIFESPAN).getName() + ' ' + Translator.translateToLocal("for.gui.life");
String tempTolerance = TextFormatting.GREEN + "T: " + AlleleManager.climateHelper.toDisplay(genome.getPrimary().getTemperature()) + " / " + tempToleranceAllele.getName();
String humidTolerance = TextFormatting.GREEN + "H: " + AlleleManager.climateHelper.toDisplay(genome.getPrimary().getHumidity()) + " / " + humidToleranceAllele.getName();
String lifespan = genome.getActiveAllele(EnumBeeChromosome.LIFESPAN).getAlleleName() + ' ' + Translator.translateToLocal("for.gui.life");
String tempTolerance = TextFormatting.GREEN + "T: " + AlleleManager.climateHelper.toDisplay(genome.getPrimary().getTemperature()) + " / " + tempToleranceAllele.getAlleleName();
String humidTolerance = TextFormatting.GREEN + "H: " + AlleleManager.climateHelper.toDisplay(genome.getPrimary().getHumidity()) + " / " + humidToleranceAllele.getAlleleName();
String flowers = genome.getFlowerProvider().getDescription();
list.add(lifespan);
@@ -1021,7 +1021,7 @@ public enum BeeDefinition implements IBeeDefinition {
for (BeeDefinition bee : values()) {
bee.registerMutations();
}
MinecraftForge.EVENT_BUS.post(new AlleleSpeciesRegisterEvent(BeeManager.beeRoot));
MinecraftForge.EVENT_BUS.post(new AlleleSpeciesRegisterEvent(BeeManager.beeRoot, IAlleleBeeSpecies.class));
}
public static void preInit() {
@@ -33,4 +33,8 @@ public class AlleleFlowers extends AlleleCategorized implements IAlleleFlowers {
return getProvider().getDescription();
}
@Override
public String getAlleleName() {
return getProvider().getDescription();
}
}
@@ -62,11 +62,11 @@ public class GuiImprinter extends GuiForestry<ContainerImprinter> {
IAlleleBeeSpecies primary = itemInventory.getPrimary();
drawBeeSpeciesIcon(primary, startX + 12, startY + 32);
fontRendererObj.drawString(primary.getName(), startX + 32, startY + 36, ColourProperties.INSTANCE.get("gui.screen"));
fontRendererObj.drawString(primary.getAlleleName(), startX + 32, startY + 36, ColourProperties.INSTANCE.get("gui.screen"));
IAlleleBeeSpecies secondary = itemInventory.getSecondary();
drawBeeSpeciesIcon(secondary, startX + 12, startY + 52);
fontRendererObj.drawString(secondary.getName(), startX + 32, startY + 56, ColourProperties.INSTANCE.get("gui.screen"));
fontRendererObj.drawString(secondary.getAlleleName(), startX + 32, startY + 56, ColourProperties.INSTANCE.get("gui.screen"));
String youCheater = Translator.translateToLocal("for.gui.imprinter.cheater");
offset = (138 - fontRendererObj.getStringWidth(youCheater)) / 2;
@@ -13,7 +13,9 @@ package forestry.apiculture.items;
import java.awt.Color;
import java.util.Locale;
public enum EnumHoneyComb {
import net.minecraft.util.IStringSerializable;
public enum EnumHoneyComb implements IStringSerializable {
HONEY(new Color(0xe8d56a), new Color(0xffa12b)),
COCOA(new Color(0x674016), new Color(0xffb62b), true),
SIMMERING(new Color(0x981919), new Color(0xffb62b)),
@@ -50,6 +52,11 @@ public enum EnumHoneyComb {
this.secondaryColor = secondary.getRGB();
this.secret = secret;
}
@Override
public String getName() {
return name;
}
public boolean isSecret() {
return secret;
@@ -0,0 +1,29 @@
package forestry.apiculture.items;
import forestry.apiculture.blocks.BlockHoneyComb;
import forestry.core.items.IColoredItem;
import forestry.core.items.ItemBlockForestry;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemBlockHoneyComb extends ItemBlockForestry<BlockHoneyComb> implements IColoredItem {
public ItemBlockHoneyComb(Block block) {
super(block);
}
@SideOnly(Side.CLIENT)
@Override
public int getColorFromItemstack(ItemStack stack, int tintIndex) {
int meta = stack.getMetadata();
EnumHoneyComb honeyComb = EnumHoneyComb.get(getBlock().minMeta + meta);
if (tintIndex == 1) {
return honeyComb.primaryColor;
} else {
return honeyComb.secondaryColor;
}
}
}
@@ -2,6 +2,7 @@ package forestry.arboriculture;
import java.util.Random;
import forestry.arboriculture.blocks.BlockAbstractLeaves;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLeaves;
import net.minecraft.block.state.IBlockState;
@@ -23,12 +24,19 @@ public class LeafDecayHelper {
leafDecayValues = new byte[ARRAY_SIZE][ARRAY_SIZE][ARRAY_SIZE];
}
public static void leafDecay(BlockLeaves leaves, World world, BlockPos pos) {
public static void leafDecay(BlockAbstractLeaves leaves, World world, BlockPos pos) {
if (world.isRemote) {
return;
}
IBlockState state = world.getBlockState(pos);
// Fix a bug where Forestry leaves were not decayable.
// The non-decayable Forestry leaves are all BlockDecorativeLeaves.
if (!state.getValue(BlockLeaves.DECAYABLE)) {
state = state.withProperty(BlockLeaves.DECAYABLE, true);
world.setBlockState(pos, state);
}
if (state.getValue(BlockLeaves.CHECK_DECAY) && state.getValue(BlockLeaves.DECAYABLE)) {
byte radius = 4;
int arrayOffset = ARRAY_SIZE / 2;
@@ -33,12 +33,14 @@ import forestry.api.core.ForestryAPI;
import forestry.api.core.IArmorNaturalist;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IBlockTranslator;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IItemTranslator;
import forestry.api.recipes.RecipeManagers;
import forestry.api.storage.ICrateRegistry;
import forestry.api.storage.StorageManager;
import forestry.arboriculture.blocks.BlockArbLog;
import forestry.arboriculture.blocks.BlockArbSlab;
import forestry.arboriculture.blocks.BlockDefaultLeaves;
import forestry.arboriculture.blocks.BlockForestryLeaves;
import forestry.arboriculture.blocks.BlockRegistryArboriculture;
import forestry.arboriculture.capabilities.ArmorNaturalist;
@@ -530,6 +532,17 @@ public class PluginArboriculture extends BlankForestryPlugin {
return null;
}
});
for (BlockDefaultLeaves leaves : getBlocks().leavesDefault) {
TreeManager.treeRoot.registerTranslator(leaves, (IBlockTranslator<IIndividual>) blockState -> {
TreeDefinition treeDefinition = leaves.getTreeDefinition(blockState);
if (treeDefinition != null) {
return treeDefinition.getIndividual();
} else {
return null;
}
});
}
}
@Override
@@ -0,0 +1,201 @@
package forestry.arboriculture.blocks;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import com.mojang.authlib.GameProfile;
import forestry.api.arboriculture.IToolGrafter;
import forestry.api.arboriculture.ITree;
import forestry.api.core.IItemModelRegister;
import forestry.api.core.Tabs;
import forestry.arboriculture.LeafDecayHelper;
import forestry.arboriculture.genetics.TreeDefinition;
import forestry.arboriculture.tiles.TileLeaves;
import forestry.core.blocks.IColoredBlock;
import forestry.core.proxy.Proxies;
import forestry.core.tiles.TileUtil;
import forestry.core.utils.BlockUtil;
import net.minecraft.block.BlockLeaves;
import net.minecraft.block.BlockPlanks;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Enchantments;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
/**
* Parent class for shared behavior between {@link BlockDefaultLeaves} and {@link BlockForestryLeaves}
*/
public abstract class BlockAbstractLeaves extends BlockLeaves implements IItemModelRegister, IColoredBlock {
@Nullable
protected abstract ITree getTree(IBlockAccess world, BlockPos pos);
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
LeafDecayHelper.leafDecay(this, world, pos);
}
public abstract int getMetaFromState(IBlockState state);
public abstract IBlockState getStateFromMeta(int meta);
@Override
public final void getSubBlocks(Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list) {
// creative menu shows BlockDecorativeLeaves instead of these
}
@Override
public final ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
ITree tree = getTree(world, pos);
if (tree == null) {
return ItemStack.EMPTY;
}
return tree.getGenome().getDecorativeLeaves();
}
@Override
public final List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) {
ITree tree = getTree(world, pos);
if (tree == null) {
tree = TreeDefinition.Oak.getIndividual();
}
ItemStack decorativeLeaves = tree.getGenome().getDecorativeLeaves();
if (decorativeLeaves.isEmpty()) {
return Collections.emptyList();
} else {
return Collections.singletonList(decorativeLeaves);
}
}
@Nullable
@Override
public final AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos) {
ITree tree = getTree(worldIn, pos);
if (tree != null && TreeDefinition.Willow.getUID().equals(tree.getIdent())) {
return null;
}
return super.getCollisionBoundingBox(blockState, worldIn, pos);
}
/**
* Used for walking through willow leaves.
*/
@Override
public final void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
super.onEntityCollidedWithBlock(worldIn, pos, state, entityIn);
entityIn.motionX *= 0.4D;
entityIn.motionZ *= 0.4D;
}
/* RENDERING */
@Override
public final boolean isOpaqueCube(IBlockState state) {
return !Proxies.render.fancyGraphicsEnabled();
}
@SideOnly(Side.CLIENT)
@Override
public final boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
return (Proxies.render.fancyGraphicsEnabled() || blockAccess.getBlockState(pos.offset(side)).getBlock() != this) &&
BlockUtil.shouldSideBeRendered(blockState, blockAccess, pos, side);
}
@Override
@SideOnly(Side.CLIENT)
public final BlockRenderLayer getBlockLayer() {
return BlockRenderLayer.CUTOUT_MIPPED; // fruit overlays require CUTOUT_MIPPED, even in Fast graphics
}
/**
* unused, just here to satisfy BlockLeaves
*/
@Override
public final BlockPlanks.EnumType getWoodType(int meta) {
return BlockPlanks.EnumType.OAK;
}
/* PROPERTIES */
@Override
public final int getFlammability(IBlockAccess world, BlockPos pos, EnumFacing face) {
return 60;
}
@Override
public final boolean isFlammable(IBlockAccess world, BlockPos pos, EnumFacing face) {
return true;
}
@Override
public final int getFireSpreadSpeed(IBlockAccess world, BlockPos pos, EnumFacing face) {
if (face == EnumFacing.DOWN) {
return 20;
} else if (face != EnumFacing.UP) {
return 10;
} else {
return 5;
}
}
/* DROP HANDLING */
// Hack: When harvesting leaves we need to get the drops in onBlockHarvested,
// because there is no Player parameter in getDrops()
// and Mojang destroys the block and tile before calling getDrops.
private final ThreadLocal<List<ItemStack>> drops = new ThreadLocal<>();
/**
* {@link IToolGrafter}'s drop bonus handling is done here.
*/
@Override
public final void onBlockHarvested(World world, BlockPos pos, IBlockState state, EntityPlayer player) {
int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, player.getActiveItemStack());
float saplingModifier = 1.0f;
ItemStack heldStack = player.inventory.getCurrentItem();
Item heldItem = heldStack.getItem();
if (heldItem instanceof IToolGrafter) {
IToolGrafter grafter = (IToolGrafter) heldItem;
saplingModifier = grafter.getSaplingModifier(heldStack, world, player, pos);
heldStack.damageItem(1, player);
if (heldStack.isEmpty()) {
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, heldStack, EnumHand.MAIN_HAND);
}
}
GameProfile playerProfile = player.getGameProfile();
List<ItemStack> leafDrops = getLeafDrop(world, playerProfile, pos, saplingModifier, fortune);
drops.set(leafDrops);
}
@Override
public final List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
List<ItemStack> ret = drops.get();
drops.remove();
// leaves not harvested, get drops normally
if (ret == null) {
ret = getLeafDrop((World) world, null, pos, 1.0f, fortune);
}
return ret;
}
protected abstract NonNullList<ItemStack> getLeafDrop(World world, @Nullable GameProfile playerProfile, BlockPos pos, float saplingModifier, int fortune);
}
@@ -44,7 +44,9 @@ public class BlockCharcoal extends Block implements IStateMapperRegister, IItemM
@SideOnly(Side.CLIENT)
@Override
public void registerModel(Item item, IModelManager manager) {
manager.registerItemModel(item, 0);
for(int i = 0;i < 16;i++){
manager.registerItemModel(item, i);
}
}
@Override
@@ -0,0 +1,192 @@
package forestry.arboriculture.blocks;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import com.mojang.authlib.GameProfile;
import forestry.api.arboriculture.EnumGermlingType;
import forestry.api.arboriculture.IFruitProvider;
import forestry.api.arboriculture.ITree;
import forestry.api.arboriculture.ITreeGenome;
import forestry.api.arboriculture.TreeManager;
import forestry.api.core.IModelManager;
import forestry.arboriculture.genetics.TreeDefinition;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
/**
* Genetic leaves with no tile entity, used for worldgen trees.
* Similar to decorative leaves, but these will drop saplings and can be used for pollination.
*/
public abstract class BlockDefaultLeaves extends BlockAbstractLeaves {
private static final int VARIANTS_PER_BLOCK = 4;
public static List<BlockDefaultLeaves> create() {
List<BlockDefaultLeaves> blocks = new ArrayList<>();
final int blockCount = PropertyTreeType.getBlockCount(VARIANTS_PER_BLOCK);
for (int blockNumber = 0; blockNumber < blockCount; blockNumber++) {
final PropertyTreeType variant = PropertyTreeType.create("variant", blockNumber, VARIANTS_PER_BLOCK);
BlockDefaultLeaves block = new BlockDefaultLeaves(blockNumber) {
@Override
public PropertyTreeType getVariant() {
return variant;
}
};
blocks.add(block);
}
return blocks;
}
private final int blockNumber;
public BlockDefaultLeaves(int blockNumber) {
this.blockNumber = blockNumber;
PropertyTreeType variant = getVariant();
setDefaultState(this.blockState.getBaseState()
.withProperty(variant, variant.getFirstType())
.withProperty(CHECK_DECAY, false)
.withProperty(DECAYABLE, true));
}
public int getBlockNumber() {
return blockNumber;
}
protected abstract PropertyTreeType getVariant();
@Nullable
public TreeDefinition getTreeDefinition(IBlockState blockState) {
if (blockState.getBlock() == this) {
return blockState.getValue(getVariant());
} else {
return null;
}
}
@Override
public int damageDropped(IBlockState state) {
TreeDefinition treeDefinition = getTreeDefinition(state);
if (treeDefinition == null) {
return 0;
}
return treeDefinition.getMetadata() - blockNumber * VARIANTS_PER_BLOCK;
}
@Override
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState()
.withProperty(getVariant(), getTreeType(meta))
.withProperty(DECAYABLE, (meta & 4) == 0)
.withProperty(CHECK_DECAY, (meta & 8) > 0);
}
@Override
public int getMetaFromState(IBlockState state) {
int i = damageDropped(state);
if (!state.getValue(DECAYABLE)) {
i |= 4;
}
if (state.getValue(CHECK_DECAY)) {
i |= 8;
}
return i;
}
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, getVariant(), CHECK_DECAY, DECAYABLE);
}
public TreeDefinition getTreeType(int meta) {
int variantCount = getVariant().getAllowedValues().size();
int variantMeta = (meta % variantCount) + blockNumber * VARIANTS_PER_BLOCK;
return TreeDefinition.byMetadata(variantMeta);
}
@Override
protected NonNullList<ItemStack> getLeafDrop(World world, @Nullable GameProfile playerProfile, BlockPos pos, float saplingModifier, int fortune) {
NonNullList<ItemStack> prod = NonNullList.create();
ITree tree = getTree(world, pos);
if (tree == null) {
return prod;
}
// Add saplings
List<ITree> saplings = tree.getSaplings(world, playerProfile, pos, saplingModifier);
for (ITree sapling : saplings) {
if (sapling != null) {
prod.add(TreeManager.treeRoot.getMemberStack(sapling, EnumGermlingType.SAPLING));
}
}
// Add fruits
ITreeGenome genome = tree.getGenome();
IFruitProvider fruitProvider = genome.getFruitProvider();
if (fruitProvider.isFruitLeaf(genome, world, pos)) {
NonNullList<ItemStack> produceStacks = tree.produceStacks(world, pos, Integer.MAX_VALUE);
prod.addAll(produceStacks);
}
return prod;
}
@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
TreeDefinition type = getTreeType(meta);
return getDefaultState().withProperty(getVariant(), type);
}
@Override
@SideOnly(Side.CLIENT)
public void registerModel(Item item, IModelManager manager) {
for (IBlockState state : blockState.getValidStates()) {
int meta = getMetaFromState(state);
ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation("forestry:leaves.default." + blockNumber, "inventory"));
}
}
@Override
protected ITree getTree(IBlockAccess world, BlockPos pos) {
IBlockState blockState = world.getBlockState(pos);
TreeDefinition treeDefinition = getTreeDefinition(blockState);
if (treeDefinition != null) {
return treeDefinition.getIndividual();
} else {
return null;
}
}
@Override
@SideOnly(Side.CLIENT)
public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex) {
TreeDefinition treeDefinition = getTreeDefinition(state);
if (treeDefinition == null) {
treeDefinition = TreeDefinition.Oak;
}
ITreeGenome genome = treeDefinition.getGenome();
if (tintIndex == 0) {
return genome.getPrimary().getLeafSpriteProvider().getColor(false);
} else {
IFruitProvider fruitProvider = genome.getFruitProvider();
return fruitProvider.getDecorativeColor();
}
}
}
@@ -11,36 +11,24 @@
package forestry.arboriculture.blocks;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import com.mojang.authlib.GameProfile;
import forestry.api.arboriculture.EnumGermlingType;
import forestry.api.arboriculture.IToolGrafter;
import forestry.api.arboriculture.ITree;
import forestry.api.arboriculture.TreeManager;
import forestry.api.core.IItemModelRegister;
import forestry.api.core.IModelManager;
import forestry.api.core.IToolScoop;
import forestry.api.core.Tabs;
import forestry.api.lepidopterology.ButterflyManager;
import forestry.api.lepidopterology.EnumFlutterType;
import forestry.api.lepidopterology.IButterfly;
import forestry.arboriculture.LeafDecayHelper;
import forestry.arboriculture.PluginArboriculture;
import forestry.arboriculture.genetics.TreeDefinition;
import forestry.arboriculture.tiles.TileLeaves;
import forestry.core.blocks.IColoredBlock;
import forestry.core.blocks.properties.UnlistedBlockAccess;
import forestry.core.blocks.properties.UnlistedBlockPos;
import forestry.core.proxy.Proxies;
import forestry.core.tiles.TileUtil;
import forestry.core.utils.BlockUtil;
import forestry.core.utils.ItemStackUtil;
import net.minecraft.block.BlockLeaves;
import net.minecraft.block.BlockPlanks;
import net.minecraft.block.IGrowable;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.properties.IProperty;
@@ -48,21 +36,14 @@ import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Enchantments;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
@@ -72,22 +53,45 @@ import net.minecraftforge.common.property.IUnlistedProperty;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockForestryLeaves extends BlockLeaves implements ITileEntityProvider, IGrowable, IItemModelRegister, IColoredBlock {
public class BlockForestryLeaves extends BlockAbstractLeaves implements ITileEntityProvider, IGrowable {
public BlockForestryLeaves() {
setCreativeTab(Tabs.tabArboriculture);
setDefaultState(this.blockState.getBaseState().withProperty(CHECK_DECAY, false).withProperty(DECAYABLE, true));
}
@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
return ((IExtendedBlockState) super.getExtendedState(state, world, pos)).withProperty(UnlistedBlockPos.POS, pos)
.withProperty(UnlistedBlockAccess.BLOCKACCESS, world);
setDefaultState(this.blockState.getBaseState()
.withProperty(CHECK_DECAY, false)
.withProperty(DECAYABLE, true));
}
@Override
protected BlockStateContainer createBlockState() {
return new ExtendedBlockState(this, new IProperty[]{DECAYABLE, CHECK_DECAY}, new IUnlistedProperty[]{UnlistedBlockPos.POS, UnlistedBlockAccess.BLOCKACCESS});
return new ExtendedBlockState(this,
new IProperty[]{DECAYABLE, CHECK_DECAY},
new IUnlistedProperty[]{UnlistedBlockPos.POS, UnlistedBlockAccess.BLOCKACCESS}
);
}
@Override
protected ITree getTree(IBlockAccess world, BlockPos pos) {
TileLeaves leaves = TileUtil.getTile(world, pos, TileLeaves.class);
if (leaves != null) {
ITree tree = leaves.getTree();
if (tree != null) {
return tree;
}
}
return null;
}
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
super.updateTick(world, pos, state, rand);
TileLeaves tileLeaves = TileUtil.getTile(world, pos, TileLeaves.class);
// check leaves tile because they might have decayed
if (tileLeaves != null && !tileLeaves.isInvalid() && rand.nextFloat() <= 0.1) {
tileLeaves.onBlockTick(world, pos, state, rand);
}
}
@Override
@@ -109,6 +113,12 @@ public class BlockForestryLeaves extends BlockLeaves implements ITileEntityProvi
return this.getDefaultState().withProperty(DECAYABLE, (meta & 4) == 0).withProperty(CHECK_DECAY, (meta & 8) > 0);
}
@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
return ((IExtendedBlockState) super.getExtendedState(state, world, pos)).withProperty(UnlistedBlockPos.POS, pos)
.withProperty(UnlistedBlockAccess.BLOCKACCESS, world);
}
/* TILE ENTITY */
@Override
public TileEntity createNewTileEntity(World world, int meta) {
@@ -116,54 +126,8 @@ public class BlockForestryLeaves extends BlockLeaves implements ITileEntityProvi
}
@Override
public void getSubBlocks(Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list) {
}
/* DROP HANDLING */
// Hack: When harvesting leaves we need to get the drops in onBlockHarvested,
// because Mojang destroys the block and tile before calling getDrops.
private final ThreadLocal<List<ItemStack>> drops = new ThreadLocal<>();
@Override
public void onBlockHarvested(World world, BlockPos pos, IBlockState state, EntityPlayer player) {
TileLeaves leafTile = TileUtil.getTile(world, pos, TileLeaves.class);
if (leafTile == null) {
return;
}
int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, player.getActiveItemStack());
float saplingModifier = 1.0f;
ItemStack held = player.inventory.getCurrentItem();
if (held.getItem() instanceof IToolGrafter) {
saplingModifier = ((IToolGrafter) held.getItem()).getSaplingModifier(held, world, player, pos);
held.damageItem(1, player);
if (held.isEmpty()) {
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, held, EnumHand.MAIN_HAND);
}
}
GameProfile playerProfile = player.getGameProfile();
List<ItemStack> leafDrops = getLeafDrop(world, playerProfile, pos, saplingModifier, fortune);
drops.set(leafDrops);
}
@Override
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
List<ItemStack> ret = drops.get();
drops.remove();
// leaves not harvested, get drops normally
if (ret == null) {
ret = getLeafDrop(world, null, pos, 1.0f, fortune);
}
return ret;
}
private static List<ItemStack> getLeafDrop(IBlockAccess world, @Nullable GameProfile playerProfile, BlockPos pos, float saplingModifier, int fortune) {
List<ItemStack> prod = new ArrayList<>();
protected NonNullList<ItemStack> getLeafDrop(World world, @Nullable GameProfile playerProfile, BlockPos pos, float saplingModifier, int fortune) {
NonNullList<ItemStack> prod = NonNullList.create();
TileLeaves tile = TileUtil.getTile(world, pos, TileLeaves.class);
if (tile == null) {
@@ -176,7 +140,7 @@ public class BlockForestryLeaves extends BlockLeaves implements ITileEntityProvi
}
// Add saplings
List<ITree> saplings = tree.getSaplings((World) world, playerProfile, pos, saplingModifier);
List<ITree> saplings = tree.getSaplings(world, playerProfile, pos, saplingModifier);
for (ITree sapling : saplings) {
if (sapling != null) {
@@ -186,100 +150,12 @@ public class BlockForestryLeaves extends BlockLeaves implements ITileEntityProvi
// Add fruits
if (tile.hasFruit()) {
prod.addAll(tree.produceStacks((World) world, pos, tile.getRipeningTime()));
prod.addAll(tree.produceStacks(world, pos, tile.getRipeningTime()));
}
return prod;
}
@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
TileLeaves leaves = TileUtil.getTile(world, pos, TileLeaves.class);
if (leaves == null) {
return ItemStack.EMPTY;
}
ITree tree = leaves.getTree();
if (tree == null) {
return ItemStack.EMPTY;
}
return tree.getGenome().getDecorativeLeaves();
}
@Override
public List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) {
ITree tree = null;
TileLeaves leaves = TileUtil.getTile(world, pos, TileLeaves.class);
if (leaves != null) {
tree = leaves.getTree();
}
if(tree == null){
tree = TreeDefinition.Oak.getIndividual();
}
ItemStack decorativeLeaves = tree.getGenome().getDecorativeLeaves();
if (decorativeLeaves.isEmpty()) {
return Collections.emptyList();
} else {
return Collections.singletonList(decorativeLeaves);
}
}
@Nullable
@Override
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos) {
TileLeaves tileLeaves = TileUtil.getTile(worldIn, pos, TileLeaves.class);
if (tileLeaves != null && TreeDefinition.Willow.getUID().equals(tileLeaves.getSpeciesUID())) {
return null;
}
return super.getCollisionBoundingBox(blockState, worldIn, pos);
}
@Override
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
super.onEntityCollidedWithBlock(worldIn, pos, state, entityIn);
entityIn.motionX *= 0.4D;
entityIn.motionZ *= 0.4D;
}
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
LeafDecayHelper.leafDecay(this, world, pos);
TileLeaves tileLeaves = TileUtil.getTile(world, pos, TileLeaves.class);
// check leaves tile because they might have decayed
if (tileLeaves != null && !tileLeaves.isInvalid() && rand.nextFloat() <= 0.1) {
tileLeaves.onBlockTick(world, pos, state, rand);
}
}
/* RENDERING */
@Override
public boolean isOpaqueCube(IBlockState state) {
return !Proxies.render.fancyGraphicsEnabled();
}
@SideOnly(Side.CLIENT)
@Override
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
return (Proxies.render.fancyGraphicsEnabled() || blockAccess.getBlockState(pos.offset(side)).getBlock() != this) && BlockUtil.shouldSideBeRendered(blockState, blockAccess, pos, side);
}
@Override
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer() {
return BlockRenderLayer.CUTOUT_MIPPED; // fruit overlays require CUTOUT_MIPPED, even in Fast graphics
}
@Override
public BlockPlanks.EnumType getWoodType(int meta) {
return BlockPlanks.EnumType.OAK;
}
/* MODELS */
@Override
@SideOnly(Side.CLIENT)
@@ -287,28 +163,6 @@ public class BlockForestryLeaves extends BlockLeaves implements ITileEntityProvi
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation("forestry:leaves", "inventory"));
}
/* PROPERTIES */
@Override
public int getFlammability(IBlockAccess world, BlockPos pos, EnumFacing face) {
return 60;
}
@Override
public boolean isFlammable(IBlockAccess world, BlockPos pos, EnumFacing face) {
return true;
}
@Override
public int getFireSpreadSpeed(IBlockAccess world, BlockPos pos, EnumFacing face) {
if (face == EnumFacing.DOWN) {
return 20;
} else if (face != EnumFacing.UP) {
return 10;
} else {
return 5;
}
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
TileLeaves leaves = TileUtil.getTile(worldIn, pos, TileLeaves.class);
@@ -15,9 +15,12 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.common.base.Preconditions;
import forestry.api.arboriculture.EnumForestryWoodType;
import forestry.api.arboriculture.EnumVanillaWoodType;
import forestry.api.arboriculture.IAlleleFruit;
import forestry.api.genetics.AlleleRegisterEvent;
import forestry.arboriculture.genetics.TreeDefinition;
import forestry.arboriculture.genetics.alleles.AlleleFruits;
import forestry.arboriculture.items.ItemBlockDecorativeLeaves;
@@ -29,8 +32,10 @@ import forestry.core.blocks.BlockRegistry;
import forestry.core.items.ItemBlockForestry;
import forestry.core.utils.OreDictUtil;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLeaves;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
public class BlockRegistryArboriculture extends BlockRegistry {
public final List<BlockArbLog> logs;
@@ -58,6 +63,8 @@ public class BlockRegistryArboriculture extends BlockRegistry {
public final BlockSapling saplingGE;
public final BlockForestryLeaves leaves;
public final List<BlockDefaultLeaves> leavesDefault;
public final Map<String, IBlockState> speciesToLeavesDefault;
public final List<BlockDecorativeLeaves> leavesDecorative;
private final Map<String, ItemStack> speciesToLeavesDecorative;
public final Map<String, BlockFruitPod> podsMap;
@@ -234,6 +241,21 @@ public class BlockRegistryArboriculture extends BlockRegistry {
registerBlock(leaves, new ItemBlockLeaves(leaves), "leaves");
registerOreDictWildcard(OreDictUtil.TREE_LEAVES, leaves);
leavesDefault = BlockDefaultLeaves.create();
speciesToLeavesDefault = new HashMap<>();
for (BlockDefaultLeaves leaves : leavesDefault) {
registerBlock(leaves, new ItemBlockLeaves(leaves), "leaves.default." + leaves.getBlockNumber());
registerOreDictWildcard(OreDictUtil.TREE_LEAVES, leaves);
PropertyTreeType treeType = leaves.getVariant();
for (TreeDefinition treeDefinition : treeType.getAllowedValues()) {
Preconditions.checkNotNull(treeDefinition);
String speciesUid = treeDefinition.getUID();
IBlockState blockState = leaves.getDefaultState().withProperty(treeType, treeDefinition);
speciesToLeavesDefault.put(speciesUid, blockState);
}
}
leavesDecorative = BlockDecorativeLeaves.create();
speciesToLeavesDecorative = new HashMap<>();
for (BlockDecorativeLeaves leaves : leavesDecorative) {
@@ -259,6 +281,7 @@ public class BlockRegistryArboriculture extends BlockRegistry {
// Pods
AlleleFruits.registerAlleles();
MinecraftForge.EVENT_BUS.post(new AlleleRegisterEvent(IAlleleFruit.class));
podsMap = new HashMap<>();
for (BlockFruitPod pod : BlockFruitPod.create()) {
IAlleleFruit fruit = pod.getFruit();
@@ -279,6 +302,10 @@ public class BlockRegistryArboriculture extends BlockRegistry {
return itemStack.copy();
}
public IBlockState getDefaultLeaves(String speciesUid) {
return speciesToLeavesDefault.get(speciesUid);
}
@Nullable
public BlockFruitPod getFruitPod(IAlleleFruit fruit) {
return podsMap.get(fruit.getUID());
@@ -32,5 +32,7 @@ public class PropertyTreeType extends PropertyEnum<TreeDefinition> {
super(name, valueClass, allowedValues);
}
public TreeDefinition getFirstType() {
return getAllowedValues().iterator().next();
}
}
@@ -23,9 +23,4 @@ public abstract class PropertyWoodType<T extends Enum<T> & IWoodType> extends Pr
public T getFirstType() {
return getAllowedValues().iterator().next();
}
@Override
public Collection<T> getAllowedValues() {
return super.getAllowedValues();
}
}
@@ -72,7 +72,7 @@ public final class CommandTreeSpawn extends SubCommand {
for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) {
if (allele instanceof IAlleleTreeSpecies) {
species.add(allele.getName().replaceAll("\\s", ""));
species.add(allele.getAlleleName().replaceAll("\\s", ""));
}
}
@@ -87,7 +87,7 @@ public final class TreeGenHelper {
if (species == null) {
for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) {
if (allele instanceof IAlleleTreeSpecies && allele.getName().replaceAll("\\s", "").equals(speciesName)) {
if (allele instanceof IAlleleTreeSpecies && allele.getAlleleName().replaceAll("\\s", "").equals(speciesName)) {
species = (IAlleleTreeSpecies) allele;
break;
}
@@ -250,15 +250,15 @@ public class Tree extends Individual implements ITree, IPlantable {
IAlleleTreeSpecies primary = genome.getPrimary();
IAlleleTreeSpecies secondary = genome.getSecondary();
if (!isPureBred(EnumTreeChromosome.SPECIES)) {
list.add(TextFormatting.BLUE + Translator.translateToLocal("for.trees.hybrid").replaceAll("%PRIMARY", primary.getName()).replaceAll("%SECONDARY", secondary.getName()));
list.add(TextFormatting.BLUE + Translator.translateToLocal("for.trees.hybrid").replaceAll("%PRIMARY", primary.getAlleleName()).replaceAll("%SECONDARY", secondary.getAlleleName()));
}
String sappiness = TextFormatting.GOLD + "S: " + genome.getActiveAllele(EnumTreeChromosome.SAPPINESS).getName();
String maturation = TextFormatting.RED + "M: " + genome.getActiveAllele(EnumTreeChromosome.MATURATION).getName();
String height = TextFormatting.LIGHT_PURPLE + "H: " + genome.getActiveAllele(EnumTreeChromosome.HEIGHT).getName();
String sappiness = TextFormatting.GOLD + "S: " + genome.getActiveAllele(EnumTreeChromosome.SAPPINESS).getAlleleName();
String maturation = TextFormatting.RED + "M: " + genome.getActiveAllele(EnumTreeChromosome.MATURATION).getAlleleName();
String height = TextFormatting.LIGHT_PURPLE + "H: " + genome.getActiveAllele(EnumTreeChromosome.HEIGHT).getAlleleName();
String girth = TextFormatting.AQUA + "G: " + String.format("%sx%s", genome.getGirth(), genome.getGirth());
String saplings = TextFormatting.YELLOW + "S: " + genome.getActiveAllele(EnumTreeChromosome.FERTILITY).getName();
String yield = TextFormatting.WHITE + "Y: " + genome.getActiveAllele(EnumTreeChromosome.YIELD).getName();
String saplings = TextFormatting.YELLOW + "S: " + genome.getActiveAllele(EnumTreeChromosome.FERTILITY).getAlleleName();
String yield = TextFormatting.WHITE + "Y: " + genome.getActiveAllele(EnumTreeChromosome.YIELD).getAlleleName();
String carbonization = TextFormatting.GRAY + "CA: " + secondary.getWoodProvider().getCarbonization();
list.add(String.format("%s, %s", saplings, maturation));
list.add(String.format("%s, %s", height, girth));
@@ -996,30 +996,31 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe
@Override
public boolean setLeaves(ITreeGenome genome, World world, @Nullable GameProfile owner, BlockPos pos) {
boolean placed = world.setBlockState(pos, PluginArboriculture.getBlocks().leaves.getDefaultState());
if (!placed) {
return false;
}
if (owner == null && genome.matchesTemplateGenome()) {
String speciesUid = genome.getPrimary().getUID();
IBlockState defaultLeaves = PluginArboriculture.getBlocks().getDefaultLeaves(speciesUid);
return world.setBlockState(pos, defaultLeaves);
} else {
IBlockState leaves = PluginArboriculture.getBlocks().leaves.getDefaultState();
boolean placed = world.setBlockState(pos, leaves);
if (!placed) {
return false;
}
Block block = world.getBlockState(pos).getBlock();
if (PluginArboriculture.getBlocks().leaves != block) {
world.setBlockToAir(pos);
return false;
}
TileLeaves tileLeaves = TileUtil.getTile(world, pos, TileLeaves.class);
if (tileLeaves == null) {
world.setBlockToAir(pos);
return false;
}
TileLeaves tileLeaves = TileUtil.getTile(world, pos, TileLeaves.class);
if (tileLeaves == null) {
world.setBlockToAir(pos);
return false;
}
if (owner != null) {
tileLeaves.getOwnerHandler().setOwner(owner);
}
tileLeaves.setTree(new Tree(genome));
if (owner != null) {
tileLeaves.getOwnerHandler().setOwner(owner);
world.markBlockRangeForRenderUpdate(pos, pos);
return true;
}
tileLeaves.setTree(new Tree(genome));
world.markBlockRangeForRenderUpdate(pos, pos);
return true;
}
public static void initTrees() {
@@ -1071,7 +1072,7 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe
}
public static void preInit() {
MinecraftForge.EVENT_BUS.post(new AlleleSpeciesRegisterEvent(TreeManager.treeRoot));
MinecraftForge.EVENT_BUS.post(new AlleleSpeciesRegisterEvent(TreeManager.treeRoot, IAlleleTreeSpecies.class));
}
@Override
@@ -10,6 +10,8 @@
******************************************************************************/
package forestry.arboriculture.genetics;
import javax.annotation.Nullable;
import com.google.common.base.Preconditions;
import forestry.api.arboriculture.EnumTreeChromosome;
import forestry.api.arboriculture.IAlleleFruit;
@@ -18,6 +20,7 @@ import forestry.api.arboriculture.IAlleleTreeSpecies;
import forestry.api.arboriculture.IFruitProvider;
import forestry.api.arboriculture.ITreeGenome;
import forestry.api.arboriculture.TreeManager;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IAlleleFloat;
import forestry.api.genetics.IAlleleInteger;
import forestry.api.genetics.IAlleleSpecies;
@@ -28,6 +31,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class TreeGenome extends Genome implements ITreeGenome {
@Nullable
private Boolean matchesTemplateCached;
public TreeGenome(IChromosome[] chromosomes) {
super(chromosomes);
@@ -109,4 +114,31 @@ public class TreeGenome extends Genome implements ITreeGenome {
public ISpeciesRoot getSpeciesRoot() {
return TreeManager.treeRoot;
}
@Override
public boolean matchesTemplateGenome() {
if (matchesTemplateCached == null) {
matchesTemplateCached = calculateMatchesTemplateGenome();
}
return matchesTemplateCached;
}
private boolean calculateMatchesTemplateGenome() {
IAlleleTreeSpecies primary = getPrimary();
IAllele[] template = getSpeciesRoot().getTemplate(primary);
IChromosome[] chromosomes = getChromosomes();
for (int i = 0; i < chromosomes.length; i++) {
IChromosome chromosome = chromosomes[i];
String templateUid = template[i].getUID();
IAllele primaryAllele = chromosome.getPrimaryAllele();
if (!primaryAllele.getUID().equals(templateUid)) {
return false;
}
IAllele secondaryAllele = chromosome.getSecondaryAllele();
if (!secondaryAllele.getUID().equals(templateUid)) {
return false;
}
}
return true;
}
}
@@ -39,6 +39,11 @@ public class AlleleFruit extends AlleleCategorized implements IAlleleFruit {
return getProvider().getDescription();
}
@Override
public String getAlleleName() {
return getProvider().getDescription();
}
@Nullable
@Override
public String getModelName() {
@@ -11,6 +11,7 @@
package forestry.arboriculture.items;
import forestry.arboriculture.PluginArboriculture;
import forestry.arboriculture.blocks.BlockAbstractLeaves;
import forestry.arboriculture.blocks.BlockForestryLeaves;
import forestry.arboriculture.tiles.TileLeaves;
import forestry.core.items.IColoredItem;
@@ -27,7 +28,7 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemBlockLeaves extends ItemBlockForestry<BlockForestryLeaves> implements IColoredItem {
public class ItemBlockLeaves extends ItemBlockForestry<BlockAbstractLeaves> implements IColoredItem {
public ItemBlockLeaves(Block block) {
super(block);
@@ -83,7 +83,7 @@ public class ItemGermlingGE extends ItemGE implements IVariableFermentable, ICol
return Translator.translateToLocal(customTreeKey);
}
String typeString = Translator.translateToLocal("for.trees.grammar." + type.getName() + ".type");
return Translator.translateToLocal("for.trees.grammar." + type.getName()).replaceAll("%SPECIES", species.getName()).replaceAll("%TYPE", typeString);
return Translator.translateToLocal("for.trees.grammar." + type.getName()).replaceAll("%SPECIES", species.getAlleleName()).replaceAll("%TYPE", typeString);
}
@Override
@@ -0,0 +1,93 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.arboriculture.models;
import com.google.common.base.Preconditions;
import forestry.api.arboriculture.IAlleleTreeSpecies;
import forestry.api.arboriculture.ILeafSpriteProvider;
import forestry.api.arboriculture.ITreeGenome;
import forestry.api.core.IModelBaker;
import forestry.arboriculture.blocks.BlockDefaultLeaves;
import forestry.arboriculture.genetics.TreeDefinition;
import forestry.core.models.ModelBlockCached;
import forestry.core.models.baker.ModelBaker;
import forestry.core.proxy.Proxies;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ModelDefaultLeaves extends ModelBlockCached<BlockDefaultLeaves, TreeDefinition> {
public ModelDefaultLeaves() {
super(BlockDefaultLeaves.class);
}
@Override
protected TreeDefinition getInventoryKey(ItemStack stack) {
Block block = Block.getBlockFromItem(stack.getItem());
Preconditions.checkArgument(block instanceof BlockDefaultLeaves, "ItemStack must be for default leaves.");
BlockDefaultLeaves bBlock = (BlockDefaultLeaves) block;
return bBlock.getTreeType(stack.getMetadata());
}
@Override
protected TreeDefinition getWorldKey(IBlockState state) {
Block block = state.getBlock();
Preconditions.checkArgument(block instanceof BlockDefaultLeaves, "state must be for default leaves.");
BlockDefaultLeaves bBlock = (BlockDefaultLeaves) block;
TreeDefinition treeDefinition = bBlock.getTreeDefinition(state);
Preconditions.checkNotNull(treeDefinition);
return treeDefinition;
}
@Override
protected void bakeBlock(BlockDefaultLeaves block, TreeDefinition treeDefinition, IModelBaker baker, boolean inventory) {
TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks();
ITreeGenome genome = treeDefinition.getGenome();
IAlleleTreeSpecies species = genome.getPrimary();
ILeafSpriteProvider leafSpriteProvider = species.getLeafSpriteProvider();
ResourceLocation leafSpriteLocation = leafSpriteProvider.getSprite(false, Proxies.render.fancyGraphicsEnabled());
TextureAtlasSprite leafSprite = map.getAtlasSprite(leafSpriteLocation.toString());
// Render the plain leaf block.
baker.addBlockModel(null, leafSprite, 0);
// Render overlay for fruit leaves.
ResourceLocation fruitSpriteLocation = genome.getFruitProvider().getDecorativeSprite();
if (fruitSpriteLocation != null) {
TextureAtlasSprite fruitSprite = map.getAtlasSprite(fruitSpriteLocation.toString());
baker.addBlockModel(null, fruitSprite, 1);
}
// Set the particle sprite
baker.setParticleSprite(leafSprite);
}
@Override
protected IBakedModel bakeModel(IBlockState state, TreeDefinition key, BlockDefaultLeaves block) {
IModelBaker baker = new ModelBaker();
bakeBlock(block, key, baker, false);
blockModel = baker.bakeModel(false);
onCreateModel(blockModel);
return blockModel;
}
}
@@ -24,7 +24,9 @@ import forestry.arboriculture.IWoodTyped;
import forestry.arboriculture.PluginArboriculture;
import forestry.arboriculture.blocks.BlockArbSlab;
import forestry.arboriculture.blocks.BlockDecorativeLeaves;
import forestry.arboriculture.blocks.BlockDefaultLeaves;
import forestry.arboriculture.models.ModelDecorativeLeaves;
import forestry.arboriculture.models.ModelDefaultLeaves;
import forestry.arboriculture.models.ModelLeaves;
import forestry.arboriculture.models.MultipartModel;
import forestry.arboriculture.models.WoodModelLoader;
@@ -75,6 +77,15 @@ public class ProxyArboricultureClient extends ProxyArboriculture {
ModelManager.getInstance().registerCustomBlockModel(blockModelIndex);
}
for (BlockDefaultLeaves leaves : PluginArboriculture.getBlocks().leavesDefault) {
String resourceName = "forestry:leaves.default." + leaves.getBlockNumber();
ModelResourceLocation blockModelLocation = new ModelResourceLocation(resourceName);
ModelResourceLocation itemModeLocation = new ModelResourceLocation(resourceName, "inventory");
BlockModelEntry blockModelIndex = new BlockModelEntry(blockModelLocation, itemModeLocation,
new ModelDefaultLeaves(), leaves);
ModelManager.getInstance().registerCustomBlockModel(blockModelIndex);
}
ModelLoaderRegistry.registerLoader(WoodModelLoader.INSTANCE);
for (BlockArbSlab slab : PluginArboriculture.getBlocks().slabsDouble) {
registerWoodModel(slab, true);
@@ -21,13 +21,14 @@ public class FruitPodStateMapper extends ForestryStateMapper {
BlockFruitPod blockFruitPod = (BlockFruitPod) block;
IAlleleFruit fruit = blockFruitPod.getFruit();
String modID = fruit.getModID();
if (Constants.MOD_ID.equals(modID)) {
String modelName = fruit.getModelName();
String resourcePath = Constants.MOD_ID + ":pods/" + modelName;
for (IBlockState state : block.getBlockState().getValidStates()) {
String propertyString = getPropertyString(state.getProperties());
mapStateModelLocations.put(state, new ModelResourceLocation(resourcePath, propertyString));
}
if(modID == null){
modID = Constants.MOD_ID;
}
String modelName = fruit.getModelName();
String resourcePath = modID + ":pods/" + modelName;
for (IBlockState state : block.getBlockState().getValidStates()) {
String propertyString = getPropertyString(state.getProperties());
mapStateModelLocations.put(state, new ModelResourceLocation(resourcePath, propertyString));
}
}
return mapStateModelLocations;
@@ -38,6 +38,7 @@ import forestry.api.lepidopterology.ButterflyManager;
import forestry.api.lepidopterology.IButterfly;
import forestry.api.lepidopterology.IButterflyGenome;
import forestry.api.lepidopterology.IButterflyNursery;
import forestry.arboriculture.PluginArboriculture;
import forestry.arboriculture.genetics.TreeDefinition;
import forestry.arboriculture.genetics.alleles.AlleleFruits;
import forestry.arboriculture.network.IRipeningPacketReceiver;
@@ -47,6 +48,7 @@ import forestry.core.network.packets.PacketTileStream;
import forestry.core.utils.ClimateUtil;
import forestry.core.utils.ColourUtil;
import forestry.core.utils.GeneticsUtil;
import forestry.core.utils.Log;
import forestry.core.utils.NetworkUtil;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
@@ -82,6 +84,13 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
private IEffectData effectData[] = new IEffectData[2];
/**
* Worldgen trees used to create TileLeaves, but now they use BlockDefaultLeaves instead.
* We add a check to convert the TileLeaves into the new format.
* This boolean keeps track of whether this leaf has checked if it should replace itself.
*/
private boolean checkedForConversionToDefaultLeaves;
/* SAVING & LOADING */
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
@@ -127,9 +136,19 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
}
ITreeGenome genome = tree.getGenome();
IAlleleTreeSpecies primary = genome.getPrimary();
if (!checkedForConversionToDefaultLeaves) {
if (shouldConvertToDefaultLeaves()) {
IBlockState defaultLeaves = PluginArboriculture.getBlocks().getDefaultLeaves(primary.getUID());
worldIn.setBlockState(getPos(), defaultLeaves);
return;
}
checkedForConversionToDefaultLeaves = true;
}
boolean isDestroyed = isDestroyed(tree, damage);
for (ILeafTickHandler tickHandler : genome.getPrimary().getRoot().getLeafTickHandlers()) {
for (ILeafTickHandler tickHandler : primary.getRoot().getLeafTickHandlers()) {
if (tickHandler.onRandomLeafTick(tree, world, rand, getPos(), isDestroyed)) {
return;
}
@@ -161,6 +180,19 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
effectData = tree.doEffect(effectData, world, getPos());
}
/**
* Worldgen trees with default genomes should be converted to leaves without tile entities.
*/
private boolean shouldConvertToDefaultLeaves() {
if (getOwnerHandler().getOwner() == null) { // null owner likely means it's a worldgen tree
ITree tree = getTree();
if (tree != null && tree.getGenome().matchesTemplateGenome()) {
return true;
}
}
return false;
}
@Override
public void setTree(ITree tree) {
super.setTree(tree);
@@ -519,4 +551,10 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
public EnumHumidity getHumidity() {
return EnumHumidity.getFromValue(ClimateUtil.getHumidity(world, pos));
}
@Override
public World getWorldObj() {
return world;
}
}
@@ -10,6 +10,7 @@
******************************************************************************/
package forestry.core;
import java.net.URL;
import java.util.Collection;
import forestry.api.genetics.AlleleManager;
@@ -18,7 +19,6 @@ import forestry.api.genetics.IBreedingTracker;
import forestry.api.genetics.ISpeciesRoot;
import forestry.core.config.Constants;
import forestry.core.errors.ErrorStateRegistry;
import forestry.core.loot.LootTableLoader;
import forestry.core.models.ModelBlockCached;
import forestry.core.render.TextureManagerForestry;
import forestry.plugins.PluginManager;
@@ -107,12 +107,15 @@ public class EventHandlerCore {
}
ResourceLocation resourceLocation = new ResourceLocation(Constants.MOD_ID, event.getName().getResourcePath());
LootTable forestryChestAdditions = LootTableLoader.loadBuiltinLootTable(resourceLocation);
if (forestryChestAdditions != null) {
for (String poolName : PluginManager.getLootPoolNames()) {
LootPool pool = forestryChestAdditions.getPool(poolName);
if (pool != null) {
event.getTable().addPool(pool);
URL url = EventHandlerCore.class.getResource("/assets/" + resourceLocation.getResourceDomain() + "/loot_tables/" + resourceLocation.getResourcePath() + ".json");
if (url != null) {
LootTable forestryChestAdditions = event.getLootTableManager().getLootTableFromLocation(resourceLocation);
if (forestryChestAdditions != LootTable.EMPTY_LOOT_TABLE) {
for (String poolName : PluginManager.getLootPoolNames()) {
LootPool pool = forestryChestAdditions.getPool(poolName);
if (pool != null) {
event.getTable().addPool(pool);
}
}
}
}
+6 -4
View File
@@ -297,6 +297,9 @@ public class PluginCore extends BlankForestryPlugin {
// / CAMOUFLAGE SPRAY CAN
RecipeUtil.addRecipe(items.camouflageSprayCan, "TTT", "TCT", "TCT", 'T', OreDictUtil.INGOT_TIN, 'C', items.craftingMaterial.getCamouflagedPaneling());
// / WEB
RecipeUtil.addRecipe(new ItemStack(Blocks.WEB, 4), "# #", " # ", "# #", '#', items.craftingMaterial.getSilkWisp());
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FACTORY)) {
// / CARPENTER
@@ -308,10 +311,9 @@ public class PluginCore extends BlankForestryPlugin {
'R', OreDictUtil.DUST_REDSTONE,
'D', OreDictUtil.GEM_DIAMOND);
// Camouflaged Paneling
RecipeManagers.carpenterManager.addRecipe(50, Fluids.BIOMASS.getFluid(500), ItemStack.EMPTY, items.craftingMaterial.getCamouflagedPaneling(4),
"YAR", "B#B", "RPY",
RecipeManagers.carpenterManager.addRecipe(50, Fluids.BIOMASS.getFluid(500), ItemStack.EMPTY, items.craftingMaterial.getCamouflagedPaneling(8),
"Y#R", "BPB", "R#Y",
'#', OreDictUtil.PLANK_WOOD,
'A', OreDictUtil.DUST_ASH,
'R', OreDictUtil.DUST_REDSTONE,
'P', OreDictUtil.PULP_WOOD,
'R', OreDictUtil.DYE_RED,
@@ -328,7 +330,7 @@ public class PluginCore extends BlankForestryPlugin {
'R', OreDictUtil.DUST_REDSTONE,
'D', OreDictUtil.GEM_DIAMOND);
// Camouflaged Paneling
RecipeUtil.addRecipe(items.craftingMaterial.getCamouflagedPaneling(4),
RecipeUtil.addRecipe(items.craftingMaterial.getCamouflagedPaneling(8),
"WWW",
"YBR",
"WWW",
@@ -7,6 +7,7 @@ import java.util.Random;
import forestry.api.core.IItemModelRegister;
import forestry.api.core.IModelManager;
import forestry.core.CreativeTabForestry;
import forestry.core.config.Config;
import forestry.core.config.Constants;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLog;
@@ -32,7 +33,7 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockHumus extends Block implements IItemModelRegister {
private static final int degradeDelimiter = 3;
private static final int degradeDelimiter = Config.humusDegradeDelimiter;
public static final PropertyInteger DEGRADE = PropertyInteger.create("degrade", 0, degradeDelimiter); // degradation level of humus
public BlockHumus() {
@@ -29,6 +29,8 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class ClimateRegion implements IClimateRegion, IStreamable {
public static final float CLIMATE_CHANGE = 0.01F;
protected final World world;
protected final IGreenhouseControllerInternal controller;
protected final Set<IClimatePosition> positions;
@@ -99,26 +101,7 @@ public class ClimateRegion implements IClimateRegion, IStreamable {
if (world.isBlockLoaded(pos)) {
hasChange |= updateSides(position);
if (!controller.isAssembled()) {
IClimateInfo climateInfo = getControl(pos);
if (position.getTemperature() != climateInfo.getTemperature()) {
if (position.getTemperature() > climateInfo.getTemperature()) {
position.addTemperature(-Math.min(0.01F, position.getTemperature() - climateInfo.getTemperature()));
hasChange = true;
} else {
position.addTemperature(Math.min(0.01F, climateInfo.getTemperature() - position.getTemperature()));
hasChange = true;
}
}
if (position.getHumidity() != climateInfo.getHumidity()) {
if (position.getHumidity() > climateInfo.getHumidity()) {
position.addHumidity(-Math.min(0.01F, position.getHumidity() - climateInfo.getHumidity()));
hasChange = true;
} else {
position.addHumidity(Math.min(0.01F, climateInfo.getHumidity() - position.getHumidity()));
hasChange = true;
}
}
hasChange |= returnClimateToDefault(position);
}
}
}
@@ -128,24 +111,28 @@ public class ClimateRegion implements IClimateRegion, IStreamable {
}
}
protected boolean updateSides(IClimatePosition positon) {
BlockPos pos = positon.getPos();
protected boolean updateSides(IClimatePosition position) {
BlockPos pos = position.getPos();
IClimateInfo climateInfo = getControl(pos);
boolean hasChange = false;
if (climateInfo.getTemperature() != temperature || climateInfo.getHumidity() != humidity) {
for (EnumFacing facing : EnumFacing.VALUES) {
IClimatePosition climatedInfoFace = getPosition(pos.offset(facing));
if (climatedInfoFace != null) {
if (positon.getTemperature() > climatedInfoFace.getTemperature() + 0.01F) {
float change = Math.min(0.01F, positon.getTemperature() - climatedInfoFace.getTemperature());
positon.addTemperature(-change);
climatedInfoFace.addTemperature(change);
IClimatePosition infoFace = getPosition(pos.offset(facing));
if (infoFace != null) {
float infoTemp = infoFace.getTemperature();
float infoHumid = infoFace.getHumidity();
float posTemp = position.getTemperature();
float posHumid = position.getHumidity();
if (posTemp > infoTemp + CLIMATE_CHANGE) {
float change = Math.min(CLIMATE_CHANGE, posTemp - infoTemp);
position.addTemperature(-change);
infoFace.addTemperature(change);
hasChange = true;
}
if (positon.getHumidity() > climatedInfoFace.getHumidity() + 0.01F) {
float change = Math.min(0.01F, positon.getHumidity() - climatedInfoFace.getHumidity());
positon.addHumidity(-change);
climatedInfoFace.addHumidity(change);
if (posHumid > infoHumid + CLIMATE_CHANGE) {
float change = Math.min(CLIMATE_CHANGE, posHumid - infoHumid);
position.addHumidity(-change);
infoFace.addHumidity(change);
hasChange = true;
}
}
@@ -153,6 +140,36 @@ public class ClimateRegion implements IClimateRegion, IStreamable {
}
return hasChange;
}
protected boolean returnClimateToDefault(IClimatePosition position){
BlockPos pos = position.getPos();
IClimateInfo climateInfo = getControl(pos);
boolean hasChange = false;
float infoTemp = climateInfo.getTemperature();
float infoHumid = climateInfo.getHumidity();
float posTemp = position.getTemperature();
float posHumid = position.getHumidity();
if (posTemp != infoTemp) {
if (posTemp > infoTemp) {
position.addTemperature(-Math.min(CLIMATE_CHANGE, posTemp - infoTemp));
hasChange = true;
} else {
position.addTemperature(Math.min(CLIMATE_CHANGE, infoTemp - posTemp));
hasChange = true;
}
}
if (posHumid != infoHumid) {
if (posHumid > infoHumid) {
position.addHumidity(-Math.min(CLIMATE_CHANGE, posHumid - infoHumid));
hasChange = true;
} else {
position.addHumidity(Math.min(CLIMATE_CHANGE, infoHumid - posHumid));
hasChange = true;
}
}
return hasChange;
}
protected IClimateInfo getControl(BlockPos pos) {
if (world.isBlockLoaded(pos)) {
@@ -177,7 +177,7 @@ public final class CommandSaveStats extends SubCommand {
notCounted = notCountedSymbol;
}
return speciesListEntry(discovered, blacklisted, notCounted, species.getUID(), species.getName(), species.getAuthority());
return speciesListEntry(discovered, blacklisted, notCounted, species.getUID(), species.getAlleleName(), species.getAuthority());
}
private static String speciesListEntry(String discovered, String blacklisted, String notCounted, String UID, String speciesName, String authority) {
@@ -18,7 +18,7 @@ public class TemplateNotFoundException extends CommandException {
private static final long serialVersionUID = 1L;
public TemplateNotFoundException(IAlleleSpecies species) {
super("Could not find template for species %s with UID %s", species.getName(), species.getUID());
super("Could not find template for species %s with UID %s", species.getAlleleName(), species.getUID());
}
}
@@ -54,6 +54,9 @@ public class Config {
// Graphics
public static boolean enableParticleFX = true;
//Humus
public static int humusDegradeDelimiter = 3;
// Genetics
public static boolean pollinateVanillaTrees = true;
public static float researchMutationBoostMultiplier = 1.5f;
@@ -213,6 +216,8 @@ public class Config {
enableBackpackResupply = configCommon.getBooleanLocalized("performance", "backpacks.resupply", enableBackpackResupply);
humusDegradeDelimiter = configCommon.getIntLocalized("tweaks.humus", "degradeDelimiter", humusDegradeDelimiter, 1, 10);
//planterThrottle = configCommon.getIntLocalized("performance", "performance.planter", planterThrottle, 1, 2000);
//propThrottle.Comment = "higher numbers increase working speeds of planters but also increase cpu load.";
@@ -54,7 +54,7 @@ public abstract class Individual implements IIndividual {
@Override
public String getDisplayName() {
return getGenome().getPrimary().getName();
return getGenome().getPrimary().getAlleleName();
}
/* INFORMATION */
@@ -92,11 +92,11 @@ public class ItemResearchNote extends ItemForestry {
return tooltips;
}
String species1 = encoded.getAllele0().getName();
String species2 = encoded.getAllele1().getName();
String species1 = encoded.getAllele0().getAlleleName();
String species2 = encoded.getAllele1().getAlleleName();
String mutationChanceKey = EnumMutateChance.rateChance(encoded.getBaseChance()).toString().toLowerCase(Locale.ENGLISH);
String mutationChance = Translator.translateToLocal("for.researchNote.chance." + mutationChanceKey);
String speciesResult = encoded.getTemplate()[root.getSpeciesChromosomeType().ordinal()].getName();
String speciesResult = encoded.getTemplate()[root.getSpeciesChromosomeType().ordinal()].getAlleleName();
tooltips.add(Translator.translateToLocal("for.researchNote.discovery.0"));
tooltips.add(Translator.translateToLocal("for.researchNote.discovery.1").replace("%SPEC1", species1).replace("%SPEC2", species2));
@@ -119,7 +119,7 @@ public class ItemResearchNote extends ItemForestry {
}
tooltips.add("researchNote.discovered.0");
tooltips.add(Translator.translateToLocalFormatted("for.researchNote.discovered.1", allele0.getName(), allele0.getBinomial()));
tooltips.add(Translator.translateToLocalFormatted("for.researchNote.discovered.1", allele0.getAlleleName(), allele0.getBinomial()));
}
return tooltips;
@@ -159,9 +159,9 @@ public class ItemResearchNote extends ItemForestry {
player.sendMessage(new TextComponentTranslation("for.chat.memorizednote"));
player.sendMessage(new TextComponentTranslation("for.chat.memorizednote2",
TextFormatting.GRAY + species0.getName(),
TextFormatting.GRAY + species1.getName(),
TextFormatting.GREEN + speciesResult.getName()));
TextFormatting.GRAY + species0.getAlleleName(),
TextFormatting.GRAY + species1.getAlleleName(),
TextFormatting.GREEN + speciesResult.getAlleleName()));
return true;
}
@@ -40,6 +40,11 @@ public abstract class Allele implements IAllele {
return Translator.translateToLocal(getUnlocalizedName());
}
@Override
public String getAlleleName() {
return Translator.translateToLocal(getUnlocalizedName());
}
@Override
public String getUnlocalizedName() {
return unlocalizedName;
@@ -94,7 +94,7 @@ public class GuiAlyzer extends GuiForestry<ContainerAlyzer> {
public final void drawChromosomeRow(String chromosomeName, IIndividual individual, IChromosomeType chromosome) {
IAllele active = individual.getGenome().getActiveAllele(chromosome);
IAllele inactive = individual.getGenome().getInactiveAllele(chromosome);
textLayout.drawRow(chromosomeName, active.getName(), inactive.getName(),
textLayout.drawRow(chromosomeName, active.getAlleleName(), inactive.getAlleleName(),
ColourProperties.INSTANCE.get("gui.screen"), getColorCoding(active.isDominant()),
getColorCoding(inactive.isDominant()));
}
@@ -111,8 +111,8 @@ public class GuiAlyzer extends GuiForestry<ContainerAlyzer> {
GuiUtil.drawItemStack(this, iconStacks.get(primary.getUID()), guiLeft + textLayout.column1 + columnwidth - 20, guiTop + 10);
GuiUtil.drawItemStack(this, iconStacks.get(secondary.getUID()), guiLeft + textLayout.column2 + columnwidth - 20, guiTop + 10);
String primaryName = customPrimaryName == null ? primary.getName() : customPrimaryName;
String secondaryName = customSecondaryName == null ? secondary.getName() : customSecondaryName;
String primaryName = customPrimaryName == null ? primary.getAlleleName() : customPrimaryName;
String secondaryName = customSecondaryName == null ? secondary.getAlleleName() : customSecondaryName;
drawSplitLine(primaryName, textLayout.column1, columnwidth, individual, chromosome, false);
drawSplitLine(secondaryName, textLayout.column2, columnwidth, individual, chromosome, true);
@@ -400,7 +400,7 @@ public class GuiAlyzer extends GuiForestry<ContainerAlyzer> {
public void drawToleranceInfo(IAlleleTolerance toleranceAllele, int x) {
int textColor = getColorCoding(toleranceAllele.isDominant());
EnumTolerance tolerance = toleranceAllele.getValue();
String text = "(" + toleranceAllele.getName() + ")";
String text = "(" + toleranceAllele.getAlleleName() + ")";
// Enable correct lighting.
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
@@ -32,7 +32,9 @@ import forestry.core.tiles.TileAnalyzer;
import forestry.core.tiles.TileEscritoire;
import forestry.core.tiles.TileNaturalistChest;
import forestry.energy.tiles.TileEngineBiogas;
import forestry.energy.tiles.TileEngineElectric;
import forestry.energy.tiles.TileEnginePeat;
import forestry.energy.tiles.TileEuGenerator;
import forestry.factory.tiles.TileBottler;
import forestry.factory.tiles.TileCarpenter;
import forestry.factory.tiles.TileCentrifuge;
@@ -86,9 +88,9 @@ public class GuiIdRegistry {
TileGreenhouse.class,
TileEngineBiogas.class,
// TileEngineElectric.class,
TileEngineElectric.class,
TileEnginePeat.class,
// TileEuGenerator.class,
TileEuGenerator.class,
TileMailbox.class,
TileStampCollector.class,
@@ -159,7 +159,7 @@ public class GuiNaturalistInventory extends GuiForestry<Container> {
return;
}
textLayout.drawLine(species.getName(), x);
textLayout.drawLine(species.getAlleleName(), x);
GuiUtil.drawItemStack(this, iconStack, guiLeft + x + 69, guiTop + textLayout.getLineY() - 2);
textLayout.newLine();
@@ -1,57 +0,0 @@
package forestry.core.loot;
import javax.annotation.Nullable;
import java.io.IOException;
import java.net.URL;
import com.google.common.base.Charsets;
import com.google.common.io.Resources;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import forestry.core.utils.Log;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.storage.loot.LootContext;
import net.minecraft.world.storage.loot.LootEntry;
import net.minecraft.world.storage.loot.LootPool;
import net.minecraft.world.storage.loot.LootTable;
import net.minecraft.world.storage.loot.LootTableManager;
import net.minecraft.world.storage.loot.RandomValueRange;
import net.minecraft.world.storage.loot.conditions.LootCondition;
import net.minecraft.world.storage.loot.conditions.LootConditionManager;
import net.minecraft.world.storage.loot.functions.LootFunction;
import net.minecraft.world.storage.loot.functions.LootFunctionManager;
/**
* Copy of {@link LootTableManager} that can load Forestry's loot table additions.
* This is a workaround so I can load loot table jsons that have pools to be added to vanilla's chests.
* During {@link net.minecraftforge.event.LootTableLoadEvent} the world's lootTable is not set yet.
*/
public class LootTableLoader {
private static final Gson GSON_INSTANCE = (new GsonBuilder()).registerTypeAdapter(RandomValueRange.class, new RandomValueRange.Serializer()).registerTypeAdapter(LootPool.class, new LootPool.Serializer()).registerTypeAdapter(LootTable.class, new LootTable.Serializer()).registerTypeHierarchyAdapter(LootEntry.class, new LootEntry.Serializer()).registerTypeHierarchyAdapter(LootFunction.class, new LootFunctionManager.Serializer()).registerTypeHierarchyAdapter(LootCondition.class, new LootConditionManager.Serializer()).registerTypeHierarchyAdapter(LootContext.EntityTarget.class, new LootContext.EntityTarget.Serializer()).create();
@Nullable
public static LootTable loadBuiltinLootTable(ResourceLocation resource) {
URL url = LootTableLoader.class.getResource("/assets/" + resource.getResourceDomain() + "/loot_tables/" + resource.getResourcePath() + ".json");
if (url != null) {
String s;
try {
s = Resources.toString(url, Charsets.UTF_8);
} catch (IOException ioexception) {
Log.warning("Couldn\'t load loot table " + resource + " from " + url, ioexception);
return LootTable.EMPTY_LOOT_TABLE;
}
try {
return net.minecraftforge.common.ForgeHooks.loadLootTable(GSON_INSTANCE, resource, s, false);
} catch (JsonParseException jsonparseexception) {
Log.error("Couldn\'t load loot table " + resource + " from " + url, jsonparseexception);
return LootTable.EMPTY_LOOT_TABLE;
}
} else {
return null;
}
}
}
@@ -58,7 +58,7 @@ public class TextureManagerForestry implements ITextureManager {
"analyzer/item", "analyzer/nocturnal", "analyzer/princess", "analyzer/pure_breed", "analyzer/pure_cave",
"analyzer/pure_flyer", "analyzer/pure_nocturnal", "analyzer/queen",
"errors/errored", "errors/unknown",
"slots/blocked", "slots/blocked_2", "slots/liquid", "slots/container", "slots/locked",
"slots/blocked", "slots/blocked_2", "slots/liquid", "slots/container", "slots/locked", "slots/cocoon",
"mail/carrier.player", "mail/carrier.trader"};
for (String identifier : defaultIconNames) {
ResourceLocation resourceLocation = getForestryGuiLocation(identifier);
@@ -12,15 +12,19 @@ package forestry.core.utils;
import java.util.ArrayList;
import java.util.Locale;
import java.util.Set;
import forestry.api.climate.IClimateInfo;
import forestry.api.climate.IClimatePosition;
import forestry.api.core.EnumHumidity;
import forestry.api.core.EnumTemperature;
import forestry.api.core.ForestryAPI;
import forestry.api.core.IErrorState;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.EnumTolerance;
import forestry.api.genetics.IClimateHelper;
import forestry.core.climate.ClimateRegion;
import forestry.core.errors.EnumErrorCode;
import forestry.core.network.PacketBufferForestry;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@@ -224,6 +228,27 @@ public class ClimateUtil implements IClimateHelper {
return Translator.translateToLocal("for.gui." + humidity.toString().toLowerCase(Locale.ENGLISH));
}
public static void addClimateErrorStates(EnumTemperature temperature, EnumHumidity humidity,
EnumTemperature baseTemp, EnumTolerance tolTemp,
EnumHumidity baseHumid, EnumTolerance tolHumid, Set<IErrorState> errorStates){
if (!AlleleManager.climateHelper.isWithinLimits(temperature, baseTemp, tolTemp)) {
if (baseTemp.ordinal() > temperature.ordinal()) {
errorStates.add(EnumErrorCode.TOO_COLD);
} else {
errorStates.add(EnumErrorCode.TOO_HOT);
}
}
if (!AlleleManager.climateHelper.isWithinLimits(humidity, baseHumid, tolHumid)) {
if (baseHumid.ordinal() > humidity.ordinal()) {
errorStates.add(EnumErrorCode.TOO_ARID);
} else {
errorStates.add(EnumErrorCode.TOO_HUMID);
}
}
}
public static float getTemperature(World world, BlockPos pos){
return ForestryAPI.climateManager.getInfo(world, pos).getTemperature();
}
@@ -152,6 +152,10 @@ public class GeneticsUtil {
IBlockState blockState = world.getBlockState(pos);
Block block = blockState.getBlock();
if(TreeManager.treeRoot == null){
return null;
}
IIndividualTranslator<IIndividual, IBlockState> leafTranslator = TreeManager.treeRoot.getTranslator(block);
if (leafTranslator == null) {
return null;
@@ -166,6 +170,10 @@ public class GeneticsUtil {
if (item instanceof ItemGE) {
return ((ItemGE) item).getIndividual(itemStack);
}
if(TreeManager.treeRoot == null){
return null;
}
IIndividualTranslator<IIndividual, ItemStack> saplingTranslator = TreeManager.treeRoot.getTranslator(item);
if (saplingTranslator == null) {
@@ -74,6 +74,32 @@ public abstract class ItemStackUtil {
return null;
}
}
/**
* @return The registry name of the block as {@link ResourceLocation}
*/
@Nullable
public static String getBlockNameFromRegistryAsString(Block block) {
IForgeRegistry<Block> itemRegistry = ForgeRegistries.BLOCKS;
if (itemRegistry.containsValue(block)) {
return itemRegistry.getKey(block).toString();
} else {
return null;
}
}
/**
* @return The registry name of the block as {@link ResourceLocation}
*/
@Nullable
public static ResourceLocation getBlockNameFromRegistry(Block block) {
IForgeRegistry<Block> itemRegistry = ForgeRegistries.BLOCKS;
if (itemRegistry.containsValue(block)) {
return itemRegistry.getKey(block);
} else {
return null;
}
}
/**
* @return The registry name of the item as {@link String}
@@ -6,7 +6,6 @@ import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import forestry.greenhouse.tiles.TileGreenhouseNursery;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
@@ -20,14 +20,16 @@ import forestry.core.tiles.TileEngine;
import forestry.energy.PluginEnergy;
import forestry.energy.tiles.TileEngineBiogas;
import forestry.energy.tiles.TileEngineClockwork;
import forestry.energy.tiles.TileEngineElectric;
import forestry.energy.tiles.TileEnginePeat;
import forestry.energy.tiles.TileEuGenerator;
public enum BlockTypeEngine implements IBlockTypeTesr {
PEAT(createEngineProperties(TileEnginePeat.class, "peat", "/engine_copper")),
BIOGAS(createEngineProperties(TileEngineBiogas.class, "biogas", "/engine_bronze")),
CLOCKWORK(createEngineProperties(TileEngineClockwork.class, "clockwork", "/engine_clock"));
// ELECTRICAL(createEngineProperties(TileEngineElectric.class, "electrical", "/engine_tin")),
// GENERATOR(createMachineProperties(TileEuGenerator.class, "generator", "/generator"));
CLOCKWORK(createEngineProperties(TileEngineClockwork.class, "clockwork", "/engine_clock")),
ELECTRICAL(createEngineProperties(TileEngineElectric.class, "electrical", "/engine_tin")),
GENERATOR(createMachineProperties(TileEuGenerator.class, "generator", "/generator"));
public static final BlockTypeEngine[] VALUES = values();
@@ -1,20 +1,20 @@
///*******************************************************************************
// * Copyright (c) 2011-2014 SirSengir.
// * All rights reserved. This program and the accompanying materials
// * are made available under the terms of the GNU Lesser Public License v3
// * which accompanies this distribution, and is available at
// * http://www.gnu.org/licenses/lgpl-3.0.txt
// *
// * Various Contributors including, but not limited to:
// * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
// ******************************************************************************/
//package forestry.energy.circuits;
//
//public class CircuitElectricBoost extends CircuitElectricChange {
//
// public CircuitElectricBoost(String uid, int eu, int rf) {
// super(uid);
// this.configureChange(eu, rf);
// }
//
//}
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http:www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.energy.circuits;
public class CircuitElectricBoost extends CircuitElectricChange {
public CircuitElectricBoost(String uid, int eu, int rf) {
super(uid);
this.configureChange(eu, rf);
}
}
@@ -1,63 +1,63 @@
///*******************************************************************************
// * Copyright (c) 2011-2014 SirSengir.
// * All rights reserved. This program and the accompanying materials
// * are made available under the terms of the GNU Lesser Public License v3
// * which accompanies this distribution, and is available at
// * http://www.gnu.org/licenses/lgpl-3.0.txt
// *
// * Various Contributors including, but not limited to:
// * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
// ******************************************************************************/
//package forestry.energy.circuits;
//
//import forestry.core.circuits.Circuit;
//import forestry.energy.tiles.TileEngineElectric;
//
//public abstract class CircuitElectricChange extends Circuit {
//
// private int euChange = 7;
// private int rfChange = 20;
//
// protected CircuitElectricChange(String uid) {
// super(uid);
// }
//
// protected void configureChange(int euChange, int rfChange) {
// this.euChange = euChange;
// this.rfChange = rfChange;
// }
//
// @Override
// public boolean isCircuitable(Object tile) {
// return tile instanceof TileEngineElectric;
// }
//
// @Override
// public void onInsertion(int slot, Object tile) {
// if (!isCircuitable(tile)) {
// return;
// }
//
// TileEngineElectric engine = (TileEngineElectric) tile;
// engine.changeEnergyConfig(euChange, rfChange, 2 * euChange);
// }
//
// @Override
// public void onLoad(int slot, Object tile) {
// onInsertion(slot, tile);
// }
//
// @Override
// public void onRemoval(int slot, Object tile) {
// if (!isCircuitable(tile)) {
// return;
// }
//
// TileEngineElectric engine = (TileEngineElectric) tile;
// engine.changeEnergyConfig(-euChange, -rfChange, -(2 * euChange));
// }
//
// @Override
// public void onTick(int slot, Object tile) {
// }
//}
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http:www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.energy.circuits;
import forestry.core.circuits.Circuit;
import forestry.energy.tiles.TileEngineElectric;
public abstract class CircuitElectricChange extends Circuit {
private int euChange = 7;
private int rfChange = 20;
protected CircuitElectricChange(String uid) {
super(uid);
}
protected void configureChange(int euChange, int rfChange) {
this.euChange = euChange;
this.rfChange = rfChange;
}
@Override
public boolean isCircuitable(Object tile) {
return tile instanceof TileEngineElectric;
}
@Override
public void onInsertion(int slot, Object tile) {
if (!isCircuitable(tile)) {
return;
}
TileEngineElectric engine = (TileEngineElectric) tile;
engine.changeEnergyConfig(euChange, rfChange, 2 * euChange);
}
@Override
public void onLoad(int slot, Object tile) {
onInsertion(slot, tile);
}
@Override
public void onRemoval(int slot, Object tile) {
if (!isCircuitable(tile)) {
return;
}
TileEngineElectric engine = (TileEngineElectric) tile;
engine.changeEnergyConfig(-euChange, -rfChange, -(2 * euChange));
}
@Override
public void onTick(int slot, Object tile) {
}
}
@@ -1,19 +1,19 @@
///*******************************************************************************
// * Copyright (c) 2011-2014 SirSengir.
// * All rights reserved. This program and the accompanying materials
// * are made available under the terms of the GNU Lesser Public License v3
// * which accompanies this distribution, and is available at
// * http://www.gnu.org/licenses/lgpl-3.0.txt
// *
// * Various Contributors including, but not limited to:
// * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
// ******************************************************************************/
//package forestry.energy.circuits;
//
//public class CircuitElectricChoke extends CircuitElectricChange {
//
// public CircuitElectricChoke(String uid) {
// super(uid);
// this.configureChange(-2, -10);
// }
//}
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http:www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.energy.circuits;
public class CircuitElectricChoke extends CircuitElectricChange {
public CircuitElectricChoke(String uid) {
super(uid);
this.configureChange(-2, -10);
}
}
@@ -1,20 +1,20 @@
///*******************************************************************************
// * Copyright (c) 2011-2014 SirSengir.
// * All rights reserved. This program and the accompanying materials
// * are made available under the terms of the GNU Lesser Public License v3
// * which accompanies this distribution, and is available at
// * http://www.gnu.org/licenses/lgpl-3.0.txt
// *
// * Various Contributors including, but not limited to:
// * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
// ******************************************************************************/
//package forestry.energy.circuits;
//
//public class CircuitElectricEfficiency extends CircuitElectricChange {
//
// public CircuitElectricEfficiency(String uid) {
// super(uid);
// this.configureChange(-1, 0);
// }
//
//}
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http:www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.energy.circuits;
public class CircuitElectricEfficiency extends CircuitElectricChange {
public CircuitElectricEfficiency(String uid) {
super(uid);
this.configureChange(-1, 0);
}
}
@@ -1,36 +1,36 @@
///*******************************************************************************
// * Copyright (c) 2011-2014 SirSengir.
// * All rights reserved. This program and the accompanying materials
// * are made available under the terms of the GNU Lesser Public License v3
// * which accompanies this distribution, and is available at
// * http://www.gnu.org/licenses/lgpl-3.0.txt
// *
// * Various Contributors including, but not limited to:
// * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
// ******************************************************************************/
//package forestry.energy.gui;
//
//import net.minecraft.entity.player.InventoryPlayer;
//
//import forestry.core.gui.ContainerSocketed;
//import forestry.core.gui.slots.SlotFiltered;
//import forestry.core.network.packets.PacketGuiUpdate;
//import forestry.energy.inventory.InventoryEngineElectric;
//import forestry.energy.tiles.TileEngineElectric;
//
//public class ContainerEngineElectric extends ContainerSocketed<TileEngineElectric> {
//
// public ContainerEngineElectric(InventoryPlayer player, TileEngineElectric tile) {
// super(tile, player, 8, 84);
//
// this.addSlotToContainer(new SlotFiltered(tile, InventoryEngineElectric.SLOT_BATTERY, 84, 53));
// }
//
// @Override
// public void detectAndSendChanges() {
// super.detectAndSendChanges();
// PacketGuiUpdate packet = new PacketGuiUpdate(tile);
// sendPacketToListeners(packet);
// }
//
//}
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http:www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.energy.gui;
import net.minecraft.entity.player.InventoryPlayer;
import forestry.core.gui.ContainerSocketed;
import forestry.core.gui.slots.SlotFiltered;
import forestry.core.network.packets.PacketGuiUpdate;
import forestry.energy.inventory.InventoryEngineElectric;
import forestry.energy.tiles.TileEngineElectric;
public class ContainerEngineElectric extends ContainerSocketed<TileEngineElectric> {
public ContainerEngineElectric(InventoryPlayer player, TileEngineElectric tile) {
super(tile, player, 8, 84);
this.addSlotToContainer(new SlotFiltered(tile, InventoryEngineElectric.SLOT_BATTERY, 84, 53));
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
PacketGuiUpdate packet = new PacketGuiUpdate(tile);
sendPacketToListeners(packet);
}
}
@@ -1,34 +1,34 @@
///*******************************************************************************
// * Copyright (c) 2011-2014 SirSengir.
// * All rights reserved. This program and the accompanying materials
// * are made available under the terms of the GNU Lesser Public License v3
// * which accompanies this distribution, and is available at
// * http://www.gnu.org/licenses/lgpl-3.0.txt
// *
// * Various Contributors including, but not limited to:
// * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
// ******************************************************************************/
//package forestry.energy.gui;
//
//import net.minecraft.entity.player.InventoryPlayer;
//import forestry.core.gui.ContainerLiquidTanks;
//import forestry.core.gui.slots.SlotLiquidIn;
//import forestry.core.network.packets.PacketGuiUpdate;
//import forestry.energy.inventory.InventoryGenerator;
//import forestry.energy.tiles.TileEuGenerator;
//
//public class ContainerGenerator extends ContainerLiquidTanks<TileEuGenerator> {
//
// public ContainerGenerator(InventoryPlayer player, TileEuGenerator tile) {
// super(tile, player, 8, 84);
//
// this.addSlotToContainer(new SlotLiquidIn(tile, InventoryGenerator.SLOT_CAN, 22, 38));
// }
//
// @Override
// public void detectAndSendChanges() {
// super.detectAndSendChanges();
// PacketGuiUpdate packet = new PacketGuiUpdate(tile);
// sendPacketToListeners(packet);
// }
//}
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http:www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.energy.gui;
import net.minecraft.entity.player.InventoryPlayer;
import forestry.core.gui.ContainerLiquidTanks;
import forestry.core.gui.slots.SlotLiquidIn;
import forestry.core.network.packets.PacketGuiUpdate;
import forestry.energy.inventory.InventoryGenerator;
import forestry.energy.tiles.TileEuGenerator;
public class ContainerGenerator extends ContainerLiquidTanks<TileEuGenerator> {
public ContainerGenerator(InventoryPlayer player, TileEuGenerator tile) {
super(tile, player, 8, 84);
this.addSlotToContainer(new SlotLiquidIn(tile, InventoryGenerator.SLOT_CAN, 22, 38));
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
PacketGuiUpdate packet = new PacketGuiUpdate(tile);
sendPacketToListeners(packet);
}
}
@@ -1,46 +1,46 @@
///*******************************************************************************
// * Copyright (c) 2011-2014 SirSengir.
// * All rights reserved. This program and the accompanying materials
// * are made available under the terms of the GNU Lesser Public License v3
// * which accompanies this distribution, and is available at
// * http://www.gnu.org/licenses/lgpl-3.0.txt
// *
// * Various Contributors including, but not limited to:
// * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
// ******************************************************************************/
//package forestry.energy.gui;
//
//import net.minecraft.entity.player.InventoryPlayer;
//
//import forestry.core.config.Constants;
//import forestry.core.gui.widgets.SocketWidget;
//import forestry.core.render.EnumTankLevel;
//import forestry.energy.tiles.TileEngineElectric;
//
//public class GuiEngineElectric extends GuiEngine<ContainerEngineElectric, TileEngineElectric> {
//
// public GuiEngineElectric(InventoryPlayer inventory, TileEngineElectric tile) {
// super(Constants.TEXTURE_PATH_GUI + "/electricalengine.png", new ContainerEngineElectric(inventory, tile), tile);
// widgetManager.add(new SocketWidget(this.widgetManager, 30, 40, tile, 0));
// }
//
// @Override
// protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) {
// super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
//
// TileEngineElectric engine = inventory;
// int storageHeight = engine.getStorageScaled(46);
// int storageMaxHeight = engine.getStorageScaled(100);
// EnumTankLevel rated = EnumTankLevel.rateTankLevel(storageMaxHeight);
//
// drawHealthMeter(guiLeft + 74, guiTop + 25, storageHeight, rated);
// }
//
// private void drawHealthMeter(int x, int y, int height, EnumTankLevel rated) {
// int i = 176 + rated.getLevelScaled(16);
// int k = 0;
//
// this.drawTexturedModalRect(x, y + 46 - height, i, k + 46 - height, 4, height);
// }
//
//}
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http:www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.energy.gui;
import net.minecraft.entity.player.InventoryPlayer;
import forestry.core.config.Constants;
import forestry.core.gui.widgets.SocketWidget;
import forestry.core.render.EnumTankLevel;
import forestry.energy.tiles.TileEngineElectric;
public class GuiEngineElectric extends GuiEngine<ContainerEngineElectric, TileEngineElectric> {
public GuiEngineElectric(InventoryPlayer inventory, TileEngineElectric tile) {
super(Constants.TEXTURE_PATH_GUI + "/electricalengine.png", new ContainerEngineElectric(inventory, tile), tile);
widgetManager.add(new SocketWidget(this.widgetManager, 30, 40, tile, 0));
}
@Override
protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) {
super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
TileEngineElectric engine = tile;
int storageHeight = engine.getStorageScaled(46);
int storageMaxHeight = engine.getStorageScaled(100);
EnumTankLevel rated = EnumTankLevel.rateTankLevel(storageMaxHeight);
drawHealthMeter(guiLeft + 74, guiTop + 25, storageHeight, rated);
}
private void drawHealthMeter(int x, int y, int height, EnumTankLevel rated) {
int i = 176 + rated.getLevelScaled(16);
int k = 0;
this.drawTexturedModalRect(x, y + 46 - height, i, k + 46 - height, 4, height);
}
}
@@ -1,37 +1,45 @@
///*******************************************************************************
// * Copyright (c) 2011-2014 SirSengir.
// * All rights reserved. This program and the accompanying materials
// * are made available under the terms of the GNU Lesser Public License v3
// * which accompanies this distribution, and is available at
// * http://www.gnu.org/licenses/lgpl-3.0.txt
// *
// * Various Contributors including, but not limited to:
// * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
// ******************************************************************************/
//package forestry.energy.gui;
//
//import net.minecraft.entity.player.InventoryPlayer;
//
//import forestry.core.config.Constants;
//import forestry.core.gui.GuiForestryTitled;
//import forestry.core.gui.widgets.TankWidget;
//import forestry.energy.tiles.TileEuGenerator;
//
//public class GuiGenerator extends GuiForestryTitled<ContainerGenerator, TileEuGenerator> {
//
// public GuiGenerator(InventoryPlayer inventory, TileEuGenerator tile) {
// super(Constants.TEXTURE_PATH_GUI + "/generator.png", new ContainerGenerator(inventory, tile), tile);
// widgetManager.add(new TankWidget(this.widgetManager, 49, 17, 0));
// }
//
// @Override
// protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) {
// super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
//
// int progress = inventory.getStoredScaled(49);
// if (progress > 0) {
// drawTexturedModalRect(guiLeft + 108, guiTop + 38, 176, 91, progress, 18);
// }
// }
//
//}
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http:www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.energy.gui;
import net.minecraft.entity.player.InventoryPlayer;
import forestry.core.config.Constants;
import forestry.core.gui.GuiForestryTitled;
import forestry.core.gui.widgets.TankWidget;
import forestry.energy.tiles.TileEuGenerator;
public class GuiGenerator extends GuiForestryTitled<ContainerGenerator> {
private final TileEuGenerator tile;
public GuiGenerator(InventoryPlayer inventory, TileEuGenerator tile) {
super(Constants.TEXTURE_PATH_GUI + "/generator.png", new ContainerGenerator(inventory, tile), tile);
widgetManager.add(new TankWidget(this.widgetManager, 49, 17, 0));
this.tile = tile;
}
@Override
protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) {
super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
int progress = tile.getStoredScaled(49);
if (progress > 0) {
drawTexturedModalRect(guiLeft + 108, guiTop + 38, 176, 91, progress, 18);
}
}
@Override
protected void addLedgers() {
}
}
@@ -1,34 +1,34 @@
///*******************************************************************************
// * Copyright (c) 2011-2014 SirSengir.
// * All rights reserved. This program and the accompanying materials
// * are made available under the terms of the GNU Lesser Public License v3
// * which accompanies this distribution, and is available at
// * http://www.gnu.org/licenses/lgpl-3.0.txt
// *
// * Various Contributors including, but not limited to:
// * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
// ******************************************************************************/
//package forestry.energy.inventory;
//
//import net.minecraft.item.ItemStack;
//
//import forestry.core.inventory.InventoryAdapterTile;
//import forestry.energy.tiles.TileEngineElectric;
//
//import ic2.api.item.ElectricItem;
//
//public class InventoryEngineElectric extends InventoryAdapterTile<TileEngineElectric> {
// public static final short SLOT_BATTERY = 0;
//
// public InventoryEngineElectric(TileEngineElectric engineTin) {
// super(engineTin, 1, "electrical");
// }
//
// @Override
// public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
// if (slotIndex == SLOT_BATTERY) {
// return ElectricItem.manager.getCharge(itemStack) > 0;
// }
// return false;
// }
//}
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http:www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.energy.inventory;
import net.minecraft.item.ItemStack;
import forestry.core.inventory.InventoryAdapterTile;
import forestry.energy.tiles.TileEngineElectric;
import ic2.api.item.ElectricItem;
public class InventoryEngineElectric extends InventoryAdapterTile<TileEngineElectric> {
public static final short SLOT_BATTERY = 0;
public InventoryEngineElectric(TileEngineElectric engineTin) {
super(engineTin, 1, "electrical");
}
@Override
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
if (slotIndex == SLOT_BATTERY) {
return ElectricItem.manager.getCharge(itemStack) > 0;
}
return false;
}
}
@@ -1,37 +1,37 @@
///*******************************************************************************
// * Copyright (c) 2011-2014 SirSengir.
// * All rights reserved. This program and the accompanying materials
// * are made available under the terms of the GNU Lesser Public License v3
// * which accompanies this distribution, and is available at
// * http://www.gnu.org/licenses/lgpl-3.0.txt
// *
// * Various Contributors including, but not limited to:
// * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
// ******************************************************************************/
//package forestry.energy.inventory;
//
//import net.minecraft.item.ItemStack;
//
//import net.minecraftforge.fluids.FluidStack;
//import net.minecraftforge.fluids.FluidUtil;
//
//import forestry.core.inventory.InventoryAdapterTile;
//import forestry.energy.tiles.TileEuGenerator;
//
//public class InventoryGenerator extends InventoryAdapterTile<TileEuGenerator> {
// public static final short SLOT_CAN = 0;
//
// public InventoryGenerator(TileEuGenerator generator) {
// super(generator, 1, "Items");
// }
//
// @Override
// public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
// if (slotIndex == SLOT_CAN) {
// FluidStack fluid = FluidUtil.getFluidContained(itemStack);
// return tile.getTankManager().canFillFluidType(fluid);
// }
//
// return false;
// }
//}
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http:www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.energy.inventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import forestry.core.inventory.InventoryAdapterTile;
import forestry.energy.tiles.TileEuGenerator;
public class InventoryGenerator extends InventoryAdapterTile<TileEuGenerator> {
public static final short SLOT_CAN = 0;
public InventoryGenerator(TileEuGenerator generator) {
super(generator, 1, "Items");
}
@Override
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
if (slotIndex == SLOT_CAN) {
FluidStack fluid = FluidUtil.getFluidContained(itemStack);
return tile.getTankManager().canFillFluidType(fluid);
}
return false;
}
}
@@ -1,310 +1,316 @@
///*******************************************************************************
// * Copyright (c) 2011-2014 SirSengir.
// * All rights reserved. This program and the accompanying materials
// * are made available under the terms of the GNU Lesser Public License v3
// * which accompanies this distribution, and is available at
// * http://www.gnu.org/licenses/lgpl-3.0.txt
// *
// * Various Contributors including, but not limited to:
// * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
// ******************************************************************************/
//package forestry.energy.tiles;
//
//import java.io.IOException;
//
//import forestry.api.circuits.ChipsetManager;
//import forestry.api.circuits.CircuitSocketType;
//import forestry.api.circuits.ICircuitBoard;
//import forestry.api.circuits.ICircuitSocketType;
//import forestry.api.core.IErrorLogic;
//import forestry.core.circuits.ISocketable;
//import forestry.core.config.Constants;
//import forestry.core.errors.EnumErrorCode;
//import forestry.core.inventory.InventoryAdapter;
//import forestry.core.network.DataInputStreamForestry;
//import forestry.core.network.DataOutputStreamForestry;
//import forestry.core.network.IStreamableGui;
//import forestry.core.tiles.TemperatureState;
//import forestry.core.tiles.TileEngine;
//import forestry.energy.gui.ContainerEngineElectric;
//import forestry.energy.gui.GuiEngineElectric;
//import forestry.energy.inventory.InventoryEngineElectric;
//import forestry.plugins.compat.PluginIC2;
//import ic2.api.energy.prefab.BasicSink;
//import net.minecraft.entity.player.EntityPlayer;
//import net.minecraft.inventory.IInventory;
//import net.minecraft.item.ItemStack;
//import net.minecraft.nbt.NBTTagCompound;
//
//public class TileEngineElectric extends TileEngine implements ISocketable, IInventory, IStreamableGui {
// protected static class EuConfig {
//
// public int euForCycle;
// public int rfPerCycle;
// public int euStorage;
//
// public EuConfig() {
// this.euForCycle = Constants.ENGINE_TIN_EU_FOR_CYCLE;
// this.rfPerCycle = Constants.ENGINE_TIN_ENERGY_PER_CYCLE;
// this.euStorage = Constants.ENGINE_TIN_MAX_EU_STORED;
// }
// }
//
// private final InventoryAdapter sockets = new InventoryAdapter(1, "sockets");
// private final EuConfig euConfig = new EuConfig();
//
// private BasicSink ic2EnergySink;
//
// public TileEngineElectric() {
// super("engine.tin", Constants.ENGINE_ELECTRIC_HEAT_MAX, 100000);
//
// setInternalInventory(new InventoryEngineElectric(this));
//
// if (PluginIC2.instance.isAvailable()) {
// ic2EnergySink = new BasicSink(this, euConfig.euStorage, 3);
// }
// }
//
// // / SAVING / LOADING
// @Override
// public void readFromNBT(NBTTagCompound nbttagcompound) {
// super.readFromNBT(nbttagcompound);
//
// if (ic2EnergySink != null) {
// ic2EnergySink.readFromNBT(nbttagcompound);
// }
// sockets.readFromNBT(nbttagcompound);
//
// ItemStack chip = sockets.getStackInSlot(0);
// if (chip != null) {
// ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitBoard(chip);
// if (chipset != null) {
// chipset.onLoad(this);
// }
// }
// }
//
// @Nonnull
// @Override
// public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
// nbttagcompound = super.writeToNBT(nbttagcompound);
//
// if (ic2EnergySink != null) {
// ic2EnergySink.writeToNBT(nbttagcompound);
// }
// sockets.writeToNBT(nbttagcompound);
// return nbttagcompound;
// }
//
// @Override
// public void onChunkUnload() {
// if (ic2EnergySink != null) {
// ic2EnergySink.onChunkUnload();
// }
//
// super.onChunkUnload();
// }
//
// @Override
// public void invalidate() {
// if (ic2EnergySink != null) {
// ic2EnergySink.invalidate();
// }
//
// super.invalidate();
// }
//
// // / HEAT MANAGEMENT
// @Override
// public int dissipateHeat() {
// if (heat <= 0) {
// return 0;
// }
//
// int loss = 0;
//
// if (!isBurning() || !isRedstoneActivated()) {
// loss += 1;
// }
//
// TemperatureState tempState = getTemperatureState();
// if (tempState == TemperatureState.OVERHEATING || tempState == TemperatureState.OPERATING_TEMPERATURE) {
// loss += 1;
// }
//
// heat -= loss;
// return loss;
// }
//
// @Override
// public int generateHeat() {
//
// int gain = 0;
// if (isRedstoneActivated() && isBurning()) {
// gain++;
// if (((double) energyManager.getEnergyStored() / (double) energyManager.getMaxEnergyStored()) > 0.5) {
// gain++;
// }
// }
//
// addHeat(gain);
// return gain;
// }
//
// // / WORK
// @Override
// public void updateServerSide() {
// IErrorLogic errorLogic = getErrorLogic();
//
// // No work to be done if IC2 is unavailable.
// if (errorLogic.setCondition(ic2EnergySink == null, EnumErrorCode.NO_ENERGY_NET)) {
// return;
// }
//
// ic2EnergySink.update();
//
// super.updateServerSide();
//
// if (forceCooldown) {
// return;
// }
//
// if (getStackInSlot(InventoryEngineElectric.SLOT_BATTERY) != null) {
// replenishFromBattery(InventoryEngineElectric.SLOT_BATTERY);
// }
//
// // Updating of gui delayed to prevent it from going crazy
// if (!updateOnInterval(80)) {
// return;
// }
//
// boolean canUseEnergy = ic2EnergySink.canUseEnergy(euConfig.euForCycle);
// errorLogic.setCondition(!canUseEnergy, EnumErrorCode.NO_FUEL);
// }
//
// @Override
// public void burn() {
//
// currentOutput = 0;
//
// if (!isRedstoneActivated()) {
// return;
// }
//
// if (ic2EnergySink.useEnergy(euConfig.euForCycle)) {
// currentOutput = euConfig.rfPerCycle;
// energyManager.generateEnergy(euConfig.rfPerCycle);
// }
//
// }
//
// private void replenishFromBattery(int slot) {
// if (!isRedstoneActivated()) {
// return;
// }
//
// ic2EnergySink.discharge(getStackInSlot(slot), euConfig.euForCycle * 3);
// }
//
// // / STATE INFORMATION
// @Override
// protected boolean isBurning() {
// return mayBurn() && ic2EnergySink != null && ic2EnergySink.canUseEnergy(euConfig.euForCycle);
// }
//
// public int getStorageScaled(int i) {
// if (ic2EnergySink == null) {
// return 0;
// }
//
// return Math.min(i, (int) (ic2EnergySink.getEnergyStored() * i) / ic2EnergySink.getCapacity());
// }
//
// // / SMP GUI
// @Override
// public void writeGuiData(PacketBufferForestry data) {
// super.writeGuiData(data);
// sockets.writeData(data);
// final boolean hasIc2EnergySink = (ic2EnergySink != null);
// data.writeBoolean(hasIc2EnergySink);
// if (hasIc2EnergySink) {
// data.writeVarInt((int) ic2EnergySink.getEnergyStored());
// }
// }
//
// @Override
// public void readGuiData(PacketBufferForestry data) throws IOException {
// super.readGuiData(data);
// sockets.readData(data);
// final boolean hasIc2EnergySink = data.readBoolean();
// if (hasIc2EnergySink) {
// final int energyStored = data.readVarInt();
// ic2EnergySink.setEnergyStored(energyStored);
// }
// }
//
// // / ENERGY CONFIG CHANGE
// public void changeEnergyConfig(int euChange, int rfChange, int storageChange) {
// euConfig.euForCycle += euChange;
// euConfig.rfPerCycle += rfChange;
// euConfig.euStorage += storageChange;
//
// if (ic2EnergySink != null) {
// ic2EnergySink.setCapacity(euConfig.euStorage);
// }
// }
//
// /* ISocketable */
// @Override
// public int getSocketCount() {
// return sockets.getSizeInventory();
// }
//
// @Override
// public ItemStack getSocket(int slot) {
// return sockets.getStackInSlot(slot);
// }
//
// @Override
// public void setSocket(int slot, ItemStack stack) {
//
// if (stack != null && !ChipsetManager.circuitRegistry.isChipset(stack)) {
// return;
// }
//
// // Dispose correctly of old chipsets
// if (sockets.getStackInSlot(slot) != null) {
// if (ChipsetManager.circuitRegistry.isChipset(sockets.getStackInSlot(slot))) {
// ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitBoard(sockets.getStackInSlot(slot));
// if (chipset != null) {
// chipset.onRemoval(this);
// }
// }
// }
//
// sockets.setInventorySlotContents(slot, stack);
// if (stack == null) {
// return;
// }
//
// ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitBoard(stack);
// if (chipset != null) {
// chipset.onInsertion(this);
// }
// }
//
// @Override
// public ICircuitSocketType getSocketType() {
// return CircuitSocketType.ELECTRIC_ENGINE;
// }
//
// @Override
// public Object getGui(EntityPlayer player, int data) {
// return new GuiEngineElectric(player.inventory, this);
// }
//
// @Override
// public Object getContainer(EntityPlayer player, int data) {
// return new ContainerEngineElectric(player.inventory, this);
// }
//}
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http:www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.energy.tiles;
import java.io.IOException;
import javax.annotation.Nonnull;
import forestry.api.circuits.ChipsetManager;
import forestry.api.circuits.CircuitSocketType;
import forestry.api.circuits.ICircuitBoard;
import forestry.api.circuits.ICircuitSocketType;
import forestry.api.core.IErrorLogic;
import forestry.core.circuits.ISocketable;
import forestry.core.config.Constants;
import forestry.core.errors.EnumErrorCode;
import forestry.core.inventory.InventoryAdapter;
import forestry.core.network.IStreamableGui;
import forestry.core.network.PacketBufferForestry;
import forestry.core.tiles.TemperatureState;
import forestry.core.tiles.TileEngine;
import forestry.energy.gui.ContainerEngineElectric;
import forestry.energy.gui.GuiEngineElectric;
import forestry.energy.inventory.InventoryEngineElectric;
import forestry.plugins.compat.PluginIC2;
import ic2.api.energy.prefab.BasicSink;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class TileEngineElectric extends TileEngine implements ISocketable, IInventory, IStreamableGui {
protected static class EuConfig {
public int euForCycle;
public int rfPerCycle;
public int euStorage;
public EuConfig() {
this.euForCycle = Constants.ENGINE_TIN_EU_FOR_CYCLE;
this.rfPerCycle = Constants.ENGINE_TIN_ENERGY_PER_CYCLE;
this.euStorage = Constants.ENGINE_TIN_MAX_EU_STORED;
}
}
private final InventoryAdapter sockets = new InventoryAdapter(1, "sockets");
private final EuConfig euConfig = new EuConfig();
private BasicSink ic2EnergySink;
public TileEngineElectric() {
super("engine.tin", Constants.ENGINE_ELECTRIC_HEAT_MAX, 100000);
setInternalInventory(new InventoryEngineElectric(this));
if (PluginIC2.instance.isAvailable()) {
ic2EnergySink = new BasicSink(this, euConfig.euStorage, 4);
}
}
// / SAVING / LOADING
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
if (ic2EnergySink != null) {
ic2EnergySink.readFromNBT(nbttagcompound);
}
sockets.readFromNBT(nbttagcompound);
ItemStack chip = sockets.getStackInSlot(0);
if (chip != null) {
ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitBoard(chip);
if (chipset != null) {
chipset.onLoad(this);
}
}
}
@Nonnull
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound = super.writeToNBT(nbttagcompound);
if (ic2EnergySink != null) {
ic2EnergySink.writeToNBT(nbttagcompound);
}
sockets.writeToNBT(nbttagcompound);
return nbttagcompound;
}
@Override
public void onChunkUnload() {
if (ic2EnergySink != null) {
ic2EnergySink.onChunkUnload();
}
super.onChunkUnload();
}
@Override
public void invalidate() {
if (ic2EnergySink != null) {
ic2EnergySink.invalidate();
}
super.invalidate();
}
// / HEAT MANAGEMENT
@Override
public int dissipateHeat() {
if (heat <= 0) {
return 0;
}
int loss = 0;
if (!isBurning() || !isRedstoneActivated()) {
loss += 1;
}
TemperatureState tempState = getTemperatureState();
if (tempState == TemperatureState.OVERHEATING || tempState == TemperatureState.OPERATING_TEMPERATURE) {
loss += 1;
}
heat -= loss;
return loss;
}
@Override
public int generateHeat() {
int gain = 0;
if (isRedstoneActivated() && isBurning()) {
gain++;
if (((double) energyManager.getEnergyStored() / (double) energyManager.getMaxEnergyStored()) > 0.5) {
gain++;
}
}
addHeat(gain);
return gain;
}
// / WORK
@Override
public void updateServerSide() {
IErrorLogic errorLogic = getErrorLogic();
//No work to be done if IC2 is unavailable.
if (errorLogic.setCondition(ic2EnergySink == null, EnumErrorCode.NO_ENERGY_NET)) {
return;
}
ic2EnergySink.update();
super.updateServerSide();
if (forceCooldown) {
return;
}
if (getStackInSlot(InventoryEngineElectric.SLOT_BATTERY) != null) {
replenishFromBattery(InventoryEngineElectric.SLOT_BATTERY);
}
//Updating of gui delayed to prevent it from going crazy
if (!updateOnInterval(80)) {
return;
}
boolean canUseEnergy = ic2EnergySink.canUseEnergy(euConfig.euForCycle);
errorLogic.setCondition(!canUseEnergy, EnumErrorCode.NO_FUEL);
}
@Override
public void burn() {
currentOutput = 0;
if (!isRedstoneActivated()) {
return;
}
if (ic2EnergySink.useEnergy(euConfig.euForCycle)) {
currentOutput = euConfig.rfPerCycle;
energyManager.generateEnergy(euConfig.rfPerCycle);
}
}
private void replenishFromBattery(int slot) {
if (!isRedstoneActivated()) {
return;
}
ic2EnergySink.discharge(getStackInSlot(slot), euConfig.euForCycle * 3);
}
// STATE INFORMATION
@Override
protected boolean isBurning() {
return mayBurn() && ic2EnergySink != null && ic2EnergySink.canUseEnergy(euConfig.euForCycle);
}
public int getStorageScaled(int i) {
if (ic2EnergySink == null) {
return 0;
}
return Math.min(i, (int) ((ic2EnergySink.getEnergyStored() * i) / ic2EnergySink.getCapacity()));
}
// SMP GUI
@Override
public void writeGuiData(PacketBufferForestry data) {
super.writeGuiData(data);
sockets.writeData(data);
final boolean hasIc2EnergySink = (ic2EnergySink != null);
data.writeBoolean(hasIc2EnergySink);
if (hasIc2EnergySink) {
data.writeVarInt((int) ic2EnergySink.getEnergyStored());
}
}
@Override
public void readGuiData(PacketBufferForestry data) throws IOException {
super.readGuiData(data);
sockets.readData(data);
final boolean hasIc2EnergySink = data.readBoolean();
if (hasIc2EnergySink) {
final int energyStored = data.readVarInt();
ic2EnergySink.setEnergyStored(energyStored);
}
}
// ENERGY CONFIG CHANGE
public void changeEnergyConfig(int euChange, int rfChange, int storageChange) {
euConfig.euForCycle += euChange;
euConfig.rfPerCycle += rfChange;
euConfig.euStorage += storageChange;
if (ic2EnergySink != null) {
ic2EnergySink.setCapacity(euConfig.euStorage);
}
}
/* ISocketable */
@Override
public int getSocketCount() {
return sockets.getSizeInventory();
}
@Override
public ItemStack getSocket(int slot) {
return sockets.getStackInSlot(slot);
}
@Override
public void setSocket(int slot, ItemStack stack) {
if (stack != null && !ChipsetManager.circuitRegistry.isChipset(stack)) {
return;
}
//Dispose correctly of old chipsets
if (sockets.getStackInSlot(slot) != null) {
if (ChipsetManager.circuitRegistry.isChipset(sockets.getStackInSlot(slot))) {
ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitBoard(sockets.getStackInSlot(slot));
if (chipset != null) {
chipset.onRemoval(this);
}
}
}
sockets.setInventorySlotContents(slot, stack);
if (stack == null) {
return;
}
ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitBoard(stack);
if (chipset != null) {
chipset.onInsertion(this);
}
}
@Override
public ICircuitSocketType getSocketType() {
return CircuitSocketType.ELECTRIC_ENGINE;
}
@SideOnly(Side.CLIENT)
@Override
public GuiContainer getGui(EntityPlayer player, int data) {
return new GuiEngineElectric(player.inventory, this);
}
@Override
public Container getContainer(EntityPlayer player, int data) {
return new ContainerEngineElectric(player.inventory, this);
}
}
@@ -1,234 +1,238 @@
///*******************************************************************************
// * Copyright (c) 2011-2014 SirSengir.
// * All rights reserved. This program and the accompanying materials
// * are made available under the terms of the GNU Lesser Public License v3
// * which accompanies this distribution, and is available at
// * http://www.gnu.org/licenses/lgpl-3.0.txt
// *
// * Various Contributors including, but not limited to:
// * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
// ******************************************************************************/
//package forestry.energy.tiles;
//
//import javax.annotation.Nullable;
//import java.io.IOException;
//
//import net.minecraft.entity.player.EntityPlayer;
//import net.minecraft.inventory.ISidedInventory;
//import net.minecraft.nbt.NBTTagCompound;
//import net.minecraft.util.EnumFacing;
//
//import net.minecraftforge.common.capabilities.Capability;
//import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
//
//import forestry.api.core.IErrorLogic;
//import forestry.api.fuels.FuelManager;
//import forestry.api.fuels.GeneratorFuel;
//import forestry.core.config.Constants;
//import forestry.core.errors.EnumErrorCode;
//import forestry.core.fluids.FluidHelper;
//import forestry.core.fluids.ITankManager;
//import forestry.core.fluids.TankManager;
//import forestry.core.fluids.FilteredTank;
//import forestry.core.network.DataInputStreamForestry;
//import forestry.core.network.DataOutputStreamForestry;
//import forestry.core.network.IStreamableGui;
//import forestry.core.render.TankRenderInfo;
//import forestry.core.tiles.ILiquidTankTile;
//import forestry.core.tiles.IRenderableTile;
//import forestry.core.tiles.TileBase;
//import forestry.energy.gui.ContainerGenerator;
//import forestry.energy.gui.GuiGenerator;
//import forestry.energy.inventory.InventoryGenerator;
//import forestry.plugins.compat.PluginIC2;
//
//import ic2.api.energy.prefab.BasicSource;
//
//public class TileEuGenerator extends TileBase implements ISidedInventory, ILiquidTankTile, IRenderableTile, IStreamableGui {
// private static final int maxEnergy = 30000;
//
// private final TankManager tankManager;
// private final FilteredTank resourceTank;
//
// private int tickCount = 0;
//
// private BasicSource ic2EnergySource;
//
// public TileEuGenerator() {
// super("generator");
//
// setInternalInventory(new InventoryGenerator(this));
//
// resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY);
// resourceTank.setFilters(FuelManager.generatorFuel.keySet());
//
// tankManager = new TankManager(this, resourceTank);
//
// if (PluginIC2.instance.isAvailable()) {
// ic2EnergySource = new BasicSource(this, maxEnergy, 1);
// }
// }
//
// @Nonnull
// @Override
// public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
// nbttagcompound = super.writeToNBT(nbttagcompound);
//
// if (ic2EnergySource != null) {
// ic2EnergySource.writeToNBT(nbttagcompound);
// }
//
// tankManager.writeToNBT(nbttagcompound);
// return nbttagcompound;
// }
//
// @Override
// public void readFromNBT(NBTTagCompound nbttagcompound) {
// super.readFromNBT(nbttagcompound);
//
// if (ic2EnergySource != null) {
// ic2EnergySource.readFromNBT(nbttagcompound);
// }
//
// tankManager.readFromNBT(nbttagcompound);
// }
//
// @Override
// public void writeData(PacketBufferForestry data) {
// super.writeData(data);
// tankManager.writeData(data);
// }
//
// @Override
// public void readData(PacketBufferForestry data) throws IOException {
// super.readData(data);
// tankManager.readData(data);
// }
//
// @Override
// public void onChunkUnload() {
// if (ic2EnergySource != null) {
// ic2EnergySource.onChunkUnload();
// }
//
// super.onChunkUnload();
// }
//
// @Override
// public void invalidate() {
// if (ic2EnergySource != null) {
// ic2EnergySource.invalidate();
// }
//
// super.invalidate();
// }
//
// @Override
// public void updateServerSide() {
// if (updateOnInterval(20)) {
// FluidHelper.drainContainers(tankManager, this, InventoryGenerator.SLOT_CAN);
// }
//
// IErrorLogic errorLogic = getErrorLogic();
//
// // No work to be done if IC2 is unavailable.
// if (errorLogic.setCondition(ic2EnergySource == null, EnumErrorCode.NO_ENERGY_NET)) {
// return;
// }
//
// ic2EnergySource.update();
//
// if (resourceTank.getFluidAmount() > 0) {
// GeneratorFuel fuel = FuelManager.generatorFuel.get(resourceTank.getFluid().getFluid());
// if (resourceTank.canDrainFluidType(fuel.getFuelConsumed()) && ic2EnergySource.getFreeCapacity() >= fuel.getEu()) {
// ic2EnergySource.addEnergy(fuel.getEu());
// this.tickCount++;
//
// if (tickCount >= fuel.getRate()) {
// tickCount = 0;
// resourceTank.drain(fuel.getFuelConsumed().amount, true);
// }
// }
//
// }
//
// boolean hasFuel = resourceTank.getFluidAmount() > 0;
// errorLogic.setCondition(!hasFuel, EnumErrorCode.NO_FUEL);
// }
//
// public boolean isWorking() {
// return resourceTank.getFluidAmount() > 0;
// }
//
// public int getResourceScaled(int i) {
// return (resourceTank.getFluidAmount() * i) / Constants.PROCESSOR_TANK_CAPACITY;
// }
//
// public int getStoredScaled(int i) {
// if (ic2EnergySource == null) {
// return 0;
// }
//
// return (int) (ic2EnergySource.getEnergyStored() * i) / maxEnergy;
// }
//
// @Override
// public TankRenderInfo getResourceTankInfo() {
// return new TankRenderInfo(resourceTank);
// }
//
// @Override
// public TankRenderInfo getProductTankInfo() {
// return TankRenderInfo.EMPTY;
// }
//
// @Override
// public void writeGuiData(PacketBufferForestry data) {
// if (ic2EnergySource != null) {
// data.writeDouble(ic2EnergySource.getEnergyStored());
// }
// }
//
// @Override
// public void readGuiData(PacketBufferForestry data) throws IOException {
// if (ic2EnergySource != null) {
// ic2EnergySource.setEnergyStored(data.readDouble());
// }
// }
//
// @Override
// public Object getGui(EntityPlayer player, int data) {
// return new GuiGenerator(player.inventory, this);
// }
//
// @Override
// public Object getContainer(EntityPlayer player, int data) {
// return new ContainerGenerator(player.inventory, this);
// }
//
// @Nonnull
// @Override
// public ITankManager getTankManager() {
// return tankManager;
// }
//
// @Override
// public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
// if (super.hasCapability(capability, facing)) {
// return true;
// }
// return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
// }
//
// @Nonnull
// @Override
// public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
// if (super.hasCapability(capability, facing)) {
// return super.getCapability(capability, facing);
// }
// if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
// return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
// }
// return null;
// }
//}
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http:www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.energy.tiles;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import forestry.api.core.IErrorLogic;
import forestry.api.fuels.FuelManager;
import forestry.api.fuels.GeneratorFuel;
import forestry.core.config.Constants;
import forestry.core.errors.EnumErrorCode;
import forestry.core.fluids.FluidHelper;
import forestry.core.fluids.ITankManager;
import forestry.core.fluids.TankManager;
import forestry.core.fluids.FilteredTank;
import forestry.core.network.IStreamableGui;
import forestry.core.network.PacketBufferForestry;
import forestry.core.render.TankRenderInfo;
import forestry.core.tiles.ILiquidTankTile;
import forestry.core.tiles.IRenderableTile;
import forestry.core.tiles.TileBase;
import forestry.energy.gui.ContainerGenerator;
import forestry.energy.gui.GuiGenerator;
import forestry.energy.inventory.InventoryGenerator;
import forestry.plugins.compat.PluginIC2;
import ic2.api.energy.prefab.BasicSource;
public class TileEuGenerator extends TileBase implements ISidedInventory, ILiquidTankTile, IRenderableTile, IStreamableGui {
private static final int maxEnergy = 30000;
private final TankManager tankManager;
private final FilteredTank resourceTank;
private int tickCount = 0;
private BasicSource ic2EnergySource;
public TileEuGenerator() {
super();//"generator"
setInternalInventory(new InventoryGenerator(this));
resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY);
resourceTank.setFilters(FuelManager.generatorFuel.keySet());
tankManager = new TankManager(this, resourceTank);
if (PluginIC2.instance.isAvailable()) {
ic2EnergySource = new BasicSource(this, maxEnergy, 1);
}
}
@Nonnull
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound = super.writeToNBT(nbttagcompound);
if (ic2EnergySource != null) {
ic2EnergySource.writeToNBT(nbttagcompound);
}
tankManager.writeToNBT(nbttagcompound);
return nbttagcompound;
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
if (ic2EnergySource != null) {
ic2EnergySource.readFromNBT(nbttagcompound);
}
tankManager.readFromNBT(nbttagcompound);
}
@Override
public void writeData(PacketBufferForestry data) {
super.writeData(data);
tankManager.writeData(data);
}
@Override
public void readData(PacketBufferForestry data) throws IOException {
super.readData(data);
tankManager.readData(data);
}
@Override
public void onChunkUnload() {
if (ic2EnergySource != null) {
ic2EnergySource.onChunkUnload();
}
super.onChunkUnload();
}
@Override
public void invalidate() {
if (ic2EnergySource != null) {
ic2EnergySource.invalidate();
}
super.invalidate();
}
@Override
public void updateServerSide() {
if (updateOnInterval(20)) {
FluidHelper.drainContainers(tankManager, this, InventoryGenerator.SLOT_CAN);
}
IErrorLogic errorLogic = getErrorLogic();
// No work to be done if IC2 is unavailable.
if (errorLogic.setCondition(ic2EnergySource == null, EnumErrorCode.NO_ENERGY_NET)) {
return;
}
ic2EnergySource.update();
if (resourceTank.getFluidAmount() > 0) {
GeneratorFuel fuel = FuelManager.generatorFuel.get(resourceTank.getFluid().getFluid());
if (resourceTank.canDrainFluidType(fuel.getFuelConsumed()) && ic2EnergySource.getFreeCapacity() >= fuel.getEu()) {
ic2EnergySource.addEnergy(fuel.getEu());
this.tickCount++;
if (tickCount >= fuel.getRate()) {
tickCount = 0;
resourceTank.drain(fuel.getFuelConsumed().amount, true);
}
}
}
boolean hasFuel = resourceTank.getFluidAmount() > 0;
errorLogic.setCondition(!hasFuel, EnumErrorCode.NO_FUEL);
}
public boolean isWorking() {
return resourceTank.getFluidAmount() > 0;
}
public int getResourceScaled(int i) {
return (resourceTank.getFluidAmount() * i) / Constants.PROCESSOR_TANK_CAPACITY;
}
public int getStoredScaled(int i) {
if (ic2EnergySource == null) {
return 0;
}
return (int) (ic2EnergySource.getEnergyStored() * i) / maxEnergy;
}
@Override
public TankRenderInfo getResourceTankInfo() {
return new TankRenderInfo(resourceTank);
}
@Override
public TankRenderInfo getProductTankInfo() {
return TankRenderInfo.EMPTY;
}
@Override
public void writeGuiData(PacketBufferForestry data) {
if (ic2EnergySource != null) {
data.writeDouble(ic2EnergySource.getEnergyStored());
}
}
@Override
public void readGuiData(PacketBufferForestry data) throws IOException {
if (ic2EnergySource != null) {
ic2EnergySource.setEnergyStored(data.readDouble());
}
}
@SideOnly(Side.CLIENT)
@Override
public GuiContainer getGui(EntityPlayer player, int data) {
return new GuiGenerator(player.inventory, this);
}
@Override
public Container getContainer(EntityPlayer player, int data) {
return new ContainerGenerator(player.inventory, this);
}
@Nonnull
@Override
public ITankManager getTankManager() {
return tankManager;
}
@Override
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
if (super.hasCapability(capability, facing)) {
return true;
}
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
}
@Nonnull
@Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
if (super.hasCapability(capability, facing)) {
return super.getCapability(capability, facing);
}
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
}
return null;
}
}
@@ -1,6 +1,7 @@
package forestry.farming;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
@@ -14,15 +15,11 @@ import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import forestry.api.core.ForestryAPI;
import forestry.api.core.ISpriteRegister;
import forestry.api.farming.Farmables;
import forestry.api.farming.IFarmLogic;
import forestry.api.farming.IFarmRegistry;
import forestry.api.farming.IFarmable;
import forestry.api.farming.ISimpleFarmLogic;
import forestry.core.config.LocalizedConfiguration;
import forestry.core.render.TextureManagerForestry;
import forestry.core.render.TextureMapForestry;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.Log;
import forestry.core.utils.Translator;
@@ -30,7 +27,6 @@ import forestry.farming.logic.FarmLogicSimple;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.oredict.OreDictionary;
import scala.actors.threadpool.Arrays;
public final class FarmRegistry implements IFarmRegistry {
@@ -63,6 +59,9 @@ public final class FarmRegistry implements IFarmRegistry {
@Override
public void registerFertilizer(ItemStack itemStack, int value) {
if(itemStack == null || itemStack.isEmpty()){
return;
}
fertilizers.put(itemStack, value);
}
@@ -13,22 +13,13 @@ package forestry.farming;
import javax.annotation.Nullable;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import com.google.common.base.Preconditions;
import forestry.Forestry;
import forestry.api.circuits.ChipsetManager;
import forestry.api.circuits.CircuitSocketType;
import forestry.api.circuits.ICircuitLayout;
import forestry.api.core.ForestryAPI;
import forestry.api.farming.Farmables;
import forestry.api.farming.IFarmRegistry;
import forestry.core.PluginCore;
import forestry.core.circuits.CircuitLayout;
@@ -39,10 +30,7 @@ import forestry.core.config.LocalizedConfiguration;
import forestry.core.items.EnumElectronTube;
import forestry.core.items.ItemRegistryCore;
import forestry.core.recipes.RecipeUtil;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.Log;
import forestry.core.utils.OreDictUtil;
import forestry.core.utils.Translator;
import forestry.farming.blocks.BlockMushroom;
import forestry.farming.blocks.BlockRegistryFarming;
import forestry.farming.blocks.EnumFarmBlockType;
@@ -85,7 +73,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
@@ -1,82 +1,87 @@
//package forestry.farming.logic;
//
//
//import java.util.Collection;
//import java.util.List;
//
//import net.minecraft.item.ItemStack;
//import net.minecraft.tileentity.TileEntity;
//import net.minecraft.util.math.BlockPos;
//import net.minecraft.world.World;
//
//import net.minecraftforge.fml.common.Optional;
//
//import forestry.plugins.compat.PluginIC2;
//
//import ic2.api.crops.ICropTile;
//
//public class CropBasicIC2Crop extends Crop {
// private final TileEntity tileEntity;
//
// public CropBasicIC2Crop(@Nonnull World world, @Nonnull TileEntity tileEntity, @Nonnull BlockPos position) {
// super(world, position);
// this.tileEntity = tileEntity;
// }
//
// @Override
// protected boolean isCrop(World world, BlockPos pos) {
// return canHarvestCrop(this.tileEntity);
// }
//
// @Override
// protected Collection<ItemStack> harvestBlock(World world, BlockPos pos) {
// return getCropDrops(this.tileEntity);
// }
//
// /**
// * Check if there is an instance of ICropTile.
// * @param tileEntity tile entity to be checked.
// * @return true if there is an IC2 crop and false otherwise.
// */
// @Optional.Method(modid = PluginIC2.modId)
// public static boolean isIC2Crop(TileEntity tileEntity) {
// if (tileEntity instanceof ICropTile) {
// return true;
// }
// return false;
// }
//
// /**
// * Check if an IC2 crop is ready to be harvested.
// * @param tileEntity tile entity to be checked.
// * @return true if crop size is optimal for harvest and false otherwise.
// */
// @Optional.Method(modid = PluginIC2.modId)
// public static boolean canHarvestCrop(TileEntity tileEntity) {
// if (isIC2Crop(tileEntity)) {
// ICropTile crop = (ICropTile) tileEntity;
// if (crop.getCrop() == null) {
// return false;
// }
// if (crop.getCurrentSize() == crop.getCrop().getOptimalHarvestSize(crop)) {
// return true;
// }
// }
// return false;
// }
//
// /**
// * This function takes care of everything related to the harvesting of the
// * crop meaning it will calculate the drops and also do setSizeAfterHarvest().
// * @param tileEntity tile entity to be checked.
// * @return list containing the drops.
// */
// @Optional.Method(modid = PluginIC2.modId)
// private static List<ItemStack> getCropDrops(TileEntity tileEntity) {
// if (isIC2Crop(tileEntity)) {
// ICropTile crop = (ICropTile) tileEntity;
// return crop.performHarvest();
// }
// return null;
// }
//}
package forestry.farming.logic;
import java.util.Collection;
import java.util.List;
import javax.annotation.Nonnull;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.Optional;
import forestry.plugins.compat.PluginIC2;
import ic2.api.crops.ICropTile;
public class CropBasicIC2Crop extends Crop {
private final TileEntity tileEntity;
public CropBasicIC2Crop(@Nonnull World world, @Nonnull TileEntity tileEntity, @Nonnull BlockPos position) {
super(world, position);
this.tileEntity = tileEntity;
}
@Override
protected boolean isCrop(World world, BlockPos pos) {
return canHarvestCrop(this.tileEntity);
}
@Override
protected NonNullList<ItemStack> harvestBlock(World world, BlockPos pos) {
return getCropDrops(this.tileEntity);
}
/**
* Check if there is an instance of ICropTile.
* @param tileEntity tile entity to be checked.
* @return true if there is an IC2 crop and false otherwise.
*/
@Optional.Method(modid = PluginIC2.modId)
public static boolean isIC2Crop(TileEntity tileEntity) {
if (tileEntity instanceof ICropTile) {
return true;
}
return false;
}
/**
* Check if an IC2 crop is ready to be harvested.
* @param tileEntity tile entity to be checked.
* @return true if crop size is optimal for harvest and false otherwise.
*/
@Optional.Method(modid = PluginIC2.modId)
public static boolean canHarvestCrop(TileEntity tileEntity) {
if (isIC2Crop(tileEntity)) {
ICropTile crop = (ICropTile) tileEntity;
if (crop.getCrop() == null) {
return false;
}
if (crop.getCurrentSize() == crop.getCrop().getOptimalHarvestSize(crop)) {
return true;
}
}
return false;
}
/**
* This function takes care of everything related to the harvesting of the
* crop meaning it will calculate the drops and also do setSizeAfterHarvest().
* @param tileEntity tile entity to be checked.
* @return list containing the drops.
*/
@Optional.Method(modid = PluginIC2.modId)
private static NonNullList<ItemStack> getCropDrops(TileEntity tileEntity) {
if (isIC2Crop(tileEntity)) {
ICropTile crop = (ICropTile) tileEntity;
NonNullList<ItemStack> drops = NonNullList.create();
drops.addAll(crop.performHarvest());
return drops;
}
return null;
}
}
@@ -1,94 +1,97 @@
///*******************************************************************************
// * Copyright (c) 2011-2014 SirSengir.
// * All rights reserved. This program and the accompanying materials
// * are made available under the terms of the GNU Lesser Public License v3
// * which accompanies this distribution, and is available at
// * http://www.gnu.org/licenses/lgpl-3.0.txt
// *
// * Various Contributors including, but not limited to:
// * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
// ******************************************************************************/
//package forestry.farming.logic;
//
//import javax.annotation.Nullable;
//import java.util.ArrayList;
//import java.util.Collection;
//import java.util.Map;
//
//import com.google.common.base.Optional;
//import com.google.common.collect.ImmutableCollection;
//import forestry.core.config.Constants;
//import forestry.core.network.packets.PacketFXSignal;
//import forestry.core.proxy.Proxies;
//import forestry.core.utils.ItemStackUtil;
//import forestry.plugins.compat.PluginIC2;
//import net.minecraft.block.Block;
//import net.minecraft.block.properties.IProperty;
//import net.minecraft.block.state.IBlockState;
//import net.minecraft.item.ItemStack;
//import net.minecraft.util.math.BlockPos;
//import net.minecraft.world.World;
//
//public class CropRubber extends CropDestroy {
//
// public CropRubber(World world, IBlockState blockState, BlockPos position) {
// super(world, blockState, position, getReplantState(blockState));
// }
//
// /**
// * Convert a "wet" rubber log blockstate into the dry version.
// * Total hack since we don't have access to the blockstates.
// */
// private static <T extends Comparable<T>> IBlockState getReplantState(IBlockState sappyState) {
// if (hasRubberToHarvest(sappyState)) {
// for (Map.Entry<IProperty<?>, Comparable<?>> wetPropertyEntry : sappyState.getProperties().entrySet()) {
// String valueWetString = wetPropertyEntry.getValue().toString();
// String valueDryString = valueWetString.replace("wet", "dry");
// IProperty<?> property = wetPropertyEntry.getKey();
//
// IBlockState baseState = sappyState.getBlock().getBlockState().getBaseState();
// IBlockState dryState = getStateWithValue(baseState, property, valueDryString);
// if (dryState != null) {
// return dryState;
// }
// }
// }
//
// return sappyState.getBlock().getDefaultState();
// }
//
// public static boolean hasRubberToHarvest(IBlockState blockState) {
// Block block = blockState.getBlock();
// if (ItemStackUtil.equals(block, PluginIC2.rubberWood)) {
// ImmutableCollection<Comparable<?>> propertyValues = blockState.getProperties().values();
// for (Comparable<?> propertyValue : propertyValues) {
// if (propertyValue.toString().contains("wet")) {
// return true;
// }
// }
// }
// return false;
// }
//
// @Nullable
// private static <T extends Comparable<T>> IBlockState getStateWithValue(IBlockState baseState, IProperty<T> property, String valueString) {
// Optional<T> value = property.parseValue(valueString);
// if (value.isPresent()) {
// return baseState.withProperty(property, value.get());
// }
// return null;
// }
//
// @Override
// protected Collection<ItemStack> harvestBlock(World world, BlockPos pos) {
// Collection<ItemStack> harvested = new ArrayList<>();
// harvested.add(PluginIC2.resin.copy());
//
// PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState);
// Proxies.net.sendNetworkPacket(packet, world);
//
// world.setBlockState(pos, replantState, Constants.FLAG_BLOCK_SYNC);
// return harvested;
// }
//
//}
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http:www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.farming.logic;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableCollection;
import forestry.core.config.Constants;
import forestry.core.network.PacketHandler;
import forestry.core.network.packets.PacketFXSignal;
import forestry.core.proxy.Proxies;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.NetworkUtil;
import forestry.plugins.compat.PluginIC2;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class CropRubber extends CropDestroy {
public CropRubber(World world, IBlockState blockState, BlockPos position) {
super(world, blockState, position, getReplantState(blockState));
}
/**
* Convert a "wet" rubber log blockstate into the dry version.
* Total hack since we don't have access to the blockstates.
*/
private static <T extends Comparable<T>> IBlockState getReplantState(IBlockState sappyState) {
if (hasRubberToHarvest(sappyState)) {
for (Map.Entry<IProperty<?>, Comparable<?>> wetPropertyEntry : sappyState.getProperties().entrySet()) {
String valueWetString = wetPropertyEntry.getValue().toString();
String valueDryString = valueWetString.replace("wet", "dry");
IProperty<?> property = wetPropertyEntry.getKey();
IBlockState baseState = sappyState.getBlock().getBlockState().getBaseState();
IBlockState dryState = getStateWithValue(baseState, property, valueDryString);
if (dryState != null) {
return dryState;
}
}
}
return sappyState.getBlock().getDefaultState();
}
public static boolean hasRubberToHarvest(IBlockState blockState) {
Block block = blockState.getBlock();
if (ItemStackUtil.equals(block, PluginIC2.rubberWood)) {
ImmutableCollection<Comparable<?>> propertyValues = blockState.getProperties().values();
for (Comparable<?> propertyValue : propertyValues) {
if (propertyValue.toString().contains("wet")) {
return true;
}
}
}
return false;
}
@Nullable
private static <T extends Comparable<T>> IBlockState getStateWithValue(IBlockState baseState, IProperty<T> property, String valueString) {
Optional<T> value = property.parseValue(valueString);
if (value.isPresent()) {
return baseState.withProperty(property, value.get());
}
return null;
}
@Override
protected NonNullList<ItemStack> harvestBlock(World world, BlockPos pos) {
NonNullList<ItemStack> harvested = NonNullList.create();
harvested.add(PluginIC2.resin.copy());
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState);
NetworkUtil.sendNetworkPacket(packet, pos, world);
world.setBlockState(pos, replantState, Constants.FLAG_BLOCK_SYNC);
return harvested;
}
}
@@ -20,7 +20,6 @@ import java.util.Set;
import java.util.Stack;
import forestry.api.farming.FarmDirection;
import forestry.api.farming.Farmables;
import forestry.api.farming.ICrop;
import forestry.api.farming.IFarmHousing;
import forestry.api.farming.IFarmable;
@@ -10,14 +10,14 @@
******************************************************************************/
package forestry.farming.logic;
import forestry.api.farming.Farmables;
import forestry.farming.FarmRegistry;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
public class FarmLogicCereal extends FarmLogicCrops {
public FarmLogicCereal() {
super(Farmables.farmables.get("farmWheat"));
super(FarmRegistry.getInstance().getFarmables("farmWheat"));
}
@Override
@@ -14,11 +14,11 @@ import java.util.Collection;
import java.util.Stack;
import forestry.api.farming.FarmDirection;
import forestry.api.farming.Farmables;
import forestry.api.farming.ICrop;
import forestry.api.farming.IFarmHousing;
import forestry.api.farming.IFarmable;
import forestry.core.utils.BlockUtil;
import forestry.farming.FarmRegistry;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
@@ -30,7 +30,7 @@ import net.minecraft.world.World;
public class FarmLogicEnder extends FarmLogicHomogeneous {
public FarmLogicEnder() {
super(new ItemStack(Blocks.END_STONE), Blocks.END_STONE.getDefaultState(), Farmables.farmables.get("farmEnder"));
super(new ItemStack(Blocks.END_STONE), Blocks.END_STONE.getDefaultState(), FarmRegistry.getInstance().getFarmables("farmEnder"));
}
@Override
@@ -14,10 +14,10 @@ import java.util.Collection;
import java.util.Stack;
import forestry.api.farming.FarmDirection;
import forestry.api.farming.Farmables;
import forestry.api.farming.ICrop;
import forestry.api.farming.IFarmHousing;
import forestry.api.farming.IFarmable;
import forestry.farming.FarmRegistry;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
@@ -30,7 +30,7 @@ public class FarmLogicGourd extends FarmLogic {
private final IFarmable[] seeds;
public FarmLogicGourd() {
Collection<IFarmable> farmables = Farmables.farmables.get("farmGourd");
Collection<IFarmable> farmables = FarmRegistry.getInstance().getFarmables("farmGourd");
seeds = farmables.toArray(new IFarmable[farmables.size()]);
}
@@ -14,11 +14,11 @@ import java.util.Collection;
import java.util.Stack;
import forestry.api.farming.FarmDirection;
import forestry.api.farming.Farmables;
import forestry.api.farming.ICrop;
import forestry.api.farming.IFarmHousing;
import forestry.api.farming.IFarmable;
import forestry.core.utils.BlockUtil;
import forestry.farming.FarmRegistry;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
@@ -30,7 +30,7 @@ import net.minecraft.world.World;
public class FarmLogicInfernal extends FarmLogicHomogeneous {
public FarmLogicInfernal() {
super(new ItemStack(Blocks.SOUL_SAND), Blocks.SOUL_SAND.getDefaultState(), Farmables.farmables.get("farmInfernal"));
super(new ItemStack(Blocks.SOUL_SAND), Blocks.SOUL_SAND.getDefaultState(), FarmRegistry.getInstance().getFarmables("farmInfernal"));
}
@Override
@@ -10,8 +10,8 @@
******************************************************************************/
package forestry.farming.logic;
import forestry.api.farming.Farmables;
import forestry.api.farming.IFarmHousing;
import forestry.farming.FarmRegistry;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
@@ -20,7 +20,7 @@ import net.minecraft.world.World;
public class FarmLogicMushroom extends FarmLogicArboreal {
public FarmLogicMushroom() {
super(new ItemStack(Blocks.MYCELIUM), Blocks.MYCELIUM.getDefaultState(), Farmables.farmables.get("farmShroom"));
super(new ItemStack(Blocks.MYCELIUM), Blocks.MYCELIUM.getDefaultState(), FarmRegistry.getInstance().getFarmables("farmShroom"));
addSoil(new ItemStack(Blocks.DIRT, 1, 2), Blocks.DIRT.getStateFromMeta(2), true);
}
@@ -21,13 +21,13 @@ import java.util.Stack;
import com.google.common.collect.ImmutableList;
import forestry.api.farming.FarmDirection;
import forestry.api.farming.Farmables;
import forestry.api.farming.ICrop;
import forestry.api.farming.IFarmHousing;
import forestry.api.farming.IFarmable;
import forestry.api.genetics.IFruitBearer;
import forestry.core.PluginCore;
import forestry.core.tiles.TileUtil;
import forestry.farming.FarmRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
@@ -42,7 +42,7 @@ public class FarmLogicOrchard extends FarmLogic {
private final ImmutableList<Block> traversalBlocks;
public FarmLogicOrchard() {
this.farmables = Farmables.farmables.get("farmOrchard");
this.farmables = FarmRegistry.getInstance().getFarmables("farmOrchard");
ImmutableList.Builder<Block> traversalBlocksBuilder = ImmutableList.builder();
// if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.AGRICRAFT) || ForestryAPI.enabledPlugins.contains(ForestryPluginUids.INDUSTRIALCRAFT)) {
@@ -14,11 +14,11 @@ import java.util.Collection;
import java.util.Stack;
import forestry.api.farming.FarmDirection;
import forestry.api.farming.Farmables;
import forestry.api.farming.ICrop;
import forestry.api.farming.IFarmHousing;
import forestry.api.farming.IFarmable;
import forestry.core.utils.ItemStackUtil;
import forestry.farming.FarmRegistry;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
@@ -28,7 +28,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class FarmLogicReeds extends FarmLogic {
private final Collection<IFarmable> germlings = Farmables.farmables.get("farmPoales");
private final Collection<IFarmable> germlings = FarmRegistry.getInstance().getFarmables("farmPoales");
@Override
public ItemStack getIconItemStack() {
@@ -1,132 +1,133 @@
///*******************************************************************************
// * Copyright (c) 2011-2014 SirSengir.
// * All rights reserved. This program and the accompanying materials
// * are made available under the terms of the GNU Lesser Public License v3
// * which accompanies this distribution, and is available at
// * http://www.gnu.org/licenses/lgpl-3.0.txt
// *
// * Various Contributors including, but not limited to:
// * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
// ******************************************************************************/
//package forestry.farming.logic;
//
//import java.util.Collection;
//import java.util.HashMap;
//import java.util.Map;
//import java.util.Stack;
//
//import forestry.api.farming.FarmDirection;
//import forestry.api.farming.ICrop;
//import forestry.api.farming.IFarmHousing;
//import forestry.core.utils.ItemStackUtil;
//import forestry.core.utils.Log;
//import forestry.plugins.compat.PluginIC2;
//import net.minecraft.block.Block;
//import net.minecraft.block.state.IBlockState;
//import net.minecraft.item.ItemStack;
//import net.minecraft.util.math.BlockPos;
//import net.minecraft.world.World;
//
//public class FarmLogicRubber extends FarmLogic {
//
// private boolean active = true;
//
// public FarmLogicRubber() {
// if (PluginIC2.rubberWood == null || PluginIC2.resin == null) {
// Log.warning("Failed to init a farm logic {} since IC2 rubber wood or resin were not found", getClass().getName());
// active = false;
// }
// }
//
// @Override
// public ItemStack getIconItemStack() {
// return PluginIC2.resin;
// }
//
// @Override
// public String getName() {
// return "Rubber Plantation";
// }
//
// @Override
// public int getFertilizerConsumption() {
// return 40;
// }
//
// @Override
// public int getWaterConsumption(float hydrationModifier) {
// return (int) (5 * hydrationModifier);
// }
//
// @Override
// public boolean isAcceptedResource(ItemStack itemstack) {
// return false;
// }
//
// @Override
// public boolean isAcceptedGermling(ItemStack itemstack) {
// return false;
// }
//
// @Override
// public boolean isAcceptedWindfall(ItemStack stack) {
// return false;
// }
//
// @Override
// public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
// return null;
// }
//
// @Override
// public boolean cultivate(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
// return false;
// }
//
// private final Map<BlockPos, Integer> lastExtents = new HashMap<>();
//
// @Override
// public Collection<ICrop> harvest(World world, BlockPos pos, FarmDirection direction, int extent) {
// if (!active) {
// return null;
// }
//
// if (!lastExtents.containsKey(pos)) {
// lastExtents.put(pos, 0);
// }
//
// int lastExtent = lastExtents.get(pos);
// if (lastExtent > extent) {
// lastExtent = 0;
// }
//
// BlockPos position = translateWithOffset(pos.up(), direction, lastExtent);
// Collection<ICrop> crops = getHarvestBlocks(world, position);
// lastExtent++;
// lastExtents.put(pos, lastExtent);
//
// return crops;
// }
//
// private Collection<ICrop> getHarvestBlocks(World world, BlockPos position) {
// Stack<ICrop> crops = new Stack<>();
//
// for (int j = 0; j < 10; j++) {
// BlockPos candidate = position.add(0, j, 0);
//
// IBlockState blockState = world.getBlockState(candidate);
// Block block = blockState.getBlock();
// if (!ItemStackUtil.equals(block, PluginIC2.rubberWood)) {
// break;
// }
//
// if (CropRubber.hasRubberToHarvest(blockState)) {
// crops.push(new CropRubber(world, blockState, candidate));
// break;
// }
// }
//
// return crops;
// }
//
//}
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http:www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.farming.logic;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import forestry.api.farming.FarmDirection;
import forestry.api.farming.ICrop;
import forestry.api.farming.IFarmHousing;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.Log;
import forestry.plugins.compat.PluginIC2;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class FarmLogicRubber extends FarmLogic {
private boolean active = true;
public FarmLogicRubber() {
if (PluginIC2.rubberWood == null || PluginIC2.resin == null) {
Log.warning("Failed to init a farm logic {} since IC2 rubber wood or resin were not found", getClass().getName());
active = false;
}
}
@Override
public ItemStack getIconItemStack() {
return PluginIC2.resin;
}
@Override
public String getName() {
return "Rubber Plantation";
}
@Override
public int getFertilizerConsumption() {
return 40;
}
@Override
public int getWaterConsumption(float hydrationModifier) {
return (int) (5 * hydrationModifier);
}
@Override
public boolean isAcceptedResource(ItemStack itemstack) {
return false;
}
@Override
public boolean isAcceptedGermling(ItemStack itemstack) {
return false;
}
@Override
public boolean isAcceptedWindfall(ItemStack stack) {
return false;
}
@Override
public NonNullList<ItemStack> collect(World world, IFarmHousing farmHousing) {
return NonNullList.create();
}
@Override
public boolean cultivate(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
return false;
}
private final Map<BlockPos, Integer> lastExtents = new HashMap<>();
@Override
public Collection<ICrop> harvest(World world, BlockPos pos, FarmDirection direction, int extent) {
if (!active) {
return null;
}
if (!lastExtents.containsKey(pos)) {
lastExtents.put(pos, 0);
}
int lastExtent = lastExtents.get(pos);
if (lastExtent > extent) {
lastExtent = 0;
}
BlockPos position = translateWithOffset(pos.up(), direction, lastExtent);
Collection<ICrop> crops = getHarvestBlocks(world, position);
lastExtent++;
lastExtents.put(pos, lastExtent);
return crops;
}
private Collection<ICrop> getHarvestBlocks(World world, BlockPos position) {
Stack<ICrop> crops = new Stack<>();
for (int j = 0; j < 10; j++) {
BlockPos candidate = position.add(0, j, 0);
IBlockState blockState = world.getBlockState(candidate);
Block block = blockState.getBlock();
if (!ItemStackUtil.equals(block, PluginIC2.rubberWood)) {
break;
}
if (CropRubber.hasRubberToHarvest(blockState)) {
crops.push(new CropRubber(world, blockState, candidate));
break;
}
}
return crops;
}
}
@@ -1,6 +1,5 @@
package forestry.farming.logic;
import forestry.api.farming.IFarmable;
import forestry.api.farming.ISimpleFarmLogic;
import net.minecraft.item.ItemStack;
@@ -14,11 +14,11 @@ import java.util.Collection;
import java.util.Stack;
import forestry.api.farming.FarmDirection;
import forestry.api.farming.Farmables;
import forestry.api.farming.ICrop;
import forestry.api.farming.IFarmHousing;
import forestry.api.farming.IFarmable;
import forestry.core.utils.ItemStackUtil;
import forestry.farming.FarmRegistry;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
@@ -28,7 +28,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class FarmLogicSucculent extends FarmLogic {
private final Collection<IFarmable> germlings = Farmables.farmables.get("farmSucculentes");
private final Collection<IFarmable> germlings = FarmRegistry.getInstance().getFarmables("farmSucculentes");
@Override
public ItemStack getIconItemStack() {
@@ -10,14 +10,14 @@
******************************************************************************/
package forestry.farming.logic;
import forestry.api.farming.Farmables;
import forestry.farming.FarmRegistry;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
public class FarmLogicVegetable extends FarmLogicCrops {
public FarmLogicVegetable() {
super(Farmables.farmables.get("farmVegetables"));
super(FarmRegistry.getInstance().getFarmables("farmVegetables"));
}
@Override
@@ -1,85 +1,85 @@
//package forestry.farming.logic;
//
//import javax.annotation.Nullable;
//
//import net.minecraft.block.state.IBlockState;
//import net.minecraft.entity.player.EntityPlayer;
//import net.minecraft.item.ItemStack;
//import net.minecraft.tileentity.TileEntity;
//import net.minecraft.util.math.BlockPos;
//import net.minecraft.world.World;
//
//import net.minecraftforge.fml.common.Optional;
//
//import forestry.api.farming.ICrop;
//import forestry.api.farming.IFarmable;
//import forestry.plugins.compat.PluginIC2;
//
//import ic2.api.crops.ICropTile;
//
//public class FarmableBasicIC2Crop implements IFarmable {
//
// /**
// * Perform some of the actions of the crop-matron.
// */
// @Optional.Method(modid = PluginIC2.modId)
// public static void babysitCrop(TileEntity tileEntity) {
// if (CropBasicIC2Crop.isIC2Crop(tileEntity)) {
// ICropTile crop = (ICropTile) tileEntity;
// /*
// This part might be unbalanced until a custom farm logic is added and makes use of weed-ex.
// if (crop.getCrop() != null) {
// if (crop.getCrop().isWeed(crop)) {
// crop.reset();
// }
// }*/
// if (crop.getStorageWater() <= 200) {
// crop.setStorageWater(200);
// }
// if (crop.getStorageNutrient() <= 100) {
// crop.setStorageNutrient(crop.getStorageNutrient() + 100);
// }
// }
// }
//
// @Override
// public boolean isSaplingAt(World world, BlockPos pos) {
// TileEntity crop = world.getTileEntity(pos);
// if (CropBasicIC2Crop.isIC2Crop(crop)) {
// babysitCrop(crop);
// return true;
// }
// return false;
// }
//
// @Nullable
// @Override
// public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) {
// TileEntity crop = world.getTileEntity(pos);
// if (crop == null) {
// return null;
// }
// if (!CropBasicIC2Crop.isIC2Crop(crop)) {
// return null;
// }
// if (!CropBasicIC2Crop.canHarvestCrop(crop)) {
// return null;
// }
// return new CropBasicIC2Crop(world, crop, pos);
// }
//
// @Override
// public boolean isGermling(ItemStack itemstack) {
// return false;
// }
//
// @Override
// public boolean isWindfall(ItemStack itemstack) {
// return false;
// }
//
// @Override
// public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
// return false;
// }
//}
package forestry.farming.logic;
import javax.annotation.Nullable;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.Optional;
import forestry.api.farming.ICrop;
import forestry.api.farming.IFarmable;
import forestry.plugins.compat.PluginIC2;
import ic2.api.crops.ICropTile;
public class FarmableBasicIC2Crop implements IFarmable {
/**
* Perform some of the actions of the crop-matron.
*/
@Optional.Method(modid = PluginIC2.modId)
public static void babysitCrop(TileEntity tileEntity) {
if (CropBasicIC2Crop.isIC2Crop(tileEntity)) {
ICropTile crop = (ICropTile) tileEntity;
/*
This part might be unbalanced until a custom farm logic is added and makes use of weed-ex.
if (crop.getCrop() != null) {
if (crop.getCrop().isWeed(crop)) {
crop.reset();
}
}*/
if (crop.getStorageWater() <= 200) {
crop.setStorageWater(200);
}
if (crop.getStorageNutrients() <= 100) {
crop.setStorageNutrients(crop.getStorageNutrients() + 100);
}
}
}
@Override
public boolean isSaplingAt(World world, BlockPos pos) {
TileEntity crop = world.getTileEntity(pos);
if (CropBasicIC2Crop.isIC2Crop(crop)) {
babysitCrop(crop);
return true;
}
return false;
}
@Nullable
@Override
public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) {
TileEntity crop = world.getTileEntity(pos);
if (crop == null) {
return null;
}
if (!CropBasicIC2Crop.isIC2Crop(crop)) {
return null;
}
if (!CropBasicIC2Crop.canHarvestCrop(crop)) {
return null;
}
return new CropBasicIC2Crop(world, crop, pos);
}
@Override
public boolean isGermling(ItemStack itemstack) {
return false;
}
@Override
public boolean isWindfall(ItemStack itemstack) {
return false;
}
@Override
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
return false;
}
}
@@ -10,12 +10,10 @@
******************************************************************************/
package forestry.farming.multiblock;
import java.util.Map.Entry;
import java.util.Stack;
import forestry.api.core.ForestryAPI;
import forestry.api.farming.FarmDirection;
import forestry.api.farming.Farmables;
import forestry.api.farming.IFarmInventory;
import forestry.api.farming.IFarmLogic;
import forestry.api.farming.IFarmable;
@@ -35,7 +33,6 @@ import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.oredict.OreDictionary;
public class InventoryFarm extends InventoryAdapterRestricted implements IFarmInventory {
public static final int SLOT_RESOURCES_1 = 0;
Loaded 100 of 137 files, more files were not shown because too many files have changed in this diff. Show more