Compare commits

...
32 Commits
Author SHA1 Message Date
mezz 0ebced9609 Fix #1845 API has references to internal classes 2017-09-07 19:23:59 -07:00
mezz b9924ea98b Fix #1843 Improve performance of worldgen hives 2017-09-06 00:35:54 -07:00
mezz 5707d27598 Fix #1577 Hives load new chunks when retrogen is active 2017-09-04 14:46:56 -07:00
mezz 42bde9e576 Fix #1836 Update minimum required JEI version 2017-09-04 14:10:55 -07:00
mezz 76f09be39d Close #1838 Make IHiveFrame's getBeeModifier() ItemStack aware 2017-09-04 13:52:32 -07:00
LachimHeigrim e6cb758e0e Fix #1827 Allow Natura nether saplings to be autofarmed in arboreal farm (#1829) 2017-09-01 19:58:46 -07:00
mezz b3549edf51 Fix #1833 Item in players hand get deleted by farm planting 2017-08-29 22:14:47 -07:00
mezz e09d159935 Fix breeding data desync after changing dimensions 2017-08-29 20:55:31 -07:00
Nedelosk 4cb2610b1c Fix #1830 Carpenter removes the wrong item 2017-08-28 16:03:12 +02:00
mezz c44f11cf09 Update dependencies 2017-08-27 14:56:59 -07:00
mezz b69c31ed8a Clean up generics for Forestry ItemBlocks 2017-08-25 21:14:13 -07:00
mezz 6a2231f8fb Fix a crash when escritoire loads with a specimen already in it 2017-08-22 23:00:27 -07:00
mezz a3a6c71c42 Fix #1762 Swapping specimens in the escritoire has strange effects 2017-08-22 22:46:13 -07:00
mezz 8d5c0c6f8b Fix #1806 Allow sapling's products to work as hint items in escritoire 2017-08-22 22:37:35 -07:00
mezz 56603fd00c Fix #1813 Saplings do not drop when removed by water of piston 2017-08-22 22:10:47 -07:00
mezz ed69411d2e Fix #1815 Stop MultiFarm from converting vanilla saplings 2017-08-22 21:45:55 -07:00
mezz e1d017f077 Fix #1819 Crash when growing short Sipiri trees 2017-08-20 22:24:53 -07:00
mezz 9269af7a13 Update to 1.12.1 2017-08-18 20:17:18 -07:00
Nedelosk 8ffdba5021 Fix build script 2017-08-17 13:59:39 +02:00
Nedelosk e00aecd886 Fix #1807 Honeycomb block uncraftable 2017-08-16 19:26:15 +02:00
Nedelosk 98f859f2fb Add a log message to the Create Model 2017-08-16 14:48:11 +02:00
mezz 55a15d23b2 Fix Pam's harvestcraft integration 2017-08-14 21:19:29 -07:00
mezz 307580aed8 Mark as working on 1.12.1 on CurseForge 2017-08-13 22:06:46 -07:00
Nedelosk d2d93004e0 Merge pull request #1801 from asiekierka/mc-1.12
Reduce SimpleModel memory usage
2017-08-13 18:21:02 +02:00
Adrian Siekierka e1df424bfd reduce SimpleModel memory usage 2017-08-13 16:35:26 +02:00
Robert Obermeier 6a75347b05 Add Red Orchid support to farm (#1800) 2017-08-12 17:09:00 -07:00
Robert Obermeier cfd513ea80 Fix Natura support (#1794) 2017-08-12 15:50:31 -07:00
Robert Obermeier edcc47a6b3 Fix #1753 Add generalized sapling support (#1798) 2017-08-12 14:44:16 -07:00
mezz 6593118f3d Fix #1787 Wood logs drop the wrong item when harvested with silk touch 2017-08-12 12:39:59 -07:00
Robert Obermeier fd724d147a Fix #1789 The End has no hives. (#1795) 2017-08-11 20:56:12 -07:00
mezz b2e1b2dc9b Fix tree generation with Mystcraft 2017-07-29 15:42:34 -07:00
mezz defc47000b Fix client visual glitch with worktable 2017-07-29 00:56:34 -07:00
89 changed files with 1484 additions and 808 deletions

No files matched your search

Executable → Regular
+5 -4
View File
@@ -62,9 +62,9 @@ repositories {
}
dependencies {
deobfCompile "net.darkhax.tesla:Tesla-${mcversion}:${tesla_version}"
deobfCompile "mezz.jei:jei_${mcversion}:${jei_version}:api"
runtime "mezz.jei:jei_${mcversion}:${jei_version}"
deobfCompile "net.darkhax.tesla:Tesla-${tesla_mcversion}:${tesla_version}"
deobfCompile "mezz.jei:jei_${jei_mcversion}:${jei_version}:api"
runtime "mezz.jei:jei_${jei_mcversion}:${jei_version}"
deobfCompile "net.industrial-craft:industrialcraft-2:${ic2_version}:api"
}
@@ -157,10 +157,11 @@ task makeChangelog(type: se.bjurr.gitchangelog.plugin.gradle.GitChangelogTask) {
curseforge {
apiKey = project.hasProperty('curseforge_apikey') ? project.curseforge_apikey : '0'
project {
id = '59751'
id = curse_project_id
changelog = file('changelog.html')
changelogType = 'html'
releaseType = 'beta'
addGameVersion '1.12'
}
}
+9 -6
View File
@@ -1,11 +1,14 @@
mcversion=1.12
forgeversion=14.21.1.2424
mcp_mappings=snapshot_20170703
mcversion=1.12.1
forgeversion=14.22.0.2469
mcp_mappings=snapshot_20170904
curse_project_id=59751
tesla_version=1.0.60
jei_version=4.7.2.77
ic2_version=2.7.30-ex111
tesla_mcversion=1.12
jei_version=4.7.8.92
jei_mcversion=1.12.1
ic2_version=2.8.24-ex112
version_major=5
version_minor=5
version_patch=0
version_patch=3
+1 -1
Submodule lang updated: f5300f059b...192d6f8584.
+13 -3
View File
@@ -15,6 +15,8 @@ import com.google.common.base.Preconditions;
import javax.annotation.Nullable;
import java.io.File;
import forestry.plugins.compat.PluginNatura;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.FluidRegistry;
@@ -26,6 +28,7 @@ import net.minecraftforge.fml.common.event.FMLInterModComms.IMCEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;
@@ -55,10 +58,11 @@ import forestry.plugins.compat.PluginIC2;
name = Constants.MOD_NAME,
version = Constants.VERSION,
guiFactory = "forestry.core.config.ForestryGuiConfigFactory",
acceptedMinecraftVersions = "[1.12]",
acceptedMinecraftVersions = "[1.12, 1.12.1]",
dependencies = "required-after:forge@[14.21.1.2395,);"
+ "after:jei@[4.7.0,);"
+ "after:" + PluginIC2.modId + ";")
+ "after:jei@[4.7.8.91,);"
+ "after:" + PluginIC2.modId + ";"
+ "after:" + PluginNatura.modId + ";")
public class Forestry {
@SuppressWarnings("NullableProblems")
@@ -73,6 +77,7 @@ public class Forestry {
ForestryAPI.errorStateRegistry = new ErrorStateRegistry();
EnumErrorCode.init();
FluidRegistry.enableUniversalBucket();
MinecraftForge.EVENT_BUS.register(this);
}
@Nullable
@@ -105,6 +110,11 @@ public class Forestry {
PluginManager.runPreInit(event.getSide());
}
@SubscribeEvent
public void registerModels(ModelRegistryEvent event) {
PluginManager.runRegisterBackpacksAndCrates();
Proxies.render.registerModels();
}
@@ -5,12 +5,14 @@
******************************************************************************/
package forestry.api.apiculture;
import java.io.IOException;
import java.util.List;
import forestry.api.core.INbtReadable;
import forestry.api.core.INbtWritable;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.relauncher.Side;
@@ -79,4 +81,12 @@ public interface IBeekeepingLogic extends INbtWritable, INbtReadable {
* These positions are synced to the client from the server.
*/
List<BlockPos> getFlowerPositions();
default void readData(PacketBuffer data) throws IOException {
}
default void writeData(PacketBuffer data) {
}
}
@@ -20,5 +20,18 @@ public interface IHiveFrame {
*/
ItemStack frameUsed(IBeeHousing housing, ItemStack frame, IBee queen, int wear);
/**
* @param frame ItemStack containing the actual frame.
* @return the {@link IBeeModifier} for this frame.
* @since Forestry 5.5.1
*/
default IBeeModifier getBeeModifier(ItemStack frame) {
return getBeeModifier();
}
/**
* @deprecated since Forestry 5.5.1. Use {@link #getBeeModifier(ItemStack)}
*/
@Deprecated
IBeeModifier getBeeModifier();
}
@@ -12,6 +12,7 @@ import java.util.List;
import com.mojang.authlib.GameProfile;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IChromosome;
import forestry.api.genetics.IFruitFamily;
import forestry.api.genetics.ISpeciesRootPollinatable;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -101,4 +102,6 @@ public interface ITreeRoot extends ISpeciesRootPollinatable {
/* MUTATIONS */
@Override
List<ITreeMutation> getMutations(boolean shuffle);
Collection<IFruitProvider> getFruitProvidersForFruitFamily(IFruitFamily fruitFamily);
}
@@ -0,0 +1,13 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.core;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public interface IBlockPosPredicate {
boolean test(World world, BlockPos blockPos);
}
@@ -7,6 +7,7 @@ package forestry.api.farming;
import java.util.Collection;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
@@ -33,6 +34,8 @@ public interface IFarmLogic {
IFarmLogic setManual(boolean manual);
void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData);
@SideOnly(Side.CLIENT)
ResourceLocation getTextureMap();
@@ -11,6 +11,13 @@ import net.minecraft.item.ItemStack;
public interface IFarmRegistry {
/**
* Registers farming logic in registry under given identifier
* @param identifier Valid identifiers: farmArboreal farmWheat farmGourd farmInfernal farmPoales farmSucculentes farmVegetables farmShroom
* @param logic corresponding instance of logic
*/
void registerFarmLogic(String identifier, IFarmLogic logic);
/**
* Can be used to add IFarmables to some of the vanilla farm logics.
* <p>
@@ -5,10 +5,12 @@
******************************************************************************/
package forestry.api.genetics;
import java.util.Iterator;
import java.util.List;
import forestry.api.apiculture.IBee;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.core.IBlockPosPredicate;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
@@ -60,17 +62,38 @@ public interface IFlowerRegistry {
*/
boolean growFlower(String flowerType, World world, IIndividual individual, BlockPos pos);
/**
* Gets an iterator over the area a bee can travel from its beeHousing.
* Starts at the bee housing and spirals outward.
*
* @param beeHousing The bee housing that will help determine the size of the area to check.
* @param bee The bee that will help determine the size of the area to check.
* @return an iterator over the area a bee can travel from its beeHousing.
* @since Forestry 5.5.2
*/
Iterator<BlockPos.MutableBlockPos> getAreaIterator(IBeeHousing beeHousing, IBee bee);
/**
* Checks a single coordinate to see if it is an accepted flower.
* @since Forestry 5.5.2
*/
IBlockPosPredicate createAcceptedFlowerPredicate(String flowerType);
/**
* @param beeHousing The bee housing that will help determine the size of the area to check.
* @param bee The bee that will help determine the size of the area to check.
* @param flowerType See {@link forestry.api.apiculture.FlowerManager}.FlowerTypeXXX
* @param maxFlowers the largest number of flowers to check for before returning. Use 1 if you only need 1.
* @return the coordinates of nearby accepted flowers, with size from 0 to maxFlowers.
* @deprecated since Forestry 5.5.2. Use {@link #getAreaIterator(IBeeHousing, IBee)} and {@link #createAcceptedFlowerPredicate(String)}.
*/
@Deprecated
List<BlockPos> getAcceptedFlowerCoordinates(IBeeHousing beeHousing, IBee bee, String flowerType, int maxFlowers);
/**
* Checks a single coordinate to see if it is an accepted flower.
* @deprecated since Forestry 5.5.2. Use {@link #createAcceptedFlowerPredicate(String)}.
*/
@Deprecated
boolean isAcceptedFlower(String flowerType, World world, BlockPos pos);
}
@@ -38,8 +38,6 @@ import forestry.apiculture.network.packets.PacketBeeLogicActive;
import forestry.apiculture.network.packets.PacketBeeLogicActiveEntity;
import forestry.core.config.Constants;
import forestry.core.errors.EnumErrorCode;
import forestry.core.network.IStreamable;
import forestry.core.network.PacketBufferForestry;
import forestry.core.utils.Log;
import forestry.core.utils.NetworkUtil;
import net.minecraft.client.Minecraft;
@@ -48,13 +46,14 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BeekeepingLogic implements IBeekeepingLogic, IStreamable {
public class BeekeepingLogic implements IBeekeepingLogic {
private static final int totalBreedingTime = Constants.APIARY_BREEDING_TIME;
@@ -136,7 +135,7 @@ public class BeekeepingLogic implements IBeekeepingLogic, IStreamable {
}
@Override
public void writeData(PacketBufferForestry data) {
public void writeData(PacketBuffer data) {
data.writeBoolean(active);
if (active) {
data.writeItemStack(queenStack);
@@ -145,7 +144,7 @@ public class BeekeepingLogic implements IBeekeepingLogic, IStreamable {
}
@Override
public void readData(PacketBufferForestry data) throws IOException {
public void readData(PacketBuffer data) throws IOException {
boolean active = data.readBoolean();
setActive(active);
if (active) {
@@ -222,7 +221,8 @@ public class BeekeepingLogic implements IBeekeepingLogic, IStreamable {
errorLogic.setCondition(true, errorState);
}
boolean hasFlowers = hasFlowersCache.hasFlowers(queen, housing);
hasFlowersCache.update(queen, housing);
boolean hasFlowers = hasFlowersCache.hasFlowers();
boolean flowerCacheNeedsSync = hasFlowersCache.needsSync();
errorLogic.setCondition(!hasFlowers, EnumErrorCode.NO_FLOWER);
@@ -10,80 +10,92 @@
******************************************************************************/
package forestry.apiculture;
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import forestry.api.apiculture.BeeManager;
import forestry.api.apiculture.FlowerManager;
import forestry.api.apiculture.IBee;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.apiculture.IBeeModifier;
import forestry.api.core.INbtReadable;
import forestry.api.core.INbtWritable;
import forestry.api.core.IBlockPosPredicate;
import forestry.api.genetics.IFlowerProvider;
import forestry.core.network.IStreamable;
import forestry.core.network.PacketBufferForestry;
import forestry.core.utils.VectUtil;
import forestry.core.utils.TickHelper;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World;
public class HasFlowersCache implements INbtWritable, INbtReadable, IStreamable {
private static final String nbtKey = "hasFlowerCache";
private static final String nbtKeyFlowers = "flowers";
private static final String nbtKeyCooldown = "cooldown";
public class HasFlowersCache implements INbtWritable, INbtReadable {
private static final String NBT_KEY = "hasFlowerCache";
private static final String NBT_KEY_FLOWERS = "flowers";
private static final int FLOWER_CHECK_INTERVAL = 200;
private static final Random random = new Random();
private static final int flowerCheckInterval = 128;
private final TickHelper tickHelper = new TickHelper();
private final int flowerCheckTime = random.nextInt(flowerCheckInterval);
private List<BlockPos> flowerCoords = new ArrayList<>();
private int cooldown = 0;
@Nullable
private FlowerData flowerData;
private final List<BlockPos> flowerCoords = new ArrayList<>();
private boolean needsSync = false;
public boolean hasFlowers(IBee queen, IBeeHousing beeHousing) {
IFlowerProvider flowerProvider = queen.getGenome().getFlowerProvider();
String flowerType = flowerProvider.getFlowerType();
private static class FlowerData {
public final String flowerType;
public final IBlockPosPredicate flowerPredicate;
public Iterator<BlockPos.MutableBlockPos> areaIterator;
public FlowerData(IBee queen, IBeeHousing beeHousing) {
IFlowerProvider flowerProvider = queen.getGenome().getFlowerProvider();
this.flowerType = flowerProvider.getFlowerType();
this.flowerPredicate = FlowerManager.flowerRegistry.createAcceptedFlowerPredicate(flowerType);
this.areaIterator = FlowerManager.flowerRegistry.getAreaIterator(beeHousing, queen);
}
public void resetIterator(IBee queen, IBeeHousing beeHousing) {
this.areaIterator = FlowerManager.flowerRegistry.getAreaIterator(beeHousing, queen);
}
}
public void update(IBee queen, IBeeHousing beeHousing) {
if (flowerData == null) {
this.flowerData = new FlowerData(queen, beeHousing);
this.flowerCoords.clear();
}
World world = beeHousing.getWorldObj();
tickHelper.onTick();
if (!flowerCoords.isEmpty()) {
if (world.getTotalWorldTime() % flowerCheckInterval != flowerCheckTime) {
return true;
}
IBeeModifier beeModifier = BeeManager.beeRoot.createBeeHousingModifier(beeHousing);
BlockPos housingCoords = beeHousing.getCoordinates();
Vec3i genomeTerritory = queen.getGenome().getTerritory();
float housingModifier = beeModifier.getTerritoryModifier(queen.getGenome(), 1f);
Vec3i area = VectUtil.scale(genomeTerritory, housingModifier * 3.0f);
BlockPos min = VectUtil.scale(area, -0.5f).add(housingCoords);
BlockPos max = VectUtil.scale(area, 0.5f).add(housingCoords);
for (BlockPos flowerPos : flowerCoords) {
if (!isFlowerValid(world, flowerPos, flowerType, min, max)) {
cooldown = 0;
break;
if (!flowerCoords.isEmpty() && tickHelper.updateOnInterval(FLOWER_CHECK_INTERVAL)) {
Iterator<BlockPos> iterator = flowerCoords.iterator();
while (iterator.hasNext()) {
BlockPos flowerPos = iterator.next();
if (!flowerData.flowerPredicate.test(world, flowerPos) && world.isBlockLoaded(flowerPos)) {
iterator.remove();
needsSync = true;
}
}
}
if (cooldown <= 0) {
List<BlockPos> newFlowerCoords = FlowerManager.flowerRegistry.getAcceptedFlowerCoordinates(beeHousing, queen, flowerType, 5);
cooldown = PluginApiculture.ticksPerBeeWorkCycle;
if (!flowerCoords.equals(newFlowerCoords)) {
flowerCoords = newFlowerCoords;
needsSync = true;
}
} else {
cooldown--;
}
final int flowerCount = flowerCoords.size();
final int ticksPerCheck = 1 + (flowerCount * flowerCount);
if (tickHelper.updateOnInterval(ticksPerCheck)) {
if (flowerData.areaIterator.hasNext()) {
BlockPos.MutableBlockPos blockPos = flowerData.areaIterator.next();
if (flowerData.flowerPredicate.test(world, blockPos)) {
flowerCoords.add(blockPos.toImmutable());
needsSync = true;
}
} else {
flowerData.resetIterator(queen, beeHousing);
}
}
}
public boolean hasFlowers() {
return !flowerCoords.isEmpty();
}
@@ -95,35 +107,23 @@ public class HasFlowersCache implements INbtWritable, INbtReadable, IStreamable
public void clear() {
flowerCoords.clear();
cooldown = 0;
flowerData = null;
}
public List<BlockPos> getFlowerCoords() {
return Collections.unmodifiableList(flowerCoords);
}
private static boolean isFlowerValid(World world, BlockPos flowerCoords, String flowerType, BlockPos min, BlockPos max) {
if (!isFlowerCoordInRange(flowerCoords, min, max)) {
return false;
}
return FlowerManager.flowerRegistry.isAcceptedFlower(flowerType, world, flowerCoords);
}
private static boolean isFlowerCoordInRange(BlockPos flowerCoords, BlockPos min, BlockPos max) {
return flowerCoords.getX() >= min.getX() && flowerCoords.getX() <= max.getX() && flowerCoords.getY() >= min.getY() && flowerCoords.getY() <= max.getY() && flowerCoords.getZ() >= min.getZ() && flowerCoords.getZ() <= max.getZ();
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
if (!nbttagcompound.hasKey(nbtKey)) {
if (!nbttagcompound.hasKey(NBT_KEY)) {
return;
}
NBTTagCompound hasFlowerCacheNBT = nbttagcompound.getCompoundTag(nbtKey);
NBTTagCompound hasFlowerCacheNBT = nbttagcompound.getCompoundTag(NBT_KEY);
if (hasFlowerCacheNBT.hasKey(nbtKeyFlowers)) {
int[] flowersList = hasFlowerCacheNBT.getIntArray(nbtKeyFlowers);
if (hasFlowerCacheNBT.hasKey(NBT_KEY_FLOWERS)) {
int[] flowersList = hasFlowerCacheNBT.getIntArray(NBT_KEY_FLOWERS);
if (flowersList.length % 3 == 0) {
int flowerCount = flowersList.length / 3;
for (int i = 0; i < flowerCount; i++) {
@@ -133,8 +133,6 @@ public class HasFlowersCache implements INbtWritable, INbtReadable, IStreamable
needsSync = true;
}
}
cooldown = hasFlowerCacheNBT.getInteger(nbtKeyCooldown);
}
@Override
@@ -151,17 +149,14 @@ public class HasFlowersCache implements INbtWritable, INbtReadable, IStreamable
i++;
}
hasFlowerCacheNBT.setIntArray(nbtKeyFlowers, flowersList);
hasFlowerCacheNBT.setIntArray(NBT_KEY_FLOWERS, flowersList);
}
hasFlowerCacheNBT.setInteger(nbtKeyCooldown, cooldown);
nbttagcompound.setTag(nbtKey, hasFlowerCacheNBT);
nbttagcompound.setTag(NBT_KEY, hasFlowerCacheNBT);
return nbttagcompound;
}
@Override
public void writeData(PacketBufferForestry data) {
public void writeData(PacketBuffer data) {
int size = flowerCoords.size();
data.writeVarInt(size);
if (size > 0) {
@@ -173,8 +168,7 @@ public class HasFlowersCache implements INbtWritable, INbtReadable, IStreamable
}
}
@Override
public void readData(PacketBufferForestry data) throws IOException {
public void readData(PacketBuffer data) throws IOException {
flowerCoords.clear();
int size = data.readVarInt();
@@ -33,6 +33,7 @@ import net.minecraft.potion.PotionUtils;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.DimensionType;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.IChunkGenerator;
@@ -45,6 +46,8 @@ import net.minecraftforge.common.brewing.BrewingRecipeRegistry;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.event.FMLInterModComms.IMCMessage;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@@ -53,7 +56,6 @@ import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.registry.VillagerRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.registries.IForgeRegistry;
import forestry.Forestry;
import forestry.api.apiculture.BeeManager;
@@ -494,13 +496,14 @@ 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("comb." + m, new ItemStack(block, 1, m),
for(int blockCount = 0;blockCount < blocks.beeCombs.length;blockCount++){
BlockHoneyComb block = blocks.beeCombs[blockCount];
for(int blockMeta = 0;blockMeta < EnumHoneyComb.VALUES.length - blockCount * 16;blockMeta++){
int itemMeta = blockMeta + blockCount * 16;
RecipeUtil.addRecipe("comb." + itemMeta, new ItemStack(block, 1, blockMeta),
"###",
"###",
"###", '#', items.beeComb.get(EnumHoneyComb.get(i * 16 + m), 1));
"###", '#', items.beeComb.get(EnumHoneyComb.get(itemMeta), 1));
}
}
@@ -897,6 +900,14 @@ public class PluginApiculture extends BlankForestryPlugin {
return new SaveEventHandlerApiculture();
}
@Override
public void populateChunk(IChunkGenerator chunkGenerator, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGenerated) {
if(!world.provider.getDimensionType().equals(DimensionType.THE_END)) return;
if (Config.getBeehivesAmount() > 0.0) {
HiveDecorator.decorateHives(world, rand, chunkX, chunkZ);
}
}
@Override
public void decorateBiome(World world, Random rand, BlockPos pos) {
if (Config.getBeehivesAmount() > 0.0) {
@@ -0,0 +1,166 @@
/*******************************************************************************
* 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.apiculture;
import java.io.IOException;
import java.util.List;
import forestry.api.apiculture.IBee;
import forestry.api.apiculture.IBeekeepingLogic;
import forestry.api.genetics.IEffectData;
import forestry.apiculture.network.packets.PacketBeeLogicActive;
import forestry.apiculture.tiles.TileHive;
import forestry.core.utils.NetworkUtil;
import forestry.core.utils.TickHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class WorldgenBeekeepingLogic implements IBeekeepingLogic {
private final TileHive housing;
private IEffectData effectData[] = new IEffectData[2];
private final HasFlowersCache hasFlowersCache = new HasFlowersCache();
private final TickHelper tickHelper = new TickHelper();
// Client
private boolean active;
public WorldgenBeekeepingLogic(TileHive housing) {
this.housing = housing;
}
// / SAVING & LOADING
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
setActive(nbttagcompound.getBoolean("Active"));
hasFlowersCache.readFromNBT(nbttagcompound);
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setBoolean("Active", active);
hasFlowersCache.writeToNBT(nbttagcompound);
return nbttagcompound;
}
@Override
public void writeData(PacketBuffer data) {
data.writeBoolean(active);
if (active) {
hasFlowersCache.writeData(data);
}
}
@Override
public void readData(PacketBuffer data) throws IOException {
boolean active = data.readBoolean();
setActive(active);
if (active) {
hasFlowersCache.readData(data);
}
}
/* Activatable */
private void setActive(boolean active) {
if (this.active == active) {
return;
}
this.active = active;
syncToClient();
}
/* UPDATING */
@Override
public boolean canWork() {
tickHelper.onTick();
IBee queen = housing.getContainedBee();
hasFlowersCache.update(queen, housing);
if (tickHelper.updateOnInterval(200)) {
World world = housing.getWorldObj();
boolean canWork = (world.isDaytime() || queen.getGenome().getNeverSleeps()) &&
(!housing.isRaining() || queen.getGenome().getToleratesRain());
boolean flowerCacheNeedsSync = hasFlowersCache.needsSync();
if (active != canWork) {
setActive(canWork);
} else if (flowerCacheNeedsSync) {
syncToClient();
}
}
return active;
}
@Override
public void doWork() {
}
@Override
public void clearCachedValues() {
if (!housing.getWorldObj().isRemote) {
hasFlowersCache.clear();
canWork();
}
}
/* CLIENT */
@Override
public void syncToClient() {
World world = housing.getWorldObj();
if (world != null && !world.isRemote) {
NetworkUtil.sendNetworkPacket(new PacketBeeLogicActive(housing), housing.getCoordinates(), world);
}
}
@Override
public void syncToClient(EntityPlayerMP player) {
World world = housing.getWorldObj();
if (world != null && !world.isRemote) {
NetworkUtil.sendToPlayer(new PacketBeeLogicActive(housing), player);
}
}
@Override
public int getBeeProgressPercent() {
return 0;
}
@Override
@SideOnly(Side.CLIENT)
public boolean canDoBeeFX() {
return !Minecraft.getMinecraft().isGamePaused() && active;
}
@Override
@SideOnly(Side.CLIENT)
public void doBeeFX() {
IBee queen = housing.getContainedBee();
queen.doFX(effectData, housing);
}
@Override
public List<BlockPos> getFlowerPositions() {
return hasFlowersCache.getFlowerCoords();
}
}
@@ -13,8 +13,8 @@ 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.apiculture.items.ItemBlockHoneyComb;
import forestry.core.blocks.BlockBase;
import forestry.core.blocks.BlockRegistry;
import forestry.core.items.ItemBlockForestry;
@@ -33,23 +33,23 @@ public class BlockRegistryApiculture extends BlockRegistry {
public BlockRegistryApiculture() {
apiary = new BlockApiculture(BlockTypeApiculture.APIARY);
registerBlock(apiary, new ItemBlockForestry(apiary), "apiary");
registerBlock(apiary, new ItemBlockForestry<>(apiary), "apiary");
beeHouse = new BlockApiculture(BlockTypeApiculture.BEE_HOUSE);
registerBlock(beeHouse, new ItemBlockForestry(beeHouse), "bee_house");
registerBlock(beeHouse, new ItemBlockForestry<>(beeHouse), "bee_house");
beeChest = new BlockBase<>(BlockTypeApicultureTesr.APIARIST_CHEST, Material.WOOD);
registerBlock(beeChest, new ItemBlockForestry(beeChest), "bee_chest");
registerBlock(beeChest, new ItemBlockForestry<>(beeChest), "bee_chest");
beeChest.setCreativeTab(Tabs.tabApiculture);
beeChest.setHarvestLevel("axe", 0);
beehives = new BlockBeeHives();
registerBlock(beehives, new ItemBlockForestry(beehives), "beehives");
registerBlock(beehives, new ItemBlockForestry<>(beehives), "beehives");
candle = new BlockCandle();
registerBlock(candle, new ItemBlockCandle(candle), "candle");
stump = new BlockStump();
registerBlock(stump, new ItemBlockForestry(stump), "stump");
registerBlock(stump, new ItemBlockForestry<>(stump), "stump");
beeCombs = BlockHoneyComb.create();
for(int i = 0;i < beeCombs.length;i++){
@@ -59,7 +59,7 @@ public class BlockRegistryApiculture extends BlockRegistry {
alvearyBlockMap = BlockAlveary.create();
for (BlockAlveary block : alvearyBlockMap.values()) {
registerBlock(block, new ItemBlockForestry(block), "alveary." + block.getAlvearyType());
registerBlock(block, new ItemBlockForestry<>(block), "alveary." + block.getAlvearyType());
}
}
@@ -21,7 +21,7 @@ public class ApicultureJeiPlugin implements IModPlugin {
ISubtypeRegistry.ISubtypeInterpreter beeSubtypeInterpreter = itemStack -> {
IAlleleSpecies species = Genome.getSpeciesDirectly(BeeManager.beeRoot, itemStack);
return species == null ? null : species.getUID();
return species == null ? ISubtypeRegistry.ISubtypeInterpreter.NONE : species.getUID();
};
subtypeRegistry.registerSubtypeInterpreter(items.beeDroneGE, beeSubtypeInterpreter);
@@ -33,6 +33,7 @@ import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Tuple;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -89,8 +90,11 @@ public class EntityMinecartApiary extends EntityMinecartBeeHousingBase implement
beeModifiers.add(beeModifier);
for (IHiveFrame frame : inventory.getFrames()) {
beeModifiers.add(frame.getBeeModifier());
for (Tuple<IHiveFrame, ItemStack> frame : inventory.getFrames()) {
IHiveFrame hiveFrame = frame.getFirst();
ItemStack stack = frame.getSecond();
IBeeModifier beeModifier = hiveFrame.getBeeModifier(stack);
beeModifiers.add(beeModifier);
}
return beeModifiers;
@@ -36,6 +36,7 @@ import forestry.core.owner.OwnerHandler;
import forestry.core.tiles.IClimatised;
import forestry.core.utils.ClimateUtil;
import forestry.core.utils.NetworkUtil;
import forestry.core.utils.TickHelper;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.EntityDataManager;
@@ -47,12 +48,10 @@ import net.minecraft.world.biome.Biome;
public abstract class EntityMinecartBeeHousingBase extends EntityMinecartContainerForestry implements IBeeHousing, IOwnedTile, IGuiBeeHousingDelegate, IClimatised, IStreamableGui {
private static final DataParameter<Optional<GameProfile>> OWNER = EntityDataManager.createKey(EntityMinecartBeeHousingBase.class, GameProfileDataSerializer.INSTANCE);
private static final Random random = new Random();
private static final int beeFXInterval = 4;
private static final int pollenFXInterval = 50;
private final int beeFXTime = random.nextInt(beeFXInterval);
private final int pollenFXTime = random.nextInt(pollenFXInterval);
private final TickHelper tickHelper = new TickHelper();
private final IBeekeepingLogic beeLogic = BeeManager.beeRoot.createBeekeepingLogic(this);
private final IErrorLogic errorLogic = ForestryAPI.errorStateRegistry.createErrorLogic();
@@ -184,6 +183,7 @@ public abstract class EntityMinecartBeeHousingBase extends EntityMinecartContain
@Override
public void onUpdate() {
super.onUpdate();
tickHelper.onTick();
if (!world.isRemote) {
if (beeLogic.canWork()) {
beeLogic.doWork();
@@ -196,11 +196,11 @@ public abstract class EntityMinecartBeeHousingBase extends EntityMinecartContain
}
if (beeLogic.canDoBeeFX()) {
if (world.getTotalWorldTime() % beeFXInterval == beeFXTime) {
if (tickHelper.updateOnInterval(beeFXInterval)) {
beeLogic.doBeeFX();
}
if (world.getTotalWorldTime() % pollenFXInterval == pollenFXTime) {
if (tickHelper.updateOnInterval(pollenFXInterval)) {
TileBeeHousingBase.doPollenFX(world, posX - 0.5, posY - 0.1, posZ - 0.5);
}
}
@@ -12,6 +12,7 @@ package forestry.apiculture.flowers;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
@@ -27,11 +28,13 @@ import forestry.api.apiculture.IBee;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.apiculture.IBeeModifier;
import forestry.api.core.IBlockPosPredicate;
import forestry.api.genetics.IFlowerAcceptableRule;
import forestry.api.genetics.IFlowerGrowthHelper;
import forestry.api.genetics.IFlowerGrowthRule;
import forestry.api.genetics.IFlowerRegistry;
import forestry.api.genetics.IIndividual;
import forestry.core.utils.BlockStateSet;
import forestry.core.utils.VectUtil;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
@@ -43,7 +46,7 @@ import net.minecraft.world.World;
public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelper {
private final HashMultimap<String, IFlowerAcceptableRule> registeredRules;
private final HashMultimap<String, Block> acceptableBlocks;
private final HashMultimap<String, IBlockState> acceptableBlockStates;
private final Map<String, BlockStateSet> acceptableBlockStates;
private final HashMultimap<String, Flower> plantableFlowers;
private final ArrayListMultimap<String, IFlowerGrowthRule> growthRules;
@@ -52,7 +55,7 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
public FlowerRegistry() {
this.registeredRules = HashMultimap.create();
this.acceptableBlocks = HashMultimap.create();
this.acceptableBlockStates = HashMultimap.create();
this.acceptableBlockStates = new HashMap<>();
this.plantableFlowers = HashMultimap.create();
this.growthRules = ArrayListMultimap.create();
this.chances = new HashMap<>();
@@ -78,7 +81,7 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
throw new NullPointerException("Tried to register flower with null type. " + blockState);
}
this.acceptableBlockStates.get(flowerType).add(blockState);
this.getAcceptedBlockStates(flowerType).add(blockState);
}
}
@@ -113,7 +116,7 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
Set<Flower> flowers = this.plantableFlowers.get(flowerType);
flowers.add(newFlower);
Set<IBlockState> blocks = this.acceptableBlockStates.get(flowerType);
Set<IBlockState> blocks = this.getAcceptedBlockStates(flowerType);
blocks.add(blockState);
if (this.chances.containsKey(flowerType)) {
@@ -129,43 +132,16 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
}
@Override
public List<BlockPos> getAcceptedFlowerCoordinates(IBeeHousing beeHousing, IBee bee, String flowerType, int maxFlowers) {
Set<IFlowerAcceptableRule> acceptableRules = this.registeredRules.get(flowerType);
Set<IBlockState> acceptedBlockStates = this.acceptableBlockStates.get(flowerType);
Set<Block> acceptedBlocks = this.acceptableBlocks.get(flowerType);
World world = beeHousing.getWorldObj();
IBeeModifier beeModifier = BeeManager.beeRoot.createBeeHousingModifier(beeHousing);
Vec3i area = getArea(bee.getGenome(), beeModifier);
BlockPos minPos = beeHousing.getCoordinates().add(-area.getX() / 2, -area.getY() / 2, -area.getZ() / 2);
BlockPos maxPos = minPos.add(area);
List<BlockPos> flowerCoords = new ArrayList<>();
for (BlockPos.MutableBlockPos posBlock : VectUtil.getAllInBoxFromCenterMutable(world, minPos, beeHousing.getCoordinates(), maxPos)) {
if (!world.isBlockLoaded(posBlock)) {
continue;
}
IBlockState blockState = world.getBlockState(posBlock);
if (blockState.getBlock().isAir(blockState, world, posBlock)) {
continue;
}
for (IFlowerAcceptableRule acceptableRule : acceptableRules) {
if (acceptableRule.isAcceptableFlower(blockState, world, posBlock, flowerType)) {
flowerCoords.add(posBlock.toImmutable());
if (flowerCoords.size() >= maxFlowers) {
return flowerCoords;
}
}
}
if (isAcceptedFlower(blockState, acceptedBlocks, acceptedBlockStates)) {
flowerCoords.add(posBlock.toImmutable());
if (flowerCoords.size() >= maxFlowers) {
return flowerCoords;
}
World world = beeHousing.getWorldObj();
IBlockPosPredicate acceptedFlowerPredicate = createAcceptedFlowerPredicate(flowerType);
Iterator<BlockPos.MutableBlockPos> areaIterator = getAreaIterator(beeHousing, bee);
while (areaIterator.hasNext() && flowerCoords.size() < maxFlowers) {
BlockPos.MutableBlockPos pos = areaIterator.next();
if (acceptedFlowerPredicate.test(world, pos)) {
flowerCoords.add(pos.toImmutable());
}
}
@@ -173,6 +149,17 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
}
@Override
public Iterator<BlockPos.MutableBlockPos> getAreaIterator(IBeeHousing beeHousing, IBee bee) {
IBeeModifier beeModifier = BeeManager.beeRoot.createBeeHousingModifier(beeHousing);
Vec3i area = getArea(bee.getGenome(), beeModifier);
BlockPos minPos = beeHousing.getCoordinates().add(-area.getX() / 2, -area.getY() / 2, -area.getZ() / 2);
BlockPos maxPos = minPos.add(area);
World world = beeHousing.getWorldObj();
return VectUtil.getAllInBoxFromCenterMutable(world, minPos, beeHousing.getCoordinates(), maxPos);
}
@Override
@Deprecated
public boolean isAcceptedFlower(String flowerType, World world, BlockPos pos) {
if (!world.isBlockLoaded(pos)) {
return true; // Avoid actually checking until the flower's position is loaded.
@@ -185,12 +172,25 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
}
}
Set<IBlockState> acceptedBlockStates = this.acceptableBlockStates.get(flowerType);
Set<IBlockState> acceptedBlockStates = this.getAcceptedBlockStates(flowerType);
Set<Block> acceptedBlocks = this.acceptableBlocks.get(flowerType);
return isAcceptedFlower(blockState, acceptedBlocks, acceptedBlockStates);
}
private Set<IBlockState> getAcceptedBlockStates(String flowerType) {
return this.acceptableBlockStates.computeIfAbsent(flowerType, k -> new BlockStateSet());
}
@Override
public IBlockPosPredicate createAcceptedFlowerPredicate(String flowerType) {
Set<IFlowerAcceptableRule> acceptableRules = this.registeredRules.get(flowerType);
Set<IBlockState> acceptedBlockStates = this.getAcceptedBlockStates(flowerType);
Set<Block> acceptedBlocks = this.acceptableBlocks.get(flowerType);
return new AcceptedFlowerPredicate(flowerType, acceptableRules, acceptedBlocks, acceptedBlockStates);
}
private static boolean isAcceptedFlower(IBlockState blockState, Set<Block> acceptedBlocks, Set<IBlockState> acceptedBlockStates) {
Block block = blockState.getBlock();
return acceptedBlocks.contains(block) || acceptedBlockStates.contains(blockState);
@@ -255,4 +255,37 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
Flower flower = getRandomPlantableFlower(flowerType, world.rand);
return world.setBlockState(pos, flower.getBlockState());
}
private static class AcceptedFlowerPredicate implements IBlockPosPredicate {
private final String flowerType;
private final Set<IFlowerAcceptableRule> acceptableRules;
private final Set<Block> acceptedBlocks;
private final Set<IBlockState> acceptedBlockStates;
public AcceptedFlowerPredicate(String flowerType, Set<IFlowerAcceptableRule> acceptableRules, Set<Block> acceptedBlocks, Set<IBlockState> acceptedBlockStates) {
this.flowerType = flowerType;
this.acceptableRules = acceptableRules;
this.acceptedBlocks = acceptedBlocks;
this.acceptedBlockStates = acceptedBlockStates;
}
@Override
public boolean test(World world, BlockPos blockPos) {
if (world.isBlockLoaded(blockPos)) {
IBlockState blockState = world.getBlockState(blockPos);
if (!blockState.getBlock().isAir(blockState, world, blockPos)) {
for (IFlowerAcceptableRule acceptableRule : acceptableRules) {
if (acceptableRule.isAcceptableFlower(blockState, world, blockPos, flowerType)) {
return true;
}
}
if (isAcceptedFlower(blockState, acceptedBlocks, acceptedBlockStates)) {
return true;
}
}
}
return false;
}
}
}
@@ -22,6 +22,7 @@ import forestry.apiculture.InventoryBeeHousing;
import forestry.core.utils.SlotUtil;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Tuple;
public class InventoryApiary extends InventoryBeeHousing implements IApiaryInventory {
public static final int SLOT_FRAMES_1 = 9;
@@ -47,14 +48,15 @@ public class InventoryApiary extends InventoryBeeHousing implements IApiaryInven
super.isItemValidForSlot(slotIndex, itemStack);
}
public Collection<IHiveFrame> getFrames() {
Collection<IHiveFrame> hiveFrames = new ArrayList<>(SLOT_FRAMES_COUNT);
public Collection<Tuple<IHiveFrame, ItemStack>> getFrames() {
Collection<Tuple<IHiveFrame, ItemStack>> hiveFrames = new ArrayList<>(SLOT_FRAMES_COUNT);
for (int i = SLOT_FRAMES_1; i < SLOT_FRAMES_1 + SLOT_FRAMES_COUNT; i++) {
ItemStack stackInSlot = getStackInSlot(i);
Item itemInSlot = stackInSlot.getItem();
if (itemInSlot instanceof IHiveFrame) {
hiveFrames.add((IHiveFrame) itemInSlot);
IHiveFrame frame = (IHiveFrame) itemInSlot;
hiveFrames.add(new Tuple<>(frame, stackInSlot.copy()));
}
}
@@ -13,7 +13,6 @@ package forestry.apiculture.items;
import forestry.apiculture.blocks.BlockCandle;
import forestry.core.items.IColoredItem;
import forestry.core.items.ItemBlockForestry;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.relauncher.Side;
@@ -21,7 +20,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemBlockCandle extends ItemBlockForestry<BlockCandle> implements IColoredItem {
public ItemBlockCandle(Block block) {
public ItemBlockCandle(BlockCandle block) {
super(block);
}
@@ -3,14 +3,13 @@ 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) {
public ItemBlockHoneyComb(BlockHoneyComb block) {
super(block);
}
@@ -52,6 +52,11 @@ public class ItemHiveFrame extends ItemForestry implements IHiveFrame {
}
}
@Override
public IBeeModifier getBeeModifier(ItemStack frame) {
return beeModifier;
}
@Override
public IBeeModifier getBeeModifier() {
return beeModifier;
@@ -14,7 +14,6 @@ import java.io.IOException;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.apiculture.IBeekeepingLogic;
import forestry.apiculture.BeekeepingLogic;
import forestry.core.network.ForestryPacket;
import forestry.core.network.IForestryPacketClient;
import forestry.core.network.IForestryPacketHandlerClient;
@@ -28,11 +27,11 @@ import net.minecraftforge.fml.relauncher.SideOnly;
public class PacketBeeLogicActive extends ForestryPacket implements IForestryPacketClient {
private final BlockPos tilePos;
private final BeekeepingLogic beekeepingLogic;
private final IBeekeepingLogic beekeepingLogic;
public PacketBeeLogicActive(IBeeHousing tile) {
this.tilePos = tile.getCoordinates();
this.beekeepingLogic = (BeekeepingLogic) tile.getBeekeepingLogic();
this.beekeepingLogic = tile.getBeekeepingLogic();
}
@Override
@@ -55,9 +54,7 @@ public class PacketBeeLogicActive extends ForestryPacket implements IForestryPac
IBeeHousing beeHousing = TileUtil.getTile(player.world, tilePos, IBeeHousing.class);
if (beeHousing != null) {
IBeekeepingLogic beekeepingLogic = beeHousing.getBeekeepingLogic();
if (beekeepingLogic instanceof BeekeepingLogic) {
((BeekeepingLogic) beekeepingLogic).readData(data);
}
beekeepingLogic.readData(data);
}
}
}
@@ -29,6 +29,8 @@ import forestry.apiculture.inventory.InventoryApiary;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Tuple;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -58,8 +60,11 @@ public class TileApiary extends TileBeeHousingBase implements IApiary {
beeModifiers.add(beeModifier);
for (IHiveFrame frame : inventory.getFrames()) {
beeModifiers.add(frame.getBeeModifier());
for (Tuple<IHiveFrame, ItemStack> frame : inventory.getFrames()) {
IHiveFrame hiveFrame = frame.getFirst();
ItemStack stack = frame.getSecond();
IBeeModifier beeModifier = hiveFrame.getBeeModifier(stack);
beeModifiers.add(beeModifier);
}
return beeModifiers;
@@ -16,6 +16,8 @@ import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import forestry.apiculture.WorldgenBeekeepingLogic;
import forestry.core.utils.TickHelper;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
@@ -59,7 +61,6 @@ import forestry.api.core.EnumTemperature;
import forestry.api.core.ForestryAPI;
import forestry.api.core.IErrorLogic;
import forestry.api.genetics.IAllele;
import forestry.apiculture.BeekeepingLogic;
import forestry.apiculture.blocks.BlockBeeHives;
import forestry.apiculture.genetics.BeeDefinition;
import forestry.apiculture.genetics.alleles.AlleleEffect;
@@ -78,9 +79,10 @@ public class TileHive extends TileEntity implements ITickable, IHiveTile, IActiv
private final InventoryAdapter contained = new InventoryAdapter(2, "Contained");
private final HiveBeeHousingInventory inventory;
private final BeekeepingLogic beeLogic;
private final WorldgenBeekeepingLogic beeLogic;
private final IErrorLogic errorLogic;
private final Predicate<EntityLivingBase> beeTargetPredicate;
private final TickHelper tickHelper = new TickHelper();
@Nullable
private IBee containedBee = null;
@@ -96,7 +98,7 @@ public class TileHive extends TileEntity implements ITickable, IHiveTile, IActiv
public TileHive() {
inventory = new HiveBeeHousingInventory(this);
beeLogic = new BeekeepingLogic(this);
beeLogic = new WorldgenBeekeepingLogic(this);
errorLogic = ForestryAPI.errorStateRegistry.createErrorLogic();
beeTargetPredicate = new BeeTargetPredicate(this);
}
@@ -106,12 +108,13 @@ public class TileHive extends TileEntity implements ITickable, IHiveTile, IActiv
if (Config.generateBeehivesDebug) {
return;
}
tickHelper.onTick();
if (world.isRemote) {
if (!updatedLight && world.getWorldTime() % 100 == 0) {
if (!updatedLight && tickHelper.updateOnInterval(100)) {
updatedLight = world.checkLightFor(EnumSkyBlock.BLOCK, getPos());
}
if (active && world.rand.nextInt(4) == 0) {
if (active && tickHelper.updateOnInterval(4)) {
if (beeLogic.canDoBeeFX()) {
beeLogic.doBeeFX();
}
@@ -119,7 +122,7 @@ public class TileHive extends TileEntity implements ITickable, IHiveTile, IActiv
} else {
boolean canWork = beeLogic.canWork(); // must be called every tick to stay updated
if (world.rand.nextInt(angry ? 10 : 200) == 0) {
if (tickHelper.updateOnInterval(angry ? 10 : 200)) {
if (calmTime == 0) {
if (canWork) {
if(world.getWorldInfo().getDifficulty() != EnumDifficulty.PEACEFUL) {
@@ -142,6 +142,14 @@ public abstract class BlockForestryLog<T extends Enum<T> & IWoodType> extends Bl
return woodType.getHardness();
}
@Override
protected ItemStack getSilkTouchDrop(IBlockState state) {
ItemStack silkTouchDrop = super.getSilkTouchDrop(state);
int damage = this.damageDropped(state);
silkTouchDrop.setItemDamage(damage);
return silkTouchDrop;
}
/* PROPERTIES */
@Override
public final int getFireSpreadSpeed(IBlockAccess world, BlockPos pos, EnumFacing face) {
@@ -32,7 +32,6 @@ 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;
@@ -79,37 +78,37 @@ public class BlockRegistryArboriculture extends BlockRegistry {
// Wood blocks
logs = BlockArbLog.create(false);
for (BlockArbLog block : logs) {
registerBlock(block, new ItemBlockWood(block), "logs." + block.getBlockNumber());
registerBlock(block, new ItemBlockWood<>(block), "logs." + block.getBlockNumber());
registerOreDictWildcard(OreDictUtil.LOG_WOOD, block);
}
logsFireproof = BlockArbLog.create(true);
for (BlockArbLog block : logsFireproof) {
registerBlock(block, new ItemBlockWood(block), "logs.fireproof." + block.getBlockNumber());
registerBlock(block, new ItemBlockWood<>(block), "logs.fireproof." + block.getBlockNumber());
registerOreDictWildcard(OreDictUtil.LOG_WOOD, block);
}
logsVanillaFireproof = BlockFireproofVanillaLog.create();
for (BlockFireproofVanillaLog block : logsVanillaFireproof) {
registerBlock(block, new ItemBlockWood(block), "logs.vanilla.fireproof." + block.getBlockNumber());
registerBlock(block, new ItemBlockWood<>(block), "logs.vanilla.fireproof." + block.getBlockNumber());
registerOreDictWildcard(OreDictUtil.LOG_WOOD, block);
}
planks = BlockArbPlanks.create(false);
for (BlockArbPlanks block : planks) {
registerBlock(block, new ItemBlockWood(block), "planks." + block.getBlockNumber());
registerBlock(block, new ItemBlockWood<>(block), "planks." + block.getBlockNumber());
registerOreDictWildcard(OreDictUtil.PLANK_WOOD, block);
}
planksFireproof = BlockArbPlanks.create(true);
for (BlockArbPlanks block : planksFireproof) {
registerBlock(block, new ItemBlockWood(block), "planks.fireproof." + block.getBlockNumber());
registerBlock(block, new ItemBlockWood<>(block), "planks.fireproof." + block.getBlockNumber());
registerOreDictWildcard(OreDictUtil.PLANK_WOOD, block);
}
planksVanillaFireproof = BlockFireproofVanillaPlanks.create();
for (BlockFireproofVanillaPlanks block : planksVanillaFireproof) {
registerBlock(block, new ItemBlockWood(block), "planks.vanilla.fireproof." + block.getBlockNumber());
registerBlock(block, new ItemBlockWood<>(block), "planks.vanilla.fireproof." + block.getBlockNumber());
registerOreDictWildcard(OreDictUtil.PLANK_WOOD, block);
}
@@ -145,19 +144,19 @@ public class BlockRegistryArboriculture extends BlockRegistry {
fences = BlockArbFence.create(false);
for (BlockArbFence block : fences) {
registerBlock(block, new ItemBlockWood(block), "fences." + block.getBlockNumber());
registerBlock(block, new ItemBlockWood<>(block), "fences." + block.getBlockNumber());
registerOreDictWildcard(OreDictUtil.FENCE_WOOD, block);
}
fencesFireproof = BlockArbFence.create(true);
for (BlockArbFence block : fencesFireproof) {
registerBlock(block, new ItemBlockWood(block), "fences.fireproof." + block.getBlockNumber());
registerBlock(block, new ItemBlockWood<>(block), "fences.fireproof." + block.getBlockNumber());
registerOreDictWildcard(OreDictUtil.FENCE_WOOD, block);
}
fencesVanillaFireproof = BlockFireproofVanillaFence.create();
for (BlockFireproofVanillaFence block : fencesVanillaFireproof) {
registerBlock(block, new ItemBlockWood(block), "fences.vanilla.fireproof." + block.getBlockNumber());
registerBlock(block, new ItemBlockWood<>(block), "fences.vanilla.fireproof." + block.getBlockNumber());
registerOreDictWildcard(OreDictUtil.FENCE_WOOD, block);
}
@@ -165,12 +164,12 @@ public class BlockRegistryArboriculture extends BlockRegistry {
fenceGatesFireproof = new ArrayList<>();
for (EnumForestryWoodType woodType : EnumForestryWoodType.VALUES) {
BlockForestryFenceGate fenceGate = new BlockForestryFenceGate<>(false, woodType);
registerBlock(fenceGate, new ItemBlockWood(fenceGate), "fence.gates." + woodType);
registerBlock(fenceGate, new ItemBlockWood<>(fenceGate), "fence.gates." + woodType);
registerOreDictWildcard(OreDictUtil.FENCE_GATE_WOOD, fenceGate);
fenceGates.add(fenceGate);
BlockForestryFenceGate fenceGateFireproof = new BlockForestryFenceGate<>(true, woodType);
registerBlock(fenceGateFireproof, new ItemBlockWood(fenceGateFireproof), "fence.gates.fireproof." + woodType);
registerBlock(fenceGateFireproof, new ItemBlockWood<>(fenceGateFireproof), "fence.gates.fireproof." + woodType);
registerOreDictWildcard(OreDictUtil.FENCE_GATE_WOOD, fenceGateFireproof);
fenceGatesFireproof.add(fenceGateFireproof);
}
@@ -178,7 +177,7 @@ public class BlockRegistryArboriculture extends BlockRegistry {
fenceGatesVanillaFireproof = new ArrayList<>();
for (EnumVanillaWoodType woodType : EnumVanillaWoodType.VALUES) {
BlockForestryFenceGate fenceGateFireproof = new BlockForestryFenceGate<>(true, woodType);
registerBlock(fenceGateFireproof, new ItemBlockWood(fenceGateFireproof), "fence.gates.vanilla.fireproof." + woodType);
registerBlock(fenceGateFireproof, new ItemBlockWood<>(fenceGateFireproof), "fence.gates.vanilla.fireproof." + woodType);
registerOreDictWildcard(OreDictUtil.FENCE_GATE_WOOD, fenceGateFireproof);
fenceGatesFireproof.add(fenceGateFireproof);
}
@@ -190,7 +189,7 @@ public class BlockRegistryArboriculture extends BlockRegistry {
EnumForestryWoodType woodType = plank.getWoodType(meta);
BlockForestryStairs stair = new BlockForestryStairs<>(false, blockState, woodType);
registerBlock(stair, new ItemBlockWood(stair), "stairs." + woodType);
registerBlock(stair, new ItemBlockWood<>(stair), "stairs." + woodType);
registerOreDictWildcard(OreDictUtil.STAIR_WOOD, stair);
stairs.add(stair);
}
@@ -203,7 +202,7 @@ public class BlockRegistryArboriculture extends BlockRegistry {
EnumForestryWoodType woodType = plank.getWoodType(meta);
BlockForestryStairs stair = new BlockForestryStairs<>(true, blockState, woodType);
registerBlock(stair, new ItemBlockWood(stair), "stairs.fireproof." + woodType);
registerBlock(stair, new ItemBlockWood<>(stair), "stairs.fireproof." + woodType);
registerOreDictWildcard(OreDictUtil.STAIR_WOOD, stair);
stairsFireproof.add(stair);
}
@@ -216,7 +215,7 @@ public class BlockRegistryArboriculture extends BlockRegistry {
EnumVanillaWoodType woodType = plank.getWoodType(meta);
BlockForestryStairs stair = new BlockForestryStairs<>(true, blockState, woodType);
registerBlock(stair, new ItemBlockWood(stair), "stairs.vanilla.fireproof." + woodType);
registerBlock(stair, new ItemBlockWood<>(stair), "stairs.vanilla.fireproof." + woodType);
registerOreDictWildcard(OreDictUtil.STAIR_WOOD, stair);
stairsVanillaFireproof.add(stair);
}
@@ -233,7 +232,7 @@ public class BlockRegistryArboriculture extends BlockRegistry {
// Saplings
TreeDefinition.preInit();
saplingGE = new BlockSapling();
registerBlock(saplingGE, new ItemBlockForestry(saplingGE), "sapling_ge");
registerBlock(saplingGE, new ItemBlockForestry<>(saplingGE), "sapling_ge");
registerOreDictWildcard(OreDictUtil.TREE_SAPLING, saplingGE);
// Leaves
@@ -271,7 +270,7 @@ public class BlockRegistryArboriculture extends BlockRegistry {
}
charcoal = new BlockCharcoal();
ItemBlockForestry itemBlockCharcoal = new ItemBlockForestry(charcoal) {
ItemBlockForestry itemBlockCharcoal = new ItemBlockForestry<BlockCharcoal>(charcoal) {
@Override
public int getItemBurnTime(ItemStack itemStack) {
return 16000;
@@ -280,7 +279,7 @@ public class BlockRegistryArboriculture extends BlockRegistry {
registerBlock(charcoal, itemBlockCharcoal, "charcoal");
woodPile = new BlockWoodPile();
ItemBlockForestry itemBlockWoodPile = new ItemBlockForestry(woodPile) {
ItemBlockForestry itemBlockWoodPile = new ItemBlockForestry<BlockWoodPile>(woodPile) {
@Override
public int getItemBurnTime(ItemStack itemStack) {
return 1200;
@@ -289,11 +288,11 @@ public class BlockRegistryArboriculture extends BlockRegistry {
registerBlock(woodPile, itemBlockWoodPile, "wood_pile");
loam = new BlockLoam();
registerBlock(loam, new ItemBlockForestry(loam), "loam");
registerBlock(loam, new ItemBlockForestry<>(loam), "loam");
// Pods
AlleleFruits.registerAlleles();
MinecraftForge.EVENT_BUS.post(new AlleleRegisterEvent(IAlleleFruit.class));
MinecraftForge.EVENT_BUS.post(new AlleleRegisterEvent<>(IAlleleFruit.class));
podsMap = new HashMap<>();
for (BlockFruitPod pod : BlockFruitPod.create()) {
IAlleleFruit fruit = pod.getFruit();
@@ -303,7 +302,7 @@ public class BlockRegistryArboriculture extends BlockRegistry {
// Machines
treeChest = new BlockArboriculture(BlockTypeArboricultureTesr.ARB_CHEST);
registerBlock(treeChest, new ItemBlockForestry(treeChest), "tree_chest");
registerBlock(treeChest, new ItemBlockForestry<>(treeChest), "tree_chest");
}
public ItemStack getDecorativeLeaves(String speciesUid) {
@@ -152,7 +152,10 @@ public class BlockSapling extends BlockTreeContainer implements IGrowable, IStat
/* REMOVING */
@Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
ItemStack drop = getDrop(world, pos);
if (!drop.isEmpty()) {
drops.add(drop);
}
}
@Override
@@ -179,13 +182,21 @@ public class BlockSapling extends BlockTreeContainer implements IGrowable, IStat
if (world.isRemote) {
return;
}
TileSapling sapling = TileUtil.getTile(world, pos, TileSapling.class);
if (sapling != null && sapling.getTree() != null) {
ItemStack saplingStack = TreeManager.treeRoot.getMemberStack(sapling.getTree(), EnumGermlingType.SAPLING);
ItemStackUtil.dropItemStackAsEntity(saplingStack, world, pos);
ItemStack drop = getDrop(world, pos);
if (!drop.isEmpty()) {
ItemStackUtil.dropItemStackAsEntity(drop, world, pos);
}
}
private static ItemStack getDrop(IBlockAccess world, BlockPos pos) {
TileSapling sapling = TileUtil.getTile(world, pos, TileSapling.class);
if (sapling != null) {
ITree tree = sapling.getTree();
if (tree != null) {
return TreeManager.treeRoot.getMemberStack(tree, EnumGermlingType.SAPLING);
}
}
return ItemStack.EMPTY;
}
/* GROWNING */
@@ -14,9 +14,11 @@ import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import com.google.common.base.Preconditions;
@@ -26,6 +28,7 @@ import forestry.api.arboriculture.EnumTreeChromosome;
import forestry.api.arboriculture.IAlleleFruit;
import forestry.api.arboriculture.IAlleleTreeSpecies;
import forestry.api.arboriculture.IArboristTracker;
import forestry.api.arboriculture.IFruitProvider;
import forestry.api.arboriculture.ILeafTickHandler;
import forestry.api.arboriculture.ITree;
import forestry.api.arboriculture.ITreeGenome;
@@ -38,6 +41,7 @@ import forestry.api.genetics.IAllele;
import forestry.api.genetics.IAlyzerPlugin;
import forestry.api.genetics.ICheckPollinatable;
import forestry.api.genetics.IChromosomeType;
import forestry.api.genetics.IFruitFamily;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IMutation;
import forestry.api.genetics.IPollinatable;
@@ -75,6 +79,7 @@ public class TreeRoot extends SpeciesRoot implements ITreeRoot {
private static ITreekeepingMode activeTreekeepingMode;
public static final List<ITree> treeTemplates = new ArrayList<>();
private final Map<IFruitFamily, Collection<IFruitProvider>> providersForFamilies = new HashMap<>();
private final List<ITreekeepingMode> treekeepingModes = new ArrayList<>();
public TreeRoot() {
@@ -154,7 +159,6 @@ public class TreeRoot extends SpeciesRoot implements ITreeRoot {
@Override
@Nullable
public ITree getMember(ItemStack itemstack) {
itemstack = GeneticsUtil.convertToGeneticEquivalent(itemstack);
if (!isMember(itemstack) || itemstack.getTagCompound() == null) {
return null;
}
@@ -440,4 +444,18 @@ public class TreeRoot extends SpeciesRoot implements ITreeRoot {
}
}
@Override
public Collection<IFruitProvider> getFruitProvidersForFruitFamily(IFruitFamily fruitFamily) {
if (providersForFamilies.isEmpty()) {
@SuppressWarnings("unchecked")
Collection<IAlleleFruit> fruitAlleles = (Collection<IAlleleFruit>) (Object) AlleleManager.alleleRegistry.getRegisteredAlleles(EnumTreeChromosome.FRUITS);
for (IAlleleFruit alleleFruit : fruitAlleles) {
IFruitProvider fruitProvider = alleleFruit.getProvider();
Collection<IFruitProvider> fruitProviders = providersForFamilies.computeIfAbsent(fruitProvider.getFamily(), k -> new ArrayList<>());
fruitProviders.add(fruitProvider);
}
}
return providersForFamilies.computeIfAbsent(fruitFamily, k -> new ArrayList<>());
}
}
@@ -11,12 +11,16 @@
package forestry.arboriculture.genetics.alleles;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import forestry.api.arboriculture.EnumGermlingType;
import forestry.api.arboriculture.EnumTreeChromosome;
import forestry.api.arboriculture.IAlleleFruit;
import forestry.api.arboriculture.IAlleleTreeSpecies;
import forestry.api.arboriculture.IAlleleTreeSpeciesBuilder;
import forestry.api.arboriculture.IFruitProvider;
import forestry.api.arboriculture.IGermlingModelProvider;
import forestry.api.arboriculture.IGrowthProvider;
import forestry.api.arboriculture.ILeafProvider;
@@ -27,6 +31,7 @@ import forestry.api.arboriculture.IWoodProvider;
import forestry.api.arboriculture.TreeManager;
import forestry.api.core.IModelManager;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IClassification;
import forestry.api.genetics.IFruitFamily;
import forestry.arboriculture.genetics.ClimateGrowthProvider;
@@ -34,6 +39,7 @@ import forestry.arboriculture.genetics.LeafProvider;
import forestry.core.genetics.alleles.AlleleSpecies;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -196,6 +202,34 @@ public class AlleleTreeSpecies extends AlleleSpecies implements IAlleleTreeSpeci
return modID;
}
@Override
public float getResearchSuitability(ItemStack itemstack) {
if (itemstack.isEmpty()) {
return 0f;
}
List<IFruitFamily> suitableFruit = getSuitableFruit();
for (IFruitFamily fruitFamily : suitableFruit) {
Collection<IFruitProvider> fruitProviders = TreeManager.treeRoot.getFruitProvidersForFruitFamily(fruitFamily);
for (IFruitProvider fruitProvider : fruitProviders) {
Map<ItemStack, Float> products = fruitProvider.getProducts();
for (ItemStack stack : products.keySet()) {
if (stack.isItemEqual(itemstack)) {
return 1.0f;
}
}
Map<ItemStack, Float> specialtyChances = fruitProvider.getSpecialty();
for (ItemStack stack : specialtyChances.keySet()) {
if (stack.isItemEqual(itemstack)) {
return 1.0f;
}
}
}
}
return super.getResearchSuitability(itemstack);
}
@Override
public int compareTo(IAlleleTreeSpecies o) {
return 0;
@@ -1,20 +1,17 @@
package forestry.arboriculture.items;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import forestry.api.arboriculture.IFruitProvider;
import forestry.api.arboriculture.ITreeGenome;
import forestry.arboriculture.blocks.BlockDecorativeLeaves;
import forestry.arboriculture.genetics.TreeDefinition;
import forestry.core.items.IColoredItem;
import forestry.core.items.ItemBlockForestry;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemBlockDecorativeLeaves extends ItemBlockForestry<BlockDecorativeLeaves> implements IColoredItem {
public ItemBlockDecorativeLeaves(Block block) {
public ItemBlockDecorativeLeaves(BlockDecorativeLeaves block) {
super(block);
}
@@ -12,12 +12,10 @@ 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;
import forestry.core.items.ItemBlockForestry;
import forestry.core.utils.Translator;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
@@ -30,7 +28,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemBlockLeaves extends ItemBlockForestry<BlockAbstractLeaves> implements IColoredItem {
public ItemBlockLeaves(Block block) {
public ItemBlockLeaves(BlockAbstractLeaves block) {
super(block);
}
@@ -13,13 +13,12 @@ package forestry.arboriculture.items;
import forestry.api.arboriculture.IWoodType;
import forestry.arboriculture.IWoodTyped;
import forestry.arboriculture.WoodHelper;
import forestry.arboriculture.blocks.BlockArbSlab;
import forestry.core.items.ItemBlockForestry;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
public class ItemBlockWood<B extends Block & IWoodTyped> extends ItemBlockForestry<B> {
public ItemBlockWood(Block block) {
public ItemBlockWood(B block) {
super(block);
}
@@ -16,7 +16,7 @@ import net.minecraft.world.World;
public class ItemBlockWoodDoor extends ItemBlockWood<BlockArbDoor> {
public ItemBlockWoodDoor(Block block) {
public ItemBlockWoodDoor(BlockArbDoor block) {
super(block);
}
@@ -47,28 +47,35 @@ public class SimpleModel implements IModel {
private static final ModelResourceLocation MISSING = new ModelResourceLocation("builtin/missing", "missing");
private final List<Variant> variants;
private final List<ResourceLocation> locations = new ArrayList<>();
private final Set<ResourceLocation> textures = Sets.newHashSet();
private final List<IModel> models = new ArrayList<>();
private final ImmutableList<ResourceLocation> locations;
private final ImmutableSet<ResourceLocation> textures;
private final ImmutableList<IModel> models;
private final IModelState defaultState;
public SimpleModel(List<ResourceLocation> locations, List<IModel> models, List<Variant> variants,
IModelState defaultState) {
this.locations.addAll(locations);
this.models.addAll(models);
this.variants = variants;
this.locations = ImmutableList.copyOf(locations);
this.models = ImmutableList.copyOf(models);
this.defaultState = defaultState;
ImmutableSet.Builder<ResourceLocation> texturesBuilder = ImmutableSet.builder();
for (IModel model : models) {
textures.addAll(model.getTextures());
texturesBuilder.addAll(model.getTextures());
}
textures = texturesBuilder.build();
}
public SimpleModel(ResourceLocation parent, VariantList variants) throws Exception {
this.variants = variants.getVariantList();
ImmutableList.Builder<Pair<IModel, IModelState>> builder = ImmutableList.builder();
ImmutableList.Builder<IModel> modelsBuilder = ImmutableList.builder();
ImmutableList.Builder<ResourceLocation> locationsBuilder = ImmutableList.builder();
ImmutableSet.Builder<ResourceLocation> texturesBuilder = ImmutableSet.builder();
for (Variant variant : this.variants) {
ResourceLocation loc = variant.getModelLocation();
locations.add(loc);
locationsBuilder.add(loc);
IModel model;
if (loc.equals(MISSING)) {
@@ -81,19 +88,23 @@ public class SimpleModel implements IModel {
for (ResourceLocation location : model.getDependencies()) {
ModelLoaderRegistry.getModelOrMissing(location);
}
textures.addAll(model.getTextures());
texturesBuilder.addAll(model.getTextures());
models.add(model);
modelsBuilder.add(model);
builder.add(Pair.of(model, variant.getState()));
}
if (models.size() == 0) {
if (this.variants.size() == 0) {
IModel missing = ModelLoaderRegistry.getMissingModel();
models.add(missing);
modelsBuilder.add(missing);
builder.add(Pair.of(missing, TRSRTransformation.identity()));
}
defaultState = new MultiModelState(builder.build());
locations = locationsBuilder.build();
models = modelsBuilder.build();
textures = texturesBuilder.build();
}
@Override
@@ -129,6 +140,7 @@ public class SimpleModel implements IModel {
@Override
public IModel retexture(ImmutableMap<String, String> textures) {
List<ResourceLocation> locations = new ArrayList<>();
List<IModel> models = new ArrayList<>();
ImmutableList.Builder<Pair<IModel, IModelState>> builder = ImmutableList.builder();
for (Variant variant : this.variants) {
@@ -10,6 +10,7 @@
******************************************************************************/
package forestry.arboriculture.worldgen;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -18,6 +19,18 @@ import java.util.Map;
import java.util.Random;
import java.util.Set;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import forestry.api.arboriculture.EnumTreeChromosome;
import forestry.api.arboriculture.IAlleleTreeSpecies;
import forestry.api.arboriculture.IGrowthProvider;
@@ -28,22 +41,10 @@ import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAllele;
import forestry.arboriculture.commands.TreeGenHelper;
import forestry.core.utils.BlockUtil;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate.EventType;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate;
public class TreeDecorator {
private static final EventType EVENT_TYPE = EnumHelper.addEnum(EventType.class, "FORESTRY_TREES", new Class[0]);
private static final List<IAlleleTreeSpecies> SPECIES = new ArrayList<>();
private static final Map<Biome, Set<ITree>> biomeCache = new HashMap<>();
private static final Map<ResourceLocation, Set<ITree>> biomeCache = new HashMap<>();
@SubscribeEvent
public void decorateTrees(Decorate event) {
@@ -53,7 +54,7 @@ public class TreeDecorator {
}
public static void decorateTrees(World world, Random rand, int worldX, int worldZ) {
if(biomeCache.isEmpty()){
if (biomeCache.isEmpty()) {
generateBiomeCache(world, rand);
}
for (int tries = 0; tries < 4 + rand.nextInt(2); tries++) {
@@ -62,9 +63,9 @@ public class TreeDecorator {
BlockPos pos = new BlockPos(x, 0, z);
Biome biome = world.getBiome(pos);
Set<ITree> trees = biomeCache.get(biome);
for(ITree tree : trees){
Set<ITree> trees = biomeCache.computeIfAbsent(biome.getRegistryName(), k -> new HashSet<>());
for (ITree tree : trees) {
IAlleleTreeSpecies species = tree.getGenome().getPrimary();
if (species.getRarity() >= rand.nextFloat()) {
pos = getValidPos(world, x, z, tree);
@@ -83,15 +84,16 @@ public class TreeDecorator {
}
}
@Nullable
private static BlockPos getValidPos(World world, int x, int z, ITree tree){
// get to the ground
final BlockPos topPos = world.getHeight(new BlockPos(x, 0, z));
if (topPos.getY() == 0) {
return null;
}
final BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(topPos);
IBlockState blockState = world.getBlockState(pos);
IBlockState downState = world.getBlockState(pos.down());
while (BlockUtil.canReplace(blockState, world, pos)) {
@@ -124,14 +126,14 @@ public class TreeDecorator {
}
private static void generateBiomeCache(World world, Random rand){
for(IAlleleTreeSpecies species : getSpecies()){
for (IAlleleTreeSpecies species : getSpecies()) {
IAllele[] template = TreeManager.treeRoot.getTemplate(species);
ITreeGenome genome = TreeManager.treeRoot.templateAsGenome(template);
ITree tree = TreeManager.treeRoot.getTree(world, genome);
IGrowthProvider growthProvider = species.getGrowthProvider();
for(Biome biome : Biome.REGISTRY){
Set<ITree> trees = biomeCache.computeIfAbsent(biome, k -> new HashSet<>());
if(growthProvider.isBiomeValid(tree, biome)){
for (Biome biome : Biome.REGISTRY) {
Set<ITree> trees = biomeCache.computeIfAbsent(biome.getRegistryName(), k -> new HashSet<>());
if (growthProvider.isBiomeValid(tree, biome)) {
trees.add(tree);
}
}
@@ -49,15 +49,17 @@ public class WorldGenGreenheart extends WorldGenTree {
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn--, 0), girth, 1.5f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
WorldGenHelper.generateCylinderFromTreeStartPos(world, leaf, startPos.add(0, leafSpawn, 0), girth, 0.5f + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
// Add some smaller twigs below for flavour
for (int times = 0; times < height / 4; times++) {
int h = 10 + rand.nextInt(height - 10);
if (rand.nextBoolean() && h < height / 2) {
h = height / 2 + rand.nextInt(height / 2);
if (height > 10) {
// Add some smaller twigs below for flavour
for (int times = 0; times < height / 4; times++) {
int h = 10 + rand.nextInt(height - 10);
if (rand.nextBoolean() && h < height / 2) {
h = height / 2 + rand.nextInt(height / 2);
}
int x_off = -1 + rand.nextInt(3);
int y_off = -1 + rand.nextInt(3);
WorldGenHelper.generateSphere(world, startPos.add(x_off, h, y_off), 1 + rand.nextInt(1), leaf, WorldGenHelper.EnumReplaceMode.AIR);
}
int x_off = -1 + rand.nextInt(3);
int y_off = -1 + rand.nextInt(3);
WorldGenHelper.generateSphere(world, startPos.add(x_off, h, y_off), 1 + rand.nextInt(1), leaf, WorldGenHelper.EnumReplaceMode.AIR);
}
}
}
@@ -62,7 +62,16 @@ public class EventHandlerCore {
@SubscribeEvent
public void handlePlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
EntityPlayer player = event.player;
syncBreedingTrackers(player);
}
@SubscribeEvent
public void handlePlayerChangedDimension(PlayerEvent.PlayerChangedDimensionEvent event) {
EntityPlayer player = event.player;
syncBreedingTrackers(player);
}
private static void syncBreedingTrackers(EntityPlayer player) {
IAlleleRegistry alleleRegistry = AlleleManager.alleleRegistry;
Collection<ISpeciesRoot> speciesRoots = alleleRegistry.getSpeciesRoot().values();
for (ISpeciesRoot speciesRoot : speciesRoots) {
@@ -12,18 +12,26 @@ package forestry.core;
import com.google.common.collect.LinkedListMultimap;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import it.unimi.dsi.fastutil.ints.IntArraySet;
import it.unimi.dsi.fastutil.ints.IntSet;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.ChunkProviderServer;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraftforge.event.world.ChunkDataEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
import net.minecraftforge.fml.common.gameevent.TickEvent.WorldTickEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import forestry.core.config.Config;
import forestry.core.config.Constants;
@@ -34,6 +42,7 @@ public class TickHandlerCoreServer {
private final WorldGenerator worldGenerator;
private final LinkedListMultimap<Integer, ChunkCoords> chunkRegenList = LinkedListMultimap.create();
private final IntSet checkForRetrogen = new IntArraySet();
public TickHandlerCoreServer(WorldGenerator worldGenerator) {
this.worldGenerator = worldGenerator;
@@ -54,27 +63,49 @@ public class TickHandlerCoreServer {
}
}
if (Config.doRetrogen) {
World world = event.world;
if (Config.doRetrogen && event.world instanceof WorldServer) {
WorldServer world = (WorldServer) event.world;
int dimensionID = world.provider.getDimension();
List<ChunkCoords> chunkList = chunkRegenList.get(dimensionID);
if (!chunkList.isEmpty()) {
ChunkCoords coords = chunkList.get(0);
chunkList.remove(0);
// This bit is from FML's GameRegistry.generateWorld where the seed is constructed.
long worldSeed = world.getSeed();
Random random = new Random(worldSeed);
long xSeed = random.nextLong() >> 2 + 1L;
long zSeed = random.nextLong() >> 2 + 1L;
random.setSeed(xSeed * coords.x + zSeed * coords.z ^ worldSeed);
worldGenerator.retroGen(random, coords.x, coords.z, world);
if (checkForRetrogen.contains(dimensionID)) {
List<ChunkCoords> chunkList = chunkRegenList.get(dimensionID);
Iterator<ChunkCoords> iterator = chunkList.iterator();
while (iterator.hasNext()) {
ChunkCoords coords = iterator.next();
if (canDecorate(world, coords)) {
iterator.remove();
Random random = getRetrogenRandom(world, coords);
worldGenerator.retroGen(random, coords.x, coords.z, world);
}
}
checkForRetrogen.remove(dimensionID);
}
}
}
/**
* This is from {@link GameRegistry#generateWorld(int, int, World, IChunkGenerator, IChunkProvider)} where the seed is constructed.
*/
private static Random getRetrogenRandom(World world, ChunkCoords coords) {
long worldSeed = world.getSeed();
Random random = new Random(worldSeed);
long xSeed = random.nextLong() >> 2 + 1L;
long zSeed = random.nextLong() >> 2 + 1L;
random.setSeed(xSeed * coords.x + zSeed * coords.z ^ worldSeed);
return random;
}
private static boolean canDecorate(WorldServer server, ChunkCoords chunkCoords) {
ChunkProviderServer chunkProvider = server.getChunkProvider();
for (int x = 0; x <= 1; x++) {
for (int z = 0; z <= 1; z++) {
if (!chunkProvider.chunkExists(chunkCoords.x + x, chunkCoords.z + z)) {
return false;
}
}
}
return true;
}
@SubscribeEvent
public void chunkSaveEventHandler(ChunkDataEvent.Save event) {
NBTTagCompound tag = new NBTTagCompound();
@@ -94,6 +125,7 @@ public class TickHandlerCoreServer {
if (!tag.hasKey("retrogen") || Config.forceRetrogen) {
ChunkCoords coords = new ChunkCoords(event.getChunk());
chunkRegenList.put(coords.dimension, coords);
checkForRetrogen.add(coords.dimension);
}
}
}
@@ -29,7 +29,7 @@ public class BlockRegistryCore extends BlockRegistry {
public BlockRegistryCore() {
analyzer = new BlockCore(BlockTypeCoreTesr.ANALYZER);
registerBlock(analyzer, new ItemBlockForestry(analyzer), "analyzer");
registerBlock(analyzer, new ItemBlockForestry<>(analyzer), "analyzer");
escritoire = new BlockCore(BlockTypeCoreTesr.ESCRITOIRE);
registerBlock(escritoire, new ItemBlockForestry<>(escritoire), "escritoire");
@@ -43,14 +43,14 @@ public class BlockRegistryCore extends BlockRegistry {
humus.setHarvestLevel("shovel", 0);
resources = new BlockResourceOre();
registerBlock(resources, new ItemBlockForestry(resources), "resources");
registerBlock(resources, new ItemBlockForestry<>(resources), "resources");
resources.setHarvestLevel("pickaxe", 1);
OreDictionary.registerOre(OreDictUtil.ORE_APATITE, resources.get(EnumResourceType.APATITE, 1));
OreDictionary.registerOre(OreDictUtil.ORE_COPPER, resources.get(EnumResourceType.COPPER, 1));
OreDictionary.registerOre(OreDictUtil.ORE_TIN, resources.get(EnumResourceType.TIN, 1));
BlockResourceStorage resourceStorage = new BlockResourceStorage();
registerBlock(resourceStorage, new ItemBlockForestry(resourceStorage), "resource_storage");
registerBlock(resourceStorage, new ItemBlockForestry<>(resourceStorage), "resource_storage");
resourceStorage.setHarvestLevel("pickaxe", 0);
resourceStorageApatite = resourceStorage.get(EnumResourceType.APATITE);
@@ -29,6 +29,7 @@ public class Circuits {
public static ICircuit farmOrchardManual;
public static ICircuit farmRubberManual;
public static ICircuit farmEnderManaged;
public static ICircuit farmOrchidManaged;
public static ICircuit machineSpeedUpgrade1;
public static ICircuit machineSpeedUpgrade2;
public static ICircuit machineEfficiencyUpgrade1;
@@ -92,6 +92,7 @@ public class Config {
public static int farmSize = 2;
public static boolean squareFarms = false;
private static boolean enableExUtilEnderLily = true;
private static boolean enableExUtilRedOrchid = true;
private static boolean enableMagicalCropsSupport = true;
// Mail
@@ -131,6 +132,8 @@ public class Config {
return enableExUtilEnderLily;
}
public static boolean isExUtilRedOrchidEnabled() { return enableExUtilRedOrchid; }
public static boolean isMagicalCropsSupportEnabled() {
return enableMagicalCropsSupport;
}
@@ -241,6 +244,7 @@ public class Config {
farmSize = configCommon.getIntLocalized("tweaks.farms", "size", farmSize, 1, 3);
squareFarms = configCommon.getBooleanLocalized("tweaks.farms", "square", squareFarms);
enableExUtilEnderLily = configCommon.getBooleanLocalized("tweaks.farms", "enderlily", enableExUtilEnderLily);
enableExUtilRedOrchid = configCommon.getBooleanLocalized("tweaks.farms", "redorchid", enableExUtilRedOrchid);
enableMagicalCropsSupport = configCommon.getBooleanLocalized("tweaks.farms", "magicalcrops", enableMagicalCropsSupport);
String[] availableStructures = new String[]{"alveary3x3", "farm3x3", "farm3x4", "farm3x5", "farm4x4", "farm5x5"};
@@ -12,11 +12,13 @@ package forestry.core.inventory;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IIndividual;
import forestry.core.tiles.EscritoireGame;
import forestry.core.tiles.TileEscritoire;
import forestry.core.utils.GeneticsUtil;
import forestry.core.utils.SlotUtil;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
public class InventoryEscritoire extends InventoryAdapterTile<TileEscritoire> {
public static final short SLOT_ANALYZE = 0;
@@ -79,8 +81,10 @@ public class InventoryEscritoire extends InventoryAdapterTile<TileEscritoire> {
super.setInventorySlotContents(SLOT_ANALYZE, ersatz);
}
}
if (!tile.getWorld().isRemote) {
tile.getGame().initialize(getStackInSlot(SLOT_ANALYZE));
World world = tile.getWorld();
if (world != null && !world.isRemote) {
EscritoireGame game = tile.getGame();
game.initialize(getStackInSlot(SLOT_ANALYZE));
}
}
}
@@ -26,7 +26,8 @@ public enum EnumElectronTube implements ItemOverlay.IOverlayInfo {
EMERALD(new Color(0x00CC41)),
APATITE(new Color(0x579CD9)),
LAPIS(new Color(0x1c57c6)),
ENDER(new Color(0x33adad), new Color(0x255661));
ENDER(new Color(0x33adad), new Color(0x255661)),
ORCHID(new Color(0x820208), new Color(0xc64f3f));
public static final EnumElectronTube[] VALUES = values();
@@ -13,6 +13,11 @@ package forestry.core.items;
import javax.annotation.Nullable;
import java.util.List;
import forestry.core.blocks.IBlockRotatable;
import forestry.core.blocks.IBlockWithMeta;
import forestry.core.tiles.TileForestry;
import forestry.core.tiles.TileUtil;
import forestry.core.utils.ItemTooltipUtil;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.util.ITooltipFlag;
@@ -22,19 +27,12 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import forestry.core.blocks.IBlockRotatable;
import forestry.core.blocks.IBlockWithMeta;
import forestry.core.tiles.TileForestry;
import forestry.core.tiles.TileUtil;
import forestry.core.utils.ItemTooltipUtil;
public class ItemBlockForestry<B extends Block> extends ItemBlock {
public ItemBlockForestry(Block block) {
public ItemBlockForestry(B block) {
super(block);
setMaxDamage(0);
setHasSubtypes(true);
@@ -25,6 +25,7 @@ import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -10,8 +10,6 @@
******************************************************************************/
package forestry.core.models;
import com.google.common.base.Preconditions;
import javax.annotation.Nullable;
import javax.vecmath.Matrix4f;
import java.util.ArrayList;
@@ -39,11 +37,12 @@ import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.model.IModel;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.client.model.PerspectiveMapWrapper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import forestry.core.items.ItemCrated;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.Log;
import forestry.core.utils.ModelUtil;
import forestry.storage.PluginStorage;
@@ -107,8 +106,16 @@ public class ModelCrate extends BlankModel {
@Override
public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity) {
ItemCrated crated = (ItemCrated) stack.getItem();
ResourceLocation itemName = ItemStackUtil.getItemNameFromRegistry(crated);
Preconditions.checkNotNull(itemName);
ResourceLocation itemName = crated.getRegistryName();
if(itemName == null){
IBakedModel baseCrateModel = cache.get("base");
if(baseCrateModel == null){
baseCrateModel = ModelUtil.getModel(new ItemStack(PluginStorage.getItems().crate, 1, 1));
baseCrateModel = ForgeHooksClient.handleCameraTransforms(baseCrateModel, TransformType.GROUND, false);
}
Log.error("Failed to load the model of the create item: {}, please report this to the authors of forestry.", itemName);
return baseCrateModel;
}
String crateUID = itemName.getResourcePath();
IBakedModel model = cache.get(crateUID);
if (model == null) {
@@ -68,32 +68,30 @@ public class ParticleRender {
int color = genome.getPrimary().getSpriteColour(0);
if (!flowerPositions.isEmpty()) {
int randomInt = world.rand.nextInt(100);
int randomInt = world.rand.nextInt(100);
if (housing instanceof IHiveTile) {
if (((IHiveTile) housing).isAngry() || randomInt >= 85) {
List<EntityLivingBase> entitiesInRange = AlleleEffect.getEntitiesInRange(genome, housing, EntityLivingBase.class);
if (!entitiesInRange.isEmpty()) {
EntityLivingBase entity = entitiesInRange.get(world.rand.nextInt(entitiesInRange.size()));
Particle particle = new ParticleBeeTargetEntity(world, particleStart, entity, color);
effectRenderer.addEffect(particle);
return;
}
if (housing instanceof IHiveTile) {
if (((IHiveTile) housing).isAngry() || randomInt >= 85) {
List<EntityLivingBase> entitiesInRange = AlleleEffect.getEntitiesInRange(genome, housing, EntityLivingBase.class);
if (!entitiesInRange.isEmpty()) {
EntityLivingBase entity = entitiesInRange.get(world.rand.nextInt(entitiesInRange.size()));
Particle particle = new ParticleBeeTargetEntity(world, particleStart, entity, color);
effectRenderer.addEffect(particle);
return;
}
}
}
if (randomInt < 75) {
BlockPos destination = flowerPositions.get(world.rand.nextInt(flowerPositions.size()));
Particle particle = new ParticleBeeRoundTrip(world, particleStart, destination, color);
effectRenderer.addEffect(particle);
} else {
Vec3i area = AlleleEffect.getModifiedArea(genome, housing);
Vec3i offset = housing.getCoordinates().add(-area.getX() / 2, -area.getY() / 4, -area.getZ() / 2);
BlockPos destination = VectUtil.getRandomPositionInArea(world.rand, area).add(offset);
Particle particle = new ParticleBeeExplore(world, particleStart, destination, color);
effectRenderer.addEffect(particle);
}
if (randomInt < 75 && !flowerPositions.isEmpty()) {
BlockPos destination = flowerPositions.get(world.rand.nextInt(flowerPositions.size()));
Particle particle = new ParticleBeeRoundTrip(world, particleStart, destination, color);
effectRenderer.addEffect(particle);
} else {
Vec3i area = AlleleEffect.getModifiedArea(genome, housing);
Vec3i offset = housing.getCoordinates().add(-area.getX() / 2, -area.getY() / 4, -area.getZ() / 2);
BlockPos destination = VectUtil.getRandomPositionInArea(world.rand, area).add(offset);
Particle particle = new ParticleBeeExplore(world, particleStart, destination, color);
effectRenderer.addEffect(particle);
}
}
@@ -97,6 +97,7 @@ public class EscritoireGame implements INbtWritable, INbtReadable, IStreamable {
/* INTERACTION */
public void initialize(ItemStack specimen) {
reset();
if (gameBoard.initialize(specimen)) {
status = Status.PLAYING;
bountyLevel = BOUNTY_MAX;
@@ -27,6 +27,7 @@ import forestry.core.network.PacketBufferForestry;
import forestry.core.network.packets.PacketTileStream;
import forestry.core.utils.NBTUtilForestry;
import forestry.core.utils.NetworkUtil;
import forestry.core.utils.TickHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
@@ -48,14 +49,12 @@ import net.minecraftforge.items.wrapper.SidedInvWrapper;
//@Optional.Interface(iface = "buildcraft.api.statements.ITriggerProvider", modid = "BuildCraftAPI|statements")
public abstract class TileForestry extends TileEntity implements IStreamable, IErrorLogicSource, ISidedInventory, IFilterSlotDelegate, ITitled, ILocatable, IGuiHandlerTile, ITickable {
private static final Random rand = new Random();
private final ErrorLogic errorHandler = new ErrorLogic();
private final AdjacentTileCache tileCache = new AdjacentTileCache(this);
private IInventoryAdapter inventory = FakeInventoryAdapter.instance();
private int tickCount = rand.nextInt(256);
private final TickHelper tickHelper = new TickHelper();
private boolean needsNetworkUpdate = false;
protected AdjacentTileCache getTileCache() {
@@ -81,7 +80,7 @@ public abstract class TileForestry extends TileEntity implements IStreamable, IE
// / UPDATING
@Override
public final void update() {
tickCount++;
tickHelper.onTick();
if (!world.isRemote) {
updateServerSide();
@@ -103,7 +102,7 @@ public abstract class TileForestry extends TileEntity implements IStreamable, IE
}
protected final boolean updateOnInterval(int tickInterval) {
return tickCount % tickInterval == 0;
return tickHelper.updateOnInterval(tickInterval);
}
// / SAVING & LOADING
@@ -0,0 +1,63 @@
package forestry.core.utils;
import java.util.AbstractSet;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
/**
* A set with fast {@link #contains(Object)} for IBlockState
*/
public class BlockStateSet extends AbstractSet<IBlockState> {
private final Set<IBlockState> blockStates = new HashSet<>();
private final Map<Block, Integer> blocks = new IdentityHashMap<>();
@Override
public boolean add(IBlockState blockState) {
Block block = blockState.getBlock();
Integer count = blocks.getOrDefault(block, 0);
blocks.put(block, count + 1);
return blockStates.add(blockState);
}
@Override
public boolean remove(Object o) {
IBlockState blockState = (IBlockState) o;
Block block = blockState.getBlock();
Integer count = blocks.getOrDefault(block, 0);
if (count > 0) {
blocks.put(block, count - 1);
} else {
blocks.remove(block);
}
return blockStates.remove(blockState);
}
@Override
public boolean contains(Object o) {
IBlockState blockState = (IBlockState) o;
Block block = blockState.getBlock();
return blocks.containsKey(block) && blockStates.contains(blockState);
}
@Override
public void clear() {
blockStates.clear();
blocks.clear();
}
@Override
public Iterator<IBlockState> iterator() {
return blockStates.iterator();
}
@Override
public int size() {
return blockStates.size();
}
}
@@ -12,12 +12,6 @@ package forestry.core.utils;
import javax.annotation.Nullable;
import forestry.api.core.ForestryAPI;
import forestry.core.circuits.ISocketable;
import forestry.core.inventory.ItemHandlerInventoryManipulator;
import forestry.core.inventory.StandardStackFilters;
import forestry.core.tiles.AdjacentTileCache;
import forestry.plugins.ForestryPluginUids;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
@@ -28,10 +22,19 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.fml.common.Optional;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.fml.common.Optional;
import forestry.api.core.ForestryAPI;
import forestry.core.circuits.ISocketable;
import forestry.core.inventory.ItemHandlerInventoryManipulator;
import forestry.core.inventory.StandardStackFilters;
import forestry.core.tiles.AdjacentTileCache;
import forestry.plugins.ForestryPluginUids;
public abstract class InventoryUtil {
/**
* Attempts to move an ItemStack from one inventory to another.
@@ -277,7 +280,7 @@ public abstract class InventoryUtil {
for (int j = 0; j < inventory.getSizeInventory(); j++) {
ItemStack stackInSlot = inventory.getStackInSlot(j);
if (!stackInSlot.isEmpty()) {
if (ItemStackUtil.isCraftingEquivalent(stackInSlot, stackToRemove, oreDictOfStack, craftingTools)) {
if (ItemStackUtil.isCraftingEquivalent(stackToRemove, stackInSlot, oreDictOfStack, craftingTools)) {
ItemStack removed = inventory.decrStackSize(j, stackToRemove.getCount());
stackToRemove.shrink(removed.getCount());
@@ -67,6 +67,26 @@ public abstract class PlayerUtil {
return player;
}
/**
* Get a fake player for a given World and GameProfile.
* Do not store references to the return value, to prevent worlds staying in memory.
*/
@Nullable
public static EntityPlayer getFakePlayer(World world, @Nullable GameProfile profile) {
if (profile == null || profile.getName() == null) {
if (world instanceof WorldServer) {
return FakePlayerFactory.getMinecraft((WorldServer) world);
} else {
return null;
}
}
if (world instanceof WorldServer) {
return FakePlayerFactory.get((WorldServer) world, profile);
}
return null;
}
public static void writeGameProfile(NBTTagCompound tagCompound, GameProfile profile) {
if (!StringUtils.isNullOrEmpty(profile.getName())) {
tagCompound.setString("Name", profile.getName());
@@ -0,0 +1,16 @@
package forestry.core.utils;
import java.util.Random;
public final class TickHelper {
private static final Random rand = new Random();
private int tickCount = rand.nextInt(2048);
public void onTick() {
tickCount++;
}
public boolean updateOnInterval(int tickInterval) {
return tickCount % tickInterval == 0;
}
}
@@ -11,6 +11,7 @@
package forestry.core.utils;
import javax.annotation.Nullable;
import java.util.Iterator;
import java.util.Random;
import com.google.common.collect.AbstractIterator;
@@ -57,11 +58,11 @@ public final class VectUtil {
}
}
public static Iterable<BlockPos.MutableBlockPos> getAllInBoxFromCenterMutable(World world, final BlockPos from, final BlockPos center, final BlockPos to) {
public static Iterator<BlockPos.MutableBlockPos> getAllInBoxFromCenterMutable(World world, final BlockPos from, final BlockPos center, final BlockPos to) {
final BlockPos minPos = new BlockPos(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()), Math.min(from.getZ(), to.getZ()));
final BlockPos maxPos = new BlockPos(Math.max(from.getX(), to.getX()), Math.max(from.getY(), to.getY()), Math.max(from.getZ(), to.getZ()));
return () -> new MutableBlockPosSpiralIterator(world, center, maxPos, minPos);
return new MutableBlockPosSpiralIterator(world, center, maxPos, minPos);
}
private static class MutableBlockPosSpiralIterator extends AbstractIterator<BlockPos.MutableBlockPos> {
@@ -325,6 +325,12 @@ public class PluginFactory extends BlankForestryPlugin {
"XXX",
'#', new ItemStack(Items.ENDER_EYE, 1, 0),
'X', new ItemStack(Blocks.END_STONE, 1, 0)});
RecipeManagers.fabricatorManager.addRecipe(ItemStack.EMPTY, Fluids.GLASS.getFluid(500), electronTube.get(EnumElectronTube.ORCHID, 4), new Object[]{
" X ",
"#X#",
"XXX",
'#', new ItemStack(Items.REPEATER, 1, 0),
'X', new ItemStack(Blocks.REDSTONE_ORE, 1, 0)});
String[] dyes = {"dyeBlack", "dyeRed", "dyeGreen", "dyeBrown", "dyeBlue", "dyePurple", "dyeCyan", "dyeLightGray", "dyeGray", "dyePink", "dyeLime",
"dyeYellow", "dyeLightBlue", "dyeMagenta", "dyeOrange", "dyeWhite"};
@@ -30,28 +30,28 @@ public class BlockRegistryFactory extends BlockRegistry {
public BlockRegistryFactory() {
bottler = new BlockFactoryTESR(BlockTypeFactoryTesr.BOTTLER);
registerBlock(bottler, new ItemBlockForestry(bottler), "bottler");
registerBlock(bottler, new ItemBlockForestry<>(bottler), "bottler");
carpenter = new BlockFactoryTESR(BlockTypeFactoryTesr.CARPENTER);
registerBlock(carpenter, new ItemBlockForestry(carpenter), "carpenter");
registerBlock(carpenter, new ItemBlockForestry<>(carpenter), "carpenter");
centrifuge = new BlockFactoryTESR(BlockTypeFactoryTesr.CENTRIFUGE);
registerBlock(centrifuge, new ItemBlockForestry(centrifuge), "centrifuge");
registerBlock(centrifuge, new ItemBlockForestry<>(centrifuge), "centrifuge");
fermenter = new BlockFactoryTESR(BlockTypeFactoryTesr.FERMENTER);
registerBlock(fermenter, new ItemBlockForestry(fermenter), "fermenter");
registerBlock(fermenter, new ItemBlockForestry<>(fermenter), "fermenter");
moistener = new BlockFactoryTESR(BlockTypeFactoryTesr.MOISTENER);
registerBlock(moistener, new ItemBlockForestry(moistener), "moistener");
registerBlock(moistener, new ItemBlockForestry<>(moistener), "moistener");
squeezer = new BlockFactoryTESR(BlockTypeFactoryTesr.SQUEEZER);
registerBlock(squeezer, new ItemBlockForestry(squeezer), "squeezer");
registerBlock(squeezer, new ItemBlockForestry<>(squeezer), "squeezer");
still = new BlockFactoryTESR(BlockTypeFactoryTesr.STILL);
registerBlock(still, new ItemBlockForestry(still), "still");
registerBlock(still, new ItemBlockForestry<>(still), "still");
rainmaker = new BlockFactoryTESR(BlockTypeFactoryTesr.RAINMAKER);
registerBlock(rainmaker, new ItemBlockForestry(rainmaker), "rainmaker");
registerBlock(rainmaker, new ItemBlockForestry<>(rainmaker), "rainmaker");
fabricator = new BlockFactoryPlain(BlockTypeFactoryPlain.FABRICATOR);
registerBlock(fabricator, new ItemBlockNBT(fabricator), "fabricator");
@@ -24,9 +24,6 @@ import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.registries.ForgeRegistry;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import forestry.api.core.INbtReadable;
@@ -38,7 +35,7 @@ import forestry.core.utils.NBTUtilForestry;
import forestry.factory.inventory.InventoryCraftingForestry;
public final class MemorizedRecipe implements INbtWritable, INbtReadable, IStreamable {
private final InventoryCraftingForestry craftMatrix = new InventoryCraftingForestry();
private InventoryCraftingForestry craftMatrix = new InventoryCraftingForestry();
private List<IRecipe> recipes = new ArrayList<>();
private int selectedRecipe;
private long lastUsed;
@@ -60,6 +57,10 @@ public final class MemorizedRecipe implements INbtWritable, INbtReadable, IStrea
public InventoryCraftingForestry getCraftMatrix() {
return craftMatrix;
}
public void setCraftMatrix(InventoryCraftingForestry craftMatrix) {
this.craftMatrix = craftMatrix;
}
public void incrementRecipe() {
selectedRecipe++;
@@ -169,9 +169,10 @@ public class TileWorktable extends TileBase implements ICrafterWorktable {
return false;
}
if (!simulate && !world.isRemote) {
if (!simulate) {
// update crafting display to match the ingredients that were actually used
setCraftingDisplay(crafting);
currentRecipe.setCraftMatrix(crafting);
setCurrentRecipe(currentRecipe);
}
return true;
@@ -7,6 +7,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
@@ -15,10 +16,8 @@ import java.util.Map.Entry;
import java.util.Set;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.oredict.OreDictionary;
import forestry.api.core.ForestryAPI;
import forestry.api.farming.IFarmLogic;
import forestry.api.farming.IFarmRegistry;
@@ -35,6 +34,7 @@ public final class FarmRegistry implements IFarmRegistry {
private static final FarmRegistry INSTANCE = new FarmRegistry();
private final Multimap<String, IFarmable> farmables = HashMultimap.create();
private final Map<ItemStack, Integer> fertilizers = new LinkedHashMap<>();
private final Map<String, IFarmLogic> logics = new HashMap<String, IFarmLogic>();
static {
ForestryAPI.farmRegistry = INSTANCE;
@@ -44,6 +44,14 @@ public final class FarmRegistry implements IFarmRegistry {
return INSTANCE;
}
public void registerFarmLogic(String identifier, IFarmLogic logic) {
logics.put(identifier, logic);
}
public IFarmLogic getFarmLogic(String identifier) {
return logics.get(identifier);
}
@Override
public void registerFarmables(String identifier, IFarmable... farmablesArray) {
farmables.putAll(identifier, Arrays.asList(farmablesArray));
@@ -190,6 +190,13 @@ public class PluginFarming extends BlankForestryPlugin {
Circuits.farmCocoaManual = new CircuitFarmLogic("manualCocoa", new FarmLogicCocoa()).setManual();
Circuits.farmOrchardManual = new CircuitFarmLogic("manualOrchard", new FarmLogicOrchard());
// Make Forestry farming logics accessible to plugins via FarmRegistry
FarmRegistry.getInstance().registerFarmLogic("farmArboreal",((CircuitFarmLogic)Circuits.farmArborealManaged).getFarmLogic());
FarmRegistry.getInstance().registerFarmLogic("farmShroom",((CircuitFarmLogic)Circuits.farmShroomManaged).getFarmLogic());
FarmRegistry.getInstance().registerFarmLogic("farmWheat",((CircuitFarmLogic)Circuits.farmCerealManaged).getFarmLogic());
FarmRegistry.getInstance().registerFarmLogic("farmVegetables",((CircuitFarmLogic)Circuits.farmVegetableManaged).getFarmLogic());
FarmRegistry.getInstance().registerFarmLogic("farmInfernal",((CircuitFarmLogic)Circuits.farmInfernalManaged).getFarmLogic());
}
@Override
@@ -20,7 +20,7 @@ public class BlockRegistryFarming extends BlockRegistry {
public BlockRegistryFarming() {
mushroom = new BlockMushroom();
registerBlock(mushroom, new ItemBlockForestry(mushroom), "mushroom");
registerBlock(mushroom, new ItemBlockForestry<>(mushroom), "mushroom");
farm = new BlockFarm();
registerBlock(farm, new ItemBlockFarm(farm), "ffarm");
@@ -26,6 +26,10 @@ public class CircuitFarmLogic extends Circuit {
super(uid);
this.logic = logic;
}
public IFarmLogic getFarmLogic() {
return logic;
}
public CircuitFarmLogic setManual() {
isManual = true;
@@ -1,7 +1,5 @@
package forestry.farming.compat;
import com.google.common.base.Preconditions;
import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagCompound;
@@ -73,6 +73,11 @@ public class FarmLogicCocoa extends FarmLogic {
public boolean isAcceptedWindfall(ItemStack stack) {
return false;
}
@Override
public void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData) {
// do nothing as soil is not managed by farm
}
@Override
public NonNullList<ItemStack> collect(World world, IFarmHousing farmHousing) {
@@ -13,34 +13,44 @@ package forestry.farming.logic;
import java.util.Collection;
import java.util.Stack;
import forestry.farming.FarmRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import forestry.api.farming.FarmDirection;
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;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class FarmLogicEnder extends FarmLogicHomogeneous {
public class FarmLogicExU extends FarmLogicHomogeneous {
public FarmLogicEnder() {
super(new ItemStack(Blocks.END_STONE), Blocks.END_STONE.getDefaultState(), FarmRegistry.getInstance().getFarmables("farmEnder"));
private final String name;
private final Item iconItem;
public FarmLogicExU(String name, Item iconItem, Block soil, String farmablesKey) {
super(new ItemStack(soil), soil.getDefaultState(), FarmRegistry.getInstance().getFarmables(farmablesKey));
if (soil.equals(Blocks.REDSTONE_ORE)) {
super.addSoil(new ItemStack(Blocks.LIT_REDSTONE_ORE), Blocks.LIT_REDSTONE_ORE.getDefaultState(), false);
}
this.name = name;
this.iconItem = iconItem;
}
@Override
public String getName() {
return "Managed Ender Farm";
return name;
}
@Override
public ItemStack getIconItemStack() {
return new ItemStack(Items.ENDER_EYE);
return new ItemStack(iconItem);
}
@Override
@@ -97,4 +97,9 @@ public class FarmLogicGourd extends FarmLogic {
return crops;
}
@Override
public void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData) {
// do nothing as soil is not managed by farm
}
}
@@ -37,17 +37,17 @@ public abstract class FarmLogicHomogeneous extends FarmLogic {
this.farmables = new ArrayList<>(farmables);
}
protected void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData){
public void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData){
soils.add(new Soil(resource, soilState, hasMetaData));
}
protected boolean isAcceptedSoil(IBlockState blockState) {
for(Soil soil : soils){
IBlockState soilState = soil.soilState;
IBlockState soilState = soil.getSoilState();
Block soilBlock = soilState.getBlock();
Block block = blockState.getBlock();
if(soilState.getBlock() == blockState.getBlock()){
if(!soil.hasMetaData || block.getMetaFromState(blockState) == soilBlock.getMetaFromState(soilState)){
if(!soil.hasMetaData() || block.getMetaFromState(blockState) == soilBlock.getMetaFromState(soilState)){
return true;
}
}
@@ -58,7 +58,7 @@ public abstract class FarmLogicHomogeneous extends FarmLogic {
@Override
public boolean isAcceptedResource(ItemStack itemstack) {
for(Soil soil : soils){
ItemStack resource = soil.resource;
ItemStack resource = soil.getResource();
if(resource.isItemEqual(itemstack)){
return true;
}
@@ -95,7 +95,7 @@ public abstract class FarmLogicHomogeneous extends FarmLogic {
private boolean maintainSoil(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
for(Soil soil : soils){
NonNullList<ItemStack> resources = NonNullList.create();
resources.add(soil.resource);
resources.add(soil.getResource());
if (!farmHousing.getFarmInventory().hasResources(resources)) {
continue;
}
@@ -120,7 +120,7 @@ public abstract class FarmLogicHomogeneous extends FarmLogic {
produce.addAll(BlockUtil.getBlockDrops(world, position));
BlockUtil.setBlockWithPlaceSound(world, position, soil.soilState);
BlockUtil.setBlockWithPlaceSound(world, position, soil.getSoilState());
farmHousing.getFarmInventory().removeResources(resources);
return true;
}
@@ -130,16 +130,4 @@ public abstract class FarmLogicHomogeneous extends FarmLogic {
}
protected abstract boolean maintainGermlings(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent);
private static class Soil{
protected final ItemStack resource;
protected final IBlockState soilState;
protected final boolean hasMetaData;
public Soil(ItemStack resource, IBlockState soilState, boolean hasMetaData) {
this.resource = resource;
this.soilState = soilState;
this.hasMetaData = hasMetaData;
}
}
}
@@ -130,6 +130,11 @@ public class FarmLogicOrchard extends FarmLogic {
public String getName() {
return "Orchard";
}
@Override
public void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData) {
// do nothing as soil is not managed by farm
}
private Collection<ICrop> getHarvestBlocks(World world, BlockPos position) {
Set<BlockPos> seen = new HashSet<>();
@@ -10,15 +10,10 @@
******************************************************************************/
package forestry.farming.logic;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Stack;
import forestry.api.farming.FarmDirection;
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;
@@ -26,10 +21,23 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import forestry.api.farming.FarmDirection;
import forestry.api.farming.ICrop;
import forestry.api.farming.IFarmHousing;
import forestry.api.farming.IFarmable;
import forestry.farming.FarmRegistry;
public class FarmLogicReeds extends FarmLogic {
private final Collection<IFarmable> germlings = FarmRegistry.getInstance().getFarmables("farmPoales");
private ArrayList<Soil> soils = new ArrayList<>();
public FarmLogicReeds() {
addSoil(new ItemStack(Blocks.SAND), Blocks.SAND.getDefaultState(),true);
addSoil(new ItemStack(Blocks.DIRT), Blocks.DIRT.getDefaultState(),false);
}
@Override
public ItemStack getIconItemStack() {
return new ItemStack(Items.REEDS);
@@ -44,6 +52,11 @@ public class FarmLogicReeds extends FarmLogic {
}
}
@Override
public void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData) {
this.soils.add(new Soil(resource,soilState,hasMetaData));
}
@Override
public int getFertilizerConsumption() {
return 10;
@@ -60,7 +73,14 @@ public class FarmLogicReeds extends FarmLogic {
return false;
}
return ItemStackUtil.equals(Blocks.SAND, itemstack) || ItemStackUtil.equals(Blocks.DIRT, itemstack);
for(Soil soil : soils){
ItemStack resource = soil.getResource();
if(resource.isItemEqual(itemstack)){
return true;
}
}
return false;
}
@Override
@@ -104,4 +124,6 @@ public class FarmLogicReeds extends FarmLogic {
return crops;
}
}
@@ -131,4 +131,9 @@ public class FarmLogicRubber extends FarmLogic {
return crops;
}
@Override
public void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData) {
// do nothing as soil is not managed by farm
}
}
@@ -10,6 +10,7 @@
******************************************************************************/
package forestry.farming.logic;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Stack;
@@ -20,7 +21,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import forestry.api.farming.FarmDirection;
import forestry.api.farming.ICrop;
import forestry.api.farming.IFarmHousing;
@@ -29,8 +29,14 @@ import forestry.core.utils.ItemStackUtil;
import forestry.farming.FarmRegistry;
public class FarmLogicSucculent extends FarmLogic {
private final Collection<IFarmable> germlings = FarmRegistry.getInstance().getFarmables("farmSucculentes");
private ArrayList<Soil> soils = new ArrayList<>();
public FarmLogicSucculent() {
addSoil(new ItemStack(Blocks.SAND), Blocks.SAND.getDefaultState(),true);
}
@Override
public ItemStack getIconItemStack() {
return new ItemStack(Items.DYE, 1, 2);
@@ -45,6 +51,11 @@ public class FarmLogicSucculent extends FarmLogic {
}
}
@Override
public void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData) {
this.soils.add(new Soil(resource,soilState,hasMetaData));
}
@Override
public int getFertilizerConsumption() {
return 10;
@@ -54,14 +65,20 @@ public class FarmLogicSucculent extends FarmLogic {
public int getWaterConsumption(float hydrationModifier) {
return 1;
}
@Override
public boolean isAcceptedResource(ItemStack itemstack) {
if (isManual) {
return false;
}
return ItemStackUtil.equals(Blocks.SAND, itemstack);
for(Soil soil : soils){
ItemStack resource = soil.getResource();
if(resource.isItemEqual(itemstack)) {
return true;
}
}
return false;
}
@Override
@@ -10,17 +10,19 @@
******************************************************************************/
package forestry.farming.logic;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import forestry.api.farming.FarmDirection;
import forestry.api.farming.IFarmHousing;
import forestry.core.utils.BlockUtil;
@@ -28,16 +30,20 @@ import forestry.farming.FarmHelper;
public abstract class FarmLogicWatered extends FarmLogic {
protected final IBlockState ground;
private final ItemStack resource;
private final List<Soil> soils = new ArrayList<>();
private static final FluidStack STACK_WATER = new FluidStack(FluidRegistry.WATER, Fluid.BUCKET_VOLUME);
protected NonNullList<ItemStack> produce = NonNullList.create();
protected FarmLogicWatered(ItemStack resource, IBlockState ground) {
this.ground = ground;
this.resource = resource;
addSoil(resource,ground,false);
}
@Override
public void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData) {
soils.add(new Soil(resource,soilState,hasMetaData));
}
@Override
@@ -51,12 +57,28 @@ public abstract class FarmLogicWatered extends FarmLogic {
}
protected boolean isAcceptedGround(IBlockState ground) {
return this.ground.getBlock() == ground.getBlock();
for(Soil soil : soils){
IBlockState soilState = soil.getSoilState();
Block soilBlock = soilState.getBlock();
Block block = ground.getBlock();
if(soilState.getBlock() == ground.getBlock()){
if(!soil.hasMetaData() || block.getMetaFromState(ground) == soilBlock.getMetaFromState(soilState)){
return true;
}
}
}
return false;
}
@Override
public boolean isAcceptedResource(ItemStack itemstack) {
return resource.isItemEqual(itemstack);
for(Soil soil : soils){
ItemStack resource = soil.getResource();
if(resource.isItemEqual(itemstack)){
return true;
}
}
return false;
}
@Override
@@ -85,34 +107,36 @@ public abstract class FarmLogicWatered extends FarmLogic {
}
private boolean maintainSoil(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
NonNullList<ItemStack> resources = NonNullList.create();
resources.add(resource);
for (Soil soil : soils) {
NonNullList<ItemStack> resources = NonNullList.create();
resources.add(soil.getResource());
for (int i = 0; i < extent; i++) {
BlockPos position = translateWithOffset(pos, direction, i);
IBlockState state = world.getBlockState(position);
if (isAcceptedGround(state) || isWaterSourceBlock(world, position) || !farmHousing.getFarmInventory().hasResources(resources)) {
continue;
}
BlockPos platformPosition = position.down();
IBlockState blockState = world.getBlockState(platformPosition);
if (!FarmHelper.bricks.contains(blockState.getBlock())) {
break;
}
if (!BlockUtil.isReplaceableBlock(state, world, position)) {
produce.addAll(BlockUtil.getBlockDrops(world, position));
world.setBlockToAir(position);
return trySetSoil(world, farmHousing, position);
}
if (!isManual) {
if (trySetWater(world, farmHousing, position)) {
return true;
for (int i = 0; i < extent; i++) {
BlockPos position = translateWithOffset(pos, direction, i);
IBlockState state = world.getBlockState(position);
if (isAcceptedGround(state) || isWaterSourceBlock(world, position) || !farmHousing.getFarmInventory().hasResources(resources)) {
continue;
}
BlockPos platformPosition = position.down();
IBlockState blockState = world.getBlockState(platformPosition);
if (!FarmHelper.bricks.contains(blockState.getBlock())) {
break;
}
if (!BlockUtil.isReplaceableBlock(state, world, position)) {
produce.addAll(BlockUtil.getBlockDrops(world, position));
world.setBlockToAir(position);
return trySetSoil(world, farmHousing, position, soil.getResource(), soil.getSoilState());
}
if (!isManual) {
if (trySetWater(world, farmHousing, position)) {
return true;
}
return trySetSoil(world, farmHousing, position, soil.getResource(), soil.getSoilState());
}
return trySetSoil(world, farmHousing, position);
}
}
@@ -142,7 +166,7 @@ public abstract class FarmLogicWatered extends FarmLogic {
return false;
}
private boolean trySetSoil(World world, IFarmHousing farmHousing, BlockPos position) {
private boolean trySetSoil(World world, IFarmHousing farmHousing, BlockPos position, ItemStack resource, IBlockState ground) {
NonNullList<ItemStack> resources = NonNullList.create();
resources.add(resource);
if (!farmHousing.getFarmInventory().hasResources(resources)) {
@@ -53,18 +53,12 @@ public class FarmableGE implements IFarmable {
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
ITreeRoot treeRoot = TreeManager.treeRoot;
germling = GeneticsUtil.convertToGeneticEquivalent(germling);
if (treeRoot.isMember(germling)) {
ITree tree = treeRoot.getMember(germling);
return treeRoot.plantSapling(world, tree, player.getGameProfile(), pos);
} else {
return false;
}
ITree tree = treeRoot.getMember(germling);
return tree != null && treeRoot.plantSapling(world, tree, player.getGameProfile(), pos);
}
@Override
public boolean isGermling(ItemStack itemstack) {
itemstack = GeneticsUtil.convertToGeneticEquivalent(itemstack);
return TreeManager.treeRoot.isMember(itemstack);
}
@@ -0,0 +1,92 @@
/*******************************************************************************
* 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 forestry.api.farming.ICrop;
import forestry.api.farming.IFarmable;
import forestry.core.network.packets.PacketFXSignal;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.NetworkUtil;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class FarmableSapling implements IFarmable {
protected final ItemStack germling;
protected final boolean ignoreMetadata;
protected final Block saplingBlock;
protected final ItemStack[] windfall;
public FarmableSapling(final ItemStack germling, final ItemStack[] windfall) {
this(germling, windfall, true);
}
public FarmableSapling(final ItemStack germling, final ItemStack[] windfall, boolean addSubItems) {
this.germling = germling;
this.windfall = windfall;
this.saplingBlock = ItemStackUtil.getBlock(germling);
this.ignoreMetadata = addSubItems;
}
@Override
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
ItemStack copy = germling.copy();
player.setHeldItem(EnumHand.MAIN_HAND, copy);
EnumActionResult actionResult = copy.onItemUse(player, world, pos.down(), EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0);
player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
if (actionResult == EnumActionResult.SUCCESS) {
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, Blocks.SAPLING.getDefaultState());
NetworkUtil.sendNetworkPacket(packet, pos, world);
return true;
}
return false;
}
@Override
public boolean isSaplingAt(World world, BlockPos pos) {
return world.getBlockState(pos).getBlock() == this.saplingBlock;
}
@Override
public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) {
Block block = blockState.getBlock();
if (!block.isWood(world, pos)) {
return null;
}
return new CropDestroy(world, blockState, pos, null);
}
@Override
public boolean isGermling(ItemStack itemstack) {
if (ignoreMetadata) {
return ItemStack.areItemsEqual(germling, new ItemStack((itemstack.getItem())));
}
return ItemStack.areItemsEqual(germling, itemstack);
}
@Override
public boolean isWindfall(ItemStack itemstack) {
for (ItemStack drop : windfall) {
if (drop.isItemEqual(itemstack)) {
return true;
}
}
return false;
}
}
@@ -10,86 +10,13 @@
******************************************************************************/
package forestry.farming.logic;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import forestry.api.arboriculture.ITree;
import forestry.api.arboriculture.TreeManager;
import forestry.api.core.ForestryAPI;
import forestry.api.farming.ICrop;
import forestry.api.farming.IFarmable;
import forestry.api.genetics.IIndividual;
import forestry.core.network.packets.PacketFXSignal;
import forestry.core.utils.GeneticsUtil;
import forestry.core.utils.NetworkUtil;
import forestry.plugins.ForestryPluginUids;
public class FarmableVanillaSapling implements IFarmable {
protected final ItemStack germling;
private final ItemStack[] windfall;
public class FarmableVanillaSapling extends FarmableSapling {
public FarmableVanillaSapling() {
this.germling = new ItemStack(Blocks.SAPLING);
this.windfall = new ItemStack[]{new ItemStack(Items.APPLE), new ItemStack(FarmableCocoa.COCOA_SEED, 1, FarmableCocoa.COCOA_META)};
}
@Override
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.ARBORICULTURE)) {
IIndividual tree = GeneticsUtil.getGeneticEquivalent(germling);
if (!(tree instanceof ITree)) {
return false;
}
return TreeManager.treeRoot.plantSapling(world, (ITree) tree, player.getGameProfile(), pos);
} else {
EnumActionResult actionResult = germling.copy().onItemUse(player, world, pos.down(), EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0);
if (actionResult == EnumActionResult.SUCCESS) {
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, Blocks.SAPLING.getDefaultState());
NetworkUtil.sendNetworkPacket(packet, pos, world);
return true;
}
return false;
}
}
@Override
public boolean isSaplingAt(World world, BlockPos pos) {
return world.getBlockState(pos).getBlock() == Blocks.SAPLING;
}
@Override
public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) {
Block block = blockState.getBlock();
if (!block.isWood(world, pos)) {
return null;
}
return new CropDestroy(world, blockState, pos, null);
}
@Override
public boolean isGermling(ItemStack itemstack) {
return ItemStack.areItemsEqual(germling, itemstack);
}
@Override
public boolean isWindfall(ItemStack itemstack) {
for (ItemStack drop : windfall) {
if (drop.isItemEqual(itemstack)) {
return true;
}
}
return false;
super(new ItemStack(Blocks.SAPLING), new ItemStack[]{new ItemStack(Items.APPLE), new ItemStack(FarmableCocoa.COCOA_SEED, 1, FarmableCocoa.COCOA_META)});
}
}
@@ -0,0 +1,28 @@
package forestry.farming.logic;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
class Soil {
private final ItemStack resource;
private final IBlockState soilState;
private final boolean hasMetaData;
public Soil(ItemStack resource, IBlockState soilState, boolean hasMetaData) {
this.resource = resource;
this.soilState = soilState;
this.hasMetaData = hasMetaData;
}
public ItemStack getResource() {
return resource;
}
public IBlockState getSoilState() {
return soilState;
}
public boolean hasMetaData() {
return this.hasMetaData;
}
}
@@ -769,7 +769,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
@Override
public boolean plantGermling(IFarmable germling, World world, BlockPos pos) {
EntityPlayer player = PlayerUtil.getPlayer(world, getOwnerHandler().getOwner());
EntityPlayer player = PlayerUtil.getFakePlayer(world, getOwnerHandler().getOwner());
return player != null && inventory.plantGermling(germling, player, pos);
}
@@ -95,8 +95,7 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
@Override
public void removeResources(NonNullList<ItemStack> resources) {
EntityPlayer player = PlayerUtil.getPlayer(farmController.getWorldObj(), farmController.getOwnerHandler().getOwner());
InventoryUtil.removeSets(resourcesInventory, 1, resources, player, false, true, false, true);
InventoryUtil.removeSets(resourcesInventory, 1, resources, null, false, true, false, true);
}
@Override
@@ -14,9 +14,9 @@ public class BlockRegistryGreenhouse extends BlockRegistry {
public BlockRegistryGreenhouse() {
greenhouseBlockMap = BlockGreenhouse.create();
for (BlockGreenhouse block : greenhouseBlockMap.values()) {
ItemBlock itemBlock = new ItemBlockForestry(block);
ItemBlock itemBlock = new ItemBlockForestry<>(block);
if (block instanceof BlockGreenhouseDoor) {
itemBlock = new ItemBlockGreenhouseDoor(block);
itemBlock = new ItemBlockGreenhouseDoor((BlockGreenhouseDoor) block);
}
registerBlock(block, itemBlock, "greenhouse." + block.getGreenhouseType());
}
@@ -27,7 +27,7 @@ import net.minecraft.world.World;
public class ItemBlockGreenhouseDoor extends ItemBlockForestry<BlockGreenhouseDoor> {
public ItemBlockGreenhouseDoor(Block block) {
public ItemBlockGreenhouseDoor(BlockGreenhouseDoor block) {
super(block);
}
@@ -21,13 +21,13 @@ public class BlockRegistryLepidopterology extends BlockRegistry {
public BlockRegistryLepidopterology() {
butterflyChest = new BlockLepidopterology(BlockTypeLepidopterologyTesr.LEPICHEST);
registerBlock(butterflyChest, new ItemBlockForestry(butterflyChest), "butterfly_chest");
registerBlock(butterflyChest, new ItemBlockForestry<>(butterflyChest), "butterfly_chest");
ButterflyAlleles.registerCocoonAlleles();
cocoon = new BlockCocoon();
registerBlock(cocoon, new ItemBlockForestry(cocoon), "cocoon");
registerBlock(cocoon, new ItemBlockForestry<>(cocoon), "cocoon");
solidCocoon = new BlockSolidCocoon();
registerBlock(solidCocoon, new ItemBlockForestry(solidCocoon), "cocoon.solid");
registerBlock(solidCocoon, new ItemBlockForestry<>(solidCocoon), "cocoon.solid");
}
}
@@ -20,12 +20,12 @@ public class BlockRegistryMail extends BlockRegistry {
public BlockRegistryMail() {
mailbox = new BlockMail(BlockTypeMail.MAILBOX);
registerBlock(mailbox, new ItemBlockForestry(mailbox), "mailbox");
registerBlock(mailbox, new ItemBlockForestry<>(mailbox), "mailbox");
tradeStation = new BlockMail(BlockTypeMail.TRADE_STATION);
registerBlock(tradeStation, new ItemBlockForestry(tradeStation), "trade_station");
registerBlock(tradeStation, new ItemBlockForestry<>(tradeStation), "trade_station");
stampCollector = new BlockMail(BlockTypeMail.PHILATELIST);
registerBlock(stampCollector, new ItemBlockForestry(stampCollector), "stamp_collector");
registerBlock(stampCollector, new ItemBlockForestry<>(stampCollector), "stamp_collector");
}
}
@@ -66,7 +66,8 @@ public class PluginManager {
SETUP, // setup API to make it functional. GameMode Configs are not yet accessible
SETUP_DISABLED, // setup fallback API to avoid crashes
REGISTER, // register basic blocks and items
PRE_INIT, // register handlers, triggers, definitions, backpacks, crates, and anything that depends on basic items
PRE_INIT, // register handlers, triggers, definitions, and anything that depends on basic items
BACKPACKS_CRATES, // backpacks, crates
INIT, // anything that depends on PreInit stages, recipe registration
POST_INIT, // stubborn mod integration, dungeon loot, and finalization of things that take input from mods
FINISHED
@@ -228,11 +229,19 @@ public class PluginManager {
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.BUILDCRAFT_STATEMENTS)) {
plugin.registerTriggers();
}
Log.debug("Pre-Init Complete: {}", plugin);
}
}
public static void runRegisterBackpacksAndCrates() {
stage = Stage.BACKPACKS_CRATES;
for (IForestryPlugin plugin : loadedPlugins) {
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.STORAGE)) {
Log.debug("BackpacksAndCrates Start: {}", plugin);
plugin.registerBackpackItems();
plugin.registerCrates();
Log.debug("BackpacksAndCrates Complete: {}", plugin);
}
Log.debug("Pre-Init Complete: {}", plugin);
}
}
@@ -11,8 +11,10 @@
package forestry.plugins.compat;
import java.util.Collections;
import java.util.function.Consumer;
import forestry.api.circuits.ChipsetManager;
import forestry.api.circuits.ICircuit;
import forestry.api.circuits.ICircuitLayout;
import forestry.api.core.ForestryAPI;
import forestry.core.PluginCore;
@@ -25,7 +27,7 @@ import forestry.core.utils.Log;
import forestry.core.utils.ModUtil;
import forestry.farming.FarmRegistry;
import forestry.farming.circuits.CircuitFarmLogic;
import forestry.farming.logic.FarmLogicEnder;
import forestry.farming.logic.FarmLogicExU;
import forestry.farming.logic.FarmableAgingCrop;
import forestry.plugins.BlankForestryPlugin;
import forestry.plugins.ForestryPlugin;
@@ -33,7 +35,6 @@ import forestry.plugins.ForestryPluginUids;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
@@ -58,33 +59,46 @@ public class PluginExtraUtilities extends BlankForestryPlugin {
public void doInit() {
super.doInit();
if (Config.isExUtilRedOrchidEnabled()) {
registerExPlant("Orchid", "redorchid", "Red Orchid", Blocks.REDSTONE_ORE, circuit -> Circuits.farmOrchidManaged = circuit);
}
if (Config.isExUtilEnderLilyEnabled()) {
Block enderLillyBlock = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(ExU, "enderlilly"));
Item enderLillyItem = Item.getItemFromBlock(enderLillyBlock);
if (enderLillyBlock == Blocks.AIR) {
Log.error("Could not find ender lilly block.");
} else if (enderLillyItem == Items.AIR) {
Log.error("Could not find ender lilly item.");
} else {
IProperty<Integer> growthProperty = BlockUtil.getProperty(enderLillyBlock, "growth", Integer.class);
if (growthProperty == null) {
Log.error("Could not find the growth property of ender lily.");
} else {
int harvestAge = Collections.max(growthProperty.getAllowedValues());
int replantAge = enderLillyBlock.getDefaultState().getValue(growthProperty);
FarmRegistry.getInstance().registerFarmables("farmEnder", new FarmableAgingCrop(new ItemStack(enderLillyItem), enderLillyBlock, growthProperty, harvestAge, replantAge));
Circuits.farmEnderManaged = new CircuitFarmLogic("managedEnder", new FarmLogicEnder());
}
}
registerExPlant("Ender", "enderlilly", "Ender Lily", Blocks.END_STONE, circuit -> Circuits.farmEnderManaged = circuit);
}
}
@Override
public void registerRecipes() {
super.registerRecipes();
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING) && Circuits.farmEnderManaged != null) {
if (!ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING)) return;
if(Circuits.farmEnderManaged != null) {
ICircuitLayout layoutManaged = ChipsetManager.circuitRegistry.getLayout("forestry.farms.managed");
ChipsetManager.solderManager.addRecipe(layoutManaged, PluginCore.getItems().tubes.get(EnumElectronTube.ENDER, 1), Circuits.farmEnderManaged);
}
if(Circuits.farmOrchidManaged != null) {
ICircuitLayout layoutManaged = ChipsetManager.circuitRegistry.getLayout("forestry.farms.managed");
ChipsetManager.solderManager.addRecipe(layoutManaged, PluginCore.items.tubes.get(EnumElectronTube.ORCHID, 1), Circuits.farmOrchidManaged);
}
}
private void registerExPlant(String id, String itemResourceName, String itemName, Block soil, Consumer<ICircuit> assignTo) {
Block plantBlock = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(ExU, itemResourceName));
Item plantItem = Item.getItemFromBlock(plantBlock);
if(plantBlock == Blocks.AIR) {
Log.error("Could not find {} block.", itemName);
} else if (plantItem == null) {
Log.error("Could not find {} item.", itemName);
} else {
IProperty<Integer> growthProperty = BlockUtil.getProperty(plantBlock, "growth", Integer.class);
if (growthProperty == null) {
Log.error("Could not find the growth property of {}.", itemName);
} else {
int harvestAge = Collections.max(growthProperty.getAllowedValues());
int replantAge = plantBlock.getDefaultState().getValue(growthProperty);
FarmRegistry.getInstance().registerFarmables(itemName, new FarmableAgingCrop(new ItemStack(plantItem), plantBlock, growthProperty, harvestAge, replantAge));
assignTo.accept(new CircuitFarmLogic("managed" + id, new FarmLogicExU("Managed " + itemName + " Farm", plantItem, soil, itemName)));
}
}
}
}
@@ -199,8 +199,8 @@ public class PluginHarvestCraft extends BlankForestryPlugin {
genericCropsBuilder.add(
"cotton",
"rice",
"tea",
"coffee",
"tealeaf",
"coffeebean",
"candleberry"
);
genericCropsBuilder.addAll(herbs);
@@ -220,9 +220,9 @@ public class PluginHarvestCraft extends BlankForestryPlugin {
juiceAmount = Math.max(juiceAmount, 1); // Produce at least 1 mb of juice.
for (String berryName : berries) {
ItemStack berry = getItemStack(berryName + "Item");
ItemStack berrySeed = getItemStack(berryName + "seedItem");
Block berryBlock = getBlock("pam" + berryName + "Crop");
ItemStack berry = getItemStack(berryName + "item");
ItemStack berrySeed = getItemStack( berryName + "seeditem");
Block berryBlock = getBlock("pam" + berryName + "crop");
if (berry != null) {
RecipeManagers.squeezerManager.addRecipe(10, berry, Fluids.JUICE.getFluid(juiceAmount));
}
@@ -238,9 +238,9 @@ public class PluginHarvestCraft extends BlankForestryPlugin {
juiceAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.apple");
for (String fruitName : fruits) {
ItemStack fruit = getItemStack(fruitName + "Item");
ItemStack fruitSeed = getItemStack(fruitName + "seedItem");
Block fruitBlock = getBlock("pam" + fruitName + "Crop");
ItemStack fruit = getItemStack(fruitName + "item");
ItemStack fruitSeed = getItemStack(fruitName + "seeditem");
Block fruitBlock = getBlock("pam" + fruitName + "crop");
if (fruit != null) {
RecipeManagers.squeezerManager.addRecipe(10, fruit, Fluids.JUICE.getFluid(juiceAmount));
}
@@ -257,9 +257,9 @@ public class PluginHarvestCraft extends BlankForestryPlugin {
juiceAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.apple") / 2; // vegetables produce less juice
juiceAmount = Math.max(juiceAmount, 1); // Produce at least 1 mb of juice.
for (String vegetableName : vegetables) {
ItemStack vegetable = getItemStack(vegetableName + "Item");
ItemStack vegetableSeed = getItemStack(vegetableName + "seedItem");
Block vegetableBlock = getBlock("pam" + vegetableName + "Crop");
ItemStack vegetable = getItemStack(vegetableName + "item");
ItemStack vegetableSeed = getItemStack(vegetableName + "seeditem");
Block vegetableBlock = getBlock("pam" + vegetableName + "crop");
if (vegetable != null) {
RecipeManagers.squeezerManager.addRecipe(10, vegetable, Fluids.JUICE.getFluid(juiceAmount));
}
@@ -275,9 +275,9 @@ public class PluginHarvestCraft extends BlankForestryPlugin {
ItemRegistryCore coreItems = PluginCore.getItems();
for (String grainName : grains) {
ItemStack grain = getItemStack(grainName + "Item");
ItemStack grainSeed = getItemStack(grainName + "seedItem");
Block grainBlock = getBlock("pam" + grainName + "Crop");
ItemStack grain = getItemStack(grainName + "item");
ItemStack grainSeed = getItemStack(grainName + "seeditem");
Block grainBlock = getBlock("pam" + grainName + "crop");
if (grain != null && wheatamount > 0) {
RecipeUtil.addRecipe("pam_compost_" + grainName, coreItems.compost.getItemStack(wheatamount), " X ", "X#X", " X ", '#', Blocks.DIRT, 'X', grain);
FuelManager.moistenerResource.put(grain, new MoistenerFuel(grain, coreItems.mouldyWheat.getItemStack(), 0, 300));
@@ -294,8 +294,8 @@ public class PluginHarvestCraft extends BlankForestryPlugin {
}
for (String treeFruitName : treeFruits) {
ItemStack treeFruit = getItemStack(treeFruitName + "Item");
Block treeFruitBlock = getBlock("pam" + (Character.toUpperCase(treeFruitName.charAt(0)) + treeFruitName.substring(1)));
ItemStack treeFruit = getItemStack(treeFruitName + "item");
Block treeFruitBlock = getBlock("pam" + treeFruitName);
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING) && treeFruitBlock != null) {
farmRegistry.registerFarmables("farmOrchard", new FarmableAgingCrop(ItemStack.EMPTY, treeFruitBlock, fruitAGE, 2, 0));
}
@@ -306,7 +306,7 @@ public class PluginHarvestCraft extends BlankForestryPlugin {
}
for (String treeName : trees) {
Block fruitBlock = getBlock("pam" + (Character.toUpperCase(treeName.charAt(0)) + treeName.substring(1)));
Block fruitBlock = getBlock("pam" + treeName);
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING) && fruitBlock != null) {
farmRegistry.registerFarmables("farmOrchard", new FarmableAgingCrop(ItemStack.EMPTY, fruitBlock, fruitAGE, 2, 0));
}
@@ -314,15 +314,22 @@ public class PluginHarvestCraft extends BlankForestryPlugin {
}
for (String treeName : treesSpecial) {
Block fruitBlock = getBlock("pam" + (Character.toUpperCase(treeName.charAt(0)) + treeName.substring(1)));
Block fruitBlock = getBlock("pam" + treeName);
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING) && fruitBlock != null) {
farmRegistry.registerFarmables("farmOrchard", new FarmableAgingCrop(ItemStack.EMPTY, fruitBlock, fruitAGE, 2, 0));
}
}
for (String cropName : genericCrops) {
ItemStack genericCropSeed = getItemStack(cropName + "seedItem");
Block genericCropBlock = getBlock("pam" + cropName + "Crop");
String seedPrefix = cropName;
if (seedPrefix.equals("tealeaf")) {
seedPrefix = "tea";
}
if (seedPrefix.equals("coffeebean")) {
seedPrefix = "coffee";
}
ItemStack genericCropSeed = getItemStack(seedPrefix + "seeditem");
Block genericCropBlock = getBlock("pam" + cropName + "crop");
if (genericCropSeed != null) {
RecipeManagers.squeezerManager.addRecipe(10, genericCropSeed, Fluids.SEED_OIL.getFluid(seedamount));
}
@@ -332,9 +339,9 @@ public class PluginHarvestCraft extends BlankForestryPlugin {
}
plants.add(cropName);
}
ItemStack mustardCropSeed = getItemStack("mustard" + "seedItem");
Block mustardCropBlock = getBlock("pam" + "mustardseeds" + "Crop");
ItemStack mustardFruit = getItemStack("mustard" + "seedsItem");
ItemStack mustardCropSeed = getItemStack("mustard" + "seeditem");
Block mustardCropBlock = getBlock("pam" + "mustardseeds" + "crop");
ItemStack mustardFruit = getItemStack("mustard" + "seedsitem");
if (mustardCropSeed != null) {
RecipeManagers.squeezerManager.addRecipe(10, mustardCropSeed, Fluids.SEED_OIL.getFluid(seedamount));
}
@@ -347,16 +354,16 @@ public class PluginHarvestCraft extends BlankForestryPlugin {
}
for (String plantName : plants.build()) {
ItemStack plant = getItemStack(plantName + "Item");
ItemStack plant = getItemStack(plantName + "item");
if (plant != null) {
RecipeUtil.addFermenterRecipes(plant, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS);
}
}
for (String cropnutName : cropNuts) {
ItemStack cropnut = getItemStack(cropnutName + "Item");
ItemStack cropnutSeed = getItemStack(cropnutName + "seedItem");
Block cropnutBlock = getBlock("pam" + cropnutName + "Crop");
ItemStack cropnut = getItemStack(cropnutName + "item");
ItemStack cropnutSeed = getItemStack(cropnutName + "seeditem");
Block cropnutBlock = getBlock("pam" + cropnutName + "crop");
if (cropnutSeed != null) {
RecipeManagers.squeezerManager.addRecipe(10, cropnutSeed, Fluids.SEED_OIL.getFluid(seedamount));
}
@@ -370,8 +377,8 @@ public class PluginHarvestCraft extends BlankForestryPlugin {
}
for (String nutName : nuts) {
ItemStack nut = getItemStack(nutName + "Item");
Block nutBlock = getBlock("pam" + (Character.toUpperCase(nutName.charAt(0)) + nutName.substring(1)));
ItemStack nut = getItemStack(nutName + "item");
Block nutBlock = getBlock("pam" + nutName);
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING) && nutBlock != null) {
farmRegistry.registerFarmables("farmOrchard", new FarmableAgingCrop(ItemStack.EMPTY, nutBlock, fruitAGE, 2, 0));
}
@@ -380,12 +387,12 @@ public class PluginHarvestCraft extends BlankForestryPlugin {
}
}
ItemStack hcHoneyItem = getItemStack("honeyItem");
ItemStack hcHoneyItem = getItemStack("honeyitem");
if (hcHoneyItem != null) {
RecipeManagers.squeezerManager.addRecipe(10, hcHoneyItem, Fluids.FOR_HONEY.getFluid(Constants.FLUID_PER_HONEY_DROP));
}
ItemStack hcBeeswaxItem = getItemStack("beeswaxItem");
ItemStack hcBeeswaxItem = getItemStack("beeswaxitem");
if (hcBeeswaxItem != null) {
RecipeUtil.addRecipe("pam_wax_capsule", PluginFluids.getItems().waxCapsuleEmpty.getItemStack(ForestryAPI.activeMode.getIntegerSetting("recipe.output.capsule")), "XXX ", 'X', hcBeeswaxItem);
}
@@ -10,11 +10,28 @@
******************************************************************************/
package forestry.plugins.compat;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Collection;
import java.util.function.Consumer;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.oredict.OreDictionary;
import com.google.common.collect.Iterables;
import forestry.api.core.ForestryAPI;
import forestry.api.farming.IFarmLogic;
import forestry.api.fuels.FuelManager;
import forestry.api.fuels.MoistenerFuel;
import forestry.api.recipes.RecipeManagers;
@@ -25,48 +42,40 @@ import forestry.core.config.Constants;
import forestry.core.fluids.Fluids;
import forestry.core.recipes.RecipeUtil;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.Log;
import forestry.core.utils.ModUtil;
import forestry.farming.FarmRegistry;
import forestry.farming.logic.FarmableAgingCrop;
import forestry.farming.logic.FarmableSapling;
import forestry.plugins.BlankForestryPlugin;
import forestry.plugins.ForestryPlugin;
import forestry.plugins.ForestryPluginUids;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.event.FMLInterModComms;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.oredict.OreDictionary;
@ForestryPlugin(pluginID = ForestryPluginUids.NATURA, name = "Natura", author = "SirSengir", url = Constants.URL, unlocalizedDescription = "for.plugin.natura.description")
public class PluginNatura extends BlankForestryPlugin {
private static final String NATURA = "Natura";
public static final String modId = "natura";
@Nullable
private static Block logNatura;
@Nullable
private static Block logWillow;
@Nullable
private static Block leavesNatura;
@Nullable
private static Block saplingNatura;
@Nullable
private static Block saplingNaturaRare;
private static ArrayList<ItemStack> fruits = new ArrayList<>();
private static ArrayList<ItemStack> soups = new ArrayList<>();
private static ArrayList<ItemStack> berries = new ArrayList<>();
private static ArrayList<ItemStack> edibles = new ArrayList<>();
private static ArrayList<ItemStack> seeds = new ArrayList<>();
private static ArrayList<ItemStack> logs = new ArrayList<>();
private static ArrayList<ItemStack> saplings = new ArrayList<>();
private static ArrayList<ItemStack> shrooms = new ArrayList<>();
private static ArrayList<ItemStack> materials = new ArrayList<>();
private static ArrayList<ItemStack> crops = new ArrayList<>();
private static ArrayList<ItemStack> cropBlocks = new ArrayList<>();
private static ItemStack berryBlight = ItemStack.EMPTY;
private static ItemStack berryDusk = ItemStack.EMPTY;
private static ItemStack berrySky = ItemStack.EMPTY;
private static ItemStack berrySting = ItemStack.EMPTY;
private static ItemStack berryRasp = ItemStack.EMPTY;
private static ItemStack berryBlue = ItemStack.EMPTY;
private static ItemStack berryBlack = ItemStack.EMPTY;
private static ItemStack berryMalo = ItemStack.EMPTY;
private static ItemStack itemBarley = ItemStack.EMPTY;
public PluginNatura() {
super();
MinecraftForge.EVENT_BUS.register(this);
}
@Override
public boolean isAvailable() {
return ModUtil.isModLoaded(NATURA);
return ModUtil.isModLoaded(modId);
}
@Override
@@ -74,44 +83,103 @@ public class PluginNatura extends BlankForestryPlugin {
return "Natura not found";
}
@Override
public void preInit() {
super.preInit();
@SubscribeEvent
public void registerItems(RegistryEvent<Item> itemRegistryEvent) {
ForgeRegistries.ITEMS.forEach(item -> {
final ResourceLocation registryName = item.getRegistryName();
if(!registryName.getResourceDomain().equals(modId)) return;
logNatura = getBlock("tree");
logWillow = getBlock("willow");
leavesNatura = getBlock("floraleaves");
saplingNatura = getBlock("florasapling");
saplingNaturaRare = getBlock("Rare Sapling");
final String itemName = registryName.getResourcePath();
ArrayList<String> saplingItemKeys = new ArrayList<>();
if(itemName.matches("^.*_sapling\\d?$")) {
consumeSubItems(item, "saplings", saplings);
if (saplingNatura != null) {
saplingItemKeys.add("florasapling");
}
if (saplingNaturaRare != null) {
saplingItemKeys.add("Rare Sapling");
}
RecipeUtil.addFermenterRecipes(
new ItemStack(item, 1, OreDictionary.WILDCARD_VALUE),
ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.sapling"),
Fluids.BIOMASS
);
for (String key : saplingItemKeys) {
ItemStack saplingWild = getItemStack(key, OreDictionary.WILDCARD_VALUE);
if (!saplingWild.isEmpty()) {
RecipeUtil.addFermenterRecipes(saplingWild, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.sapling"), Fluids.BIOMASS);
String saplingName = ItemStackUtil.getItemNameFromRegistryAsString(saplingWild.getItem());
FMLInterModComms.sendMessage(Constants.MOD_ID, "add-farmable-sapling", String.format("farmArboreal@%s.-1", saplingName));
FarmRegistry.getInstance().registerFarmables("farmArboreal", new FarmableSapling(
new ItemStack(item),
new ItemStack[] {}
));
return;
}
if(itemName.matches("^edibles|.*fruit_item|soups$")) {
complexConsumeSubItems(item, "edibles", subitem -> {
final String subItemName = subitem.getUnlocalizedName();
if(subItemName.matches("^.*berry$")) {
berries.add(subitem);
return;
}
if(subItemName.matches("^.*(fruit_item|apple)$")) {
fruits.add(subitem);
return;
}
if(subItemName.matches("^.*stew$")) {
soups.add(subitem);
return;
}
edibles.add(subitem);
});
}
if(itemName.matches("^.*_seeds$")) {
consumeSubItems(item, "seeds", seeds);
return;
}
if(itemName.matches("^.*_logs\\d?$")) {
consumeSubItems(item, "logs", logs);
return;
}
if(itemName.matches("^.*_crop\\d?$")) {
consumeSubItems(item, "cropBlocks", cropBlocks);
return;
}
if(itemName.matches("^materials$")) {
complexConsumeSubItems(item, "materials", subitem -> {
final String subItemName = subitem.getUnlocalizedName();
if (subItemName.matches("^.*(barley|cotton)$")) {
crops.add(subitem);
return;
}
materials.add(subitem);
});
}
});
}
private void consumeSubItems(Item item, String groupName, Collection<ItemStack> consumer) {
complexConsumeSubItems(item, groupName, subItem -> consumer.add(subItem));
}
private void complexConsumeSubItems(Item item, String groupName, Consumer<ItemStack> consumer) {
final NonNullList<ItemStack> subItems = NonNullList.create();
item.getSubItems(CreativeTabs.SEARCH, subItems);
// Fallback if item is not returned in sub items
if(subItems.isEmpty()) {
final ItemStack itemStack = new ItemStack(item, 1);
final String subItemName = itemStack.getUnlocalizedName();
Log.info("[PluginNatura] Adding '{}' to list of {}", subItemName, groupName);
consumer.accept(itemStack);
return;
}
berryBlight = getItemStack("berry.nether", 0);
berryDusk = getItemStack("berry.nether", 1);
berrySky = getItemStack("berry.nether", 2);
berrySting = getItemStack("berry.nether", 3);
berryRasp = getItemStack("berry", 0);
berryBlue = getItemStack("berry", 1);
berryBlack = getItemStack("berry", 2);
berryMalo = getItemStack("berry", 3);
itemBarley = getItemStack("barleyFood", 0);
subItems.forEach(itemStack -> {
final String subItemName = itemStack.getUnlocalizedName();
Log.info("[PluginNatura] Adding '{}' to list of {}", subItemName, groupName);
consumer.accept(itemStack);
});
}
@Override
@@ -120,196 +188,86 @@ public class PluginNatura extends BlankForestryPlugin {
ICrateRegistry crateRegistry = StorageManager.crateRegistry;
if (!berryBlight.isEmpty()) {
crateRegistry.registerCrate(berryBlight);
}
if (!berryDusk.isEmpty()) {
crateRegistry.registerCrate(berryDusk);
}
if (!berrySky.isEmpty()) {
crateRegistry.registerCrate(berrySky);
}
if (!berrySting.isEmpty()) {
crateRegistry.registerCrate(berrySting);
}
if (!berryRasp.isEmpty()) {
crateRegistry.registerCrate(berryRasp);
}
if (!berryBlue.isEmpty()) {
crateRegistry.registerCrate(berryBlue);
}
if (!berryBlack.isEmpty()) {
crateRegistry.registerCrate(berryBlack);
}
if (!berryMalo.isEmpty()) {
crateRegistry.registerCrate(berryMalo);
}
if (!itemBarley.isEmpty()) {
crateRegistry.registerCrate(itemBarley);
}
if (saplingNatura != null) {
crateRegistry.registerCrate(new ItemStack(saplingNatura, 1, 0));
crateRegistry.registerCrate(new ItemStack(saplingNatura, 1, 1));
crateRegistry.registerCrate(new ItemStack(saplingNatura, 1, 2));
crateRegistry.registerCrate(new ItemStack(saplingNatura, 1, 3));
crateRegistry.registerCrate(new ItemStack(saplingNatura, 1, 4));
crateRegistry.registerCrate(new ItemStack(saplingNatura, 1, 5));
crateRegistry.registerCrate(new ItemStack(saplingNatura, 1, 6));
crateRegistry.registerCrate(new ItemStack(saplingNatura, 1, 7));
}
if (saplingNaturaRare != null) {
crateRegistry.registerCrate(new ItemStack(saplingNaturaRare, 1, 0));
crateRegistry.registerCrate(new ItemStack(saplingNaturaRare, 1, 1));
crateRegistry.registerCrate(new ItemStack(saplingNaturaRare, 1, 2));
crateRegistry.registerCrate(new ItemStack(saplingNaturaRare, 1, 3));
crateRegistry.registerCrate(new ItemStack(saplingNaturaRare, 1, 4));
}
ItemStack potashApple = getItemStack("Natura.netherfood", 0);
if (!potashApple.isEmpty()) {
crateRegistry.registerCrate(potashApple);
}
Item glowShroom = getItem("Glowshroom");
if (glowShroom != null) {
crateRegistry.registerCrate(new ItemStack(glowShroom, 1, 0));
crateRegistry.registerCrate(new ItemStack(glowShroom, 1, 1));
crateRegistry.registerCrate(new ItemStack(glowShroom, 1, 2));
}
if (logNatura != null) {
crateRegistry.registerCrate(new ItemStack(logNatura, 1, 0));
crateRegistry.registerCrate(new ItemStack(logNatura, 1, 1));
crateRegistry.registerCrate(new ItemStack(logNatura, 1, 2));
crateRegistry.registerCrate(new ItemStack(logNatura, 1, 3));
}
if (logWillow != null) {
crateRegistry.registerCrate(new ItemStack(logWillow, 1, 0));
}
Item bloodWood = getItem("bloodwood");
if (bloodWood != null) {
crateRegistry.registerCrate(new ItemStack(bloodWood, 1, 0));
}
Item darkTree = getItem("Dark Tree");
if (darkTree != null) {
crateRegistry.registerCrate(new ItemStack(darkTree, 1, 0));
crateRegistry.registerCrate(new ItemStack(darkTree, 1, 1));
}
Item heatSand = getItem("heatsand");
if (heatSand != null) {
crateRegistry.registerCrate(new ItemStack(heatSand, 1, 0));
}
Item taintedSoil = getItem("soil.tainted");
if (taintedSoil != null) {
crateRegistry.registerCrate(new ItemStack(taintedSoil, 1, 0));
}
Iterables.concat(
edibles, logs, saplings, shrooms,
materials, seeds, berries, fruits,
crops
).forEach(item -> crateRegistry.registerCrate(item));
}
@Override
public void registerRecipes() {
int amount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed");
Item seed = getItem("barley.seed");
if (seed != null) {
ItemStack seedBarley = new ItemStack(seed, 1, 0);
ItemStack seedCotton = new ItemStack(seed, 1, 1);
ArrayList<ItemStack> seedList = new ArrayList<>();
if (!seedBarley.isEmpty()) {
seedList.add(seedBarley);
RecipeManagers.moistenerManager.addRecipe(seedBarley, new ItemStack(Blocks.MYCELIUM), 5000);
}
if (!seedCotton.isEmpty()) {
seedList.add(seedCotton);
}
for (ItemStack aSeedList : seedList) {
RecipeManagers.squeezerManager.addRecipe(10, aSeedList, Fluids.SEED_OIL.getFluid(amount));
}
for (ItemStack seed : seeds) {
RecipeManagers.squeezerManager.addRecipe(10, NonNullList.from(seed, seed), Fluids.SEED_OIL.getFluid(amount));
RecipeManagers.moistenerManager.addRecipe(seed, new ItemStack(Blocks.MYCELIUM), 5000);
}
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING)) {
Block cropBlock = getBlock("N Crops");
//TODO: Natura for 1.9
// Farmables.farmables.get("farmWheat").add(new FarmableHandPlanted(seedBarley, cropBlock, 3));
// Farmables.farmables.get("farmWheat").add(new FarmableHandPlanted(seedCotton, cropBlock, 8));
}
cropBlocks.forEach(itemStack -> {
Block block = ItemStackUtil.getBlock(itemStack);
ItemStack seedItem;
int maxAge;
try {
maxAge = (int)block.getClass().getDeclaredMethod("getMaxAge").invoke(block);
seedItem = block.getPickBlock(block.getBlockState().getBaseState(), null, null, null, null);
} catch (Exception ignored) {
return;
}
Log.info("[PluginNatura] Addding crop '{}'", itemStack);
if (seedItem.isEmpty()) {
return;
}
List<ItemStack> berries = new ArrayList<>();
if (!berryBlight.isEmpty()) {
berries.add(berryBlight);
FarmRegistry.getInstance().registerFarmables("farmWheat",
new FarmableAgingCrop(
seedItem,
block,
(IProperty<Integer>)block.getBlockState().getProperty("age"),
maxAge
)
);
});
}
if (!berryDusk.isEmpty()) {
berries.add(berryDusk);
}
if (!berrySky.isEmpty()) {
berries.add(berrySky);
}
if (!berrySting.isEmpty()) {
berries.add(berrySting);
}
if (!berryRasp.isEmpty()) {
berries.add(berryRasp);
}
if (!berryBlue.isEmpty()) {
berries.add(berryBlue);
}
if (!berryBlack.isEmpty()) {
berries.add(berryBlack);
}
if (!berryMalo.isEmpty()) {
berries.add(berryMalo);
}
amount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.apple") / 2;
amount = Math.max(amount, 1); // Produce at least 1 mb of juice.
ItemStack netherFood = getItemStack("Natura.netherfood", 0);
ItemStack mulch = PluginCore.getItems().mulch.getItemStack();
RecipeManagers.squeezerManager.addRecipe(10, netherFood, Fluids.JUICE.getFluid(amount), mulch, ForestryAPI.activeMode.getIntegerSetting("squeezer.mulch.apple"));
final int juiceAmount = Math.max(amount, 1); // Produce at least 1 mb of juice.
ItemStack mulch = PluginCore.items.mulch.getItemStack();
fruits.forEach(fruit -> RecipeManagers.squeezerManager.addRecipe(
10, NonNullList.from(fruit, fruit),
Fluids.JUICE.getFluid(juiceAmount), mulch,
ForestryAPI.activeMode.getIntegerSetting("squeezer.mulch.apple"))
);
amount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.apple") / 25;
amount = Math.max(amount, 1); // Produce at least 1 mb of juice.
for (ItemStack berry : berries) {
RecipeManagers.squeezerManager.addRecipe(3, berry, Fluids.JUICE.getFluid(amount));
RecipeManagers.squeezerManager.addRecipe(3, NonNullList.from(berry, berry), Fluids.JUICE.getFluid(amount));
}
if (!itemBarley.isEmpty()) {
RecipeUtil.addFermenterRecipes(itemBarley, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS);
crops.forEach(crop -> {
RecipeUtil.addFermenterRecipes(crop, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS);
if (crop.getUnlocalizedName().matches("^.*cotton$")) return;
int compostWheatAmount = ForestryAPI.activeMode.getIntegerSetting("recipe.output.compost.wheat");
if (compostWheatAmount > 0) {
ItemStack compostWheat = PluginCore.getItems().compost.getItemStack(compostWheatAmount);
RecipeUtil.addRecipe("natura_compost_wheat", compostWheat, " X ", "X#X", " X ", '#', Blocks.DIRT, 'X', itemBarley);
ItemStack compostWheat = PluginCore.items.fertilizerCompound.getItemStack(compostWheatAmount);
RecipeUtil.addRecipe(compostWheat.getUnlocalizedName(), compostWheat, " X ", "X#X", " X ", '#', Blocks.DIRT, 'X', crop);
}
FuelManager.moistenerResource.put(itemBarley, new MoistenerFuel(itemBarley, PluginCore.getItems().mouldyWheat.getItemStack(), 0, 300));
}
FuelManager.moistenerResource.put(crop, new MoistenerFuel(crop, PluginCore.items.mouldyWheat.getItemStack(), 0, 300));
});
}
/*
* Register soils required by Natura trees. Must run in postInit(), after core PluginFarming has registered FarmingLogic instances
*/
@Override
public void postInit() {
IFarmLogic farmArboreal = FarmRegistry.getInstance().getFarmLogic("farmArboreal");
farmArboreal.addSoil(new ItemStack(Blocks.NETHERRACK), Blocks.NETHERRACK.getDefaultState(), false);
}
@Nullable
private static Block getBlock(String blockName) {
ResourceLocation key = new ResourceLocation(NATURA, blockName);
if (ForgeRegistries.BLOCKS.containsKey(key)) {
return ForgeRegistries.BLOCKS.getValue(key);
} else {
return null;
}
}
@Nullable
private static Item getItem(String itemName) {
ResourceLocation key = new ResourceLocation(NATURA, itemName);
if (ForgeRegistries.ITEMS.containsKey(key)) {
return ForgeRegistries.ITEMS.getValue(key);
} else {
return null;
}
}
private static ItemStack getItemStack(String itemName, int meta) {
ResourceLocation key = new ResourceLocation(NATURA, itemName);
if (ForgeRegistries.ITEMS.containsKey(key)) {
return new ItemStack(ForgeRegistries.ITEMS.getValue(key), 1, meta);
} else {
return ItemStack.EMPTY;
}
}
}