mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-15 01:24:59 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dea1fb144a | ||
|
|
a01190a242 | ||
|
|
0ebced9609 | ||
|
|
b9924ea98b | ||
|
|
5707d27598 | ||
|
|
42bde9e576 | ||
|
|
76f09be39d | ||
|
|
e6cb758e0e | ||
|
|
b3549edf51 | ||
|
|
e09d159935 | ||
|
|
4cb2610b1c | ||
|
|
c44f11cf09 | ||
|
|
b69c31ed8a | ||
|
|
6a2231f8fb | ||
|
|
a3a6c71c42 | ||
|
|
8d5c0c6f8b | ||
|
|
56603fd00c | ||
|
|
ed69411d2e | ||
|
|
e1d017f077 | ||
|
|
9269af7a13 | ||
|
|
8ffdba5021 | ||
|
|
e00aecd886 | ||
|
|
98f859f2fb | ||
|
|
55a15d23b2 | ||
|
|
307580aed8 | ||
|
|
d2d93004e0 | ||
|
|
e1df424bfd | ||
|
|
6a75347b05 | ||
|
|
cfd513ea80 | ||
|
|
edcc47a6b3 | ||
|
|
6593118f3d | ||
|
|
fd724d147a | ||
|
|
b2e1b2dc9b | ||
|
|
defc47000b | ||
|
|
0a37ad0666 | ||
|
|
13d4907bff | ||
|
|
78725009c1 | ||
|
|
a1bc9144bd | ||
|
|
b897056824 | ||
|
|
87563b6c97 | ||
|
|
62d6294da2 | ||
|
|
b4d71543db | ||
|
|
73db1a608a | ||
|
|
1c6b60122e | ||
|
|
1e7a042b53 | ||
|
|
bf08336bc5 |
No files matched your search
Executable → Regular
+10
-17
@@ -5,15 +5,17 @@ buildscript {
|
||||
}
|
||||
dependencies {
|
||||
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
|
||||
classpath "gradle.plugin.se.bjurr.gitchangelog:git-changelog-gradle-plugin:1.47"
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id "com.matthewprenger.cursegradle" version "1.0.9"
|
||||
id "se.bjurr.gitchangelog.git-changelog-gradle-plugin" version "1.32"
|
||||
}
|
||||
apply plugin: 'net.minecraftforge.gradle.forge'
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'maven'
|
||||
apply plugin: "se.bjurr.gitchangelog.git-changelog-gradle-plugin"
|
||||
|
||||
version = version_major + '.' + version_minor + '.' + version_patch + '.' + getBuildNumber()
|
||||
if (project.hasProperty('buildQualifier')) {
|
||||
@@ -60,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"
|
||||
}
|
||||
|
||||
@@ -149,26 +151,17 @@ task makeChangelog(type: se.bjurr.gitchangelog.plugin.gradle.GitChangelogTask) {
|
||||
untaggedName = "Current release ${project.version}"
|
||||
fromCommit = "5a3850c2642e535656d090d1473054d5fa8d3331"
|
||||
toRef = "HEAD"
|
||||
templateContent = """
|
||||
Please help the Forestry project by <a href="https://github.com/ForestryMC/ForestryMC/issues">reporting issues here.</a><br/>
|
||||
{{#tags}}
|
||||
<h3>{{name}}</h3>
|
||||
<ul>
|
||||
{{#commits}}
|
||||
<li>{{{message}}} - {{authorName}}</li>
|
||||
{{/commits}}
|
||||
</ul>
|
||||
{{/tags}}
|
||||
"""
|
||||
templateContent = file('changelog.mustache').getText('UTF-8')
|
||||
}
|
||||
|
||||
curseforge {
|
||||
apiKey = project.hasProperty('curseforge_apikey') ? project.curseforge_apikey : '0'
|
||||
project {
|
||||
id = '59751'
|
||||
id = curse_project_id
|
||||
changelog = file('changelog.html')
|
||||
changelogType = 'html'
|
||||
releaseType = 'alpha'
|
||||
releaseType = 'beta'
|
||||
addGameVersion '1.12'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
Please help the Forestry project by <a href="https://github.com/ForestryMC/ForestryMC/issues">reporting issues here.</a><br/>
|
||||
{{#tags}}
|
||||
<h3>{{name}}</h3>
|
||||
<ul>
|
||||
{{#commits}}
|
||||
<li>{{{message}}} - {{authorName}}</li>
|
||||
{{/commits}}
|
||||
</ul>
|
||||
{{/tags}}
|
||||
+10
-7
@@ -1,11 +1,14 @@
|
||||
mcversion=1.12
|
||||
forgeversion=14.21.1.2395
|
||||
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.0.67
|
||||
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=4
|
||||
version_patch=3
|
||||
version_minor=5
|
||||
version_patch=4
|
||||
+1
-1
Submodule lang updated: f5300f059b...774ccbb680.
@@ -15,12 +15,11 @@ import com.google.common.base.Preconditions;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import forestry.plugins.compat.PluginNatura;
|
||||
import net.minecraftforge.client.event.ModelRegistryEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
@@ -29,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;
|
||||
|
||||
@@ -44,7 +44,6 @@ import forestry.core.gui.GuiHandler;
|
||||
import forestry.core.multiblock.MultiblockEventHandler;
|
||||
import forestry.core.network.PacketHandler;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.MigrationHelper;
|
||||
import forestry.core.worldgen.WorldGenerator;
|
||||
import forestry.plugins.PluginManager;
|
||||
import forestry.plugins.compat.PluginIC2;
|
||||
@@ -59,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")
|
||||
@@ -77,6 +77,7 @@ public class Forestry {
|
||||
ForestryAPI.errorStateRegistry = new ErrorStateRegistry();
|
||||
EnumErrorCode.init();
|
||||
FluidRegistry.enableUniversalBucket();
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -109,6 +110,11 @@ public class Forestry {
|
||||
|
||||
PluginManager.runPreInit(event.getSide());
|
||||
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void registerModels(ModelRegistryEvent event) {
|
||||
PluginManager.runRegisterBackpacksAndCrates();
|
||||
Proxies.render.registerModels();
|
||||
}
|
||||
|
||||
@@ -151,14 +157,4 @@ public class Forestry {
|
||||
public void processIMCMessages(IMCEvent event) {
|
||||
PluginManager.processIMCMessages(event.getMessages());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMissingBlockMappings(RegistryEvent.MissingMappings<Block> event) {
|
||||
MigrationHelper.onMissingBlockMappings(event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMissingItemMappings(RegistryEvent.MissingMappings<Item> event) {
|
||||
MigrationHelper.onMissingItemMappings(event);
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,10 @@ import forestry.api.core.IErrorState;
|
||||
import forestry.api.genetics.IEffectData;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.IIndividualLiving;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@@ -85,8 +87,26 @@ public interface IBee extends IIndividualLiving {
|
||||
|
||||
List<IBee> spawnDrones(IBeeHousing housing);
|
||||
|
||||
/**
|
||||
* @deprecated since Forestry 5.5.4. Use {@link #plantFlowerRandom(IBeeHousing, List)}
|
||||
*/
|
||||
@Deprecated
|
||||
void plantFlowerRandom(IBeeHousing housing);
|
||||
|
||||
/**
|
||||
* Plants a random flower from the given list near the housing
|
||||
* @param housing the location the bee is living
|
||||
* @param potentialFlowers the flowers to choose from
|
||||
* @return the position of the planted flower, or null of none were planted
|
||||
* @since Forestry 5.5.4
|
||||
*/
|
||||
@Nullable
|
||||
default BlockPos plantFlowerRandom(IBeeHousing housing, List<IBlockState> potentialFlowers) {
|
||||
//noinspection deprecation
|
||||
plantFlowerRandom(housing);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
IIndividual retrievePollen(IBeeHousing housing);
|
||||
|
||||
|
||||
@@ -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,6 +5,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.genetics;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -13,6 +16,19 @@ public interface IFlowerGrowthHelper {
|
||||
* Plants a random flower from flowerType at the specified position.
|
||||
*
|
||||
* @return true if successful, false if it could not be planted.
|
||||
* @deprecated since Forestry 5.5.4. Use {@link #plantRandomFlower(String, World, BlockPos, Collection)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean plantRandomFlower(String flowerType, World world, BlockPos pos);
|
||||
|
||||
/**
|
||||
* Plants a random flower from flowerType at the specified position.
|
||||
* @param flowerType the flower type that can be planted
|
||||
* @param world the world to plant flowers in
|
||||
* @param pos the position to plant the flowers
|
||||
* @param potentialFlowers the potential flowers that can be planted
|
||||
* @return true if a flower was planted, false otherwise
|
||||
* @since Forestry 5.5.4
|
||||
*/
|
||||
boolean plantRandomFlower(String flowerType, World world, BlockPos pos, Collection<IBlockState> potentialFlowers);
|
||||
}
|
||||
@@ -5,6 +5,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.genetics;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -18,6 +21,20 @@ public interface IFlowerGrowthRule {
|
||||
* For implementers, you can plant a random flower using IFlowerGrowthHelper.plantRandomFlower
|
||||
*
|
||||
* @since Forestry 4.0.8
|
||||
* @deprecated since Forestry 5.5.4. Use {@link #growFlower(IFlowerGrowthHelper, String, World, BlockPos, Collection)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean growFlower(IFlowerGrowthHelper helper, String flowerType, World world, BlockPos pos);
|
||||
|
||||
/**
|
||||
* Checks a position for suitability, and then plants a flower there.
|
||||
* Returns true on success.
|
||||
* For implementers, you can plant a random flower using IFlowerGrowthHelper.plantRandomFlower
|
||||
*
|
||||
* @since Forestry 5.5.4
|
||||
*/
|
||||
default boolean growFlower(IFlowerGrowthHelper helper, String flowerType, World world, BlockPos pos, Collection<IBlockState> potentialFlowers) {
|
||||
//noinspection deprecation
|
||||
return growFlower(helper, flowerType, world, pos);
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,13 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.genetics;
|
||||
|
||||
import java.util.Collection;
|
||||
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;
|
||||
@@ -57,8 +60,26 @@ public interface IFlowerRegistry {
|
||||
|
||||
/**
|
||||
* Calls the appropriate IFlowerGrowthRule to grow a flower at a specified position.
|
||||
* @since Forestry 5.5.4
|
||||
*/
|
||||
boolean growFlower(String flowerType, World world, IIndividual individual, BlockPos pos);
|
||||
boolean growFlower(String flowerType, World world, IIndividual individual, BlockPos pos, Collection<IBlockState> potentialFlowers);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -66,11 +87,22 @@ public interface IFlowerRegistry {
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* Calls the appropriate IFlowerGrowthRule to grow a flower at a specified position.
|
||||
* @deprecated since Forestry 5.5.4. Use {@link #growFlower(String, World, IIndividual, BlockPos, Collection)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean growFlower(String flowerType, World world, IIndividual individual, BlockPos pos);
|
||||
}
|
||||
@@ -38,23 +38,23 @@ 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.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
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 +136,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 +145,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) {
|
||||
@@ -203,11 +203,13 @@ public class BeekeepingLogic implements IBeekeepingLogic, IStreamable {
|
||||
if (this.queenStack != queenStack) {
|
||||
if (!queenStack.isEmpty()) {
|
||||
this.queen = BeeManager.beeRoot.getMember(queenStack);
|
||||
if (this.queen != null) {
|
||||
hasFlowersCache.onNewQueen(queen, housing);
|
||||
}
|
||||
} else {
|
||||
this.queen = null;
|
||||
}
|
||||
this.queenStack = queenStack;
|
||||
hasFlowersCache.clear();
|
||||
queenCanWorkCache.clear();
|
||||
}
|
||||
|
||||
@@ -222,7 +224,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);
|
||||
|
||||
@@ -250,9 +253,11 @@ public class BeekeepingLogic implements IBeekeepingLogic, IStreamable {
|
||||
@Override
|
||||
public void clearCachedValues() {
|
||||
if (!housing.getWorldObj().isRemote) {
|
||||
hasFlowersCache.clear();
|
||||
queenCanWorkCache.clear();
|
||||
canWork();
|
||||
if (queen != null) {
|
||||
hasFlowersCache.forceLookForFlowers(queen, housing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,14 +277,21 @@ public class BeekeepingLogic implements IBeekeepingLogic, IStreamable {
|
||||
queenWorkCycleThrottle = 0;
|
||||
|
||||
doProduction(queen, housing, beeListener);
|
||||
queen.plantFlowerRandom(housing);
|
||||
World world = housing.getWorldObj();
|
||||
List<IBlockState> flowers = hasFlowersCache.getFlowers(world);
|
||||
if (flowers.size() < PluginApiculture.maxFlowersSpawnedPerHive) {
|
||||
BlockPos blockPos = queen.plantFlowerRandom(housing, flowers);
|
||||
if (blockPos != null) {
|
||||
hasFlowersCache.addFlowerPos(blockPos);
|
||||
}
|
||||
}
|
||||
pollenHandler.doPollination(queen, housing, beeListener);
|
||||
|
||||
// Age the queen
|
||||
IBeeGenome mate = queen.getMate();
|
||||
Preconditions.checkState(mate != null);
|
||||
float lifespanModifier = beeModifier.getLifespanModifier(queen.getGenome(), mate, 1.0f);
|
||||
queen.age(housing.getWorldObj(), lifespanModifier);
|
||||
queen.age(world, lifespanModifier);
|
||||
|
||||
// Write the changed queen back into the item stack.
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
|
||||
@@ -10,80 +10,99 @@
|
||||
******************************************************************************/
|
||||
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.IBeeGenome;
|
||||
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.block.state.IBlockState;
|
||||
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 final List<IBlockState> flowers = 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 Vec3i territory;
|
||||
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.territory = queen.getGenome().getTerritory();
|
||||
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();
|
||||
this.flowers.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();
|
||||
flowers.clear();
|
||||
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)) {
|
||||
addFlowerPos(blockPos.toImmutable());
|
||||
}
|
||||
} else {
|
||||
flowerData.resetIterator(queen, beeHousing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasFlowers() {
|
||||
return !flowerCoords.isEmpty();
|
||||
}
|
||||
|
||||
@@ -93,37 +112,65 @@ public class HasFlowersCache implements INbtWritable, INbtReadable, IStreamable
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
flowerCoords.clear();
|
||||
cooldown = 0;
|
||||
public void onNewQueen(IBee queen, IBeeHousing housing) {
|
||||
if (this.flowerData != null) {
|
||||
IBeeGenome genome = queen.getGenome();
|
||||
String flowerType = genome.getFlowerProvider().getFlowerType();
|
||||
if (!this.flowerData.flowerType.equals(flowerType)
|
||||
|| !this.flowerData.territory.equals(genome.getTerritory())) {
|
||||
flowerData = new FlowerData(queen, housing);
|
||||
flowerCoords.clear();
|
||||
flowers.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
public List<IBlockState> getFlowers(World world) {
|
||||
if (flowers.isEmpty() && !flowerCoords.isEmpty()) {
|
||||
flowers.clear();
|
||||
for (BlockPos flowerCoord : flowerCoords) {
|
||||
IBlockState blockState = world.getBlockState(flowerCoord);
|
||||
flowers.add(blockState);
|
||||
}
|
||||
}
|
||||
return FlowerManager.flowerRegistry.isAcceptedFlower(flowerType, world, flowerCoords);
|
||||
return Collections.unmodifiableList(flowers);
|
||||
}
|
||||
|
||||
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();
|
||||
public void addFlowerPos(BlockPos blockPos) {
|
||||
flowerCoords.add(blockPos);
|
||||
flowers.clear();
|
||||
needsSync = true;
|
||||
}
|
||||
|
||||
public void forceLookForFlowers(IBee queen, IBeeHousing housing) {
|
||||
if (flowerData != null) {
|
||||
flowerCoords.clear();
|
||||
flowers.clear();
|
||||
flowerData.resetIterator(queen, housing);
|
||||
World world = housing.getWorldObj();
|
||||
while (flowerData.areaIterator.hasNext()) {
|
||||
BlockPos.MutableBlockPos blockPos = flowerData.areaIterator.next();
|
||||
if (flowerData.flowerPredicate.test(world, blockPos)) {
|
||||
addFlowerPos(blockPos.toImmutable());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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 +180,7 @@ public class HasFlowersCache implements INbtWritable, INbtReadable, IStreamable
|
||||
needsSync = true;
|
||||
}
|
||||
}
|
||||
|
||||
cooldown = hasFlowerCacheNBT.getInteger(nbtKeyCooldown);
|
||||
flowers.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -151,17 +197,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,9 +216,9 @@ public class HasFlowersCache implements INbtWritable, INbtReadable, IStreamable
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(PacketBufferForestry data) throws IOException {
|
||||
public void readData(PacketBuffer data) throws IOException {
|
||||
flowerCoords.clear();
|
||||
flowers.clear();
|
||||
|
||||
int size = data.readVarInt();
|
||||
while (size > 0) {
|
||||
|
||||
@@ -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;
|
||||
@@ -149,6 +151,7 @@ public class PluginApiculture extends BlankForestryPlugin {
|
||||
|
||||
public static String beekeepingMode = "NORMAL";
|
||||
public static final int ticksPerBeeWorkCycle = 550;
|
||||
public static int maxFlowersSpawnedPerHive = 20;
|
||||
@Nullable
|
||||
public static VillagerRegistry.VillagerProfession villagerApiarist;
|
||||
|
||||
@@ -259,6 +262,8 @@ public class PluginApiculture extends BlankForestryPlugin {
|
||||
|
||||
secondPrincessChance = config.getFloatLocalized("beekeeping", "second.princess", secondPrincessChance, 0.0f, 100.0f);
|
||||
|
||||
maxFlowersSpawnedPerHive = config.getIntLocalized("beekeeping", "flowers.spawn", 20, 0, 1000);
|
||||
|
||||
String[] blacklist = config.getStringListLocalized("species", "blacklist", Constants.EMPTY_STRINGS);
|
||||
parseBeeBlacklist(blacklist);
|
||||
|
||||
@@ -494,13 +499,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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -899,8 +905,18 @@ public class PluginApiculture extends BlankForestryPlugin {
|
||||
|
||||
@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(chunkGenerator, world, rand, chunkX, chunkZ, hasVillageGenerated);
|
||||
HiveDecorator.decorateHives(world, rand, chunkX, chunkZ);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decorateBiome(World world, Random rand, BlockPos pos) {
|
||||
if (Config.getBeehivesAmount() > 0.0) {
|
||||
int chunkX = pos.getX() >> 4;
|
||||
int chunkZ = pos.getZ() >> 4;
|
||||
HiveDecorator.decorateHives(world, rand, chunkX, chunkZ);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
/*******************************************************************************
|
||||
* 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() {
|
||||
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.flowers;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
@@ -27,12 +30,15 @@ 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 forestry.core.utils.WeightedCollection;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
@@ -43,16 +49,16 @@ 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;
|
||||
private final Map<String, TreeMap<Double, Flower>> chances;
|
||||
private final Map<String, WeightedCollection<Flower>> chances;
|
||||
|
||||
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 +84,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 +119,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 +135,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 +152,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,18 +175,32 @@ 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean growFlower(String flowerType, World world, IIndividual individual, BlockPos pos) {
|
||||
if (!this.growthRules.containsKey(flowerType)) {
|
||||
return false;
|
||||
@@ -211,6 +215,23 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean growFlower(String flowerType, World world, IIndividual individual, BlockPos pos, Collection<IBlockState> potentialFlowers) {
|
||||
if (!this.growthRules.containsKey(flowerType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<IFlowerGrowthRule> growthRules = this.growthRules.get(flowerType);
|
||||
Collections.shuffle(growthRules);
|
||||
for (IFlowerGrowthRule rule : growthRules) {
|
||||
if (rule.growFlower(this, flowerType, world, pos, potentialFlowers)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerGrowthRule(IFlowerGrowthRule rule, String... flowerTypes) {
|
||||
Preconditions.checkNotNull(rule);
|
||||
@@ -220,20 +241,18 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Flower getRandomPlantableFlower(String flowerType, Random rand) {
|
||||
TreeMap<Double, Flower> chancesMap = getChancesMap(flowerType);
|
||||
double maxKey = chancesMap.lastKey() + 1.0;
|
||||
return chancesMap.get(chancesMap.lowerKey(rand.nextDouble() * maxKey));
|
||||
WeightedCollection<Flower> chancesMap = getFlowerChances(flowerType);
|
||||
return chancesMap.getRandom(rand);
|
||||
}
|
||||
|
||||
private TreeMap<Double, Flower> getChancesMap(String flowerType) {
|
||||
private WeightedCollection<Flower> getFlowerChances(String flowerType) {
|
||||
if (!this.chances.containsKey(flowerType)) {
|
||||
TreeMap<Double, Flower> flowerChances = new TreeMap<>();
|
||||
double count = 0.0;
|
||||
WeightedCollection<Flower> flowerChances = new WeightedCollection<>();
|
||||
for (Flower flower : this.plantableFlowers.get(flowerType)) {
|
||||
if (flower.isPlantable()) {
|
||||
flowerChances.put(count, flower);
|
||||
count += flower.getWeight();
|
||||
flowerChances.put(flower.getWeight(), flower);
|
||||
}
|
||||
}
|
||||
this.chances.put(flowerType, flowerChances);
|
||||
@@ -253,6 +272,56 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
|
||||
@Override
|
||||
public boolean plantRandomFlower(String flowerType, World world, BlockPos pos) {
|
||||
Flower flower = getRandomPlantableFlower(flowerType, world.rand);
|
||||
return world.setBlockState(pos, flower.getBlockState());
|
||||
return flower != null && world.setBlockState(pos, flower.getBlockState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plantRandomFlower(String flowerType, World world, BlockPos pos, Collection<IBlockState> potentialFlowers) {
|
||||
WeightedCollection<Flower> chances = getFlowerChances(flowerType);
|
||||
WeightedCollection<IBlockState> potentialChances = new WeightedCollection<>();
|
||||
|
||||
for (Map.Entry<Double, Flower> entry : chances.entrySet()) {
|
||||
Flower flower = entry.getValue();
|
||||
IBlockState blockState = flower.getBlockState();
|
||||
if (potentialFlowers.contains(blockState)) {
|
||||
potentialChances.put(entry.getKey(), blockState);
|
||||
}
|
||||
}
|
||||
|
||||
final IBlockState blockState = potentialChances.getRandom(world.rand);
|
||||
return blockState != null && world.setBlockState(pos, blockState);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,12 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.flowers;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import forestry.api.genetics.IFlowerGrowthHelper;
|
||||
import forestry.api.genetics.IFlowerGrowthRule;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
@@ -20,14 +23,24 @@ import net.minecraft.world.World;
|
||||
public class GrowthRuleDirtGrass implements IFlowerGrowthRule {
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean growFlower(IFlowerGrowthHelper helper, String flowerType, World world, BlockPos pos) {
|
||||
return isValidSpot(world, pos) &&
|
||||
helper.plantRandomFlower(flowerType, world, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean growFlower(IFlowerGrowthHelper helper, String flowerType, World world, BlockPos pos, Collection<IBlockState> potentialFlowers) {
|
||||
return isValidSpot(world, pos) &&
|
||||
helper.plantRandomFlower(flowerType, world, pos, potentialFlowers);
|
||||
}
|
||||
|
||||
private boolean isValidSpot(World world, BlockPos pos) {
|
||||
if (!world.isBlockLoaded(pos) || !world.isAirBlock(pos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Block ground = world.getBlockState(new BlockPos(pos.getX(), pos.getY() - 1, pos.getZ())).getBlock();
|
||||
return (ground == Blocks.DIRT || ground == Blocks.GRASS) &&
|
||||
helper.plantRandomFlower(flowerType, world, pos);
|
||||
return (ground == Blocks.DIRT || ground == Blocks.GRASS);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.apiculture.flowers;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import forestry.api.genetics.IFlowerGrowthHelper;
|
||||
@@ -33,6 +34,11 @@ public class GrowthRuleFertilize implements IFlowerGrowthRule {
|
||||
return growFlower(world, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean growFlower(IFlowerGrowthHelper helper, String flowerType, World world, BlockPos pos, Collection<IBlockState> potentialFlowers) {
|
||||
return growFlower(world, pos);
|
||||
}
|
||||
|
||||
private boolean growFlower(World world, BlockPos pos) {
|
||||
if (!world.isBlockLoaded(pos)) {
|
||||
return false;
|
||||
|
||||
@@ -10,9 +10,12 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.flowers;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import forestry.api.genetics.IFlowerGrowthHelper;
|
||||
import forestry.api.genetics.IFlowerGrowthRule;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
@@ -20,14 +23,25 @@ import net.minecraft.world.World;
|
||||
public class GrowthRuleMycelium implements IFlowerGrowthRule {
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean growFlower(IFlowerGrowthHelper helper, String flowerType, World world, BlockPos pos) {
|
||||
return isValidSpot(world, pos) &&
|
||||
helper.plantRandomFlower(flowerType, world, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean growFlower(IFlowerGrowthHelper helper, String flowerType, World world, BlockPos pos, Collection<IBlockState> potentialFlowers) {
|
||||
return isValidSpot(world, pos) &&
|
||||
helper.plantRandomFlower(flowerType, world, pos, potentialFlowers);
|
||||
}
|
||||
|
||||
private boolean isValidSpot(World world, BlockPos pos) {
|
||||
if (!world.isBlockLoaded(pos) || !world.isAirBlock(pos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Block ground = world.getBlockState(new BlockPos(pos.getX(), pos.getY() - 1, pos.getZ())).getBlock();
|
||||
return ground == Blocks.MYCELIUM &&
|
||||
helper.plantRandomFlower(flowerType, world, pos);
|
||||
return ground == Blocks.MYCELIUM;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,8 +10,11 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.flowers;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import forestry.api.genetics.IFlowerGrowthHelper;
|
||||
import forestry.api.genetics.IFlowerGrowthRule;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -22,4 +25,8 @@ public class GrowthRuleNone implements IFlowerGrowthRule {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean growFlower(IFlowerGrowthHelper helper, String flowerType, World world, BlockPos pos, Collection<IBlockState> potentialFlowers) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,12 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.flowers;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import forestry.api.genetics.IFlowerGrowthHelper;
|
||||
import forestry.api.genetics.IFlowerGrowthRule;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
@@ -20,14 +23,24 @@ import net.minecraft.world.World;
|
||||
public class GrowthRuleSnow implements IFlowerGrowthRule {
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean growFlower(IFlowerGrowthHelper helper, String flowerType, World world, BlockPos pos) {
|
||||
return isValidSpot(world, pos) &&
|
||||
helper.plantRandomFlower(flowerType, world, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean growFlower(IFlowerGrowthHelper helper, String flowerType, World world, BlockPos pos, Collection<IBlockState> potentialFlowers) {
|
||||
return isValidSpot(world, pos) &&
|
||||
helper.plantRandomFlower(flowerType, world, pos, potentialFlowers);
|
||||
}
|
||||
|
||||
private boolean isValidSpot(World world, BlockPos pos) {
|
||||
if (!world.isBlockLoaded(pos) || world.getBlockState(pos).getBlock() != Blocks.SNOW) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Block ground = world.getBlockState(new BlockPos(pos.getX(), pos.getY() - 1, pos.getZ())).getBlock();
|
||||
return (ground == Blocks.DIRT || ground == Blocks.GRASS) &&
|
||||
helper.plantRandomFlower(flowerType, world, pos);
|
||||
return (ground == Blocks.DIRT || ground == Blocks.GRASS);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -735,7 +736,11 @@ public class Bee extends IndividualLiving implements IBee {
|
||||
|
||||
@Override
|
||||
public void plantFlowerRandom(IBeeHousing housing) {
|
||||
plantFlowerRandom(housing, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos plantFlowerRandom(IBeeHousing housing, @Nullable List<IBlockState> potentialFlowers) {
|
||||
IBeeModifier beeModifier = BeeManager.beeRoot.createBeeHousingModifier(housing);
|
||||
|
||||
int chance = Math.round(genome.getFlowering() * beeModifier.getFloweringModifier(getGenome(), 1f));
|
||||
@@ -745,9 +750,8 @@ public class Bee extends IndividualLiving implements IBee {
|
||||
|
||||
// Correct speed
|
||||
if (random.nextInt(100) >= chance) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
// Gather required info
|
||||
IFlowerProvider provider = genome.getFlowerProvider();
|
||||
Vec3i area = getArea(genome, beeModifier);
|
||||
@@ -758,10 +762,18 @@ public class Bee extends IndividualLiving implements IBee {
|
||||
BlockPos randomPos = VectUtil.getRandomPositionInArea(random, area);
|
||||
BlockPos posBlock = VectUtil.add(housingPos, randomPos, offset);
|
||||
|
||||
if (FlowerManager.flowerRegistry.growFlower(provider.getFlowerType(), world, this, posBlock)) {
|
||||
break;
|
||||
if (potentialFlowers != null) {
|
||||
if (FlowerManager.flowerRegistry.growFlower(provider.getFlowerType(), world, this, posBlock, potentialFlowers)) {
|
||||
return posBlock;
|
||||
}
|
||||
} else { // legacy
|
||||
//noinspection deprecation
|
||||
if (FlowerManager.flowerRegistry.growFlower(provider.getFlowerType(), world, this, posBlock)) {
|
||||
return posBlock;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Vec3i getArea(IBeeGenome genome, IBeeModifier beeModifier) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -286,7 +286,9 @@ public class VillageApiaristHouse extends StructureVillagePieces.House1 {
|
||||
|
||||
FlowerRegistry flowerRegistry = (FlowerRegistry) FlowerManager.flowerRegistry;
|
||||
Flower flower = flowerRegistry.getRandomPlantableFlower(FlowerManager.FlowerTypeVanilla, world.rand);
|
||||
setBlockState(world, flower.getBlockState(), j, i, k, box);
|
||||
if (flower != null) {
|
||||
setBlockState(world, flower.getBlockState(), j, i, k, box);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -10,13 +10,32 @@
|
||||
******************************************************************************/
|
||||
package forestry.core;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.command.ICommand;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.storage.loot.functions.LootFunctionManager;
|
||||
|
||||
import net.minecraftforge.client.event.ModelBakeEvent;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.circuits.ChipsetManager;
|
||||
import forestry.api.core.CamouflageManager;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
@@ -59,21 +78,6 @@ import forestry.core.utils.OreDictUtil;
|
||||
import forestry.plugins.BlankForestryPlugin;
|
||||
import forestry.plugins.ForestryPlugin;
|
||||
import forestry.plugins.ForestryPluginUids;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.command.ICommand;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.storage.loot.functions.LootFunctionManager;
|
||||
import net.minecraftforge.client.event.ModelBakeEvent;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
@ForestryPlugin(pluginID = ForestryPluginUids.CORE, name = "Core", author = "SirSengir", url = Constants.URL, unlocalizedDescription = "for.plugin.core.description")
|
||||
public class PluginCore extends BlankForestryPlugin {
|
||||
@@ -330,7 +334,6 @@ public class PluginCore extends BlankForestryPlugin {
|
||||
"YBR",
|
||||
"WWW",
|
||||
'W', OreDictUtil.PLANK_WOOD,
|
||||
'D', OreDictUtil.DUST_REDSTONE,
|
||||
'Y', OreDictUtil.DYE_YELLOW,
|
||||
'B', OreDictUtil.DYE_BLUE,
|
||||
'R', OreDictUtil.DYE_RED);
|
||||
|
||||
@@ -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,7 +12,6 @@ package forestry.core.fluids;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -107,7 +106,7 @@ public final class FluidHelper {
|
||||
|
||||
boolean moveToOutput = fluidInContainer.amount >= containerCapacity;
|
||||
if (moveToOutput) {
|
||||
if (!output.isEmpty() && (output.getCount() >= output.getMaxStackSize() || !InventoryUtil.isItemEqual(filled, output))) {
|
||||
if (!output.isEmpty() && (output.getCount() >= output.getMaxStackSize() || !ItemStackUtil.areItemStacksEqualIgnoreCount(filled, output))) {
|
||||
return FillStatus.NO_SPACE;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
package forestry.core.genetics;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
@@ -26,6 +25,7 @@ import forestry.api.genetics.IChromosome;
|
||||
import forestry.api.genetics.IChromosomeType;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.core.utils.Log;
|
||||
|
||||
public abstract class Genome implements IGenome {
|
||||
private static final String SLOT_TAG = "Slot";
|
||||
@@ -138,12 +138,23 @@ public abstract class Genome implements IGenome {
|
||||
|
||||
private static IChromosome getChromosome(ItemStack itemStack, IChromosomeType chromosomeType, ISpeciesRoot speciesRoot) {
|
||||
NBTTagCompound nbtTagCompound = itemStack.getTagCompound();
|
||||
Preconditions.checkArgument(nbtTagCompound != null, "itemStack must have nbt");
|
||||
if (nbtTagCompound == null) {
|
||||
nbtTagCompound = new NBTTagCompound();
|
||||
itemStack.setTagCompound(nbtTagCompound);
|
||||
}
|
||||
|
||||
NBTTagCompound genome = nbtTagCompound.getCompoundTag("Genome");
|
||||
Preconditions.checkArgument(!genome.hasNoTags(), "itemStack nbt must have a genome tag");
|
||||
NBTTagCompound genomeNbt = nbtTagCompound.getCompoundTag("Genome");
|
||||
if (genomeNbt.hasNoTags()) {
|
||||
Log.error("Got a genetic item with no genome, setting it to a default value.");
|
||||
genomeNbt = new NBTTagCompound();
|
||||
|
||||
IAllele[] defaultTemplate = speciesRoot.getDefaultTemplate();
|
||||
IGenome genome = speciesRoot.templateAsGenome(defaultTemplate);
|
||||
genome.writeToNBT(genomeNbt);
|
||||
nbtTagCompound.setTag("Genome", genomeNbt);
|
||||
}
|
||||
|
||||
IChromosome[] chromosomes = getChromosomes(genome, speciesRoot);
|
||||
IChromosome[] chromosomes = getChromosomes(genomeNbt, speciesRoot);
|
||||
|
||||
return chromosomes[chromosomeType.ordinal()];
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -57,58 +57,58 @@ public abstract class RecipeUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static InventoryCraftingForestry getCraftRecipe(NonNullList<ItemStack> recipeItems, NonNullList<ItemStack> availableItems, World world, IRecipe recipe) {
|
||||
// Need at least one matched set
|
||||
if (ItemStackUtil.containsSets(recipeItems, availableItems, true, true) == 0) {
|
||||
public static InventoryCraftingForestry getCraftRecipe(InventoryCrafting originalCrafting, NonNullList<ItemStack> availableItems, World world, IRecipe recipe) {
|
||||
if (!recipe.matches(originalCrafting, world)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check that it doesn't make a different recipe.
|
||||
// For example:
|
||||
// Wood Logs are all ore dictionary equivalent with each other,
|
||||
// but an Oak Log shouldn't be able to make Ebony Wood Planks
|
||||
// because it makes Oak Wood Planks using the same recipe.
|
||||
// Strategy:
|
||||
// Create a fake crafting inventory using items we have in availableItems
|
||||
// in place of the ones in the saved crafting inventory.
|
||||
// Check that the recipe it makes is the same as the currentRecipe.
|
||||
|
||||
ItemStack expectedOutput = recipe.getCraftingResult(originalCrafting);
|
||||
if (expectedOutput.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
InventoryCraftingForestry crafting = new InventoryCraftingForestry();
|
||||
NonNullList<ItemStack> stockCopy = ItemStackUtil.condenseStacks(availableItems);
|
||||
|
||||
for (int slot = 0; slot < recipeItems.size(); slot++) {
|
||||
ItemStack recipeStack = recipeItems.get(slot);
|
||||
if (recipeStack.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Use crafting equivalent (not oredict) items first
|
||||
for (ItemStack stockStack : stockCopy) {
|
||||
if (stockStack.getCount() > 0 && ItemStackUtil.isCraftingEquivalent(recipeStack, stockStack, false, false)) {
|
||||
ItemStack stack = ItemStackUtil.createCopyWithCount(stockStack, 1);
|
||||
stockStack.shrink(1);
|
||||
crafting.setInventorySlotContents(slot, stack);
|
||||
break;
|
||||
for (int slot = 0; slot < originalCrafting.getSizeInventory(); slot++) {
|
||||
ItemStack stackInSlot = originalCrafting.getStackInSlot(slot);
|
||||
if (!stackInSlot.isEmpty()) {
|
||||
ItemStack equivalent = getCraftingEquivalent(stockCopy, originalCrafting, slot, world, recipe, expectedOutput);
|
||||
if (equivalent.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
crafting.setInventorySlotContents(slot, equivalent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (recipe.matches(crafting, world)) {
|
||||
ItemStack output = recipe.getCraftingResult(crafting);
|
||||
if (ItemStack.areItemStacksEqual(output, expectedOutput)) {
|
||||
return crafting;
|
||||
}
|
||||
}
|
||||
|
||||
// Use oredict items if crafting equivalent items aren't available
|
||||
if (crafting.getStackInSlot(slot).isEmpty()) {
|
||||
for (ItemStack stockStack : stockCopy) {
|
||||
if (stockStack.getCount() > 0 && ItemStackUtil.isCraftingEquivalent(recipeStack, stockStack, true, true)) {
|
||||
ItemStack stack = ItemStackUtil.createCopyWithCount(stockStack, 1);
|
||||
stockStack.shrink(1);
|
||||
crafting.setInventorySlotContents(slot, stack);
|
||||
break;
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ItemStack getCraftingEquivalent(NonNullList<ItemStack> stockCopy, InventoryCrafting crafting, int slot, World world, IRecipe recipe, ItemStack expectedOutput) {
|
||||
ItemStack originalStack = crafting.getStackInSlot(slot);
|
||||
for (ItemStack stockStack : stockCopy) {
|
||||
if (!stockStack.isEmpty()) {
|
||||
ItemStack singleStockStack = ItemStackUtil.createCopyWithCount(stockStack, 1);
|
||||
crafting.setInventorySlotContents(slot, singleStockStack);
|
||||
if (recipe.matches(crafting, world)) {
|
||||
ItemStack output = recipe.getCraftingResult(crafting);
|
||||
if (ItemStack.areItemStacksEqual(output, expectedOutput)) {
|
||||
crafting.setInventorySlotContents(slot, originalStack);
|
||||
return stockStack.splitStack(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<IRecipe> outputs = findMatchingRecipes(crafting, world);
|
||||
if (outputs.contains(recipe)) {
|
||||
return crafting;
|
||||
}
|
||||
return null;
|
||||
crafting.setInventorySlotContents(slot, originalStack);
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public static List<IRecipe> findMatchingRecipes(InventoryCrafting inventory, World world) {
|
||||
@@ -147,6 +147,7 @@ public abstract class RecipeUtil {
|
||||
GameRegistry.addSmelting(res, prod, xp);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String[][] matches(IDescriptiveRecipe recipe, IInventory inventoryCrafting) {
|
||||
NonNullList<NonNullList<ItemStack>> recipeIngredients = recipe.getRawIngredients();
|
||||
NonNullList<String> oreDicts = recipe.getOreDicts();
|
||||
@@ -155,6 +156,7 @@ public abstract class RecipeUtil {
|
||||
return matches(recipeIngredients, oreDicts, width, height, inventoryCrafting);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String[][] matches(NonNullList<NonNullList<ItemStack>> recipeIngredients, NonNullList<String> oreDicts, int width, int height, IInventory inventoryCrafting) {
|
||||
ItemStack[][] resources = getResources(inventoryCrafting);
|
||||
return matches(recipeIngredients, oreDicts, width, height, resources);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -11,14 +11,7 @@
|
||||
package forestry.core.utils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
|
||||
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;
|
||||
@@ -29,78 +22,20 @@ 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.oredict.OreDictionary;
|
||||
|
||||
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 {
|
||||
|
||||
public static boolean isWildcard(ItemStack stack) {
|
||||
return stack.getItemDamage() == OreDictionary.WILDCARD_VALUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* A more robust item comparison function. Supports items with damage = -1
|
||||
* matching any sub-type.
|
||||
*
|
||||
* @param a An ItemStack
|
||||
* @param b An ItemStack
|
||||
* @return True if equal
|
||||
*/
|
||||
public static boolean isItemEqual(ItemStack a, ItemStack b) {
|
||||
return isItemEqual(a, b, true, true);
|
||||
}
|
||||
|
||||
public static boolean isItemEqual(final ItemStack a, final ItemStack b, final boolean matchDamage, final boolean matchNBT) {
|
||||
if (a.isEmpty() || b.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
if (a.getItem() != b.getItem()) {
|
||||
return false;
|
||||
}
|
||||
if (matchNBT && !ItemStack.areItemStackTagsEqual(a, b)) {
|
||||
return false;
|
||||
}
|
||||
if (matchDamage && a.getHasSubtypes()) {
|
||||
if (isWildcard(a) || isWildcard(b)) {
|
||||
return true;
|
||||
}
|
||||
if (a.getItemDamage() != b.getItemDamage()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the item is equal to any one of several possible matches.
|
||||
*/
|
||||
public static boolean isItemEqual(ItemStack stack, ItemStack... matches) {
|
||||
for (ItemStack match : matches) {
|
||||
if (isItemEqual(stack, match)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the item is equal to any one of several possible matches.
|
||||
*
|
||||
* @param stack the ItemStack to test
|
||||
* @param matches the ItemStacks to test against
|
||||
* @return true if a match is found
|
||||
*/
|
||||
public static boolean isItemEqual(ItemStack stack, Collection<ItemStack> matches) {
|
||||
for (ItemStack match : matches) {
|
||||
if (isItemEqual(stack, match)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to move an ItemStack from one inventory to another.
|
||||
*
|
||||
@@ -218,6 +153,48 @@ public abstract class InventoryUtil {
|
||||
return ItemStackUtil.containsSets(set, stock, oreDicts, craftingTools) >= count;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean deleteExactSet(IInventory inventory, NonNullList<ItemStack> required) {
|
||||
NonNullList<ItemStack> offered = getStacks(inventory);
|
||||
NonNullList<ItemStack> condensedRequired = ItemStackUtil.condenseStacks(required);
|
||||
NonNullList<ItemStack> condensedOffered = ItemStackUtil.condenseStacks(offered);
|
||||
|
||||
for (ItemStack req : condensedRequired) {
|
||||
if (!containsExactStack(req, condensedOffered)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (ItemStack itemStack : condensedRequired) {
|
||||
deleteExactStack(inventory, itemStack);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean containsExactStack(ItemStack req, NonNullList<ItemStack> condensedOffered) {
|
||||
for (ItemStack offer : condensedOffered) {
|
||||
if (offer.getCount() >= req.getCount() && ItemStackUtil.areItemStacksEqualIgnoreCount(req, offer)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void deleteExactStack(IInventory inventory, ItemStack itemStack) {
|
||||
int count = itemStack.getCount();
|
||||
for (int j = 0; j < inventory.getSizeInventory(); j++) {
|
||||
ItemStack stackInSlot = inventory.getStackInSlot(j);
|
||||
if (!stackInSlot.isEmpty()) {
|
||||
if (ItemStackUtil.areItemStacksEqualIgnoreCount(itemStack, stackInSlot)) {
|
||||
ItemStack removed = inventory.decrStackSize(j, count);
|
||||
count -= removed.getCount();
|
||||
if (count == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static NonNullList<ItemStack> removeSets(IInventory inventory, int count, NonNullList<ItemStack> set, @Nullable EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools) {
|
||||
@@ -303,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());
|
||||
|
||||
@@ -394,7 +371,7 @@ public abstract class InventoryUtil {
|
||||
public static boolean tryAddStacksCopy(IInventory inventory, NonNullList<ItemStack> stacks, int startSlot, int slots, boolean all) {
|
||||
|
||||
for (ItemStack stack : stacks) {
|
||||
if (stack == null) {
|
||||
if (stack == null || stack.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -594,5 +594,24 @@ public abstract class ItemStackUtil {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks like {@link ItemStack#areItemStacksEqual(ItemStack, ItemStack)}
|
||||
* but ignores stack size (count).
|
||||
*/
|
||||
public static boolean areItemStacksEqualIgnoreCount(ItemStack a, ItemStack b) {
|
||||
if (a.isEmpty() && b.isEmpty()) {
|
||||
return true;
|
||||
} else if (a.isEmpty() || b.isEmpty()) {
|
||||
return false;
|
||||
} else if (a.getItem() != b.getItem()) {
|
||||
return false;
|
||||
} else if (a.getItemDamage() != b.getItemDamage()) {
|
||||
return false;
|
||||
} else if (a.getTagCompound() == null && b.getTagCompound() != null) {
|
||||
return false;
|
||||
} else {
|
||||
return (a.getTagCompound() == null || a.getTagCompound().equals(b.getTagCompound())) && a.areCapsCompatible(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,12 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
|
||||
@Mod.EventBusSubscriber
|
||||
public class MigrationHelper {
|
||||
private static Map<String, String> blockRemappings = new HashMap<>();
|
||||
private static Map<String, String> itemRemappings = new HashMap<>();
|
||||
@@ -51,6 +55,7 @@ public class MigrationHelper {
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onMissingBlockMappings(RegistryEvent.MissingMappings<Block> event) {
|
||||
for (RegistryEvent.MissingMappings.Mapping<Block> missingMapping : event.getMappings()) {
|
||||
ResourceLocation resourceLocation = missingMapping.key;
|
||||
@@ -70,6 +75,7 @@ public class MigrationHelper {
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onMissingItemMappings(RegistryEvent.MissingMappings<Item> event) {
|
||||
for (RegistryEvent.MissingMappings.Mapping<Item> missingMapping : event.getMappings()) {
|
||||
ResourceLocation resourceLocation = missingMapping.key;
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -12,6 +12,7 @@ package forestry.core.utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import forestry.core.gui.slots.SlotCrafter;
|
||||
import forestry.core.gui.slots.SlotForestry;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
@@ -70,7 +71,7 @@ public abstract class SlotUtil {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
boolean fromCraftingSlot = slot instanceof SlotCrafting;
|
||||
boolean fromCraftingSlot = slot instanceof SlotCrafting || slot instanceof SlotCrafter;
|
||||
|
||||
int numSlots = inventorySlots.size();
|
||||
ItemStack stackInSlot = slot.getStack();
|
||||
@@ -82,7 +83,7 @@ public abstract class SlotUtil {
|
||||
|
||||
slot.onSlotChange(stackInSlot, originalStack);
|
||||
if (stackInSlot.isEmpty()) {
|
||||
slot.putStack(stackInSlot);
|
||||
slot.putStack(ItemStack.EMPTY);
|
||||
} else {
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package forestry.core.utils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
public class WeightedCollection<T> {
|
||||
private final NavigableMap<Double, T> map = new TreeMap<>();
|
||||
private double total = 0;
|
||||
|
||||
public void put(double weight, T value) {
|
||||
Preconditions.checkArgument(weight > 0);
|
||||
total += weight;
|
||||
map.put(total, value);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public T getRandom(Random random) {
|
||||
double value = random.nextDouble() * total;
|
||||
Map.Entry<Double, T> higherEntry = map.higherEntry(value);
|
||||
if (higherEntry == null) {
|
||||
return null;
|
||||
}
|
||||
return higherEntry.getValue();
|
||||
}
|
||||
|
||||
public Set<Map.Entry<Double, T>> entrySet() {
|
||||
return Collections.unmodifiableSet(map.entrySet());
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import net.minecraft.world.gen.IChunkGenerator;
|
||||
import net.minecraft.world.gen.feature.WorldGenMinable;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.terraingen.DecorateBiomeEvent;
|
||||
import net.minecraftforge.event.terraingen.PopulateChunkEvent;
|
||||
import net.minecraftforge.fml.common.IWorldGenerator;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
@@ -54,6 +55,11 @@ public class WorldGenerator implements IWorldGenerator {
|
||||
PluginManager.populateChunk(event.getGen(), event.getWorld(), event.getRand(), event.getChunkX(), event.getChunkZ(), event.isHasVillageGenerated());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void decorateBiome(DecorateBiomeEvent.Post event) {
|
||||
PluginManager.decorateBiome(event.getWorld(), event.getRand(), event.getPos());
|
||||
}
|
||||
|
||||
public void retroGen(Random random, int chunkX, int chunkZ, World world) {
|
||||
generateWorld(random, chunkX, chunkZ, world);
|
||||
PluginManager.populateChunkRetroGen(world, random, chunkX, chunkZ);
|
||||
@@ -79,9 +85,11 @@ public class WorldGenerator implements IWorldGenerator {
|
||||
|
||||
// / APATITE
|
||||
if (Config.generateApatiteOre) {
|
||||
final int lowest = Math.round(world.getActualHeight() * 0.22f); // 56
|
||||
final int range = Math.round(world.getActualHeight() * 0.72f); // 184
|
||||
if (random.nextFloat() < 0.8f) {
|
||||
int randPosX = x + random.nextInt(16);
|
||||
int randPosY = random.nextInt(world.getActualHeight() - 72) + 56; // Does not generate below y = 64
|
||||
int randPosY = random.nextInt(range) + lowest;
|
||||
int randPosZ = y + random.nextInt(16);
|
||||
apatiteGenerator.generate(world, random, new BlockPos(randPosX, randPosY, randPosZ));
|
||||
}
|
||||
@@ -90,8 +98,10 @@ public class WorldGenerator implements IWorldGenerator {
|
||||
// / COPPER
|
||||
if (Config.generateCopperOre) {
|
||||
for (int i = 0; i < 20; i++) {
|
||||
final int lowest = Math.round(world.getActualHeight() / 8f); // 32
|
||||
final int range = Math.round(world.getActualHeight() * 0.297f); // 76
|
||||
int randPosX = x + random.nextInt(16);
|
||||
int randPosY = random.nextInt(76) + 32;
|
||||
int randPosY = random.nextInt(range) + lowest;
|
||||
int randPosZ = y + random.nextInt(16);
|
||||
copperGenerator.generate(world, random, new BlockPos(randPosX, randPosY, randPosZ));
|
||||
}
|
||||
@@ -100,8 +110,10 @@ public class WorldGenerator implements IWorldGenerator {
|
||||
// / TIN
|
||||
if (Config.generateTinOre) {
|
||||
for (int i = 0; i < 18; i++) {
|
||||
final int lowest = Math.round(world.getActualHeight() / 16f); // 16
|
||||
final int range = Math.round(world.getActualHeight() * 0.297f); // 76
|
||||
int randPosX = x + random.nextInt(16);
|
||||
int randPosY = random.nextInt(76) + 16;
|
||||
int randPosY = random.nextInt(range) + lowest;
|
||||
int randPosZ = y + random.nextInt(16);
|
||||
tinGenerator.generate(world, random, new BlockPos(randPosX, randPosY, randPosZ));
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -12,14 +12,31 @@ package forestry.factory.inventory;
|
||||
|
||||
import forestry.core.gui.ContainerDummy;
|
||||
import forestry.factory.gui.ContainerWorktable;
|
||||
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
|
||||
public class InventoryCraftingForestry extends InventoryCrafting {
|
||||
private final Container eventHandlerIn;
|
||||
|
||||
public InventoryCraftingForestry(ContainerWorktable containerWorktable) {
|
||||
super(containerWorktable, 3, 3);
|
||||
this(containerWorktable, 3, 3);
|
||||
}
|
||||
|
||||
public InventoryCraftingForestry() {
|
||||
super(ContainerDummy.instance, 3, 3);
|
||||
this(ContainerDummy.instance, 3, 3);
|
||||
}
|
||||
|
||||
private InventoryCraftingForestry(Container eventHandlerIn, int width, int height) {
|
||||
super(eventHandlerIn, width, height);
|
||||
this.eventHandlerIn = eventHandlerIn;
|
||||
}
|
||||
|
||||
public InventoryCraftingForestry copy() {
|
||||
InventoryCraftingForestry copy = new InventoryCraftingForestry(this.eventHandlerIn, getWidth(), getHeight());
|
||||
for (int slot = 0; slot < getSizeInventory(); slot++) {
|
||||
copy.setInventorySlotContents(slot, getStackInSlot(slot).copy());
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
@@ -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++;
|
||||
|
||||
@@ -23,7 +23,6 @@ import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryBasic;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.NonNullList;
|
||||
@@ -150,14 +149,13 @@ public class TileWorktable extends TileBase implements ICrafterWorktable {
|
||||
return false;
|
||||
}
|
||||
|
||||
NonNullList<ItemStack> recipeItems = InventoryUtil.getStacks(currentRecipe.getCraftMatrix());
|
||||
NonNullList<ItemStack> inventoryStacks = InventoryUtil.getStacks(this);
|
||||
InventoryCraftingForestry crafting = RecipeUtil.getCraftRecipe(recipeItems, inventoryStacks, world, selectedRecipe);
|
||||
InventoryCraftingForestry crafting = RecipeUtil.getCraftRecipe(currentRecipe.getCraftMatrix(), inventoryStacks, world, selectedRecipe);
|
||||
if (crafting == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
recipeItems = InventoryUtil.getStacks(crafting);
|
||||
|
||||
NonNullList<ItemStack> recipeItems = InventoryUtil.getStacks(crafting);
|
||||
|
||||
IInventory inventory;
|
||||
if (simulate) {
|
||||
@@ -167,15 +165,14 @@ public class TileWorktable extends TileBase implements ICrafterWorktable {
|
||||
inventory = this;
|
||||
}
|
||||
|
||||
// craft recipe should exactly match ingredients here, so no oreDict or tool matching
|
||||
NonNullList<ItemStack> removed = InventoryUtil.removeSets(inventory, 1, recipeItems, null, false, false, false);
|
||||
if (removed == null) {
|
||||
if (!InventoryUtil.deleteExactSet(inventory, recipeItems)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!simulate) {
|
||||
// update crafting display to match the ingredients that were actually used
|
||||
setCraftingDisplay(crafting);
|
||||
currentRecipe.setCraftMatrix(crafting);
|
||||
setCurrentRecipe(currentRecipe);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -184,13 +181,16 @@ public class TileWorktable extends TileBase implements ICrafterWorktable {
|
||||
@Override
|
||||
public void onCraftingComplete(EntityPlayer player) {
|
||||
Preconditions.checkState(currentRecipe != null);
|
||||
|
||||
IRecipe selectedRecipe = currentRecipe.getSelectedRecipe();
|
||||
Preconditions.checkState(selectedRecipe != null);
|
||||
|
||||
ForgeHooks.setCraftingPlayer(player);
|
||||
NonNullList<ItemStack> remainingItems = CraftingManager.getRemainingItems(currentRecipe.getCraftMatrix(), player.world);
|
||||
InventoryCraftingForestry craftMatrix = currentRecipe.getCraftMatrix();
|
||||
NonNullList<ItemStack> remainingItems = selectedRecipe.getRemainingItems(craftMatrix.copy());
|
||||
ForgeHooks.setCraftingPlayer(null);
|
||||
|
||||
for (ItemStack remainingItem : remainingItems) {
|
||||
if (remainingItem != null) {
|
||||
if (remainingItem != null && !remainingItem.isEmpty()) {
|
||||
if (!InventoryUtil.tryAddStack(this, remainingItem, true)) {
|
||||
player.dropItem(remainingItem, false);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
package forestry.farming;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
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;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
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;
|
||||
@@ -24,15 +28,13 @@ import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.core.utils.Translator;
|
||||
import forestry.farming.logic.FarmLogicSimple;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
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;
|
||||
@@ -42,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));
|
||||
@@ -90,7 +100,11 @@ public final class FarmRegistry implements IFarmRegistry {
|
||||
try {
|
||||
String fertilizer = fertilizerList[i];
|
||||
String[] fertilizers = fertilizer.split(";");
|
||||
ItemStack fertilizerItem = ItemStackUtil.parseItemStackString(fertilizers[0], OreDictionary.WILDCARD_VALUE);
|
||||
String itemName = fertilizers[0];
|
||||
if(itemName.equals("forestry:fertilizerCompound")){
|
||||
itemName = "forestry:fertilizer_compound";
|
||||
}
|
||||
ItemStack fertilizerItem = ItemStackUtil.parseItemStackString(itemName, OreDictionary.WILDCARD_VALUE);
|
||||
int fertilizerValue = Integer.parseInt(fertilizers[1]);
|
||||
registerFertilizer(fertilizerItem, fertilizerValue);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -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
|
||||
@@ -213,7 +220,7 @@ public class PluginFarming extends BlankForestryPlugin {
|
||||
valve.setTagCompound(compound);
|
||||
control.setTagCompound(compound);
|
||||
|
||||
RecipeUtil.addRecipe("farm_basic", basic,
|
||||
RecipeUtil.addRecipe("farm_basic_" + block.getUid(), basic,
|
||||
"I#I",
|
||||
"WCW",
|
||||
'#', block.getBase(),
|
||||
@@ -221,27 +228,27 @@ public class PluginFarming extends BlankForestryPlugin {
|
||||
'C', coreItems.tubes.get(EnumElectronTube.TIN, 1),
|
||||
'I', "ingotCopper");
|
||||
|
||||
RecipeUtil.addRecipe("farm_gearbox", gearbox,
|
||||
RecipeUtil.addRecipe("farm_gearbox_" + block.getUid(), gearbox,
|
||||
" # ",
|
||||
"TTT",
|
||||
'#', basic,
|
||||
'T', "gearTin");
|
||||
|
||||
RecipeUtil.addRecipe("farm_hatch", hatch,
|
||||
RecipeUtil.addRecipe("farm_hatch_" + block.getUid(), hatch,
|
||||
" # ",
|
||||
"TDT",
|
||||
'#', basic,
|
||||
'T', "gearTin",
|
||||
'D', OreDictUtil.TRAPDOOR_WOOD);
|
||||
|
||||
RecipeUtil.addRecipe("farm_valve", valve,
|
||||
RecipeUtil.addRecipe("farm_valve_" + block.getUid(), valve,
|
||||
" # ",
|
||||
"XTX",
|
||||
'#', basic,
|
||||
'T', "gearTin",
|
||||
'X', "blockGlass");
|
||||
|
||||
RecipeUtil.addRecipe("farm_control", control,
|
||||
RecipeUtil.addRecipe("farm_control_" + block.getUid(), control,
|
||||
" # ",
|
||||
"XTX",
|
||||
'#', basic,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package forestry.farming.compat;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.farming.PluginFarming;
|
||||
import forestry.farming.blocks.BlockRegistryFarming;
|
||||
import forestry.farming.models.EnumFarmBlockTexture;
|
||||
import forestry.plugins.ForestryPluginUids;
|
||||
|
||||
import mezz.jei.api.IModPlugin;
|
||||
import mezz.jei.api.ISubtypeRegistry;
|
||||
import mezz.jei.api.JEIPlugin;
|
||||
|
||||
@JEIPlugin
|
||||
public class FarmingJeiPlugin implements IModPlugin {
|
||||
@Override
|
||||
public void registerItemSubtypes(ISubtypeRegistry subtypeRegistry) {
|
||||
if (!ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING)) {
|
||||
return;
|
||||
}
|
||||
|
||||
BlockRegistryFarming blocks = PluginFarming.getBlocks();
|
||||
Item farmBlock = Item.getItemFromBlock(blocks.farm);
|
||||
subtypeRegistry.registerSubtypeInterpreter(farmBlock, itemStack -> {
|
||||
NBTTagCompound nbt = itemStack.getTagCompound();
|
||||
EnumFarmBlockTexture texture = EnumFarmBlockTexture.getFromCompound(nbt);
|
||||
return itemStack.getItemDamage() + "." + texture.getUid();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.farming.compat;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
@@ -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) {
|
||||
|
||||
+23
-13
@@ -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)});
|
||||
}
|
||||
}
|
||||
Loaded 100 of 117 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user