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>.
|
|
|
|
*/
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
package appeng.server;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.server.MinecraftServer;
|
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
|
|
|
import net.minecraft.world.World;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
|
|
|
import cpw.mods.fml.common.FMLCommonHandler;
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.api.parts.CableRenderMode;
|
|
|
|
import appeng.block.AEBaseBlock;
|
|
|
|
import appeng.client.EffectType;
|
|
|
|
import appeng.core.CommonHelper;
|
|
|
|
import appeng.core.sync.AppEngPacket;
|
|
|
|
import appeng.core.sync.network.NetworkHandler;
|
|
|
|
import appeng.items.tools.ToolNetworkTool;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
public class ServerHelper extends CommonHelper
|
|
|
|
{
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private EntityPlayer renderModeBased;
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void init()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public World getWorld()
|
|
|
|
{
|
2015-03-23 10:14:35 +01:00
|
|
|
throw new UnsupportedOperationException( "This is a server..." );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void bindTileEntitySpecialRenderer( Class tile, AEBaseBlock blk )
|
|
|
|
{
|
2015-03-23 10:14:35 +01:00
|
|
|
throw new UnsupportedOperationException( "This is a server..." );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
@Override
|
|
|
|
public List<EntityPlayer> getPlayers()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !Platform.isClient() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( server != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
return server.getConfigurationManager().playerEntityList;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2014-09-28 22:20:14 +02:00
|
|
|
return new ArrayList<EntityPlayer>();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void sendToAllNearExcept( EntityPlayer p, double x, double y, double z, double dist, World w, AppEngPacket packet )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( Platform.isClient() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
return;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( EntityPlayer o : this.getPlayers() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
EntityPlayerMP entityplayermp = (EntityPlayerMP) o;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( entityplayermp != p && entityplayermp.worldObj == w )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
double dX = x - entityplayermp.posX;
|
|
|
|
double dY = y - entityplayermp.posY;
|
|
|
|
double dZ = z - entityplayermp.posZ;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( dX * dX + dY * dY + dZ * dZ < dist * dist )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
NetworkHandler.instance.sendTo( packet, entityplayermp );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void spawnEffect( EffectType type, World worldObj, double posX, double posY, double posZ, Object o )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
// :P
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean shouldAddParticles( Random r )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return false;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public MovingObjectPosition getMOP()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return null;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void doRenderItem( ItemStack sis, World tile )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void postInit()
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public CableRenderMode getRenderMode()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.renderModeBased == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
return CableRenderMode.Standard;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.renderModeForPlayer( this.renderModeBased );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
protected CableRenderMode renderModeForPlayer( EntityPlayer player )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( player != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int x = 0; x < InventoryPlayer.getHotbarSize(); x++ )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
ItemStack is = player.inventory.getStackInSlot( x );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( is != null && is.getItem() instanceof ToolNetworkTool )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
NBTTagCompound c = is.getTagCompound();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( c != null && c.getBoolean( "hideFacades" ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
return CableRenderMode.CableView;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CableRenderMode.Standard;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void triggerUpdates()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public void updateRenderMode( EntityPlayer player )
|
|
|
|
{
|
|
|
|
this.renderModeBased = player;
|
|
|
|
}
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
@Override
|
|
|
|
public void missingCoreMod()
|
|
|
|
{
|
2015-03-23 10:14:35 +01:00
|
|
|
throw new IllegalStateException( "Unable to Load Core Mod, please verify that AE2 is properly install in the mods folder, with a .jar extension." );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|