2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
2015-05-16 20:48:32 +02:00
|
|
|
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
2014-11-14 12:02:52 +01:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2015-03-23 10:14:35 +01:00
|
|
|
import java.security.InvalidParameterException;
|
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;
|
2016-10-04 01:34:29 +02:00
|
|
|
import java.util.Collections;
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.util.EnumSet;
|
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;
|
|
|
|
import java.util.WeakHashMap;
|
2016-12-14 22:37:10 +01:00
|
|
|
|
2015-04-07 00:17:55 +02:00
|
|
|
import javax.annotation.Nonnull;
|
2015-03-23 10:14:35 +01:00
|
|
|
import javax.annotation.Nullable;
|
2015-04-05 20:16:02 +02:00
|
|
|
|
2016-10-09 12:01:31 +02:00
|
|
|
import com.google.common.collect.Iterables;
|
2016-10-04 01:34:29 +02:00
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.block.Block;
|
2015-06-16 02:44:59 +02:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
2017-07-06 01:57:19 +02:00
|
|
|
import net.minecraft.client.util.ITooltipFlag;
|
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.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.item.crafting.CraftingManager;
|
|
|
|
import net.minecraft.item.crafting.IRecipe;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-06-19 14:43:27 +02:00
|
|
|
import net.minecraft.network.play.server.SPacketChunkData;
|
|
|
|
import net.minecraft.server.management.PlayerChunkMap;
|
2016-06-21 11:03:10 +02:00
|
|
|
import net.minecraft.server.management.PlayerChunkMapEntry;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.tileentity.TileEntityChest;
|
2015-06-16 02:44:59 +02:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-06-19 14:43:27 +02:00
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.MathHelper;
|
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
|
|
|
import net.minecraft.util.math.Vec3d;
|
|
|
|
import net.minecraft.util.registry.RegistryNamespaced;
|
|
|
|
import net.minecraft.util.text.translation.I18n;
|
2013-12-27 23:59:59 +01:00
|
|
|
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;
|
2015-06-16 02:44:59 +02:00
|
|
|
import net.minecraftforge.fml.common.FMLCommonHandler;
|
|
|
|
import net.minecraftforge.fml.common.Loader;
|
|
|
|
import net.minecraftforge.fml.common.ModContainer;
|
2017-07-06 01:57:19 +02:00
|
|
|
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
2015-06-16 02:44:59 +02:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2014-09-07 00:54:12 +02:00
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
2017-07-20 21:18:49 +02:00
|
|
|
import net.minecraftforge.registries.IForgeRegistry;
|
2015-12-24 02:07:03 +01:00
|
|
|
|
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.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;
|
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;
|
2015-06-16 02:44:59 +02:00
|
|
|
import appeng.api.util.AEPartLocation;
|
2014-08-29 04:37:08 +02:00
|
|
|
import appeng.api.util.DimensionalCoord;
|
2016-10-26 22:58:23 +02:00
|
|
|
import appeng.capabilities.Capabilities;
|
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;
|
2016-11-06 20:23:14 +01:00
|
|
|
import appeng.integration.Integrations;
|
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;
|
2016-11-04 09:27:52 +01:00
|
|
|
import appeng.util.helpers.ItemComparisonHelper;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.util.item.AEItemStack;
|
|
|
|
import appeng.util.item.AESharedNBT;
|
2016-11-01 16:15:05 +01:00
|
|
|
import appeng.util.prioritylist.IPartitionList;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-04-05 20:16:02 +02:00
|
|
|
/**
|
|
|
|
* @author AlgorithmX2
|
|
|
|
* @author thatsIch
|
|
|
|
* @version rv2
|
|
|
|
* @since rv0
|
|
|
|
*/
|
2013-12-27 23:59:59 +01:00
|
|
|
public class Platform
|
|
|
|
{
|
|
|
|
|
2016-06-19 14:43:27 +02:00
|
|
|
public static final Block AIR_BLOCK = 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;
|
|
|
|
|
2016-11-04 21:01:25 +01:00
|
|
|
private static final boolean CLIENT_INSTALL = FMLCommonHandler.instance().getSide().isClient();
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
/*
|
|
|
|
* random source, use it for item drop locations...
|
|
|
|
*/
|
2015-04-06 00:35:42 +02:00
|
|
|
private static final Random RANDOM_GENERATOR = new Random();
|
2017-07-20 21:21:45 +02:00
|
|
|
private static final WeakHashMap<World, EntityPlayer> FAKE_PLAYERS = new WeakHashMap<>();
|
2016-11-26 14:08:10 +01:00
|
|
|
// private static Method getEntry;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2016-11-04 09:27:52 +01:00
|
|
|
private static final ItemComparisonHelper ITEM_COMPARISON_HELPER = new ItemComparisonHelper();
|
|
|
|
|
|
|
|
public static ItemComparisonHelper itemComparisons()
|
|
|
|
{
|
|
|
|
return ITEM_COMPARISON_HELPER;
|
|
|
|
}
|
|
|
|
|
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-12-24 02:03:16 +01: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-09-30 14:24:40 +02:00
|
|
|
public static String formatPowerLong( final long n, final 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
|
|
|
|
2016-11-26 14:07:34 +01:00
|
|
|
final PowerUnits displayUnits = AEConfig.instance().selectedPowerUnit();
|
2014-05-25 01:22:50 +02:00
|
|
|
p = PowerUnits.AE.convertTo( displayUnits, p );
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final String[] preFixes = { "k", "M", "G", "T", "P", "T", "P", "E", "Z", "Y" };
|
2014-05-25 01:22:50 +02:00
|
|
|
String unitName = displayUnits.name();
|
|
|
|
|
2015-09-30 14:22:21 +02:00
|
|
|
String level = "";
|
|
|
|
int offset = 0;
|
2015-04-03 08:54:31 +02:00
|
|
|
while( p > 1000 && offset < preFixes.length )
|
2014-05-25 01:22:50 +02:00
|
|
|
{
|
|
|
|
p /= 1000;
|
2015-05-08 23:34:24 +02:00
|
|
|
level = preFixes[offset];
|
2014-05-25 01:22:50 +02:00
|
|
|
offset++;
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final DecimalFormat df = new DecimalFormat( "#.##" );
|
2015-05-08 23:34:24 +02:00
|
|
|
return df.format( p ) + ' ' + level + unitName + ( isRate ? "/t" : "" );
|
2014-05-25 01:22:50 +02:00
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static AEPartLocation crossProduct( final AEPartLocation forward, final AEPartLocation up )
|
2015-06-16 02:44:59 +02:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final int west_x = forward.yOffset * up.zOffset - forward.zOffset * up.yOffset;
|
|
|
|
final int west_y = forward.zOffset * up.xOffset - forward.xOffset * up.zOffset;
|
|
|
|
final int west_z = forward.xOffset * up.yOffset - forward.yOffset * up.xOffset;
|
2015-06-16 02:44:59 +02:00
|
|
|
|
|
|
|
switch( west_x + west_y * 2 + west_z * 3 )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
return AEPartLocation.EAST;
|
|
|
|
case -1:
|
|
|
|
return AEPartLocation.WEST;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
return AEPartLocation.UP;
|
|
|
|
case -2:
|
|
|
|
return AEPartLocation.DOWN;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
return AEPartLocation.SOUTH;
|
|
|
|
case -3:
|
|
|
|
return AEPartLocation.NORTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AEPartLocation.INTERNAL;
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static EnumFacing crossProduct( final EnumFacing forward, final EnumFacing up )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final int west_x = forward.getFrontOffsetY() * up.getFrontOffsetZ() - forward.getFrontOffsetZ() * up.getFrontOffsetY();
|
|
|
|
final int west_y = forward.getFrontOffsetZ() * up.getFrontOffsetX() - forward.getFrontOffsetX() * up.getFrontOffsetZ();
|
|
|
|
final int west_z = forward.getFrontOffsetX() * up.getFrontOffsetY() - forward.getFrontOffsetY() * up.getFrontOffsetX();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
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:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.EAST;
|
2015-04-03 08:54:31 +02:00
|
|
|
case -1:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.WEST;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
case 2:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.UP;
|
2015-04-03 08:54:31 +02:00
|
|
|
case -2:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.DOWN;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
case 3:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.SOUTH;
|
2015-04-03 08:54:31 +02:00
|
|
|
case -3:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.NORTH;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-12-24 02:03:16 +01:00
|
|
|
// something is better then nothing?
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.NORTH;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static <T extends Enum> T rotateEnum( T ce, final boolean backwards, final EnumSet validOptions )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if( backwards )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
ce = prevEnum( ce );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
ce = nextEnum( ce );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
2015-05-08 23:25:19 +02:00
|
|
|
while( !validOptions.contains( ce ) || isNotValidSetting( ce ) );
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
return ce;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
/*
|
|
|
|
* Simple way to cycle an enum...
|
|
|
|
*/
|
2015-10-08 15:42:42 +02:00
|
|
|
private static <T extends Enum> T prevEnum( final T ce )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final EnumSet valList = EnumSet.allOf( ce.getClass() );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
int pLoc = ce.ordinal() - 1;
|
|
|
|
if( pLoc < 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
pLoc = valList.size() - 1;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( pLoc < 0 || pLoc >= valList.size() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
pLoc = 0;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
int pos = 0;
|
2015-09-30 14:24:40 +02:00
|
|
|
for( final Object g : valList )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( pos == pLoc )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return (T) g;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
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-09-30 14:24:40 +02:00
|
|
|
public static <T extends Enum> T nextEnum( final T ce )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final EnumSet valList = EnumSet.allOf( ce.getClass() );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
int pLoc = ce.ordinal() + 1;
|
|
|
|
if( pLoc >= valList.size() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
pLoc = 0;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( pLoc < 0 || pLoc >= valList.size() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
pLoc = 0;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
int pos = 0;
|
2015-09-30 14:24:40 +02:00
|
|
|
for( final Object g : valList )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( pos == pLoc )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return (T) g;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-03-26 11:07:26 +01:00
|
|
|
pos++;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
private static boolean isNotValidSetting( final Enum e )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2016-11-06 20:23:14 +01:00
|
|
|
if( e == SortOrder.INVTWEAKS && !Integrations.invTweaks().isEnabled() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2016-11-06 20:23:14 +01:00
|
|
|
if( e == SearchBoxMode.JEI_AUTOSEARCH && !Integrations.jei().isEnabled() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2016-11-06 20:23:14 +01:00
|
|
|
if( e == SearchBoxMode.JEI_MANUAL_SEARCH && !Integrations.jei().isEnabled() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
return false;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static void openGUI( @Nonnull final EntityPlayer p, @Nullable final TileEntity tile, @Nullable final AEPartLocation side, @Nonnull final GuiBridge type )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( isClient() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
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
|
|
|
{
|
2015-06-16 02:44:59 +02:00
|
|
|
x = tile.getPos().getX();
|
|
|
|
y = tile.getPos().getY();
|
|
|
|
z = tile.getPos().getZ();
|
2014-02-01 06:37:27 +01:00
|
|
|
}
|
|
|
|
|
2015-12-24 02:03:16 +01: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-07 00:17:55 +02:00
|
|
|
if( tile == null && type.getType() == GuiHostType.ITEM )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-05-16 20:48:32 +02:00
|
|
|
p.openGui( AppEng.instance(), type.ordinal() << 4, p.getEntityWorld(), p.inventory.currentItem, 0, 0 );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-07 00:17:55 +02:00
|
|
|
else if( tile == null || type.getType() == GuiHostType.ITEM )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-05-16 20:48:32 +02:00
|
|
|
p.openGui( AppEng.instance(), type.ordinal() << 4 | ( 1 << 3 ), p.getEntityWorld(), x, y, z );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-27 05:00:36 +01:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-06-16 02:44:59 +02:00
|
|
|
p.openGui( AppEng.instance(), type.ordinal() << 4 | ( side.ordinal() ), tile.getWorld(), x, y, z );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
|
2016-11-04 21:01:25 +01:00
|
|
|
/*
|
|
|
|
* returns true if client classes are available.
|
|
|
|
*/
|
|
|
|
public static boolean isClientInstall()
|
|
|
|
{
|
|
|
|
return CLIENT_INSTALL;
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static boolean hasPermissions( final DimensionalCoord dc, final EntityPlayer player )
|
2014-02-01 06:37:27 +01:00
|
|
|
{
|
2015-06-16 02:44:59 +02:00
|
|
|
return dc.getWorld().canMineBlockBody( player, dc.getPos() );
|
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-09-30 14:24:40 +02:00
|
|
|
public static boolean isBlockAir( final World w, final BlockPos pos )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2016-06-19 14:43:27 +02:00
|
|
|
return w.getBlockState( pos ).getBlock().isAir( w.getBlockState( pos ), w, pos );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2015-09-30 14:24:40 +02:00
|
|
|
catch( final Throwable e )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
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-09-30 14:24:40 +02:00
|
|
|
public static IRecipe findMatchingRecipe( final InventoryCrafting inventoryCrafting, final World par2World )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2017-07-06 01:57:19 +02:00
|
|
|
IForgeRegistry<IRecipe> recipes = ForgeRegistries.RECIPES;
|
|
|
|
final List<IRecipe> rl = recipes.getValues();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
for( final IRecipe r : rl )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-05-08 23:25:19 +02:00
|
|
|
if( r.matches( inventoryCrafting, par2World ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static ItemStack[] getBlockDrops( final World w, final BlockPos pos )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2017-07-20 21:21:45 +02:00
|
|
|
List<ItemStack> out = new ArrayList<>();
|
2015-09-30 14:24:40 +02:00
|
|
|
final IBlockState state = w.getBlockState( pos );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-06-16 02:44:59 +02:00
|
|
|
if( state != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-06-16 02:44:59 +02:00
|
|
|
out = state.getBlock().getDrops( w, pos, state, 0 );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( out == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return new ItemStack[0];
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
return out.toArray( new ItemStack[out.size()] );
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static AEPartLocation cycleOrientations( final AEPartLocation dir, final 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:
|
2015-06-16 02:44:59 +02:00
|
|
|
return AEPartLocation.SOUTH;
|
2015-04-03 08:54:31 +02:00
|
|
|
case SOUTH:
|
2015-06-16 02:44:59 +02:00
|
|
|
return AEPartLocation.EAST;
|
2015-04-03 08:54:31 +02:00
|
|
|
case EAST:
|
2015-06-16 02:44:59 +02:00
|
|
|
return AEPartLocation.WEST;
|
2015-04-03 08:54:31 +02:00
|
|
|
case WEST:
|
2015-06-16 02:44:59 +02:00
|
|
|
return AEPartLocation.NORTH;
|
2015-04-03 08:54:31 +02:00
|
|
|
case UP:
|
2015-06-16 02:44:59 +02:00
|
|
|
return AEPartLocation.UP;
|
2015-04-03 08:54:31 +02:00
|
|
|
case DOWN:
|
2015-06-16 02:44:59 +02:00
|
|
|
return AEPartLocation.DOWN;
|
|
|
|
case INTERNAL:
|
|
|
|
return AEPartLocation.INTERNAL;
|
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:
|
2015-06-16 02:44:59 +02:00
|
|
|
return AEPartLocation.DOWN;
|
2015-04-03 08:54:31 +02:00
|
|
|
case DOWN:
|
2015-06-16 02:44:59 +02:00
|
|
|
return AEPartLocation.NORTH;
|
2015-04-03 08:54:31 +02:00
|
|
|
case NORTH:
|
2015-06-16 02:44:59 +02:00
|
|
|
return AEPartLocation.SOUTH;
|
2015-04-03 08:54:31 +02:00
|
|
|
case SOUTH:
|
2015-06-16 02:44:59 +02:00
|
|
|
return AEPartLocation.EAST;
|
2015-04-03 08:54:31 +02:00
|
|
|
case EAST:
|
2015-06-16 02:44:59 +02:00
|
|
|
return AEPartLocation.WEST;
|
2015-04-03 08:54:31 +02:00
|
|
|
case WEST:
|
2015-06-16 02:44:59 +02:00
|
|
|
return AEPartLocation.UP;
|
|
|
|
case INTERNAL:
|
|
|
|
return AEPartLocation.INTERNAL;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-16 02:44:59 +02:00
|
|
|
return AEPartLocation.INTERNAL;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
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-09-30 14:24:40 +02:00
|
|
|
public static NBTTagCompound openNbtData( final 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-09-30 14:24:40 +02:00
|
|
|
public static void spawnDrops( final World w, final BlockPos pos, final 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-09-30 14:24:40 +02:00
|
|
|
for( final ItemStack i : drops )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2017-06-26 05:15:25 +02:00
|
|
|
if( !i.isEmpty() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2016-12-08 12:42:00 +01:00
|
|
|
if( i.getCount() > 0 )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final double offset_x = ( getRandomInt() % 32 - 16 ) / 82;
|
|
|
|
final double offset_y = ( getRandomInt() % 32 - 16 ) / 82;
|
|
|
|
final double offset_z = ( getRandomInt() % 32 - 16 ) / 82;
|
2016-12-08 12:42:00 +01:00
|
|
|
final EntityItem ei = new EntityItem( w, 0.5 + offset_x + pos.getX(), 0.5 + offset_y + pos.getY(), 0.2 + offset_z + pos.getZ(), i
|
|
|
|
.copy() );
|
|
|
|
w.spawnEntity( ei );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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() );
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static boolean isModLoaded( final 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-09-30 14:24:40 +02:00
|
|
|
catch( final Throwable ignored )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
for( final 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;
|
|
|
|
}
|
|
|
|
|
2016-12-08 12:42:00 +01:00
|
|
|
public static ItemStack findMatchingRecipeOutput( final InventoryCrafting ic, final World world )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2017-07-06 01:57:19 +02:00
|
|
|
return CraftingManager.findMatchingResult( ic, world );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@SideOnly( Side.CLIENT )
|
2015-09-30 14:24:40 +02:00
|
|
|
public static List getTooltip( final Object o )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( o == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return new ArrayList();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2017-06-27 20:39:06 +02:00
|
|
|
ItemStack itemStack = ItemStack.EMPTY;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( o instanceof AEItemStack )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final AEItemStack ais = (AEItemStack) o;
|
2013-12-27 23:59:59 +01:00
|
|
|
return ais.getToolTip();
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( o instanceof ItemStack )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
itemStack = (ItemStack) o;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return new ArrayList();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2017-07-20 21:17:10 +02:00
|
|
|
ITooltipFlag.TooltipFlags tooltipFlag = Minecraft
|
|
|
|
.getMinecraft().gameSettings.advancedItemTooltips ? ITooltipFlag.TooltipFlags.ADVANCED : ITooltipFlag.TooltipFlags.NORMAL;
|
2017-07-06 01:57:19 +02:00
|
|
|
return itemStack.getTooltip( Minecraft.getMinecraft().player, tooltipFlag );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2015-09-30 14:24:40 +02:00
|
|
|
catch( final Exception errB )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return new ArrayList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static String getModId( final IAEItemStack is )
|
2014-07-03 04:09:17 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( is == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-03 04:09:17 +02:00
|
|
|
return "** Null";
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-03 04:09:17 +02:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final String n = ( (AEItemStack) is ).getModID();
|
2014-07-03 04:09:17 +02:00
|
|
|
return n == null ? "** Null" : n;
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static String getItemDisplayName( final Object o )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( o == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return "** Null";
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2017-06-27 20:39:06 +02:00
|
|
|
ItemStack itemStack = ItemStack.EMPTY;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( o instanceof AEItemStack )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final 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 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
itemStack = (ItemStack) o;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return "**Invalid Object";
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
String name = itemStack.getDisplayName();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( name == null || name.isEmpty() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
name = itemStack.getItem().getUnlocalizedName( itemStack );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
return name == null ? "** Null" : name;
|
|
|
|
}
|
2015-09-30 14:24:40 +02:00
|
|
|
catch( final Exception errA )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final String n = itemStack.getUnlocalizedName();
|
2013-12-27 23:59:59 +01:00
|
|
|
return n == null ? "** Null" : n;
|
|
|
|
}
|
2015-09-30 14:24:40 +02:00
|
|
|
catch( final Exception errB )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return "** Exception";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static boolean hasSpecialComparison( final IAEItemStack willAdd )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( willAdd == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-09-30 14:24:40 +02:00
|
|
|
final IAETagCompound tag = willAdd.getTagCompound();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( tag != null && tag.getSpecialComparison() != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static boolean hasSpecialComparison( final 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-05-09 00:00:52 +02:00
|
|
|
if( ( (IAETagCompound) willAdd.getTagCompound() ).getSpecialComparison() != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static boolean isWrench( final EntityPlayer player, final ItemStack eq, final BlockPos pos )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2017-06-26 05:15:25 +02:00
|
|
|
if( !eq.isEmpty() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-06-16 02:44:59 +02:00
|
|
|
// TODO: Build Craft Wrench?
|
|
|
|
/*
|
2015-12-24 02:03:16 +01:00
|
|
|
* if( eq.getItem() instanceof IToolWrench )
|
|
|
|
* {
|
|
|
|
* IToolWrench wrench = (IToolWrench) eq.getItem();
|
|
|
|
* return wrench.canWrench( player, x, y, z );
|
|
|
|
* }
|
|
|
|
*/
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2015-09-30 14:24:40 +02:00
|
|
|
catch( final 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
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final IAEWrench wrench = (IAEWrench) eq.getItem();
|
2015-06-16 02:44:59 +02:00
|
|
|
return wrench.canWrench( eq, player, pos );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static boolean isChargeable( final ItemStack i )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2017-06-26 05:15:25 +02:00
|
|
|
if( i.isEmpty() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-09-30 14:24:40 +02:00
|
|
|
final 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-09-30 14:24:40 +02:00
|
|
|
public static EntityPlayer getPlayer( final WorldServer w )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( w == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-03-23 10:14:35 +01:00
|
|
|
throw new InvalidParameterException( "World is null." );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-04 08:19:45 +02:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final EntityPlayer wrp = FAKE_PLAYERS.get( w );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( wrp != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return wrp;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final 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-09-30 14:24:40 +02:00
|
|
|
public static int MC2MEColor( final int color )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-06-19 14:43:27 +02:00
|
|
|
public static int findEmpty( final RegistryNamespaced registry, final int minId, final int maxId )
|
|
|
|
{
|
|
|
|
for( int x = minId; x < maxId; x++ )
|
|
|
|
{
|
|
|
|
if( registry.getObjectById( x ) == null )
|
|
|
|
{
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2016-11-04 09:27:52 +01:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static int findEmpty( final 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 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return x;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-10-09 12:01:31 +02:00
|
|
|
/**
|
|
|
|
* Returns a random element from the given collection.
|
2017-07-20 21:23:01 +02:00
|
|
|
*
|
2016-10-09 12:01:31 +02:00
|
|
|
* @return null if the collection is empty
|
|
|
|
*/
|
|
|
|
@Nullable
|
2015-09-30 14:24:40 +02:00
|
|
|
public static <T> T pickRandom( final Collection<T> outs )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2016-10-09 12:01:31 +02:00
|
|
|
if( outs.isEmpty() )
|
2015-03-26 11:07:26 +01:00
|
|
|
{
|
2016-10-09 12:01:31 +02:00
|
|
|
return null;
|
2015-03-26 11:07:26 +01:00
|
|
|
}
|
2016-10-09 12:01:31 +02:00
|
|
|
|
|
|
|
int index = RANDOM_GENERATOR.nextInt( outs.size() );
|
|
|
|
return Iterables.get( outs, index, null );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static AEPartLocation rotateAround( final AEPartLocation forward, final AEPartLocation axis )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-06-16 02:44:59 +02:00
|
|
|
if( axis == AEPartLocation.INTERNAL || forward == AEPartLocation.INTERNAL )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return forward;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
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:
|
2015-06-16 02:44:59 +02:00
|
|
|
return AEPartLocation.EAST;
|
|
|
|
case SOUTH:
|
|
|
|
return AEPartLocation.WEST;
|
|
|
|
case EAST:
|
|
|
|
return AEPartLocation.NORTH;
|
|
|
|
case WEST:
|
|
|
|
return AEPartLocation.SOUTH;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UP:
|
|
|
|
switch( axis )
|
|
|
|
{
|
|
|
|
case NORTH:
|
|
|
|
return AEPartLocation.WEST;
|
|
|
|
case SOUTH:
|
|
|
|
return AEPartLocation.EAST;
|
|
|
|
case EAST:
|
|
|
|
return AEPartLocation.SOUTH;
|
|
|
|
case WEST:
|
|
|
|
return AEPartLocation.NORTH;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NORTH:
|
|
|
|
switch( axis )
|
|
|
|
{
|
|
|
|
case UP:
|
|
|
|
return AEPartLocation.WEST;
|
|
|
|
case DOWN:
|
|
|
|
return AEPartLocation.EAST;
|
|
|
|
case EAST:
|
|
|
|
return AEPartLocation.UP;
|
|
|
|
case WEST:
|
|
|
|
return AEPartLocation.DOWN;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SOUTH:
|
|
|
|
switch( axis )
|
|
|
|
{
|
|
|
|
case UP:
|
|
|
|
return AEPartLocation.EAST;
|
|
|
|
case DOWN:
|
|
|
|
return AEPartLocation.WEST;
|
|
|
|
case EAST:
|
|
|
|
return AEPartLocation.DOWN;
|
|
|
|
case WEST:
|
|
|
|
return AEPartLocation.UP;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EAST:
|
|
|
|
switch( axis )
|
|
|
|
{
|
|
|
|
case UP:
|
|
|
|
return AEPartLocation.NORTH;
|
|
|
|
case DOWN:
|
|
|
|
return AEPartLocation.SOUTH;
|
|
|
|
case NORTH:
|
|
|
|
return AEPartLocation.UP;
|
|
|
|
case SOUTH:
|
|
|
|
return AEPartLocation.DOWN;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WEST:
|
|
|
|
switch( axis )
|
|
|
|
{
|
|
|
|
case UP:
|
|
|
|
return AEPartLocation.SOUTH;
|
|
|
|
case DOWN:
|
|
|
|
return AEPartLocation.NORTH;
|
|
|
|
case NORTH:
|
|
|
|
return AEPartLocation.DOWN;
|
|
|
|
case SOUTH:
|
|
|
|
return AEPartLocation.UP;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return forward;
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static EnumFacing rotateAround( final EnumFacing forward, final EnumFacing axis )
|
2015-06-16 02:44:59 +02:00
|
|
|
{
|
|
|
|
switch( forward )
|
|
|
|
{
|
|
|
|
case DOWN:
|
|
|
|
switch( axis )
|
|
|
|
{
|
|
|
|
case DOWN:
|
|
|
|
return forward;
|
|
|
|
case UP:
|
|
|
|
return forward;
|
|
|
|
case NORTH:
|
|
|
|
return EnumFacing.EAST;
|
2015-04-03 08:54:31 +02:00
|
|
|
case SOUTH:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.WEST;
|
2015-04-03 08:54:31 +02:00
|
|
|
case EAST:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.NORTH;
|
2015-04-03 08:54:31 +02:00
|
|
|
case WEST:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.SOUTH;
|
2015-04-03 08:54:31 +02:00
|
|
|
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:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.WEST;
|
2015-04-03 08:54:31 +02:00
|
|
|
case SOUTH:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.EAST;
|
2015-04-03 08:54:31 +02:00
|
|
|
case EAST:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.SOUTH;
|
2015-04-03 08:54:31 +02:00
|
|
|
case WEST:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.NORTH;
|
2015-04-03 08:54:31 +02:00
|
|
|
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:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.WEST;
|
2015-04-03 08:54:31 +02:00
|
|
|
case DOWN:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.EAST;
|
2015-04-03 08:54:31 +02:00
|
|
|
case EAST:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.UP;
|
2015-04-03 08:54:31 +02:00
|
|
|
case WEST:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.DOWN;
|
2015-04-03 08:54:31 +02:00
|
|
|
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:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.EAST;
|
2015-04-03 08:54:31 +02:00
|
|
|
case DOWN:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.WEST;
|
2015-04-03 08:54:31 +02:00
|
|
|
case EAST:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.DOWN;
|
2015-04-03 08:54:31 +02:00
|
|
|
case WEST:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.UP;
|
2015-04-03 08:54:31 +02:00
|
|
|
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:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.NORTH;
|
2015-04-03 08:54:31 +02:00
|
|
|
case DOWN:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.SOUTH;
|
2015-04-03 08:54:31 +02:00
|
|
|
case NORTH:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.UP;
|
2015-04-03 08:54:31 +02:00
|
|
|
case SOUTH:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.DOWN;
|
2015-04-03 08:54:31 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
case WEST:
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( axis )
|
|
|
|
{
|
|
|
|
case UP:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.SOUTH;
|
2015-04-03 08:54:31 +02:00
|
|
|
case DOWN:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.NORTH;
|
2015-04-03 08:54:31 +02:00
|
|
|
case NORTH:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.DOWN;
|
2015-04-03 08:54:31 +02:00
|
|
|
case SOUTH:
|
2015-06-16 02:44:59 +02:00
|
|
|
return EnumFacing.UP;
|
2015-04-03 08:54:31 +02:00
|
|
|
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 )
|
2015-09-30 14:24:40 +02:00
|
|
|
public static String gui_localize( final String string )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2016-06-19 14:43:27 +02:00
|
|
|
return I18n.translateToLocal( string );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static LookDirection getPlayerRay( final EntityPlayer playerIn, final float eyeOffset )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-06-16 02:44:59 +02:00
|
|
|
double reachDistance = 5.0d;
|
2014-08-29 04:37:08 +02:00
|
|
|
|
2015-06-16 02:44:59 +02:00
|
|
|
final double x = playerIn.prevPosX + ( playerIn.posX - playerIn.prevPosX );
|
|
|
|
final double y = playerIn.prevPosY + ( playerIn.posY - playerIn.prevPosY ) + playerIn.getEyeHeight();
|
|
|
|
final double z = playerIn.prevPosZ + ( playerIn.posZ - playerIn.prevPosZ );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-06-16 02:44:59 +02:00
|
|
|
final float playerPitch = playerIn.prevRotationPitch + ( playerIn.rotationPitch - playerIn.prevRotationPitch );
|
|
|
|
final float playerYaw = playerIn.prevRotationYaw + ( playerIn.rotationYaw - playerIn.prevRotationYaw );
|
|
|
|
|
2015-12-24 02:03:16 +01:00
|
|
|
final float yawRayX = MathHelper.sin( -playerYaw * 0.017453292f - (float) Math.PI );
|
|
|
|
final float yawRayZ = MathHelper.cos( -playerYaw * 0.017453292f - (float) Math.PI );
|
2015-06-16 02:44:59 +02:00
|
|
|
|
|
|
|
final float pitchMultiplier = -MathHelper.cos( -playerPitch * 0.017453292F );
|
|
|
|
final float eyeRayY = MathHelper.sin( -playerPitch * 0.017453292F );
|
|
|
|
final float eyeRayX = yawRayX * pitchMultiplier;
|
|
|
|
final float eyeRayZ = yawRayZ * pitchMultiplier;
|
|
|
|
|
2015-12-24 02:03:16 +01:00
|
|
|
if( playerIn instanceof EntityPlayerMP )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2016-06-19 14:43:27 +02:00
|
|
|
reachDistance = ( (EntityPlayerMP) playerIn ).interactionManager.getBlockReachDistance();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2015-06-16 02:44:59 +02:00
|
|
|
|
2016-06-19 14:43:27 +02:00
|
|
|
final Vec3d from = new Vec3d( x, y, z );
|
|
|
|
final Vec3d to = from.addVector( eyeRayX * reachDistance, eyeRayY * reachDistance, eyeRayZ * reachDistance );
|
2015-06-16 02:44:59 +02:00
|
|
|
|
|
|
|
return new LookDirection( from, to );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2016-06-19 14:43:27 +02:00
|
|
|
public static RayTraceResult rayTrace( final EntityPlayer p, final boolean hitBlocks, final boolean hitEntities )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final World w = p.getEntityWorld();
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final float f = 1.0F;
|
2015-04-03 08:54:31 +02:00
|
|
|
float f1 = p.prevRotationPitch + ( p.rotationPitch - p.prevRotationPitch ) * f;
|
2015-09-30 14:24:40 +02:00
|
|
|
final float f2 = p.prevRotationYaw + ( p.rotationYaw - p.prevRotationYaw ) * f;
|
|
|
|
final double d0 = p.prevPosX + ( p.posX - p.prevPosX ) * f;
|
|
|
|
final double d1 = p.prevPosY + ( p.posY - p.prevPosY ) * f + 1.62D - p.getYOffset();
|
|
|
|
final double d2 = p.prevPosZ + ( p.posZ - p.prevPosZ ) * f;
|
2016-06-19 14:43:27 +02:00
|
|
|
final Vec3d vec3 = new Vec3d( d0, d1, d2 );
|
2015-09-30 14:24:40 +02:00
|
|
|
final float f3 = MathHelper.cos( -f2 * 0.017453292F - (float) Math.PI );
|
|
|
|
final float f4 = MathHelper.sin( -f2 * 0.017453292F - (float) Math.PI );
|
|
|
|
final float f5 = -MathHelper.cos( -f1 * 0.017453292F );
|
|
|
|
final float f6 = MathHelper.sin( -f1 * 0.017453292F );
|
|
|
|
final float f7 = f4 * f5;
|
|
|
|
final float f8 = f3 * f5;
|
|
|
|
final double d3 = 32.0D;
|
|
|
|
|
2016-06-19 14:43:27 +02:00
|
|
|
final Vec3d vec31 = vec3.addVector( f7 * d3, f6 * d3, f8 * d3 );
|
2015-09-30 14:24:40 +02:00
|
|
|
|
2017-07-03 06:54:45 +02:00
|
|
|
final AxisAlignedBB bb = new AxisAlignedBB( Math.min( vec3.x, vec31.x ), Math.min( vec3.y, vec31.y ), Math.min( vec3.z,
|
2017-07-06 01:57:19 +02:00
|
|
|
vec31.z ), Math.max( vec3.x, vec31.x ), Math.max( vec3.y, vec31.y ), Math.max( vec3.z, vec31.z ) ).grow(
|
2016-11-26 14:08:10 +01:00
|
|
|
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
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final List list = w.getEntitiesWithinAABBExcludingEntity( p, bb );
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2015-09-30 14:22:21 +02:00
|
|
|
for( int l = 0; l < list.size(); ++l )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final Entity entity1 = (Entity) list.get( l );
|
2014-01-20 17:41:37 +01:00
|
|
|
|
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.
|
2016-06-19 14:43:27 +02:00
|
|
|
if( entity1.isRidingOrBeingRiddenBy( p ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
continue;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-20 17:41:37 +01:00
|
|
|
|
|
|
|
f1 = 0.3F;
|
2017-07-06 01:57:19 +02:00
|
|
|
final AxisAlignedBB boundingBox = entity1.getEntityBoundingBox().grow( f1, f1, f1 );
|
2016-06-19 14:43:27 +02:00
|
|
|
final RayTraceResult RayTraceResult = boundingBox.calculateIntercept( vec3, vec31 );
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2016-06-19 14:43:27 +02:00
|
|
|
if( RayTraceResult != null )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2016-06-19 14:43:27 +02:00
|
|
|
final double nd = vec3.squareDistanceTo( RayTraceResult.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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-19 14:43:27 +02:00
|
|
|
RayTraceResult pos = null;
|
|
|
|
Vec3d 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
|
|
|
{
|
2016-06-19 14:43:27 +02:00
|
|
|
vec = new Vec3d( 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
|
|
|
{
|
2016-06-19 14:43:27 +02:00
|
|
|
pos = new RayTraceResult( entity );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( entity != null && pos == null )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2016-06-19 14:43:27 +02:00
|
|
|
pos = new RayTraceResult( entity );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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-09-30 14:24:40 +02:00
|
|
|
public static <StackType extends IAEStack> StackType poweredExtraction( final IEnergySource energy, final IMEInventory<StackType> cell, final StackType request, final BaseActionSource src )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final 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 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
retrieved = possible.getStackSize();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final double availablePower = energy.extractAEPower( retrieved, Actionable.SIMULATE, PowerMultiplier.CONFIG );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final 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 );
|
2015-09-30 14:24:40 +02:00
|
|
|
final 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-09-30 14:24:40 +02:00
|
|
|
public static <StackType extends IAEStack> StackType poweredInsert( final IEnergySource energy, final IMEInventory<StackType> cell, final StackType input, final BaseActionSource src )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final 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 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
stored -= possible.getStackSize();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final double availablePower = energy.extractAEPower( stored, Actionable.SIMULATE, PowerMultiplier.CONFIG );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final 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
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final long original = input.getStackSize();
|
|
|
|
final 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
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final 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
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final 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
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final 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-09-30 14:24:40 +02:00
|
|
|
public static void postChanges( final IStorageGrid gs, final ItemStack removed, final ItemStack added, final BaseActionSource src )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final IItemList<IAEItemStack> itemChanges = AEApi.instance().storage().createItemList();
|
|
|
|
final IItemList<IAEFluidStack> fluidChanges = AEApi.instance().storage().createFluidList();
|
2014-09-11 06:12:34 +02:00
|
|
|
|
2017-06-26 05:15:25 +02:00
|
|
|
if( !removed.isEmpty() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final 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-09-30 14:24:40 +02:00
|
|
|
for( final IAEItemStack is : myItems.getAvailableItems( itemChanges ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
is.setStackSize( -is.getStackSize() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final 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-09-30 14:24:40 +02:00
|
|
|
for( final IAEFluidStack is : myFluids.getAvailableItems( fluidChanges ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
is.setStackSize( -is.getStackSize() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-26 05:15:25 +02:00
|
|
|
if( !added.isEmpty() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final 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 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-11 06:12:34 +02:00
|
|
|
myItems.getAvailableItems( itemChanges );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final 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 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-11 06:12:34 +02:00
|
|
|
myFluids.getAvailableItems( fluidChanges );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
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-09-30 14:24:40 +02:00
|
|
|
public static <T extends IAEStack<T>> void postListChanges( final IItemList<T> before, final IItemList<T> after, final IMEMonitorHandlerReceiver<T> meMonitorPassthrough, final BaseActionSource source )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2017-07-20 21:21:45 +02:00
|
|
|
final LinkedList<T> changes = new LinkedList<>();
|
2014-09-11 06:12:34 +02:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
for( final T is : before )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
is.setStackSize( -is.getStackSize() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
for( final T is : after )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
before.add( is );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
for( final 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() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
meMonitorPassthrough.postChange( null, changes, source );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static int generateTileHash( final TileEntity target )
|
2013-12-28 22:05:58 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( target == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-28 22:05:58 +01:00
|
|
|
return 0;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-28 22:05:58 +01:00
|
|
|
|
|
|
|
int hash = target.hashCode();
|
|
|
|
|
2016-10-26 22:58:23 +02:00
|
|
|
if( target.hasCapability( Capabilities.STORAGE_MONITORABLE_ACCESSOR, null ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-01-03 19:25:29 +01:00
|
|
|
return 0;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( target instanceof TileEntityChest )
|
2014-01-02 06:52:16 +01:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final TileEntityChest chest = (TileEntityChest) target;
|
2014-09-28 11:47:17 +02:00
|
|
|
chest.checkForAdjacentChests();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( chest.adjacentChestZNeg != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
hash ^= chest.adjacentChestZNeg.hashCode();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( chest.adjacentChestZPos != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
hash ^= chest.adjacentChestZPos.hashCode();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( chest.adjacentChestXPos != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
hash ^= chest.adjacentChestXPos.hashCode();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( chest.adjacentChestXNeg != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
hash ^= chest.adjacentChestXNeg.hashCode();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
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-09-30 14:24:40 +02:00
|
|
|
for( final EnumFacing dir : EnumFacing.VALUES )
|
2013-12-28 22:05:58 +01:00
|
|
|
{
|
2014-08-01 06:52:16 +02:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final int[] sides = ( (ISidedInventory) target ).getSlotsForFace( dir );
|
2014-08-01 06:52:16 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( sides == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-08-01 06:52:16 +02:00
|
|
|
return 0;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-08-01 06:52:16 +02:00
|
|
|
|
2015-09-30 14:22:21 +02:00
|
|
|
int offset = 0;
|
2015-09-30 14:24:40 +02:00
|
|
|
for( final int side : sides )
|
2014-01-02 06:52:16 +01:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final 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-09-30 14:24:40 +02:00
|
|
|
public static boolean securityCheck( final GridNode a, final GridNode b )
|
2014-01-27 05:00:36 +01:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
if( a.getLastSecurityKey() == -1 && b.getLastSecurityKey() == -1 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-01-27 05:00:36 +01:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-10-08 15:42:42 +02:00
|
|
|
else if( a.getLastSecurityKey() == b.getLastSecurityKey() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-01-27 05:00:36 +01:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
final boolean a_isSecure = isPowered( a.getGrid() ) && a.getLastSecurityKey() != -1;
|
|
|
|
final boolean b_isSecure = isPowered( b.getGrid() ) && b.getLastSecurityKey() != -1;
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2016-11-26 14:07:34 +01:00
|
|
|
if( AEConfig.instance().isFeatureEnabled( AEFeature.LOG_SECURITY_AUDITS ) )
|
2014-09-05 05:08:07 +02:00
|
|
|
{
|
2016-11-26 14:08:10 +01:00
|
|
|
AELog.info(
|
2016-12-08 12:42:00 +01:00
|
|
|
"Audit: " + a_isSecure + " : " + b_isSecure + " @ " + a.getLastSecurityKey() + " vs " + b.getLastSecurityKey() + " & " + a
|
|
|
|
.getPlayerID() + " vs " + b.getPlayerID() );
|
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 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-01-27 05:00:36 +01:00
|
|
|
return true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !a_isSecure && b_isSecure )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return checkPlayerPermissions( b.getGrid(), a.getPlayerID() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( a_isSecure && !b_isSecure )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
return checkPlayerPermissions( a.getGrid(), b.getPlayerID() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-27 05:00:36 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
private static boolean isPowered( final IGrid grid )
|
2014-01-27 05:00:36 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( grid == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-01-27 05:00:36 +01:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final IEnergyGrid eg = grid.getCache( IEnergyGrid.class );
|
2014-01-27 05:00:36 +01:00
|
|
|
return eg.isNetworkPowered();
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
private static boolean checkPlayerPermissions( final IGrid grid, final int playerID )
|
2014-01-27 05:00:36 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( grid == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-01-27 05:00:36 +01:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final 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 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-01-27 05:00:36 +01:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !gs.isAvailable() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-01-27 05:00:36 +01:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-27 05:00:36 +01:00
|
|
|
|
|
|
|
return !gs.hasPermission( playerID, SecurityPermissions.BUILD );
|
|
|
|
}
|
2014-02-09 02:34:52 +01:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static void configurePlayer( final EntityPlayer player, final AEPartLocation side, final 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;
|
2015-06-16 02:44:59 +02:00
|
|
|
// player.yOffset = 1.8f;
|
2014-02-27 08:10:45 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( side )
|
|
|
|
{
|
|
|
|
case DOWN:
|
|
|
|
pitch = 90.0f;
|
2015-06-16 02:44:59 +02:00
|
|
|
// player.getYOffset() = -1.8f;
|
2015-04-03 08:54:31 +02:00
|
|
|
break;
|
|
|
|
case EAST:
|
|
|
|
yaw = -90.0f;
|
|
|
|
break;
|
|
|
|
case NORTH:
|
|
|
|
yaw = 180.0f;
|
|
|
|
break;
|
|
|
|
case SOUTH:
|
|
|
|
yaw = 0.0f;
|
|
|
|
break;
|
2015-06-16 02:44:59 +02:00
|
|
|
case INTERNAL:
|
2015-04-03 08:54:31 +02:00
|
|
|
break;
|
|
|
|
case UP:
|
|
|
|
pitch = 90.0f;
|
|
|
|
break;
|
|
|
|
case WEST:
|
|
|
|
yaw = 90.0f;
|
|
|
|
break;
|
2014-02-27 08:10:45 +01:00
|
|
|
}
|
|
|
|
|
2015-06-16 02:44:59 +02:00
|
|
|
player.posX = tile.getPos().getX() + 0.5;
|
|
|
|
player.posY = tile.getPos().getY() + 0.5;
|
|
|
|
player.posZ = tile.getPos().getZ() + 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-09-30 14:24:40 +02:00
|
|
|
public static boolean canAccess( final AENetworkProxy gridProxy, final 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-09-30 14:24:40 +02:00
|
|
|
final IActionHost te = ( (MachineSource) src ).via;
|
|
|
|
final IGridNode n = te.getActionableNode();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( n == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-05-04 21:54:21 +02:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-05-04 21:54:21 +02:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final int playerID = n.getPlayerID();
|
2014-04-18 05:33:48 +02:00
|
|
|
return gridProxy.getSecurity().hasPermission( playerID, SecurityPermissions.BUILD );
|
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-04-18 05:33:48 +02:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-04-18 05:33:48 +02:00
|
|
|
}
|
2015-09-30 14:24:40 +02:00
|
|
|
catch( final GridAccessException gae )
|
2014-04-18 05:33:48 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static ItemStack extractItemsByRecipe( final IEnergySource energySrc, final BaseActionSource mySrc, final IMEMonitor<IAEItemStack> src, final World w, final IRecipe r, final ItemStack output, final InventoryCrafting ci, final ItemStack providedTemplate, final int slot, final IItemList<IAEItemStack> items, final Actionable realForFake, final 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 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2016-12-21 20:27:23 +01:00
|
|
|
return ItemStack.EMPTY;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-05-01 06:01:22 +02:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final AEItemStack ae_req = AEItemStack.create( providedTemplate );
|
2014-05-01 06:01:22 +02:00
|
|
|
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
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final 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
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final ItemStack extracted = ae_ext.getItemStack();
|
2017-06-26 05:15:25 +02:00
|
|
|
if( !extracted.isEmpty() )
|
2014-09-17 06:26:25 +02:00
|
|
|
{
|
|
|
|
energySrc.extractAEPower( 1, realForFake, PowerMultiplier.CONFIG );
|
|
|
|
return extracted;
|
|
|
|
}
|
2014-05-01 06:01:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-08 12:42:00 +01:00
|
|
|
final 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-09-30 14:24:40 +02:00
|
|
|
for( final IAEItemStack x : items )
|
2014-05-01 06:01:22 +02:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final ItemStack sh = x.getItemStack();
|
2016-11-26 14:08:10 +01:00
|
|
|
if( ( Platform.itemComparisons().isEqualItemType( providedTemplate,
|
|
|
|
sh ) || ae_req.sameOre( x ) ) && !Platform.itemComparisons().isEqualItem( sh, output ) )
|
2014-05-01 06:01:22 +02:00
|
|
|
{ // Platform.isSameItemType( sh, providedTemplate )
|
2015-09-30 14:24:40 +02:00
|
|
|
final ItemStack cp = Platform.cloneItemStack( sh );
|
2016-12-08 12:42:00 +01:00
|
|
|
cp.setCount( 1 );
|
2014-05-01 06:01:22 +02:00
|
|
|
ci.setInventorySlotContents( slot, cp );
|
2016-11-04 09:27:52 +01:00
|
|
|
if( r.matches( ci, w ) && Platform.itemComparisons().isEqualItem( r.getCraftingResult( ci ), output ) )
|
2014-05-01 06:01:22 +02:00
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final IAEItemStack ax = x.copy();
|
2014-08-02 06:00:12 +02:00
|
|
|
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
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final 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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-21 20:27:23 +01:00
|
|
|
return ItemStack.EMPTY;
|
2014-05-01 06:01:22 +02:00
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static ItemStack cloneItemStack( final ItemStack a )
|
2014-06-22 09:00:38 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return a.copy();
|
|
|
|
}
|
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static ItemStack getContainerItem( final ItemStack stackInSlot )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
if( stackInSlot == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2016-12-21 20:27:23 +01:00
|
|
|
return ItemStack.EMPTY;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-06-22 09:00:38 +02:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
final 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
|
|
|
{
|
2016-12-08 12:42:00 +01:00
|
|
|
if( stackInSlot.getCount() > 1 )
|
2014-06-22 09:00:38 +02:00
|
|
|
{
|
2016-12-08 12:42:00 +01:00
|
|
|
stackInSlot.setCount( stackInSlot.getCount() - 1 );
|
2014-06-22 09:00:38 +02:00
|
|
|
return stackInSlot;
|
|
|
|
}
|
2016-12-21 20:27:23 +01:00
|
|
|
return ItemStack.EMPTY;
|
2014-06-22 09:00:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ItemStack ci = i.getContainerItem( stackInSlot.copy() );
|
2017-06-26 05:15:25 +02:00
|
|
|
if( !ci.isEmpty() && ci.isItemStackDamageable() && ci.getItemDamage() == ci.getMaxDamage() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2016-12-21 20:27:23 +01:00
|
|
|
ci = ItemStack.EMPTY;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-06-22 09:00:38 +02:00
|
|
|
|
|
|
|
return ci;
|
|
|
|
}
|
|
|
|
|
2016-12-08 12:42:00 +01:00
|
|
|
public static void notifyBlocksOfNeighbors( final World world, final BlockPos pos )
|
2014-07-08 06:54:28 +02:00
|
|
|
{
|
2016-12-08 12:42:00 +01:00
|
|
|
if( !world.isRemote )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2016-12-08 12:42:00 +01:00
|
|
|
TickHandler.INSTANCE.addCallable( world, new BlockUpdate( pos ) );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-09 02:36:20 +02:00
|
|
|
}
|
2014-07-08 06:54:28 +02:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static boolean canRepair( final AEFeature type, final ItemStack a, final ItemStack b )
|
2014-07-13 00:57:53 +02:00
|
|
|
{
|
2017-06-26 05:15:25 +02:00
|
|
|
if( b.isEmpty() || a.isEmpty() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-13 00:57:53 +02:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-13 00:57:53 +02:00
|
|
|
|
2016-11-26 14:07:34 +01:00
|
|
|
if( type == AEFeature.CERTUS_QUARTZ_TOOLS )
|
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
|
|
|
|
2016-11-26 14:07:34 +01:00
|
|
|
if( type == AEFeature.NETHER_QUARTZ_TOOLS )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2016-06-19 14:43:27 +02:00
|
|
|
return Items.QUARTZ == b.getItem();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-13 00:57:53 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-04 01:34:29 +02:00
|
|
|
public static List<ItemStack> findPreferred( final 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-09-30 14:24:40 +02:00
|
|
|
for( final ItemStack stack : is )
|
2014-07-26 02:31:12 +02:00
|
|
|
{
|
2016-09-17 15:02:51 +02:00
|
|
|
if( parts.cableGlass().sameAs( AEColor.TRANSPARENT, stack ) )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2016-11-04 09:27:52 +01:00
|
|
|
return Collections.singletonList( stack );
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
2014-07-26 02:31:12 +02:00
|
|
|
|
2016-09-17 15:02:51 +02:00
|
|
|
if( parts.cableCovered().sameAs( AEColor.TRANSPARENT, stack ) )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2016-11-04 09:27:52 +01:00
|
|
|
return Collections.singletonList( stack );
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
2014-07-26 02:31:12 +02:00
|
|
|
|
2016-09-17 15:02:51 +02:00
|
|
|
if( parts.cableSmart().sameAs( AEColor.TRANSPARENT, stack ) )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2016-11-04 09:27:52 +01:00
|
|
|
return Collections.singletonList( stack );
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
2014-07-26 02:31:12 +02:00
|
|
|
|
2016-09-17 15:02:51 +02:00
|
|
|
if( parts.cableDense().sameAs( AEColor.TRANSPARENT, stack ) )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2016-11-04 09:27:52 +01:00
|
|
|
return Collections.singletonList( stack );
|
2015-01-03 02:53:14 +01:00
|
|
|
}
|
2014-07-26 02:31:12 +02:00
|
|
|
}
|
|
|
|
|
2016-10-04 01:34:29 +02:00
|
|
|
return Lists.newArrayList( is );
|
2014-07-26 02:31:12 +02:00
|
|
|
}
|
2014-08-07 08:47:42 +02:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static void sendChunk( final Chunk c, final int verticalBits )
|
2014-08-07 08:47:42 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-09-30 14:24:40 +02:00
|
|
|
final WorldServer ws = (WorldServer) c.getWorld();
|
2016-06-19 14:43:27 +02:00
|
|
|
final PlayerChunkMap pm = ws.getPlayerChunkMap();
|
2017-07-03 06:54:45 +02:00
|
|
|
final PlayerChunkMapEntry playerInstance = pm.getEntry( c.x, c.z );
|
2014-08-07 08:47:42 +02:00
|
|
|
|
2016-11-26 14:08:10 +01:00
|
|
|
if( playerInstance != null )
|
2014-08-07 08:47:42 +02:00
|
|
|
{
|
2016-11-26 14:08:10 +01:00
|
|
|
playerInstance.sendPacket( new SPacketChunkData( c, verticalBits ) );
|
2014-08-07 08:47:42 +02:00
|
|
|
}
|
|
|
|
}
|
2015-09-30 14:24:40 +02:00
|
|
|
catch( final Throwable t )
|
2014-08-07 08:47:42 +02:00
|
|
|
{
|
2015-11-22 15:54:29 +01:00
|
|
|
AELog.debug( t );
|
2014-08-07 08:47:42 +02:00
|
|
|
}
|
|
|
|
}
|
2014-08-08 08:36:50 +02:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static float getEyeOffset( final EntityPlayer player )
|
2014-08-18 23:12:45 +02:00
|
|
|
{
|
2016-12-08 12:42:00 +01:00
|
|
|
assert player.world.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
|
|
|
|
2017-07-20 21:17:10 +02:00
|
|
|
// public static void addStat( final int playerID, final Achievement achievement )
|
|
|
|
// {
|
|
|
|
// final EntityPlayer p = AEApi.instance().registries().players().findPlayer( playerID );
|
|
|
|
// if( p != null )
|
|
|
|
// {
|
|
|
|
// p.addStat( achievement, 1 );
|
|
|
|
// }
|
|
|
|
// }
|
2014-09-17 18:25:30 +02:00
|
|
|
|
2015-09-30 14:24:40 +02:00
|
|
|
public static boolean isRecipePrioritized( final 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
|
|
|
}
|