2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
|
|
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
package appeng.util;
|
|
|
|
|
2014-11-28 04:36:46 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.lang.reflect.Field;
|
2014-08-07 08:47:42 +02:00
|
|
|
import java.lang.reflect.Method;
|
2014-05-25 01:22:50 +02:00
|
|
|
import java.text.DecimalFormat;
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.Iterator;
|
2014-09-11 06:12:34 +02:00
|
|
|
import java.util.LinkedList;
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
2014-02-09 02:34:52 +01:00
|
|
|
import java.util.Set;
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.util.WeakHashMap;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.client.Minecraft;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
2014-01-20 17:41:37 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.entity.item.EntityItem;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.init.Blocks;
|
2014-07-13 00:57:53 +02:00
|
|
|
import net.minecraft.init.Items;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.inventory.IInventory;
|
2013-12-28 22:05:58 +01:00
|
|
|
import net.minecraft.inventory.ISidedInventory;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.inventory.InventoryCrafting;
|
|
|
|
import net.minecraft.inventory.InventoryLargeChest;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.item.crafting.CraftingManager;
|
|
|
|
import net.minecraft.item.crafting.IRecipe;
|
|
|
|
import net.minecraft.nbt.NBTBase;
|
|
|
|
import net.minecraft.nbt.NBTTagByte;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.nbt.NBTTagDouble;
|
|
|
|
import net.minecraft.nbt.NBTTagFloat;
|
|
|
|
import net.minecraft.nbt.NBTTagInt;
|
|
|
|
import net.minecraft.nbt.NBTTagList;
|
|
|
|
import net.minecraft.nbt.NBTTagLong;
|
|
|
|
import net.minecraft.nbt.NBTTagString;
|
2014-08-07 08:47:42 +02:00
|
|
|
import net.minecraft.network.Packet;
|
|
|
|
import net.minecraft.network.play.server.S21PacketChunkData;
|
|
|
|
import net.minecraft.server.management.PlayerManager;
|
2014-09-14 07:02:02 +02:00
|
|
|
import net.minecraft.stats.Achievement;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.tileentity.TileEntityChest;
|
2014-01-20 17:41:37 +01:00
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.util.MathHelper;
|
2014-01-20 17:41:37 +01:00
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.util.StatCollector;
|
|
|
|
import net.minecraft.util.Vec3;
|
|
|
|
import net.minecraft.world.World;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.world.WorldServer;
|
2014-08-07 08:47:42 +02:00
|
|
|
import net.minecraft.world.chunk.Chunk;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.FakePlayerFactory;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-09-07 00:54:12 +02:00
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
2014-11-28 04:36:46 +01:00
|
|
|
|
|
|
|
import cpw.mods.fml.common.FMLCommonHandler;
|
|
|
|
import cpw.mods.fml.common.Loader;
|
|
|
|
import cpw.mods.fml.common.ModContainer;
|
|
|
|
import cpw.mods.fml.relauncher.ReflectionHelper;
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
import buildcraft.api.tools.IToolWrench;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.AEApi;
|
|
|
|
import appeng.api.config.AccessRestriction;
|
|
|
|
import appeng.api.config.Actionable;
|
|
|
|
import appeng.api.config.FuzzyMode;
|
|
|
|
import appeng.api.config.PowerMultiplier;
|
2014-05-25 01:22:50 +02:00
|
|
|
import appeng.api.config.PowerUnits;
|
2014-02-27 08:10:11 +01:00
|
|
|
import appeng.api.config.SearchBoxMode;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.api.config.SecurityPermissions;
|
2014-02-27 08:10:11 +01:00
|
|
|
import appeng.api.config.SortOrder;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.api.definitions.IItemDefinition;
|
|
|
|
import appeng.api.definitions.IMaterials;
|
|
|
|
import appeng.api.definitions.IParts;
|
2014-01-23 20:02:48 +01:00
|
|
|
import appeng.api.implementations.items.IAEItemPowerStorage;
|
|
|
|
import appeng.api.implementations.items.IAEWrench;
|
|
|
|
import appeng.api.implementations.tiles.ITileStorageMonitorable;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.api.networking.IGrid;
|
2014-05-04 21:54:21 +02:00
|
|
|
import appeng.api.networking.IGridNode;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.api.networking.energy.IEnergyGrid;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.networking.energy.IEnergySource;
|
2014-01-05 09:43:49 +01:00
|
|
|
import appeng.api.networking.security.BaseActionSource;
|
2014-04-18 05:33:48 +02:00
|
|
|
import appeng.api.networking.security.IActionHost;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.api.networking.security.ISecurityGrid;
|
2014-04-18 05:33:48 +02:00
|
|
|
import appeng.api.networking.security.MachineSource;
|
|
|
|
import appeng.api.networking.security.PlayerSource;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.networking.storage.IStorageGrid;
|
|
|
|
import appeng.api.storage.IMEInventory;
|
2014-05-01 06:01:22 +02:00
|
|
|
import appeng.api.storage.IMEMonitor;
|
2014-02-12 17:35:42 +01:00
|
|
|
import appeng.api.storage.IMEMonitorHandlerReceiver;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.storage.StorageChannel;
|
|
|
|
import appeng.api.storage.data.IAEFluidStack;
|
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
|
|
|
import appeng.api.storage.data.IAEStack;
|
|
|
|
import appeng.api.storage.data.IAETagCompound;
|
|
|
|
import appeng.api.storage.data.IItemList;
|
2014-07-26 02:31:12 +02:00
|
|
|
import appeng.api.util.AEColor;
|
2014-08-29 04:37:08 +02:00
|
|
|
import appeng.api.util.DimensionalCoord;
|
2014-05-25 01:22:50 +02:00
|
|
|
import appeng.core.AEConfig;
|
2014-02-09 02:34:52 +01:00
|
|
|
import appeng.core.AELog;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.core.AppEng;
|
2014-07-13 00:57:53 +02:00
|
|
|
import appeng.core.features.AEFeature;
|
2014-08-31 10:06:06 +02:00
|
|
|
import appeng.core.stats.Stats;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.core.sync.GuiBridge;
|
2014-08-09 21:09:49 +02:00
|
|
|
import appeng.core.sync.GuiHostType;
|
2014-07-08 06:54:28 +02:00
|
|
|
import appeng.hooks.TickHandler;
|
2014-07-24 00:26:23 +02:00
|
|
|
import appeng.integration.IntegrationType;
|
2014-04-18 05:33:48 +02:00
|
|
|
import appeng.me.GridAccessException;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.me.GridNode;
|
2014-04-18 05:33:48 +02:00
|
|
|
import appeng.me.helpers.AENetworkProxy;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.util.item.AEItemStack;
|
|
|
|
import appeng.util.item.AESharedNBT;
|
2014-02-13 06:24:07 +01:00
|
|
|
import appeng.util.item.OreHelper;
|
2014-11-28 04:36:46 +01:00
|
|
|
import appeng.util.item.OreReference;
|
2014-09-17 06:26:25 +02:00
|
|
|
import appeng.util.prioitylist.IPartitionList;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public class Platform
|
|
|
|
{
|
|
|
|
|
2015-01-01 22:13:10 +01:00
|
|
|
public static final Block AIR = Blocks.air;
|
2014-02-09 02:34:52 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public static final int DEF_OFFSET = 16;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* random source, use it for item drop locations...
|
|
|
|
*/
|
2015-01-01 22:13:10 +01:00
|
|
|
static private final Random RANDOM_GENERATOR = new Random();
|
2015-04-03 08:54:31 +02:00
|
|
|
private static final WeakHashMap<World, EntityPlayer> FAKE_PLAYERS = new WeakHashMap<World, EntityPlayer>();
|
|
|
|
private static Field tagList;
|
|
|
|
private static Class playerInstance;
|
|
|
|
private static Method getOrCreateChunkWatcher;
|
|
|
|
private static Method sendToAllPlayersWatchingChunk;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-02-14 06:32:35 +01:00
|
|
|
public static Random getRandom()
|
|
|
|
{
|
2015-01-01 22:13:10 +01:00
|
|
|
return RANDOM_GENERATOR;
|
2014-02-14 06:32:35 +01:00
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public static float getRandomFloat()
|
|
|
|
{
|
2015-01-01 22:13:10 +01:00
|
|
|
return RANDOM_GENERATOR.nextFloat();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-05-25 01:22:50 +02:00
|
|
|
/**
|
|
|
|
* This displays the value for encoded longs ( double *100 )
|
2015-02-03 12:04:13 +01:00
|
|
|
*
|
2015-04-03 08:54:31 +02:00
|
|
|
* @param n to be formatted long value
|
2014-09-27 23:17:47 +02:00
|
|
|
* @param isRate if true it adds a /t to the formatted string
|
2015-04-03 08:54:31 +02:00
|
|
|
*
|
2014-09-27 23:17:47 +02:00
|
|
|
* @return formatted long value
|
2014-05-25 01:22:50 +02:00
|
|
|
*/
|
2015-04-03 08:54:31 +02:00
|
|
|
public static String formatPowerLong( long n, boolean isRate )
|
2014-05-25 01:22:50 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
double p = ( (double) n ) / 100;
|
2014-05-25 01:22:50 +02:00
|
|
|
|
|
|
|
PowerUnits displayUnits = AEConfig.instance.selectedPowerUnit();
|
|
|
|
p = PowerUnits.AE.convertTo( displayUnits, p );
|
|
|
|
|
|
|
|
int offset = 0;
|
|
|
|
String Lvl = "";
|
2015-01-01 21:15:03 +01:00
|
|
|
String[] preFixes = new String[] { "k", "M", "G", "T", "P", "T", "P", "E", "Z", "Y" };
|
2014-05-25 01:22:50 +02:00
|
|
|
String unitName = displayUnits.name();
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( displayUnits == PowerUnits.WA )
|
2014-05-25 01:22:50 +02:00
|
|
|
unitName = "J";
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( displayUnits == PowerUnits.MK )
|
2014-05-25 01:22:50 +02:00
|
|
|
unitName = "J";
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
while( p > 1000 && offset < preFixes.length )
|
2014-05-25 01:22:50 +02:00
|
|
|
{
|
|
|
|
p /= 1000;
|
|
|
|
Lvl = preFixes[offset];
|
|
|
|
offset++;
|
|
|
|
}
|
|
|
|
|
|
|
|
DecimalFormat df = new DecimalFormat( "#.##" );
|
2015-04-03 08:54:31 +02:00
|
|
|
return df.format( p ) + ' ' + Lvl + unitName + ( isRate ? "/t" : "" );
|
2014-05-25 01:22:50 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static ForgeDirection crossProduct( ForgeDirection forward, ForgeDirection up )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
int west_x = forward.offsetY * up.offsetZ - forward.offsetZ * up.offsetY;
|
|
|
|
int west_y = forward.offsetZ * up.offsetX - forward.offsetX * up.offsetZ;
|
|
|
|
int west_z = forward.offsetX * up.offsetY - forward.offsetY * up.offsetX;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( west_x + west_y * 2 + west_z * 3 )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
case 1:
|
|
|
|
return ForgeDirection.EAST;
|
|
|
|
case -1:
|
|
|
|
return ForgeDirection.WEST;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
case 2:
|
|
|
|
return ForgeDirection.UP;
|
|
|
|
case -2:
|
|
|
|
return ForgeDirection.DOWN;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
case 3:
|
|
|
|
return ForgeDirection.SOUTH;
|
|
|
|
case -3:
|
|
|
|
return ForgeDirection.NORTH;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ForgeDirection.UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static <T extends Enum> T rotateEnum( T ce, boolean backwards, EnumSet ValidOptions )
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if( backwards )
|
|
|
|
ce = prevEnum( ce );
|
|
|
|
else
|
|
|
|
ce = nextEnum( ce );
|
|
|
|
}
|
|
|
|
while( !ValidOptions.contains( ce ) || isNotValidSetting( ce ) );
|
|
|
|
|
|
|
|
return ce;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
/*
|
|
|
|
* Simple way to cycle an enum...
|
|
|
|
*/
|
2015-04-03 08:54:31 +02:00
|
|
|
public static <T extends Enum> T prevEnum( T ce )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
EnumSet valList = EnumSet.allOf( ce.getClass() );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
int pLoc = ce.ordinal() - 1;
|
|
|
|
if( pLoc < 0 )
|
|
|
|
pLoc = valList.size() - 1;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( pLoc < 0 || pLoc >= valList.size() )
|
2013-12-27 23:59:59 +01:00
|
|
|
pLoc = 0;
|
|
|
|
|
|
|
|
int pos = 0;
|
2015-04-03 08:54:31 +02:00
|
|
|
for( Object g : valList )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( pos == pLoc )
|
2013-12-27 23:59:59 +01:00
|
|
|
return (T) g;
|
2015-03-26 11:07:26 +01:00
|
|
|
pos++;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simple way to cycle an enum...
|
|
|
|
*/
|
2015-04-03 08:54:31 +02:00
|
|
|
public static <T extends Enum> T nextEnum( T ce )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
EnumSet valList = EnumSet.allOf( ce.getClass() );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
int pLoc = ce.ordinal() + 1;
|
|
|
|
if( pLoc >= valList.size() )
|
|
|
|
pLoc = 0;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( pLoc < 0 || pLoc >= valList.size() )
|
2013-12-27 23:59:59 +01:00
|
|
|
pLoc = 0;
|
|
|
|
|
|
|
|
int pos = 0;
|
2015-04-03 08:54:31 +02:00
|
|
|
for( Object g : valList )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( pos == pLoc )
|
2013-12-27 23:59:59 +01:00
|
|
|
return (T) g;
|
2015-03-26 11:07:26 +01:00
|
|
|
pos++;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private static boolean isNotValidSetting( Enum e )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( e == SortOrder.INVTWEAKS && !AppEng.instance.isIntegrationEnabled( IntegrationType.InvTweaks ) )
|
|
|
|
return true;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( e == SearchBoxMode.NEI_AUTOSEARCH && !AppEng.instance.isIntegrationEnabled( IntegrationType.NEI ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( e == SearchBoxMode.NEI_MANUAL_SEARCH && !AppEng.instance.isIntegrationEnabled( IntegrationType.NEI ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static void openGUI( EntityPlayer p, TileEntity tile, ForgeDirection side, GuiBridge type )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( isClient() )
|
2013-12-27 23:59:59 +01:00
|
|
|
return;
|
|
|
|
|
2015-03-26 12:13:34 +01:00
|
|
|
int x = (int) p.posX;
|
|
|
|
int y = (int) p.posY;
|
|
|
|
int z = (int) p.posZ;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( tile != null )
|
2014-02-01 06:37:27 +01:00
|
|
|
{
|
|
|
|
x = tile.xCoord;
|
|
|
|
y = tile.yCoord;
|
|
|
|
z = tile.zCoord;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ( type.getType().isItem() && tile == null ) || type.hasPermissions( tile, x, y, z, side, p ) )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( tile == null || type.getType() == GuiHostType.ITEM )
|
|
|
|
p.openGui( AppEng.instance, type.ordinal() << 4 | ( 1 << 3 ), p.getEntityWorld(), x, y, z );
|
2014-01-27 05:00:36 +01:00
|
|
|
else
|
2015-04-03 08:54:31 +02:00
|
|
|
p.openGui( AppEng.instance, type.ordinal() << 4 | ( side.ordinal() ), tile.getWorldObj(), x, y, z );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
/*
|
|
|
|
* returns true if the code is on the client.
|
|
|
|
*/
|
|
|
|
public static boolean isClient()
|
|
|
|
{
|
|
|
|
return FMLCommonHandler.instance().getEffectiveSide().isClient();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean hasPermissions( DimensionalCoord dc, EntityPlayer player )
|
2014-02-01 06:37:27 +01:00
|
|
|
{
|
2014-08-29 04:37:08 +02:00
|
|
|
return dc.getWorld().canMineBlock( player, dc.x, dc.y, dc.z );
|
2014-02-01 06:37:27 +01:00
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
/*
|
|
|
|
* Checks to see if a block is air?
|
|
|
|
*/
|
2015-04-03 08:54:31 +02:00
|
|
|
public static boolean isBlockAir( World w, int x, int y, int z )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
return w.getBlock( x, y, z ).isAir( w, x, y, z );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( Throwable e )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-09-21 02:31:13 +02:00
|
|
|
* Lots of silliness to try and account for weird tag related junk, basically requires that two tags have at least
|
2014-02-09 02:34:52 +01:00
|
|
|
* something in their tags before it wasts its time comparing them.
|
2013-12-27 23:59:59 +01:00
|
|
|
*/
|
2015-04-03 08:54:31 +02:00
|
|
|
public static boolean sameStackStags( ItemStack a, ItemStack b )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( a == null && b == null )
|
2013-12-27 23:59:59 +01:00
|
|
|
return true;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( a == null || b == null )
|
2013-12-27 23:59:59 +01:00
|
|
|
return false;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( a == b )
|
2013-12-27 23:59:59 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
NBTTagCompound ta = a.getTagCompound();
|
|
|
|
NBTTagCompound tb = b.getTagCompound();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ta == tb )
|
2013-12-27 23:59:59 +01:00
|
|
|
return true;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ( ta == null && tb == null ) || ( ta != null && ta.hasNoTags() && tb == null ) || ( tb != null && tb.hasNoTags() && ta == null ) || ( ta != null && ta.hasNoTags() && tb != null && tb.hasNoTags() ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
return true;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ( ta == null && tb != null ) || ( ta != null && tb == null ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// if both tags are shared this is easy...
|
2015-04-03 08:54:31 +02:00
|
|
|
if( AESharedNBT.isShared( ta ) && AESharedNBT.isShared( tb ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return ta == tb;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NBTEqualityTest( ta, tb );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-02-09 02:34:52 +01:00
|
|
|
* recursive test for NBT Equality, this was faster then trying to compare / generate hashes, its also more reliable
|
|
|
|
* then the vanilla version which likes to fail when NBT Compound data changes order, it is pretty expensive
|
|
|
|
* performance wise, so try an use shared tag compounds as long as the system remains in AE.
|
2013-12-27 23:59:59 +01:00
|
|
|
*/
|
2015-04-03 08:54:31 +02:00
|
|
|
public static boolean NBTEqualityTest( NBTBase A, NBTBase B )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
// same type?
|
|
|
|
byte id = A.getId();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( id == B.getId() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( id )
|
2014-09-14 07:02:02 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
case 10:
|
|
|
|
{
|
|
|
|
NBTTagCompound ctA = (NBTTagCompound) A;
|
|
|
|
NBTTagCompound ctB = (NBTTagCompound) B;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
Set<String> cA = ctA.func_150296_c();
|
|
|
|
Set<String> cB = ctB.func_150296_c();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( cA.size() != cB.size() )
|
2013-12-27 23:59:59 +01:00
|
|
|
return false;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( String name : cA )
|
2014-09-29 09:26:35 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
NBTBase tag = ctA.getTag( name );
|
|
|
|
NBTBase aTag = ctB.getTag( name );
|
|
|
|
if( aTag == null )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !NBTEqualityTest( tag, aTag ) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
return true;
|
|
|
|
}
|
2014-02-15 08:05:28 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
case 9: // ) // A instanceof NBTTagList )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
NBTTagList lA = (NBTTagList) A;
|
|
|
|
NBTTagList lB = (NBTTagList) B;
|
|
|
|
if( lA.tagCount() != lB.tagCount() )
|
2013-12-27 23:59:59 +01:00
|
|
|
return false;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
List<NBTBase> tag = tagList( lA );
|
|
|
|
List<NBTBase> aTag = tagList( lB );
|
|
|
|
if( tag.size() != aTag.size() )
|
2013-12-27 23:59:59 +01:00
|
|
|
return false;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int x = 0; x < tag.size(); x++ )
|
|
|
|
{
|
|
|
|
if( aTag.get( x ) == null )
|
|
|
|
return false;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !NBTEqualityTest( tag.get( x ), aTag.get( x ) ) )
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
return true;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
case 1: // ( A instanceof NBTTagByte )
|
|
|
|
return ( (NBTTagByte) A ).func_150287_d() == ( (NBTTagByte) B ).func_150287_d();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
case 4: // else if ( A instanceof NBTTagLong )
|
|
|
|
return ( (NBTTagLong) A ).func_150291_c() == ( (NBTTagLong) B ).func_150291_c();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
case 8: // else if ( A instanceof NBTTagString )
|
|
|
|
return ( (NBTTagString) A ).func_150285_a_().equals( ( (NBTTagString) B ).func_150285_a_() ) || ( (NBTTagString) A ).func_150285_a_().equals( ( (NBTTagString) B ).func_150285_a_() );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
case 6: // else if ( A instanceof NBTTagDouble )
|
|
|
|
return ( (NBTTagDouble) A ).func_150286_g() == ( (NBTTagDouble) B ).func_150286_g();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
case 5: // else if ( A instanceof NBTTagFloat )
|
|
|
|
return ( (NBTTagFloat) A ).func_150288_h() == ( (NBTTagFloat) B ).func_150288_h();
|
|
|
|
|
|
|
|
case 3: // else if ( A instanceof NBTTagInt )
|
|
|
|
return ( (NBTTagInt) A ).func_150287_d() == ( (NBTTagInt) B ).func_150287_d();
|
|
|
|
|
|
|
|
default:
|
|
|
|
return A.equals( B );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private static List<NBTBase> tagList( NBTTagList lB )
|
2014-02-09 02:34:52 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( tagList == null )
|
2014-02-09 02:34:52 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
tagList = lB.getClass().getDeclaredField( "tagList" );
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( Throwable t )
|
2014-02-09 02:34:52 +01:00
|
|
|
{
|
2014-02-15 08:05:28 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
tagList = lB.getClass().getDeclaredField( "field_74747_a" );
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( Throwable z )
|
2014-02-15 08:05:28 +01:00
|
|
|
{
|
|
|
|
AELog.error( t );
|
|
|
|
AELog.error( z );
|
|
|
|
}
|
2014-02-09 02:34:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
tagList.setAccessible( true );
|
|
|
|
return (List<NBTBase>) tagList.get( lB );
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( Throwable t )
|
2014-02-09 02:34:52 +01:00
|
|
|
{
|
|
|
|
AELog.error( t );
|
|
|
|
}
|
|
|
|
|
2014-09-28 22:20:14 +02:00
|
|
|
return new ArrayList<NBTBase>();
|
2014-02-09 02:34:52 +01:00
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
/*
|
2014-09-21 03:02:40 +02:00
|
|
|
* Orderless hash on NBT Data, used to work thought huge piles fast, but ignores the order just in case MC decided
|
2014-02-09 02:34:52 +01:00
|
|
|
* to change it... WHICH IS BAD...
|
2013-12-27 23:59:59 +01:00
|
|
|
*/
|
2015-04-03 08:54:31 +02:00
|
|
|
public static int NBTOrderlessHash( NBTBase A )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
// same type?
|
|
|
|
int hash = 0;
|
|
|
|
byte id = A.getId();
|
|
|
|
hash += id;
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( id )
|
2014-09-14 07:02:02 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
case 10:
|
|
|
|
{
|
|
|
|
NBTTagCompound ctA = (NBTTagCompound) A;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
Set<String> cA = ctA.func_150296_c();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( String name : cA )
|
|
|
|
{
|
|
|
|
hash += name.hashCode() ^ NBTOrderlessHash( ctA.getTag( name ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return hash;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
case 9: // ) // A instanceof NBTTagList )
|
|
|
|
{
|
|
|
|
NBTTagList lA = (NBTTagList) A;
|
|
|
|
hash += 9 * lA.tagCount();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
List<NBTBase> l = tagList( lA );
|
|
|
|
for( int x = 0; x < l.size(); x++ )
|
|
|
|
{
|
|
|
|
hash += ( (Integer) x ).hashCode() ^ NBTOrderlessHash( l.get( x ) );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
return hash;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
case 1: // ( A instanceof NBTTagByte )
|
|
|
|
return hash + ( (NBTTagByte) A ).func_150290_f();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
case 4: // else if ( A instanceof NBTTagLong )
|
|
|
|
return hash + (int) ( (NBTTagLong) A ).func_150291_c();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
case 8: // else if ( A instanceof NBTTagString )
|
|
|
|
return hash + ( (NBTTagString) A ).func_150285_a_().hashCode();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
case 6: // else if ( A instanceof NBTTagDouble )
|
|
|
|
return hash + (int) ( (NBTTagDouble) A ).func_150286_g();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
case 5: // else if ( A instanceof NBTTagFloat )
|
|
|
|
return hash + (int) ( (NBTTagFloat) A ).func_150288_h();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
case 3: // else if ( A instanceof NBTTagInt )
|
|
|
|
return hash + ( (NBTTagInt) A ).func_150287_d();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
default:
|
|
|
|
return hash;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-02-09 02:34:52 +01:00
|
|
|
* The usual version of this returns an ItemStack, this version returns the recipe.
|
2013-12-27 23:59:59 +01:00
|
|
|
*/
|
2015-04-03 08:54:31 +02:00
|
|
|
public static IRecipe findMatchingRecipe( InventoryCrafting par1InventoryCrafting, World par2World )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
CraftingManager cm = CraftingManager.getInstance();
|
|
|
|
List<IRecipe> rl = cm.getRecipeList();
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( IRecipe r : rl )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( r.matches( par1InventoryCrafting, par2World ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static ItemStack[] getBlockDrops( World w, int x, int y, int z )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
List<ItemStack> out = new ArrayList<ItemStack>();
|
2014-02-09 02:34:52 +01:00
|
|
|
Block which = w.getBlock( x, y, z );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( which != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
out = which.getDrops( w, x, y, z, w.getBlockMetadata( x, y, z ), 0 );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( out == null )
|
2013-12-27 23:59:59 +01:00
|
|
|
return new ItemStack[0];
|
|
|
|
return out.toArray( new ItemStack[out.size()] );
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static ForgeDirection cycleOrientations( ForgeDirection dir, boolean upAndDown )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( upAndDown )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( dir )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
case NORTH:
|
|
|
|
return ForgeDirection.SOUTH;
|
|
|
|
case SOUTH:
|
|
|
|
return ForgeDirection.EAST;
|
|
|
|
case EAST:
|
|
|
|
return ForgeDirection.WEST;
|
|
|
|
case WEST:
|
|
|
|
return ForgeDirection.NORTH;
|
|
|
|
case UP:
|
|
|
|
return ForgeDirection.UP;
|
|
|
|
case DOWN:
|
|
|
|
return ForgeDirection.DOWN;
|
|
|
|
case UNKNOWN:
|
|
|
|
return ForgeDirection.UNKNOWN;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( dir )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
case UP:
|
|
|
|
return ForgeDirection.DOWN;
|
|
|
|
case DOWN:
|
|
|
|
return ForgeDirection.NORTH;
|
|
|
|
case NORTH:
|
|
|
|
return ForgeDirection.SOUTH;
|
|
|
|
case SOUTH:
|
|
|
|
return ForgeDirection.EAST;
|
|
|
|
case EAST:
|
|
|
|
return ForgeDirection.WEST;
|
|
|
|
case WEST:
|
|
|
|
return ForgeDirection.UP;
|
|
|
|
case UNKNOWN:
|
|
|
|
return ForgeDirection.UNKNOWN;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ForgeDirection.UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-02-09 02:34:52 +01:00
|
|
|
* Creates / or loads previous NBT Data on items, used for editing items owned by AE.
|
2013-12-27 23:59:59 +01:00
|
|
|
*/
|
2015-04-03 08:54:31 +02:00
|
|
|
public static NBTTagCompound openNbtData( ItemStack i )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
NBTTagCompound compound = i.getTagCompound();
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( compound == null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
i.setTagCompound( compound = new NBTTagCompound() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return compound;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-09-21 01:46:46 +02:00
|
|
|
* Generates Item entities in the world similar to how items are generally dropped.
|
2013-12-27 23:59:59 +01:00
|
|
|
*/
|
2015-04-03 08:54:31 +02:00
|
|
|
public static void spawnDrops( World w, int x, int y, int z, List<ItemStack> drops )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( isServer() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ItemStack i : drops )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( i != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( i.stackSize > 0 )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
double offset_x = ( getRandomInt() % 32 - 16 ) / 82;
|
|
|
|
double offset_y = ( getRandomInt() % 32 - 16 ) / 82;
|
|
|
|
double offset_z = ( getRandomInt() % 32 - 16 ) / 82;
|
2013-12-27 23:59:59 +01:00
|
|
|
EntityItem ei = new EntityItem( w, 0.5 + offset_x + x, 0.5 + offset_y + y, 0.2 + offset_z + z, i.copy() );
|
|
|
|
w.spawnEntityInWorld( ei );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
/*
|
|
|
|
* returns true if the code is on the server.
|
|
|
|
*/
|
|
|
|
public static boolean isServer()
|
|
|
|
{
|
|
|
|
return FMLCommonHandler.instance().getEffectiveSide().isServer();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getRandomInt()
|
|
|
|
{
|
|
|
|
return Math.abs( RANDOM_GENERATOR.nextInt() );
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
/*
|
2014-02-09 02:34:52 +01:00
|
|
|
* Utility function to get the full inventory for a Double Chest in the World.
|
2013-12-27 23:59:59 +01:00
|
|
|
*/
|
2015-04-03 08:54:31 +02:00
|
|
|
public static IInventory GetChestInv( Object te )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
TileEntityChest teA = (TileEntityChest) te;
|
|
|
|
TileEntity teB = null;
|
2014-02-09 02:34:52 +01:00
|
|
|
Block myBlockID = teA.getWorldObj().getBlock( teA.xCoord, teA.yCoord, teA.zCoord );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( teA.getWorldObj().getBlock( teA.xCoord + 1, teA.yCoord, teA.zCoord ) == myBlockID )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
teB = teA.getWorldObj().getTileEntity( teA.xCoord + 1, teA.yCoord, teA.zCoord );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !( teB instanceof TileEntityChest ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
teB = null;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( teB == null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( teA.getWorldObj().getBlock( teA.xCoord - 1, teA.yCoord, teA.zCoord ) == myBlockID )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
teB = teA.getWorldObj().getTileEntity( teA.xCoord - 1, teA.yCoord, teA.zCoord );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !( teB instanceof TileEntityChest ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
teB = null;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TileEntityChest x = teA;
|
|
|
|
teA = (TileEntityChest) teB;
|
|
|
|
teB = x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( teB == null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( teA.getWorldObj().getBlock( teA.xCoord, teA.yCoord, teA.zCoord + 1 ) == myBlockID )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
teB = teA.getWorldObj().getTileEntity( teA.xCoord, teA.yCoord, teA.zCoord + 1 );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !( teB instanceof TileEntityChest ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
teB = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( teB == null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( teA.getWorldObj().getBlock( teA.xCoord, teA.yCoord, teA.zCoord - 1 ) == myBlockID )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
teB = teA.getWorldObj().getTileEntity( teA.xCoord, teA.yCoord, teA.zCoord - 1 );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !( teB instanceof TileEntityChest ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
teB = null;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TileEntityChest x = teA;
|
|
|
|
teA = (TileEntityChest) teB;
|
|
|
|
teB = x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( teB == null )
|
2013-12-27 23:59:59 +01:00
|
|
|
return teA;
|
|
|
|
|
|
|
|
return new InventoryLargeChest( "", teA, (TileEntityChest) teB );
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static boolean isModLoaded( String modid )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// if this fails for some reason, try the other method.
|
|
|
|
return Loader.isModLoaded( modid );
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( Throwable ignored )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ModContainer f : Loader.instance().getActiveModList() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( f.getModId().equals( modid ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static ItemStack findMatchingRecipeOutput( InventoryCrafting ic, World worldObj )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return CraftingManager.getInstance().findMatchingRecipe( ic, worldObj );
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@SideOnly( Side.CLIENT )
|
|
|
|
public static List getTooltip( Object o )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( o == null )
|
2013-12-27 23:59:59 +01:00
|
|
|
return new ArrayList();
|
|
|
|
|
|
|
|
ItemStack itemStack = null;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( o instanceof AEItemStack )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
AEItemStack ais = (AEItemStack) o;
|
|
|
|
return ais.getToolTip();
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( o instanceof ItemStack )
|
2013-12-27 23:59:59 +01:00
|
|
|
itemStack = (ItemStack) o;
|
|
|
|
else
|
|
|
|
return new ArrayList();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return itemStack.getTooltip( Minecraft.getMinecraft().thePlayer, false );
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( Exception errB )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return new ArrayList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static String getModId( IAEItemStack is )
|
2014-07-03 04:09:17 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( is == null )
|
2014-07-03 04:09:17 +02:00
|
|
|
return "** Null";
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
String n = ( (AEItemStack) is ).getModID();
|
2014-07-03 04:09:17 +02:00
|
|
|
return n == null ? "** Null" : n;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static String getItemDisplayName( Object o )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( o == null )
|
2013-12-27 23:59:59 +01:00
|
|
|
return "** Null";
|
|
|
|
|
|
|
|
ItemStack itemStack = null;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( o instanceof AEItemStack )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
String n = ( (AEItemStack) o ).getDisplayName();
|
2013-12-27 23:59:59 +01:00
|
|
|
return n == null ? "** Null" : n;
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( o instanceof ItemStack )
|
2013-12-27 23:59:59 +01:00
|
|
|
itemStack = (ItemStack) o;
|
|
|
|
else
|
|
|
|
return "**Invalid Object";
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
String name = itemStack.getDisplayName();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( name == null || name.isEmpty() )
|
2013-12-27 23:59:59 +01:00
|
|
|
name = itemStack.getItem().getUnlocalizedName( itemStack );
|
|
|
|
return name == null ? "** Null" : name;
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( Exception errA )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
String n = itemStack.getUnlocalizedName();
|
|
|
|
return n == null ? "** Null" : n;
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( Exception errB )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return "** Exception";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static boolean hasSpecialComparison( IAEItemStack willAdd )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( willAdd == null )
|
2013-12-27 23:59:59 +01:00
|
|
|
return false;
|
|
|
|
IAETagCompound tag = willAdd.getTagCompound();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( tag != null && tag.getSpecialComparison() != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static boolean hasSpecialComparison( ItemStack willAdd )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( AESharedNBT.isShared( willAdd.getTagCompound() ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ( (AESharedNBT) willAdd.getTagCompound() ).getSpecialComparison() != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static boolean isWrench( EntityPlayer player, ItemStack eq, int x, int y, int z )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( eq != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( eq.getItem() instanceof IToolWrench )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
IToolWrench wrench = (IToolWrench) eq.getItem();
|
|
|
|
return wrench.canWrench( player, x, y, z );
|
|
|
|
}
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( Throwable ignore )
|
2013-12-27 23:59:59 +01:00
|
|
|
{ // explodes without BC
|
2014-01-30 19:53:06 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( eq.getItem() instanceof IAEWrench )
|
2014-01-30 19:53:06 +01:00
|
|
|
{
|
|
|
|
IAEWrench wrench = (IAEWrench) eq.getItem();
|
|
|
|
return wrench.canWrench( eq, player, x, y, z );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static boolean isChargeable( ItemStack i )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( i == null )
|
2013-12-27 23:59:59 +01:00
|
|
|
return false;
|
|
|
|
Item it = i.getItem();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( it instanceof IAEItemPowerStorage )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return ( (IAEItemPowerStorage) it ).getPowerFlow( i ) != AccessRestriction.READ;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static EntityPlayer getPlayer( WorldServer w )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( w == null )
|
2014-07-04 08:19:45 +02:00
|
|
|
throw new NullPointerException();
|
|
|
|
|
2015-01-01 22:13:10 +01:00
|
|
|
EntityPlayer wrp = FAKE_PLAYERS.get( w );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( wrp != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
return wrp;
|
|
|
|
|
2014-06-25 03:19:42 +02:00
|
|
|
EntityPlayer p = FakePlayerFactory.getMinecraft( w );
|
2015-01-01 22:13:10 +01:00
|
|
|
FAKE_PLAYERS.put( w, p );
|
2013-12-27 23:59:59 +01:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static int MC2MEColor( int color )
|
|
|
|
{
|
|
|
|
switch( color )
|
|
|
|
{
|
|
|
|
case 4: // "blue"
|
|
|
|
return 0;
|
|
|
|
case 0: // "black"
|
|
|
|
return 1;
|
|
|
|
case 15: // "white"
|
|
|
|
return 2;
|
|
|
|
case 3: // "brown"
|
|
|
|
return 3;
|
|
|
|
case 1: // "red"
|
|
|
|
return 4;
|
|
|
|
case 11: // "yellow"
|
|
|
|
return 5;
|
|
|
|
case 2: // "green"
|
|
|
|
return 6;
|
|
|
|
|
|
|
|
case 5: // "purple"
|
|
|
|
case 6: // "cyan"
|
|
|
|
case 7: // "silver"
|
|
|
|
case 8: // "gray"
|
|
|
|
case 9: // "pink"
|
|
|
|
case 10: // "lime"
|
|
|
|
case 12: // "lightBlue"
|
|
|
|
case 13: // "magenta"
|
|
|
|
case 14: // "orange"
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static int findEmpty( Object[] l )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int x = 0; x < l.length; x++ )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( l[x] == null )
|
2013-12-27 23:59:59 +01:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static <T> T pickRandom( Collection<T> outs )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-01-01 22:13:10 +01:00
|
|
|
int index = RANDOM_GENERATOR.nextInt( outs.size() );
|
2013-12-27 23:59:59 +01:00
|
|
|
Iterator<T> i = outs.iterator();
|
2015-04-03 08:54:31 +02:00
|
|
|
while( i.hasNext() && index > 0 )
|
2015-03-26 11:07:26 +01:00
|
|
|
{
|
|
|
|
index--;
|
2013-12-27 23:59:59 +01:00
|
|
|
i.next();
|
2015-03-26 11:07:26 +01:00
|
|
|
}
|
|
|
|
index--;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( i.hasNext() )
|
2013-12-27 23:59:59 +01:00
|
|
|
return i.next();
|
|
|
|
return null; // wtf?
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static ForgeDirection rotateAround( ForgeDirection forward, ForgeDirection axis )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( axis == ForgeDirection.UNKNOWN || forward == ForgeDirection.UNKNOWN )
|
2013-12-27 23:59:59 +01:00
|
|
|
return forward;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( forward )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
case DOWN:
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( axis )
|
|
|
|
{
|
|
|
|
case DOWN:
|
|
|
|
return forward;
|
|
|
|
case UP:
|
|
|
|
return forward;
|
|
|
|
case NORTH:
|
|
|
|
return ForgeDirection.EAST;
|
|
|
|
case SOUTH:
|
|
|
|
return ForgeDirection.WEST;
|
|
|
|
case EAST:
|
|
|
|
return ForgeDirection.NORTH;
|
|
|
|
case WEST:
|
|
|
|
return ForgeDirection.SOUTH;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2013-12-27 23:59:59 +01:00
|
|
|
case UP:
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( axis )
|
|
|
|
{
|
|
|
|
case NORTH:
|
|
|
|
return ForgeDirection.WEST;
|
|
|
|
case SOUTH:
|
|
|
|
return ForgeDirection.EAST;
|
|
|
|
case EAST:
|
|
|
|
return ForgeDirection.SOUTH;
|
|
|
|
case WEST:
|
|
|
|
return ForgeDirection.NORTH;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
break;
|
|
|
|
case NORTH:
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( axis )
|
|
|
|
{
|
|
|
|
case UP:
|
|
|
|
return ForgeDirection.WEST;
|
|
|
|
case DOWN:
|
|
|
|
return ForgeDirection.EAST;
|
|
|
|
case EAST:
|
|
|
|
return ForgeDirection.UP;
|
|
|
|
case WEST:
|
|
|
|
return ForgeDirection.DOWN;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
break;
|
2015-04-03 08:54:31 +02:00
|
|
|
case SOUTH:
|
|
|
|
switch( axis )
|
|
|
|
{
|
|
|
|
case UP:
|
|
|
|
return ForgeDirection.EAST;
|
|
|
|
case DOWN:
|
|
|
|
return ForgeDirection.WEST;
|
|
|
|
case EAST:
|
|
|
|
return ForgeDirection.DOWN;
|
|
|
|
case WEST:
|
|
|
|
return ForgeDirection.UP;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
break;
|
|
|
|
case EAST:
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( axis )
|
|
|
|
{
|
|
|
|
case UP:
|
|
|
|
return ForgeDirection.NORTH;
|
|
|
|
case DOWN:
|
|
|
|
return ForgeDirection.SOUTH;
|
|
|
|
case NORTH:
|
|
|
|
return ForgeDirection.UP;
|
|
|
|
case SOUTH:
|
|
|
|
return ForgeDirection.DOWN;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
case WEST:
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( axis )
|
|
|
|
{
|
|
|
|
case UP:
|
|
|
|
return ForgeDirection.SOUTH;
|
|
|
|
case DOWN:
|
|
|
|
return ForgeDirection.NORTH;
|
|
|
|
case NORTH:
|
|
|
|
return ForgeDirection.DOWN;
|
|
|
|
case SOUTH:
|
|
|
|
return ForgeDirection.UP;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return forward;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@SideOnly( Side.CLIENT )
|
|
|
|
public static String gui_localize( String string )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return StatCollector.translateToLocal( string );
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static boolean isSameItemPrecise( ItemStack is, ItemStack filter )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-31 01:50:39 +01:00
|
|
|
return isSameItem( is, filter ) && sameStackStags( is, filter );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static boolean isSameItemFuzzy( ItemStack a, ItemStack b, FuzzyMode Mode )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( a == null && b == null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( a == null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( b == null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-02-09 02:34:52 +01:00
|
|
|
* if ( a.itemID != 0 && b.itemID != 0 && a.isItemStackDamageable() && ! a.getHasSubtypes() && a.itemID ==
|
|
|
|
* b.itemID ) { return (a.getItemDamage() > 0) == (b.getItemDamage() > 0); }
|
2013-12-27 23:59:59 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
// test damageable items..
|
2015-04-03 08:54:31 +02:00
|
|
|
if( a.getItem() != null && b.getItem() != null && a.getItem().isDamageable() && a.getItem() == b.getItem() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( Mode == FuzzyMode.IGNORE_ALL )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( Mode == FuzzyMode.PERCENT_99 )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return ( a.getItemDamageForDisplay() > 1 ) == ( b.getItemDamageForDisplay() > 1 );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float APercentDamaged = 1.0f - (float) a.getItemDamageForDisplay() / (float) a.getMaxDamage();
|
|
|
|
float BPercentDamaged = 1.0f - (float) b.getItemDamageForDisplay() / (float) b.getMaxDamage();
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
return ( APercentDamaged > Mode.breakPoint ) == ( BPercentDamaged > Mode.breakPoint );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( Throwable e )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( Mode == FuzzyMode.IGNORE_ALL )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( Mode == FuzzyMode.PERCENT_99 )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return ( a.getItemDamage() > 1 ) == ( b.getItemDamage() > 1 );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float APercentDamaged = (float) a.getItemDamage() / (float) a.getMaxDamage();
|
|
|
|
float BPercentDamaged = (float) b.getItemDamage() / (float) b.getMaxDamage();
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
return ( APercentDamaged > Mode.breakPoint ) == ( BPercentDamaged > Mode.breakPoint );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-01 22:13:10 +01:00
|
|
|
OreReference aOR = OreHelper.INSTANCE.isOre( a );
|
|
|
|
OreReference bOR = OreHelper.INSTANCE.isOre( b );
|
2014-02-13 06:24:07 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( OreHelper.INSTANCE.sameOre( aOR, bOR ) )
|
2014-02-13 06:24:07 +01:00
|
|
|
return true;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
/*
|
2014-02-09 02:34:52 +01:00
|
|
|
* // test ore dictionary.. int OreID = getOreID( a ); if ( OreID != -1 ) return OreID == getOreID( b );
|
2015-02-03 12:04:13 +01:00
|
|
|
*
|
2014-02-09 02:34:52 +01:00
|
|
|
* if ( Mode != FuzzyMode.IGNORE_ALL ) { if ( a.hasTagCompound() && !isShared( a.getTagCompound() ) ) { a =
|
|
|
|
* Platform.getSharedItemStack( AEItemStack.create( a ) ); }
|
2015-02-03 12:04:13 +01:00
|
|
|
*
|
2014-02-09 02:34:52 +01:00
|
|
|
* if ( b.hasTagCompound() && !isShared( b.getTagCompound() ) ) { b = Platform.getSharedItemStack(
|
|
|
|
* AEItemStack.create( b ) ); }
|
2015-02-03 12:04:13 +01:00
|
|
|
*
|
2014-02-09 02:34:52 +01:00
|
|
|
* // test regular items with damage values and what not... if ( isShared( a.getTagCompound() ) && isShared(
|
|
|
|
* b.getTagCompound() ) && a.itemID == b.itemID ) { return ((AppEngSharedNBTTagCompound)
|
|
|
|
* a.getTagCompound()).compareFuzzyWithRegistry( (AppEngSharedNBTTagCompound) b.getTagCompound() ); } }
|
2013-12-27 23:59:59 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
return a.isItemEqual( b );
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static LookDirection getPlayerRay( EntityPlayer player, float eyeOffset )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
float f = 1.0F;
|
2015-04-03 08:54:31 +02:00
|
|
|
float f1 = player.prevRotationPitch + ( player.rotationPitch - player.prevRotationPitch ) * f;
|
|
|
|
float f2 = player.prevRotationYaw + ( player.rotationYaw - player.prevRotationYaw ) * f;
|
|
|
|
double d0 = player.prevPosX + ( player.posX - player.prevPosX ) * f;
|
2014-09-28 11:47:17 +02:00
|
|
|
double d1 = eyeOffset;
|
2015-04-03 08:54:31 +02:00
|
|
|
double d2 = player.prevPosZ + ( player.posZ - player.prevPosZ ) * f;
|
2014-08-29 04:37:08 +02:00
|
|
|
|
2014-06-13 19:42:09 +02:00
|
|
|
Vec3 vec3 = Vec3.createVectorHelper( d0, d1, d2 );
|
2013-12-27 23:59:59 +01:00
|
|
|
float f3 = MathHelper.cos( -f2 * 0.017453292F - (float) Math.PI );
|
|
|
|
float f4 = MathHelper.sin( -f2 * 0.017453292F - (float) Math.PI );
|
|
|
|
float f5 = -MathHelper.cos( -f1 * 0.017453292F );
|
|
|
|
float f6 = MathHelper.sin( -f1 * 0.017453292F );
|
|
|
|
float f7 = f4 * f5;
|
|
|
|
float f8 = f3 * f5;
|
|
|
|
double d3 = 5.0D;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( player instanceof EntityPlayerMP )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
d3 = ( (EntityPlayerMP) player ).theItemInWorldManager.getBlockReachDistance();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-09-28 20:56:16 +02:00
|
|
|
Vec3 vec31 = vec3.addVector( f7 * d3, f6 * d3, f8 * d3 );
|
2013-12-27 23:59:59 +01:00
|
|
|
return new LookDirection( vec3, vec31 );
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static MovingObjectPosition rayTrace( EntityPlayer p, boolean hitBlocks, boolean hitEntities )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
|
|
|
World w = p.getEntityWorld();
|
|
|
|
|
|
|
|
float f = 1.0F;
|
2015-04-03 08:54:31 +02:00
|
|
|
float f1 = p.prevRotationPitch + ( p.rotationPitch - p.prevRotationPitch ) * f;
|
|
|
|
float f2 = p.prevRotationYaw + ( p.rotationYaw - p.prevRotationYaw ) * f;
|
|
|
|
double d0 = p.prevPosX + ( p.posX - p.prevPosX ) * f;
|
|
|
|
double d1 = p.prevPosY + ( p.posY - p.prevPosY ) * f + 1.62D - p.yOffset;
|
|
|
|
double d2 = p.prevPosZ + ( p.posZ - p.prevPosZ ) * f;
|
2014-06-13 19:42:09 +02:00
|
|
|
Vec3 vec3 = Vec3.createVectorHelper( d0, d1, d2 );
|
2014-01-20 17:41:37 +01:00
|
|
|
float f3 = MathHelper.cos( -f2 * 0.017453292F - (float) Math.PI );
|
|
|
|
float f4 = MathHelper.sin( -f2 * 0.017453292F - (float) Math.PI );
|
|
|
|
float f5 = -MathHelper.cos( -f1 * 0.017453292F );
|
|
|
|
float f6 = MathHelper.sin( -f1 * 0.017453292F );
|
|
|
|
float f7 = f4 * f5;
|
|
|
|
float f8 = f3 * f5;
|
|
|
|
double d3 = 32.0D;
|
|
|
|
|
2014-09-28 20:56:16 +02:00
|
|
|
Vec3 vec31 = vec3.addVector( f7 * d3, f6 * d3, f8 * d3 );
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
AxisAlignedBB bb = AxisAlignedBB.getBoundingBox( Math.min( vec3.xCoord, vec31.xCoord ), Math.min( vec3.yCoord, vec31.yCoord ), Math.min( vec3.zCoord, vec31.zCoord ), Math.max( vec3.xCoord, vec31.xCoord ), Math.max( vec3.yCoord, vec31.yCoord ), Math.max( vec3.zCoord, vec31.zCoord ) ).expand( 16, 16, 16 );
|
2014-01-20 17:41:37 +01:00
|
|
|
|
|
|
|
Entity entity = null;
|
2014-09-21 01:46:15 +02:00
|
|
|
double closest = 9999999.0D;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( hitEntities )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
|
|
|
List list = w.getEntitiesWithinAABBExcludingEntity( p, bb );
|
|
|
|
int l;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( l = 0; l < list.size(); ++l )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
|
|
|
Entity entity1 = (Entity) list.get( l );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !entity1.isDead && entity1 != p && !( entity1 instanceof EntityItem ) )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( entity1.isEntityAlive() )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
|
|
|
// prevent killing / flying of mounts.
|
2015-04-03 08:54:31 +02:00
|
|
|
if( entity1.riddenByEntity == p )
|
2014-01-20 17:41:37 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
f1 = 0.3F;
|
2014-09-28 20:56:16 +02:00
|
|
|
AxisAlignedBB boundingBox = entity1.boundingBox.expand( f1, f1, f1 );
|
2014-09-28 11:47:17 +02:00
|
|
|
MovingObjectPosition movingObjectPosition = boundingBox.calculateIntercept( vec3, vec31 );
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( movingObjectPosition != null )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
double nd = vec3.squareDistanceTo( movingObjectPosition.hitVec );
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( nd < closest )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
|
|
|
entity = entity1;
|
2014-09-21 01:46:15 +02:00
|
|
|
closest = nd;
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MovingObjectPosition pos = null;
|
2014-09-28 11:47:17 +02:00
|
|
|
Vec3 vec = null;
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( hitBlocks )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
vec = Vec3.createVectorHelper( d0, d1, d2 );
|
2014-02-09 02:34:52 +01:00
|
|
|
pos = w.rayTraceBlocks( vec3, vec31, true );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( entity != null && pos != null && pos.hitVec.squareDistanceTo( vec ) > closest )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
|
|
|
pos = new MovingObjectPosition( entity );
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( entity != null && pos == null )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
|
|
|
pos = new MovingObjectPosition( entity );
|
|
|
|
}
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public static long nanoTime()
|
|
|
|
{
|
2015-01-01 22:13:10 +01:00
|
|
|
// if ( Configuration.INSTANCE.enableNetworkProfiler )
|
2014-01-20 17:41:37 +01:00
|
|
|
// return System.nanoTime();
|
2013-12-27 23:59:59 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static <StackType extends IAEStack> StackType poweredExtraction( IEnergySource energy, IMEInventory<StackType> cell, StackType request, BaseActionSource src )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
StackType possible = cell.extractItems( (StackType) request.copy(), Actionable.SIMULATE, src );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
long retrieved = 0;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( possible != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
retrieved = possible.getStackSize();
|
|
|
|
|
|
|
|
double availablePower = energy.extractAEPower( retrieved, Actionable.SIMULATE, PowerMultiplier.CONFIG );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
long itemToExtract = Math.min( (long) ( availablePower + 0.9 ), retrieved );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( itemToExtract > 0 )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
energy.extractAEPower( retrieved, Actionable.MODULATE, PowerMultiplier.CONFIG );
|
|
|
|
|
|
|
|
possible.setStackSize( itemToExtract );
|
2014-01-20 17:41:37 +01:00
|
|
|
StackType ret = cell.extractItems( possible, Actionable.MODULATE, src );
|
2014-01-05 09:43:49 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ret != null && src.isPlayer() )
|
2014-08-31 10:06:06 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
Stats.ItemsExtracted.addToPlayer( ( (PlayerSource) src ).player, (int) ret.getStackSize() );
|
2014-08-31 10:06:06 +02:00
|
|
|
}
|
|
|
|
|
2014-01-05 09:43:49 +01:00
|
|
|
return ret;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static <StackType extends IAEStack> StackType poweredInsert( IEnergySource energy, IMEInventory<StackType> cell, StackType input, BaseActionSource src )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
StackType possible = cell.injectItems( (StackType) input.copy(), Actionable.SIMULATE, src );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
long stored = input.getStackSize();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( possible != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
stored -= possible.getStackSize();
|
|
|
|
|
|
|
|
double availablePower = energy.extractAEPower( stored, Actionable.SIMULATE, PowerMultiplier.CONFIG );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
long itemToAdd = Math.min( (long) ( availablePower + 0.9 ), stored );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( itemToAdd > 0 )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
energy.extractAEPower( stored, Actionable.MODULATE, PowerMultiplier.CONFIG );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( itemToAdd < input.getStackSize() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-08-31 10:06:06 +02:00
|
|
|
long original = input.getStackSize();
|
2014-01-20 17:41:37 +01:00
|
|
|
StackType split = (StackType) input.copy();
|
2013-12-27 23:59:59 +01:00
|
|
|
split.decStackSize( itemToAdd );
|
|
|
|
input.setStackSize( itemToAdd );
|
2014-01-20 17:41:37 +01:00
|
|
|
split.add( cell.injectItems( input, Actionable.MODULATE, src ) );
|
2014-08-31 10:06:06 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( src.isPlayer() )
|
2014-08-31 10:06:06 +02:00
|
|
|
{
|
|
|
|
long diff = original - split.getStackSize();
|
2015-04-03 08:54:31 +02:00
|
|
|
Stats.ItemsInserted.addToPlayer( ( (PlayerSource) src ).player, (int) diff );
|
2014-08-31 10:06:06 +02:00
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
return split;
|
|
|
|
}
|
2014-01-05 09:43:49 +01:00
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
StackType ret = cell.injectItems( input, Actionable.MODULATE, src );
|
2014-01-05 09:43:49 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( src.isPlayer() )
|
2014-08-31 10:06:06 +02:00
|
|
|
{
|
|
|
|
long diff = ret == null ? input.getStackSize() : input.getStackSize() - ret.getStackSize();
|
2015-04-03 08:54:31 +02:00
|
|
|
Stats.ItemsInserted.addToPlayer( ( (PlayerSource) src ).player, (int) diff );
|
2014-08-31 10:06:06 +02:00
|
|
|
}
|
|
|
|
|
2014-01-05 09:43:49 +01:00
|
|
|
return ret;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static void postChanges( IStorageGrid gs, ItemStack removed, ItemStack added, BaseActionSource src )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-09-11 06:12:34 +02:00
|
|
|
IItemList<IAEItemStack> itemChanges = AEApi.instance().storage().createItemList();
|
|
|
|
IItemList<IAEFluidStack> fluidChanges = AEApi.instance().storage().createFluidList();
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( removed != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-07-28 07:11:34 +02:00
|
|
|
IMEInventory<IAEItemStack> myItems = AEApi.instance().registries().cell().getCellInventory( removed, null, StorageChannel.ITEMS );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( myItems != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( IAEItemStack is : myItems.getAvailableItems( itemChanges ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
is.setStackSize( -is.getStackSize() );
|
|
|
|
}
|
|
|
|
|
2014-07-28 07:11:34 +02:00
|
|
|
IMEInventory<IAEFluidStack> myFluids = AEApi.instance().registries().cell().getCellInventory( removed, null, StorageChannel.FLUIDS );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( myFluids != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( IAEFluidStack is : myFluids.getAvailableItems( fluidChanges ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
is.setStackSize( -is.getStackSize() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( added != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-07-28 07:11:34 +02:00
|
|
|
IMEInventory<IAEItemStack> myItems = AEApi.instance().registries().cell().getCellInventory( added, null, StorageChannel.ITEMS );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( myItems != null )
|
2014-09-11 06:12:34 +02:00
|
|
|
myItems.getAvailableItems( itemChanges );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-07-28 07:11:34 +02:00
|
|
|
IMEInventory<IAEFluidStack> myFluids = AEApi.instance().registries().cell().getCellInventory( added, null, StorageChannel.FLUIDS );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( myFluids != null )
|
2014-09-11 06:12:34 +02:00
|
|
|
myFluids.getAvailableItems( fluidChanges );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-09-11 06:12:34 +02:00
|
|
|
|
|
|
|
gs.postAlterationOfStoredItems( StorageChannel.ITEMS, itemChanges, src );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
static public <T extends IAEStack<T>> void postListChanges( IItemList<T> before, IItemList<T> after, IMEMonitorHandlerReceiver<T> meMonitorPassthrough, BaseActionSource source )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-09-28 22:20:14 +02:00
|
|
|
LinkedList<T> changes = new LinkedList<T>();
|
2014-09-11 06:12:34 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( T is : before )
|
2013-12-27 23:59:59 +01:00
|
|
|
is.setStackSize( -is.getStackSize() );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( T is : after )
|
2013-12-27 23:59:59 +01:00
|
|
|
before.add( is );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( T is : before )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( is.getStackSize() != 0 )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-09-11 06:12:34 +02:00
|
|
|
changes.add( is );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
2014-09-11 06:12:34 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !changes.isEmpty() )
|
2014-09-28 11:47:17 +02:00
|
|
|
meMonitorPassthrough.postChange( null, changes, source );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static int generateTileHash( TileEntity target )
|
2013-12-28 22:05:58 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( target == null )
|
2013-12-28 22:05:58 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
int hash = target.hashCode();
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( target instanceof ITileStorageMonitorable )
|
2014-01-03 19:25:29 +01:00
|
|
|
return 0;
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( target instanceof TileEntityChest )
|
2014-01-02 06:52:16 +01:00
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
TileEntityChest chest = (TileEntityChest) target;
|
|
|
|
chest.checkForAdjacentChests();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( chest.adjacentChestZNeg != null )
|
2014-09-28 11:47:17 +02:00
|
|
|
hash ^= chest.adjacentChestZNeg.hashCode();
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( chest.adjacentChestZPos != null )
|
2014-09-28 11:47:17 +02:00
|
|
|
hash ^= chest.adjacentChestZPos.hashCode();
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( chest.adjacentChestXPos != null )
|
2014-09-28 11:47:17 +02:00
|
|
|
hash ^= chest.adjacentChestXPos.hashCode();
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( chest.adjacentChestXNeg != null )
|
2014-09-28 11:47:17 +02:00
|
|
|
hash ^= chest.adjacentChestXNeg.hashCode();
|
2014-01-02 06:52:16 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( target instanceof IInventory )
|
2014-01-02 06:52:16 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
hash ^= ( (IInventory) target ).getSizeInventory();
|
2013-12-28 22:05:58 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( target instanceof ISidedInventory )
|
2013-12-28 22:05:58 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS )
|
2013-12-28 22:05:58 +01:00
|
|
|
{
|
2014-01-02 06:52:16 +01:00
|
|
|
int offset = 0;
|
2014-08-01 06:52:16 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
int[] sides = ( (ISidedInventory) target ).getAccessibleSlotsFromSide( dir.ordinal() );
|
2014-08-01 06:52:16 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( sides == null )
|
2014-08-01 06:52:16 +02:00
|
|
|
return 0;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( Integer Side : sides )
|
2014-01-02 06:52:16 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
int c = ( Side << ( offset % 8 ) ) ^ ( 1 << dir.ordinal() );
|
2015-03-26 11:07:26 +01:00
|
|
|
offset++;
|
2015-04-03 08:54:31 +02:00
|
|
|
hash = c + ( hash << 6 ) + ( hash << 16 ) - hash;
|
2014-01-02 06:52:16 +01:00
|
|
|
}
|
2013-12-28 22:05:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static boolean securityCheck( GridNode a, GridNode b )
|
2014-01-27 05:00:36 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( a.lastSecurityKey == -1 && b.lastSecurityKey == -1 )
|
2014-01-27 05:00:36 +01:00
|
|
|
return false;
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( a.lastSecurityKey == b.lastSecurityKey )
|
2014-01-27 05:00:36 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
boolean a_isSecure = isPowered( a.getGrid() ) && a.lastSecurityKey != -1;
|
|
|
|
boolean b_isSecure = isPowered( b.getGrid() ) && b.lastSecurityKey != -1;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( AEConfig.instance.isFeatureEnabled( AEFeature.LogSecurityAudits ) )
|
2014-09-05 05:08:07 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
AELog.info( "Audit: " + a_isSecure + " : " + b_isSecure + " @ " + a.lastSecurityKey + " vs " + b.lastSecurityKey + " & " + a.playerID + " vs " + b.playerID );
|
2014-09-05 05:08:07 +02:00
|
|
|
}
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
// can't do that son...
|
2015-04-03 08:54:31 +02:00
|
|
|
if( a_isSecure && b_isSecure )
|
2014-01-27 05:00:36 +01:00
|
|
|
return true;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !a_isSecure && b_isSecure )
|
2014-01-27 05:00:36 +01:00
|
|
|
return checkPlayerPermissions( b.getGrid(), a.playerID );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( a_isSecure && !b_isSecure )
|
2014-01-27 05:00:36 +01:00
|
|
|
return checkPlayerPermissions( a.getGrid(), b.playerID );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private static boolean isPowered( IGrid grid )
|
2014-01-27 05:00:36 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( grid == null )
|
2014-01-27 05:00:36 +01:00
|
|
|
return false;
|
|
|
|
|
2014-09-29 09:42:50 +02:00
|
|
|
IEnergyGrid eg = grid.getCache( IEnergyGrid.class );
|
2014-01-27 05:00:36 +01:00
|
|
|
return eg.isNetworkPowered();
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private static boolean checkPlayerPermissions( IGrid grid, int playerID )
|
2014-01-27 05:00:36 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( grid == null )
|
2014-01-27 05:00:36 +01:00
|
|
|
return false;
|
|
|
|
|
2014-09-29 09:42:50 +02:00
|
|
|
ISecurityGrid gs = grid.getCache( ISecurityGrid.class );
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( gs == null )
|
2014-01-27 05:00:36 +01:00
|
|
|
return false;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !gs.isAvailable() )
|
2014-01-27 05:00:36 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return !gs.hasPermission( playerID, SecurityPermissions.BUILD );
|
|
|
|
}
|
2014-02-09 02:34:52 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static boolean isDrawing( Tessellator tess )
|
2014-02-09 02:34:52 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-14 06:32:35 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static void configurePlayer( EntityPlayer player, ForgeDirection side, TileEntity tile )
|
2014-02-27 08:10:45 +01:00
|
|
|
{
|
2015-03-26 12:13:34 +01:00
|
|
|
float pitch = 0.0f;
|
|
|
|
float yaw = 0.0f;
|
2014-02-27 08:10:45 +01:00
|
|
|
player.yOffset = 1.8f;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( side )
|
|
|
|
{
|
|
|
|
case DOWN:
|
|
|
|
pitch = 90.0f;
|
|
|
|
player.yOffset = -1.8f;
|
|
|
|
break;
|
|
|
|
case EAST:
|
|
|
|
yaw = -90.0f;
|
|
|
|
break;
|
|
|
|
case NORTH:
|
|
|
|
yaw = 180.0f;
|
|
|
|
break;
|
|
|
|
case SOUTH:
|
|
|
|
yaw = 0.0f;
|
|
|
|
break;
|
|
|
|
case UNKNOWN:
|
|
|
|
break;
|
|
|
|
case UP:
|
|
|
|
pitch = 90.0f;
|
|
|
|
break;
|
|
|
|
case WEST:
|
|
|
|
yaw = 90.0f;
|
|
|
|
break;
|
2014-02-27 08:10:45 +01:00
|
|
|
}
|
|
|
|
|
2014-09-28 20:56:16 +02:00
|
|
|
player.posX = tile.xCoord + 0.5;
|
|
|
|
player.posY = tile.yCoord + 0.5;
|
|
|
|
player.posZ = tile.zCoord + 0.5;
|
2014-02-27 08:10:45 +01:00
|
|
|
|
|
|
|
player.rotationPitch = player.prevCameraPitch = player.cameraPitch = pitch;
|
|
|
|
player.rotationYaw = player.prevCameraYaw = player.cameraYaw = yaw;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static boolean canAccess( AENetworkProxy gridProxy, BaseActionSource src )
|
2014-04-18 05:33:48 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( src.isPlayer() )
|
2014-04-18 05:33:48 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return gridProxy.getSecurity().hasPermission( ( (PlayerSource) src ).player, SecurityPermissions.BUILD );
|
2014-04-18 05:33:48 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( src.isMachine() )
|
2014-04-18 05:33:48 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
IActionHost te = ( (MachineSource) src ).via;
|
2014-05-04 21:54:21 +02:00
|
|
|
IGridNode n = te.getActionableNode();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( n == null )
|
2014-05-04 21:54:21 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
int playerID = n.getPlayerID();
|
2014-04-18 05:33:48 +02:00
|
|
|
return gridProxy.getSecurity().hasPermission( playerID, SecurityPermissions.BUILD );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( GridAccessException gae )
|
2014-04-18 05:33:48 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static ItemStack extractItemsByRecipe( IEnergySource energySrc, BaseActionSource mySrc, IMEMonitor<IAEItemStack> src, World w, IRecipe r, ItemStack output, InventoryCrafting ci, ItemStack providedTemplate, int slot, IItemList<IAEItemStack> items, Actionable realForFake, IPartitionList<IAEItemStack> filter )
|
2014-05-01 06:01:22 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( energySrc.extractAEPower( 1, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > 0.9 )
|
2014-05-01 06:01:22 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( providedTemplate == null )
|
2014-05-01 06:01:22 +02:00
|
|
|
return null;
|
|
|
|
|
|
|
|
AEItemStack ae_req = AEItemStack.create( providedTemplate );
|
|
|
|
ae_req.setStackSize( 1 );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( filter == null || filter.isListed( ae_req ) )
|
2014-05-01 06:01:22 +02:00
|
|
|
{
|
2014-09-17 06:26:25 +02:00
|
|
|
IAEItemStack ae_ext = src.extractItems( ae_req, realForFake, mySrc );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ae_ext != null )
|
2014-05-01 06:01:22 +02:00
|
|
|
{
|
2014-09-17 06:26:25 +02:00
|
|
|
ItemStack extracted = ae_ext.getItemStack();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( extracted != null )
|
2014-09-17 06:26:25 +02:00
|
|
|
{
|
|
|
|
energySrc.extractAEPower( 1, realForFake, PowerMultiplier.CONFIG );
|
|
|
|
return extracted;
|
|
|
|
}
|
2014-05-01 06:01:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
boolean checkFuzzy = ae_req.isOre() || providedTemplate.getItemDamage() == OreDictionary.WILDCARD_VALUE || providedTemplate.hasTagCompound() || providedTemplate.isItemStackDamageable();
|
2014-09-07 00:54:12 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( items != null && checkFuzzy )
|
2014-05-01 06:01:22 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( IAEItemStack x : items )
|
2014-05-01 06:01:22 +02:00
|
|
|
{
|
|
|
|
ItemStack sh = x.getItemStack();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ( Platform.isSameItemType( providedTemplate, sh ) || ae_req.sameOre( x ) ) && !Platform.isSameItem( sh, output ) )
|
2014-05-01 06:01:22 +02:00
|
|
|
{ // Platform.isSameItemType( sh, providedTemplate )
|
|
|
|
ItemStack cp = Platform.cloneItemStack( sh );
|
|
|
|
cp.stackSize = 1;
|
|
|
|
ci.setInventorySlotContents( slot, cp );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( r.matches( ci, w ) && Platform.isSameItem( r.getCraftingResult( ci ), output ) )
|
2014-05-01 06:01:22 +02:00
|
|
|
{
|
2014-08-02 06:00:12 +02:00
|
|
|
IAEItemStack ax = x.copy();
|
|
|
|
ax.setStackSize( 1 );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( filter == null || filter.isListed( ax ) )
|
2014-05-01 06:01:22 +02:00
|
|
|
{
|
2014-09-17 06:26:25 +02:00
|
|
|
IAEItemStack ex = src.extractItems( ax, realForFake, mySrc );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ex != null )
|
2014-09-17 06:26:25 +02:00
|
|
|
{
|
|
|
|
energySrc.extractAEPower( 1, realForFake, PowerMultiplier.CONFIG );
|
|
|
|
return ex.getItemStack();
|
|
|
|
}
|
2014-05-01 06:01:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ci.setInventorySlotContents( slot, providedTemplate );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static boolean isSameItemType( ItemStack ol, ItemStack op )
|
|
|
|
{
|
|
|
|
if( ol != null && op != null && ol.getItem() == op.getItem() )
|
|
|
|
{
|
|
|
|
if( ol.isItemStackDamageable() )
|
|
|
|
return true;
|
|
|
|
return ol.getItemDamage() == ol.getItemDamage();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isSameItem( ItemStack left, ItemStack right )
|
|
|
|
{
|
|
|
|
return left != null && right != null && left.isItemEqual( right );
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ItemStack cloneItemStack( ItemStack a )
|
2014-06-22 09:00:38 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return a.copy();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ItemStack getContainerItem( ItemStack stackInSlot )
|
|
|
|
{
|
|
|
|
if( stackInSlot == null )
|
2014-06-22 09:00:38 +02:00
|
|
|
return null;
|
|
|
|
|
|
|
|
Item i = stackInSlot.getItem();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( i == null || !i.hasContainerItem( stackInSlot ) )
|
2014-06-22 09:00:38 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( stackInSlot.stackSize > 1 )
|
2014-06-22 09:00:38 +02:00
|
|
|
{
|
|
|
|
stackInSlot.stackSize--;
|
|
|
|
return stackInSlot;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemStack ci = i.getContainerItem( stackInSlot.copy() );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ci != null && ci.isItemStackDamageable() && ci.getItemDamage() == ci.getMaxDamage() )
|
2014-06-22 09:00:38 +02:00
|
|
|
ci = null;
|
|
|
|
|
|
|
|
return ci;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static void notifyBlocksOfNeighbors( World worldObj, int xCoord, int yCoord, int zCoord )
|
2014-07-08 06:54:28 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !worldObj.isRemote )
|
2015-01-01 22:13:10 +01:00
|
|
|
TickHandler.INSTANCE.addCallable( worldObj, new BlockUpdate( worldObj, xCoord, yCoord, zCoord ) );
|
2014-07-09 02:36:20 +02:00
|
|
|
}
|
2014-07-08 06:54:28 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static boolean canRepair( AEFeature type, ItemStack a, ItemStack b )
|
2014-07-13 00:57:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( b == null || a == null )
|
2014-07-13 00:57:53 +02:00
|
|
|
return false;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( type == AEFeature.CertusQuartzTools )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
final IItemDefinition certusQuartzCrystal = AEApi.instance().definitions().materials().certusQuartzCrystal();
|
|
|
|
|
|
|
|
return certusQuartzCrystal.isSameAs( b );
|
|
|
|
}
|
2014-07-13 00:57:53 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( type == AEFeature.NetherQuartzTools )
|
2014-07-13 00:57:53 +02:00
|
|
|
return Items.quartz == b.getItem();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static Object findPreferred( ItemStack[] is )
|
2014-07-26 02:31:12 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
final IParts parts = AEApi.instance().definitions().parts();
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( ItemStack stack : is )
|
2014-07-26 02:31:12 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( parts.cableGlass().sameAs( AEColor.Transparent, stack ) )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2014-07-26 02:31:12 +02:00
|
|
|
return stack;
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
2014-07-26 02:31:12 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( parts.cableCovered().sameAs( AEColor.Transparent, stack ) )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2014-07-26 02:31:12 +02:00
|
|
|
return stack;
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
2014-07-26 02:31:12 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( parts.cableSmart().sameAs( AEColor.Transparent, stack ) )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2014-07-26 02:31:12 +02:00
|
|
|
return stack;
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
2014-07-26 02:31:12 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( parts.cableDense().sameAs( AEColor.Transparent, stack ) )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2014-07-26 02:31:12 +02:00
|
|
|
return stack;
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
2014-07-26 02:31:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return is;
|
|
|
|
}
|
2014-08-07 08:47:42 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static void sendChunk( Chunk c, int verticalBits )
|
2014-08-07 08:47:42 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
WorldServer ws = (WorldServer) c.worldObj;
|
|
|
|
PlayerManager pm = ws.getPlayerManager();
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( getOrCreateChunkWatcher == null )
|
2014-08-07 08:47:42 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
getOrCreateChunkWatcher = ReflectionHelper.findMethod( PlayerManager.class, pm, new String[] { "getOrCreateChunkWatcher", "func_72690_a" }, int.class, int.class, boolean.class );
|
2014-08-07 08:47:42 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( getOrCreateChunkWatcher != null )
|
2014-08-07 08:47:42 +02:00
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
Object playerInstance = getOrCreateChunkWatcher.invoke( pm, c.xPosition, c.zPosition, false );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( playerInstance != null )
|
2014-08-07 08:47:42 +02:00
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
Platform.playerInstance = playerInstance.getClass();
|
2014-08-07 08:47:42 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( sendToAllPlayersWatchingChunk == null )
|
2014-08-07 08:47:42 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
sendToAllPlayersWatchingChunk = ReflectionHelper.findMethod( Platform.playerInstance, playerInstance, new String[] { "sendToAllPlayersWatchingChunk", "func_151251_a" }, Packet.class );
|
2014-08-07 08:47:42 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( sendToAllPlayersWatchingChunk != null )
|
2014-09-28 11:47:17 +02:00
|
|
|
sendToAllPlayersWatchingChunk.invoke( playerInstance, new S21PacketChunkData( c, false, verticalBits ) );
|
2014-08-07 08:47:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( Throwable t )
|
2014-08-07 08:47:42 +02:00
|
|
|
{
|
|
|
|
AELog.error( t );
|
|
|
|
}
|
|
|
|
}
|
2014-08-08 08:36:50 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static AxisAlignedBB getPrimaryBox( ForgeDirection side, int facadeThickness )
|
2014-08-08 08:36:50 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( side )
|
2014-08-08 08:36:50 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
case DOWN:
|
|
|
|
return AxisAlignedBB.getBoundingBox( 0.0, 0.0, 0.0, 1.0, ( facadeThickness ) / 16.0, 1.0 );
|
|
|
|
case EAST:
|
|
|
|
return AxisAlignedBB.getBoundingBox( ( 16.0 - facadeThickness ) / 16.0, 0.0, 0.0, 1.0, 1.0, 1.0 );
|
|
|
|
case NORTH:
|
|
|
|
return AxisAlignedBB.getBoundingBox( 0.0, 0.0, 0.0, 1.0, 1.0, ( facadeThickness ) / 16.0 );
|
|
|
|
case SOUTH:
|
|
|
|
return AxisAlignedBB.getBoundingBox( 0.0, 0.0, ( 16.0 - facadeThickness ) / 16.0, 1.0, 1.0, 1.0 );
|
|
|
|
case UP:
|
|
|
|
return AxisAlignedBB.getBoundingBox( 0.0, ( 16.0 - facadeThickness ) / 16.0, 0.0, 1.0, 1.0, 1.0 );
|
|
|
|
case WEST:
|
|
|
|
return AxisAlignedBB.getBoundingBox( 0.0, 0.0, 0.0, ( facadeThickness ) / 16.0, 1.0, 1.0 );
|
|
|
|
default:
|
|
|
|
break;
|
2014-08-08 08:36:50 +02:00
|
|
|
}
|
|
|
|
return AxisAlignedBB.getBoundingBox( 0, 0, 0, 1, 1, 1 );
|
|
|
|
}
|
2014-08-18 23:12:45 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static float getEyeOffset( EntityPlayer player )
|
2014-08-18 23:12:45 +02:00
|
|
|
{
|
|
|
|
assert player.worldObj.isRemote : "Valid only on client";
|
2015-04-03 08:54:31 +02:00
|
|
|
return (float) ( player.posY + player.getEyeHeight() - player.getDefaultEyeHeight() );
|
2014-08-18 23:12:45 +02:00
|
|
|
}
|
2014-09-14 07:02:02 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static void addStat( int playerID, Achievement achievement )
|
2014-09-14 07:02:02 +02:00
|
|
|
{
|
|
|
|
EntityPlayer p = AEApi.instance().registries().players().findPlayer( playerID );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( p != null )
|
2014-09-14 07:02:02 +02:00
|
|
|
{
|
2014-09-28 00:58:48 +02:00
|
|
|
p.addStat( achievement, 1 );
|
2014-09-14 07:02:02 +02:00
|
|
|
}
|
|
|
|
}
|
2014-09-17 18:25:30 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public static boolean isRecipePrioritized( ItemStack what )
|
2014-09-17 06:23:19 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
final IMaterials materials = AEApi.instance().definitions().materials();
|
|
|
|
|
|
|
|
boolean isPurified = materials.purifiedCertusQuartzCrystal().isSameAs( what );
|
|
|
|
isPurified |= materials.purifiedFluixCrystal().isSameAs( what );
|
|
|
|
isPurified |= materials.purifiedNetherQuartzCrystal().isSameAs( what );
|
|
|
|
|
|
|
|
return isPurified;
|
2014-09-17 06:23:19 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|