2014-12-19 19:01:51 +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>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package appeng.integration.modules.waila;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
2015-05-09 13:06:09 +02:00
|
|
|
import com.google.common.base.Optional;
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
2014-12-19 19:01:51 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
import mcp.mobius.waila.api.IWailaConfigHandler;
|
|
|
|
import mcp.mobius.waila.api.IWailaDataAccessor;
|
|
|
|
import mcp.mobius.waila.api.IWailaDataProvider;
|
|
|
|
|
|
|
|
import appeng.api.parts.IPart;
|
|
|
|
import appeng.integration.modules.waila.part.ChannelWailaDataProvider;
|
|
|
|
import appeng.integration.modules.waila.part.IPartWailaDataProvider;
|
|
|
|
import appeng.integration.modules.waila.part.PartAccessor;
|
2015-05-16 20:58:00 +02:00
|
|
|
import appeng.integration.modules.waila.part.PartStackWailaDataProvider;
|
2014-12-19 19:01:51 +01:00
|
|
|
import appeng.integration.modules.waila.part.PowerStateWailaDataProvider;
|
|
|
|
import appeng.integration.modules.waila.part.StorageMonitorWailaDataProvider;
|
|
|
|
import appeng.integration.modules.waila.part.Tracer;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delegation provider for parts through {@link appeng.integration.modules.waila.part.IPartWailaDataProvider}
|
|
|
|
*
|
|
|
|
* @author thatsIch
|
|
|
|
* @version rv2
|
|
|
|
* @since rv2
|
|
|
|
*/
|
|
|
|
public final class PartWailaDataProvider implements IWailaDataProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Contains all providers
|
|
|
|
*/
|
|
|
|
private final List<IPartWailaDataProvider> providers;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Can access parts through view-hits
|
|
|
|
*/
|
|
|
|
private final PartAccessor accessor = new PartAccessor();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Traces views hit on blocks
|
|
|
|
*/
|
|
|
|
private final Tracer tracer = new Tracer();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the provider list with all wanted providers
|
|
|
|
*/
|
|
|
|
public PartWailaDataProvider()
|
|
|
|
{
|
|
|
|
final IPartWailaDataProvider channel = new ChannelWailaDataProvider();
|
|
|
|
final IPartWailaDataProvider storageMonitor = new StorageMonitorWailaDataProvider();
|
|
|
|
final IPartWailaDataProvider powerState = new PowerStateWailaDataProvider();
|
2015-05-16 20:58:00 +02:00
|
|
|
final IPartWailaDataProvider partStack = new PartStackWailaDataProvider();
|
2014-12-19 19:01:51 +01:00
|
|
|
|
2015-05-16 20:58:00 +02:00
|
|
|
this.providers = Lists.newArrayList( channel, storageMonitor, powerState, partStack );
|
2014-12-19 19:01:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getWailaStack( IWailaDataAccessor accessor, IWailaConfigHandler config )
|
|
|
|
{
|
2015-05-16 20:58:00 +02:00
|
|
|
final TileEntity te = accessor.getTileEntity();
|
|
|
|
final MovingObjectPosition mop = accessor.getPosition();
|
|
|
|
|
|
|
|
final Optional<IPart> maybePart = this.accessor.getMaybePart( te, mop );
|
|
|
|
|
|
|
|
if( maybePart.isPresent() )
|
|
|
|
{
|
|
|
|
final IPart part = maybePart.get();
|
|
|
|
|
|
|
|
ItemStack wailaStack = null;
|
|
|
|
|
|
|
|
for( IPartWailaDataProvider provider : this.providers )
|
|
|
|
{
|
|
|
|
wailaStack = provider.getWailaStack( part, config, wailaStack );
|
|
|
|
}
|
|
|
|
return wailaStack;
|
|
|
|
}
|
|
|
|
|
2014-12-19 19:01:51 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> getWailaHead( ItemStack itemStack, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config )
|
|
|
|
{
|
|
|
|
final TileEntity te = accessor.getTileEntity();
|
|
|
|
final MovingObjectPosition mop = accessor.getPosition();
|
|
|
|
|
|
|
|
final Optional<IPart> maybePart = this.accessor.getMaybePart( te, mop );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( maybePart.isPresent() )
|
2014-12-19 19:01:51 +01:00
|
|
|
{
|
|
|
|
final IPart part = maybePart.get();
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( IPartWailaDataProvider provider : this.providers )
|
2014-12-19 19:01:51 +01:00
|
|
|
{
|
|
|
|
provider.getWailaHead( part, currentToolTip, accessor, config );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return currentToolTip;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> getWailaBody( ItemStack itemStack, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config )
|
|
|
|
{
|
|
|
|
final TileEntity te = accessor.getTileEntity();
|
|
|
|
final MovingObjectPosition mop = accessor.getPosition();
|
|
|
|
|
|
|
|
final Optional<IPart> maybePart = this.accessor.getMaybePart( te, mop );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( maybePart.isPresent() )
|
2014-12-19 19:01:51 +01:00
|
|
|
{
|
|
|
|
final IPart part = maybePart.get();
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( IPartWailaDataProvider provider : this.providers )
|
2014-12-19 19:01:51 +01:00
|
|
|
{
|
|
|
|
provider.getWailaBody( part, currentToolTip, accessor, config );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return currentToolTip;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> getWailaTail( ItemStack itemStack, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config )
|
|
|
|
{
|
|
|
|
final TileEntity te = accessor.getTileEntity();
|
|
|
|
final MovingObjectPosition mop = accessor.getPosition();
|
|
|
|
|
|
|
|
final Optional<IPart> maybePart = this.accessor.getMaybePart( te, mop );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( maybePart.isPresent() )
|
2014-12-19 19:01:51 +01:00
|
|
|
{
|
|
|
|
final IPart part = maybePart.get();
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( IPartWailaDataProvider provider : this.providers )
|
2014-12-19 19:01:51 +01:00
|
|
|
{
|
|
|
|
provider.getWailaTail( part, currentToolTip, accessor, config );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return currentToolTip;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public NBTTagCompound getNBTData( EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, int x, int y, int z )
|
|
|
|
{
|
|
|
|
final MovingObjectPosition mop = this.tracer.retraceBlock( world, player, x, y, z );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( mop != null )
|
2014-12-19 19:01:51 +01:00
|
|
|
{
|
|
|
|
final Optional<IPart> maybePart = this.accessor.getMaybePart( te, mop );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( maybePart.isPresent() )
|
2014-12-19 19:01:51 +01:00
|
|
|
{
|
|
|
|
final IPart part = maybePart.get();
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( IPartWailaDataProvider provider : this.providers )
|
2014-12-19 19:01:51 +01:00
|
|
|
{
|
|
|
|
provider.getNBTData( player, part, te, tag, world, x, y, z );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
}
|