mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-22 04:52:26 +00:00
Fix #1833 Item in players hand get deleted by farm planting
This commit is contained in:
1 parent
e09d159935
commit
b3549edf51
4 files changed
+22
-13
No files matched your search
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -769,7 +769,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
@Override
|
||||
public boolean plantGermling(IFarmable germling, World world, BlockPos pos) {
|
||||
EntityPlayer player = PlayerUtil.getPlayer(world, getOwnerHandler().getOwner());
|
||||
EntityPlayer player = PlayerUtil.getFakePlayer(world, getOwnerHandler().getOwner());
|
||||
return player != null && inventory.plantGermling(germling, player, pos);
|
||||
}
|
||||
|
||||
|
||||
@@ -95,8 +95,7 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
|
||||
|
||||
@Override
|
||||
public void removeResources(NonNullList<ItemStack> resources) {
|
||||
EntityPlayer player = PlayerUtil.getPlayer(farmController.getWorldObj(), farmController.getOwnerHandler().getOwner());
|
||||
InventoryUtil.removeSets(resourcesInventory, 1, resources, player, false, true, false, true);
|
||||
InventoryUtil.removeSets(resourcesInventory, 1, resources, null, false, true, false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user