diff --git a/src/main/java/forestry/core/utils/PlayerUtil.java b/src/main/java/forestry/core/utils/PlayerUtil.java index 7662c4b81..8da580398 100644 --- a/src/main/java/forestry/core/utils/PlayerUtil.java +++ b/src/main/java/forestry/core/utils/PlayerUtil.java @@ -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()); diff --git a/src/main/java/forestry/farming/logic/FarmableSapling.java b/src/main/java/forestry/farming/logic/FarmableSapling.java index e4a36f0eb..02add135a 100644 --- a/src/main/java/forestry/farming/logic/FarmableSapling.java +++ b/src/main/java/forestry/farming/logic/FarmableSapling.java @@ -10,31 +10,21 @@ ******************************************************************************/ package forestry.farming.logic; -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.blocks.BlockRegistry; import forestry.core.network.packets.PacketFXSignal; -import forestry.core.utils.GeneticsUtil; import forestry.core.utils.ItemStackUtil; import forestry.core.utils.NetworkUtil; -import forestry.plugins.ForestryPluginUids; 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.EnumAction; -import net.minecraft.item.Item; 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 net.minecraftforge.fml.common.registry.GameRegistry; public class FarmableSapling implements IFarmable { protected final ItemStack germling; diff --git a/src/main/java/forestry/farming/multiblock/FarmController.java b/src/main/java/forestry/farming/multiblock/FarmController.java index b98445f72..a7a4371d8 100755 --- a/src/main/java/forestry/farming/multiblock/FarmController.java +++ b/src/main/java/forestry/farming/multiblock/FarmController.java @@ -769,7 +769,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen @Override public boolean plantGermling(IFarmable germling, World world, BlockPos pos) { - EntityPlayer player = PlayerUtil.getPlayer(world, getOwnerHandler().getOwner()); + EntityPlayer player = PlayerUtil.getFakePlayer(world, getOwnerHandler().getOwner()); return player != null && inventory.plantGermling(germling, player, pos); } diff --git a/src/main/java/forestry/farming/multiblock/InventoryFarm.java b/src/main/java/forestry/farming/multiblock/InventoryFarm.java index 904598585..f423d7997 100644 --- a/src/main/java/forestry/farming/multiblock/InventoryFarm.java +++ b/src/main/java/forestry/farming/multiblock/InventoryFarm.java @@ -95,8 +95,7 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn @Override public void removeResources(NonNullList resources) { - EntityPlayer player = PlayerUtil.getPlayer(farmController.getWorldObj(), farmController.getOwnerHandler().getOwner()); - InventoryUtil.removeSets(resourcesInventory, 1, resources, player, false, true, false, true); + InventoryUtil.removeSets(resourcesInventory, 1, resources, null, false, true, false, true); } @Override