mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-19 11:49:14 +00:00
Move getPlayer from ProxyCommon to PlayerUtil
This commit is contained in:
1 parent
84968c6021
commit
02c25142cd
9 files changed
+41
-35
No files matched your search
@@ -113,25 +113,4 @@ public class ProxyCommon {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a player for a given World and GameProfile.
|
||||
* If they are not in the World, returns a FakePlayer.
|
||||
* Do not store references to the return value, to prevent worlds staying in memory.
|
||||
*/
|
||||
public EntityPlayer getPlayer(World world, GameProfile profile) {
|
||||
if (world == null) {
|
||||
throw new IllegalArgumentException("World cannot be null");
|
||||
}
|
||||
|
||||
if (profile == null || profile.getName() == null) {
|
||||
return FakePlayerFactory.getMinecraft((WorldServer) world);
|
||||
}
|
||||
|
||||
EntityPlayer player = world.getPlayerEntityByName(profile.getName());
|
||||
if (player != null) {
|
||||
return player;
|
||||
} else {
|
||||
return FakePlayerFactory.get((WorldServer) world, profile);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,9 +133,4 @@ public class ProxyCommonClient extends ProxyCommon {
|
||||
public EntityPlayer getPlayer() {
|
||||
return Minecraft.getMinecraft().thePlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPlayer getPlayer(World world, GameProfile profile) {
|
||||
return super.getPlayer(world, profile);
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,13 @@ import java.util.UUID;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraftforge.common.util.FakePlayerFactory;
|
||||
|
||||
import forestry.core.access.IOwnable;
|
||||
|
||||
import buildcraft.api.tools.IToolWrench;
|
||||
@@ -77,4 +81,29 @@ public abstract class PlayerUtil {
|
||||
IToolWrench wrench = (IToolWrench) itemstack.getItem();
|
||||
wrench.wrenchUsed(player, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a player for a given World and GameProfile.
|
||||
* If they are not in the World, returns a FakePlayer.
|
||||
* Do not store references to the return value, to prevent worlds staying in memory.
|
||||
*/
|
||||
public static EntityPlayer getPlayer(World world, GameProfile profile) {
|
||||
if (world == null) {
|
||||
throw new IllegalArgumentException("World cannot be null");
|
||||
}
|
||||
|
||||
if (profile == null || profile.getName() == null) {
|
||||
if (world instanceof WorldServer) {
|
||||
return FakePlayerFactory.getMinecraft((WorldServer) world);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
EntityPlayer player = world.getPlayerEntityByName(profile.getName());
|
||||
if (player == null && world instanceof WorldServer) {
|
||||
player = FakePlayerFactory.get((WorldServer) world, profile);
|
||||
}
|
||||
return player;
|
||||
}
|
||||
}
|
||||
@@ -41,13 +41,13 @@ import forestry.core.inventory.TileInventoryAdapter;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.TankRenderInfo;
|
||||
import forestry.core.tiles.IItemStackDisplay;
|
||||
import forestry.core.tiles.ILiquidTankTile;
|
||||
import forestry.core.tiles.TilePowered;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import forestry.core.utils.SlotUtil;
|
||||
import forestry.factory.recipes.CarpenterRecipeManager;
|
||||
|
||||
@@ -298,7 +298,7 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
|
||||
}
|
||||
|
||||
private boolean removeSets(int count, ItemStack[] set) {
|
||||
EntityPlayer player = Proxies.common.getPlayer(worldObj, getAccessHandler().getOwner());
|
||||
EntityPlayer player = PlayerUtil.getPlayer(worldObj, getAccessHandler().getOwner());
|
||||
return InventoryUtil.removeSets(getInternalInventory(), count, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,12 +44,12 @@ import forestry.core.inventory.TileInventoryAdapter;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.TankRenderInfo;
|
||||
import forestry.core.tiles.ILiquidTankTile;
|
||||
import forestry.core.tiles.TilePowered;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import forestry.factory.recipes.SqueezerRecipeManager;
|
||||
|
||||
public class TileSqueezer extends TilePowered implements ISocketable, ISidedInventory, ILiquidTankTile, ISpeedUpgradable {
|
||||
@@ -140,7 +140,7 @@ public class TileSqueezer extends TilePowered implements ISocketable, ISidedInve
|
||||
|
||||
@Override
|
||||
public boolean workCycle() {
|
||||
EntityPlayer player = Proxies.common.getPlayer(worldObj, getAccessHandler().getOwner());
|
||||
EntityPlayer player = PlayerUtil.getPlayer(worldObj, getAccessHandler().getOwner());
|
||||
if (!inventory.removeResources(currentRecipe.getResources(), player)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.PacketGuiUpdate;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import forestry.core.utils.vect.Vect;
|
||||
import forestry.core.utils.vect.VectUtil;
|
||||
import forestry.farming.FarmHelper;
|
||||
@@ -803,7 +804,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
@Override
|
||||
public boolean plantGermling(IFarmable germling, World world, int x, int y, int z) {
|
||||
EntityPlayer player = Proxies.common.getPlayer(world, getAccessHandler().getOwner());
|
||||
EntityPlayer player = PlayerUtil.getPlayer(world, getAccessHandler().getOwner());
|
||||
return inventory.plantGermling(germling, player, x, y, z);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,9 +26,9 @@ import forestry.core.fluids.FluidHelper;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.inventory.InventoryAdapterRestricted;
|
||||
import forestry.core.inventory.wrappers.InventoryMapper;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import forestry.core.utils.SlotUtil;
|
||||
import forestry.plugins.PluginFarming;
|
||||
|
||||
@@ -91,7 +91,7 @@ public class FarmInventory extends InventoryAdapterRestricted implements IFarmIn
|
||||
|
||||
@Override
|
||||
public void removeResources(ItemStack[] resources) {
|
||||
EntityPlayer player = Proxies.common.getPlayer(farmController.getWorld(), farmController.getAccessHandler().getOwner());
|
||||
EntityPlayer player = PlayerUtil.getPlayer(farmController.getWorld(), farmController.getAccessHandler().getOwner());
|
||||
InventoryUtil.removeSets(resourcesInventory, 1, resources, player, false, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ import forestry.api.mail.ITradeStation;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.core.config.ForestryItem;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import forestry.mail.items.ItemLetter;
|
||||
import forestry.mail.network.PacketPOBoxInfoResponse;
|
||||
|
||||
@@ -73,7 +74,7 @@ public class PostRegistry implements IPostRegistry {
|
||||
pobox.markDirty();
|
||||
cachedPOBoxes.put(address, pobox);
|
||||
|
||||
EntityPlayer player = Proxies.common.getPlayer(world, address.getPlayerProfile());
|
||||
EntityPlayer player = PlayerUtil.getPlayer(world, address.getPlayerProfile());
|
||||
if (player != null) {
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfoResponse(pobox.getPOBoxInfo()), player);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import forestry.api.mail.ITradeStation;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.TextureManager;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import forestry.core.utils.StringUtil;
|
||||
import forestry.mail.network.PacketPOBoxInfoResponse;
|
||||
|
||||
@@ -85,7 +86,7 @@ public class PostalCarrier implements IPostalCarrier {
|
||||
if (!pobox.storeLetter(letterStack.copy())) {
|
||||
return EnumDeliveryState.MAILBOX_FULL;
|
||||
} else {
|
||||
EntityPlayer player = Proxies.common.getPlayer(world, recipient.getPlayerProfile());
|
||||
EntityPlayer player = PlayerUtil.getPlayer(world, recipient.getPlayerProfile());
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfoResponse(pobox.getPOBoxInfo()), (EntityPlayerMP) player);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user