Fixes #304 WAILA Integration updated and fixed

WAILA offers a new interface to sync the server data to the client.
This commit is contained in:
thatsIch
2014-12-19 19:01:51 +01:00
parent 63e375f208
commit c6f232ab63
44 changed files with 1514 additions and 330 deletions
@@ -0,0 +1,74 @@
/*
* 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;
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;
/**
* Base implementation for {@link mcp.mobius.waila.api.IWailaDataProvider}
*
* @author thatsIch
* @version rv2
* @since rv2
*/
public abstract class BaseWailaDataProvider implements IWailaDataProvider
{
@Override
public ItemStack getWailaStack( IWailaDataAccessor accessor, IWailaConfigHandler config )
{
return null;
}
@Override
public List<String> getWailaHead( ItemStack itemStack, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config )
{
return currentToolTip;
}
@Override
public List<String> getWailaBody( ItemStack itemStack, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config )
{
return currentToolTip;
}
@Override
public List<String> getWailaTail( ItemStack itemStack, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config )
{
return currentToolTip;
}
@Override
public NBTTagCompound getNBTData( EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, int x, int y, int z )
{
return tag;
}
}
@@ -0,0 +1,173 @@
/*
* 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;
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 com.google.common.base.Optional;
import com.google.common.collect.Lists;
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;
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();
this.providers = Lists.newArrayList( channel, storageMonitor, powerState );
}
@Override
public ItemStack getWailaStack( IWailaDataAccessor accessor, IWailaConfigHandler config )
{
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 );
if ( maybePart.isPresent() )
{
final IPart part = maybePart.get();
for ( IPartWailaDataProvider provider : this.providers )
{
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 );
if ( maybePart.isPresent() )
{
final IPart part = maybePart.get();
for ( IPartWailaDataProvider provider : this.providers )
{
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 );
if ( maybePart.isPresent() )
{
final IPart part = maybePart.get();
for ( IPartWailaDataProvider provider : this.providers )
{
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 );
if ( mop != null )
{
final Optional<IPart> maybePart = this.accessor.getMaybePart( te, mop );
if ( maybePart.isPresent() )
{
final IPart part = maybePart.get();
for ( IPartWailaDataProvider provider : this.providers )
{
provider.getNBTData( player, part, te, tag, world, x, y, z );
}
}
}
return tag;
}
}
@@ -0,0 +1,117 @@
/*
* 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;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import com.google.common.collect.Lists;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import mcp.mobius.waila.api.IWailaDataProvider;
import appeng.integration.modules.waila.tile.ChargerWailaDataProvider;
import appeng.integration.modules.waila.tile.CraftingMonitorWailaDataProvider;
import appeng.integration.modules.waila.tile.PowerStateWailaDataProvider;
import appeng.integration.modules.waila.tile.PowerStorageWailaDataProvider;
/**
* Delegation provider for tiles through {@link mcp.mobius.waila.api.IWailaDataProvider}
*
* @author thatsIch
* @version rv2
* @since rv2
*/
public final class TileWailaDataProvider implements IWailaDataProvider
{
/**
* Contains all providers
*/
private final List<IWailaDataProvider> providers;
/**
* Initializes the provider list with all wanted providers
*/
public TileWailaDataProvider()
{
final IWailaDataProvider charger = new ChargerWailaDataProvider();
final IWailaDataProvider energyCell = new PowerStorageWailaDataProvider();
final IWailaDataProvider craftingBlock = new PowerStateWailaDataProvider();
final IWailaDataProvider craftingMonitor = new CraftingMonitorWailaDataProvider();
this.providers = Lists.newArrayList( charger, energyCell, craftingBlock, craftingMonitor );
}
@Override
public ItemStack getWailaStack( IWailaDataAccessor accessor, IWailaConfigHandler config )
{
return null;
}
@Override
public List<String> getWailaHead( ItemStack itemStack, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config )
{
for ( IWailaDataProvider provider : this.providers )
{
provider.getWailaHead( itemStack, currentToolTip, accessor, config );
}
return currentToolTip;
}
@Override
public List<String> getWailaBody( ItemStack itemStack, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config )
{
for ( IWailaDataProvider provider : this.providers )
{
provider.getWailaBody( itemStack, currentToolTip, accessor, config );
}
return currentToolTip;
}
@Override
public List<String> getWailaTail( ItemStack itemStack, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config )
{
for ( IWailaDataProvider provider : this.providers )
{
provider.getWailaTail( itemStack, currentToolTip, accessor, config );
}
return currentToolTip;
}
@Override
public NBTTagCompound getNBTData( EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, int x, int y, int z )
{
for ( IWailaDataProvider provider : this.providers )
{
provider.getNBTData( player, te, tag, world, x, y, z );
}
return tag;
}
}
@@ -0,0 +1,67 @@
/*
* 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.part;
import java.util.List;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import appeng.api.parts.IPart;
/**
* Default implementation of {@link appeng.integration.modules.waila.part.IPartWailaDataProvider}
*
* @author thatsIch
* @version rv2
* @since rv2
*/
public abstract class BasePartWailaDataProvider implements IPartWailaDataProvider
{
@Override
public List<String> getWailaHead( IPart part, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config )
{
return currentToolTip;
}
@Override
public List<String> getWailaBody( IPart part, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config )
{
return currentToolTip;
}
@Override
public List<String> getWailaTail( IPart part, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config )
{
return currentToolTip;
}
@Override
public NBTTagCompound getNBTData( EntityPlayerMP player, IPart part, TileEntity te, NBTTagCompound tag, World world, int x, int y, int z )
{
return tag;
}
}
@@ -0,0 +1,162 @@
/*
* 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.part;
import java.util.List;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import gnu.trove.map.TObjectByteMap;
import gnu.trove.map.hash.TObjectByteHashMap;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import appeng.api.parts.IPart;
import appeng.core.localization.GuiText;
import appeng.core.localization.WailaText;
import appeng.parts.networking.PartCableSmart;
import appeng.parts.networking.PartDenseCable;
/**
* Channel-information provider for WAILA
*
* @author thatsIch
* @version rv2
* @since rv2
*/
public final class ChannelWailaDataProvider extends BasePartWailaDataProvider
{
/**
* Channel key used for the transferred {@link net.minecraft.nbt.NBTTagCompound}
*/
private static final String ID_USED_CHANNELS = "usedChannels";
/**
* Used cache for channels if the channel was not transmitted through the server.
* <p/>
* This is useful, when a player just started to look at a tile
* and thus just requested the new information from the server.
* <p/>
* The cache will be updated from the server.
*/
private final TObjectByteMap<IPart> cache = new TObjectByteHashMap<IPart>();
/**
* Adds the used and max channel to the tool tip
*
* @param part being looked at part
* @param currentToolTip current tool tip
* @param accessor wrapper for various world information
* @param config config to react to various settings
*
* @return modified tool tip
*/
@Override
public List<String> getWailaBody( IPart part, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config )
{
if ( part instanceof PartCableSmart || part instanceof PartDenseCable )
{
final NBTTagCompound tag = accessor.getNBTData();
final byte usedChannels = this.getUsedChannels( part, tag, this.cache );
final byte maxChannels = ( byte ) ( ( part instanceof PartDenseCable ) ? 32 : 8 );
currentToolTip.add( usedChannels + " " + GuiText.Of.getLocal() + ' ' + maxChannels + ' ' + WailaText.Channels.getLocal() );
}
return currentToolTip;
}
/**
* Determines the source of the channel.
* <p/>
* If the client received information of the channels on the server, they are used,
* else if the cache contains a previous stored value, this will be used.
* Default value is 0.
*
* @param part part to be looked at
* @param tag tag maybe containing the channel information
* @param cache cache with previous knowledge
*
* @return used channels on the cable
*/
private byte getUsedChannels( IPart part, NBTTagCompound tag, TObjectByteMap<IPart> cache )
{
final byte usedChannels;
if ( tag.hasKey( ID_USED_CHANNELS ) )
{
usedChannels = tag.getByte( ID_USED_CHANNELS );
this.cache.put( part, usedChannels );
}
else if ( this.cache.containsKey( part ) )
{
usedChannels = this.cache.get( part );
}
else
{
usedChannels = 0;
}
return usedChannels;
}
/**
* Called on server to transfer information from server to client.
* <p/>
* If the part is a cable,
* it writes the channel information in the {@code #tag}
* using the {@code ID_USED_CHANNELS} key.
*
* @param player player looking at the part
* @param part part being looked at
* @param te host of the part
* @param tag transferred tag which is send to the client
* @param world world of the part
* @param x x pos of the part
* @param y y pos of the part
* @param z z pos of the part
*
* @return tag send to the client
*/
@Override
public NBTTagCompound getNBTData( EntityPlayerMP player, IPart part, TileEntity te, NBTTagCompound tag, World world, int x, int y, int z )
{
if ( part instanceof PartCableSmart || part instanceof PartDenseCable )
{
final NBTTagCompound tempTag = new NBTTagCompound();
part.writeToNBT( tempTag );
if ( tempTag.hasKey( ID_USED_CHANNELS ) )
{
final byte usedChannels = tempTag.getByte( ID_USED_CHANNELS );
tag.setByte( ID_USED_CHANNELS, usedChannels );
}
}
return tag;
}
}
@@ -0,0 +1,51 @@
/*
* 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.part;
import java.util.List;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import appeng.api.parts.IPart;
/**
* An abstraction layer of the {@link appeng.integration.modules.waila.part.IPartWailaDataProvider} for {@link appeng.api.parts.IPart}.
*
* @author thatsIch
* @version rv2
* @since rv2
*/
public interface IPartWailaDataProvider
{
List<String> getWailaHead( IPart part, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config );
List<String> getWailaBody( IPart part, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config );
List<String> getWailaTail( IPart part, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config );
NBTTagCompound getNBTData(EntityPlayerMP player, IPart part, TileEntity te, NBTTagCompound tag, World world, int x, int y, int z);
}
@@ -0,0 +1,69 @@
/*
* 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.part;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import com.google.common.base.Optional;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost;
import appeng.api.parts.SelectedPart;
/**
* Accessor to access specific parts for WAILA
*
* @author thatsIch
* @version rv2
* @since rv2
*/
public final class PartAccessor
{
/**
* Hits a {@link appeng.api.parts.IPartHost} with {@link net.minecraft.util.MovingObjectPosition}.
* <p/>
* You can derive the looked at {@link appeng.api.parts.IPart} by doing that.
* If a facade is being looked at, it is defined as being absent.
*
* @param te being looked at {@link net.minecraft.tileentity.TileEntity}
* @param mop type of raytrace
*
* @return maybe the looked at {@link appeng.api.parts.IPart}
*/
public Optional<IPart> getMaybePart( TileEntity te, MovingObjectPosition mop )
{
if ( te instanceof IPartHost )
{
final Vec3 position = mop.hitVec.addVector( -mop.blockX, -mop.blockY, -mop.blockZ );
final IPartHost host = ( IPartHost ) te;
final SelectedPart sp = host.selectPart( position );
if ( sp.part != null )
{
return Optional.of( sp.part );
}
}
return Optional.absent();
}
}
@@ -0,0 +1,91 @@
/*
* 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.part;
import java.util.List;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import appeng.api.implementations.IPowerChannelState;
import appeng.api.parts.IPart;
import appeng.core.localization.WailaText;
/**
* Power state provider for WAILA
*
* @author thatsIch
* @version rv2
* @since rv2
*/
public final class PowerStateWailaDataProvider extends BasePartWailaDataProvider
{
/**
* Adds state to the tooltip
*
* @param part part with state
* @param currentToolTip to be added to tooltip
* @param accessor wrapper for various information
* @param config config settings
*
* @return modified tooltip
*/
@Override
public List<String> getWailaBody( IPart part, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config )
{
if ( part instanceof IPowerChannelState )
{
final IPowerChannelState state = ( IPowerChannelState ) part;
currentToolTip.add( this.getToolTip( state.isActive(), state.isPowered() ) );
}
return currentToolTip;
}
/**
* Gets the corresponding tool tip for different values of {@code #isActive} and {@code #isPowered}
*
* @param isActive if part is active
* @param isPowered if part is powered
*
* @return tooltip of the state
*/
private String getToolTip( boolean isActive, boolean isPowered )
{
final String result;
if ( isActive && isPowered )
{
result = WailaText.DeviceOnline.getLocal();
}
else if ( isPowered )
{
result = WailaText.DeviceMissingChannel.getLocal();
}
else
{
result = WailaText.DeviceOffline.getLocal();
}
return result;
}
}
@@ -0,0 +1,81 @@
/*
* 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.part;
import java.util.List;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import appeng.api.implementations.parts.IPartStorageMonitor;
import appeng.api.parts.IPart;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.core.localization.WailaText;
/**
* Storage monitor provider for WAILA
*
* @author thatsIch
* @version rv2
* @since rv2
*/
public final class StorageMonitorWailaDataProvider extends BasePartWailaDataProvider
{
/**
* Displays the stack if present and if the monitor is locked.
* Can handle fluids and items.
*
* @param part maybe storage monitor
* @param currentToolTip to be written to tooltip
* @param accessor information wrapper
* @param config config option
*
* @return modified tooltip
*/
@Override
public List<String> getWailaBody( IPart part, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config )
{
if ( part instanceof IPartStorageMonitor )
{
final IPartStorageMonitor monitor = ( IPartStorageMonitor ) part;
final IAEStack<?> displayed = monitor.getDisplayed();
final boolean isLocked = monitor.isLocked();
if ( displayed instanceof IAEItemStack )
{
IAEItemStack ais = ( IAEItemStack ) displayed;
currentToolTip.add( WailaText.Showing.getLocal() + ": " + ais.getItemStack().getDisplayName() );
}
else if ( displayed instanceof IAEFluidStack )
{
IAEFluidStack ais = ( IAEFluidStack ) displayed;
currentToolTip.add( WailaText.Showing.getLocal() + ": " + ais.getFluid().getLocalizedName( ais.getFluidStack() ) );
}
currentToolTip.add( ( isLocked ) ? WailaText.Locked.getLocal() : WailaText.Unlocked.getLocal() );
}
return currentToolTip;
}
}
@@ -0,0 +1,96 @@
/*
* 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.part;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
/**
* Tracer for players hitting blocks
*
* @author thatsIch
* @version rv2
* @since rv2
*/
public final class Tracer
{
/**
* Trace view of players to blocks.
* Ignore all which are out of reach.
*
* @param world word of block
* @param player player viewing block
* @param x x pos of block
* @param y y pos of block
* @param z z pos of block
*
* @return trace movement. Can be null
*/
public MovingObjectPosition retraceBlock( World world, EntityPlayerMP player, int x, int y, int z )
{
Block block = world.getBlock( x, y, z );
Vec3 headVec = this.getCorrectedHeadVec( player );
Vec3 lookVec = player.getLook( 1.0F );
double reach = this.getBlockReachDistance_server( player );
Vec3 endVec = headVec.addVector( lookVec.xCoord * reach, lookVec.yCoord * reach, lookVec.zCoord * reach );
return block.collisionRayTrace( world, x, y, z, headVec, endVec );
}
/**
* Gets the view point of a player
*
* @param player player with head
*
* @return view point of player
*/
private Vec3 getCorrectedHeadVec( EntityPlayer player )
{
Vec3 v = Vec3.createVectorHelper( player.posX, player.posY, player.posZ );
if ( player.worldObj.isRemote )
{
//compatibility with eye height changing mods
v.yCoord += player.getEyeHeight() - player.getDefaultEyeHeight();
}
else
{
v.yCoord += player.getEyeHeight();
if ( player instanceof EntityPlayerMP && player.isSneaking() )
v.yCoord -= 0.08;
}
return v;
}
/**
* @param player multi-player player
*
* @return block reach distance of player
*/
private double getBlockReachDistance_server( EntityPlayerMP player )
{
return player.theItemInWorldManager.getBlockReachDistance();
}
}
@@ -0,0 +1,78 @@
/*
* 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.tile;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import appeng.core.localization.WailaText;
import appeng.integration.modules.waila.BaseWailaDataProvider;
import appeng.tile.misc.TileCharger;
/**
* Charger provider for WAILA
*
* @author thatsIch
* @version rv2
* @since rv2
*/
public final class ChargerWailaDataProvider extends BaseWailaDataProvider
{
/**
* Displays the holding item and its tooltip
*
* @param itemStack stack of charger
* @param currentToolTip unmodified tooltip
* @param accessor wrapper information
* @param config config option
*
* @return modified tooltip
*/
@Override
public List<String> getWailaBody( ItemStack itemStack, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config )
{
final TileEntity te = accessor.getTileEntity();
if ( te instanceof TileCharger )
{
final TileCharger charger = ( TileCharger ) te;
final IInventory chargerInventory = charger.getInternalInventory();
final ItemStack chargingItem = chargerInventory.getStackInSlot( 0 );
if ( chargingItem != null )
{
final String currentInventory = chargingItem.getDisplayName();
final EntityPlayer player = accessor.getPlayer();
currentToolTip.add( WailaText.Contains + ": " + currentInventory );
chargingItem.getItem().addInformation( chargingItem, player, currentToolTip, true );
}
}
return currentToolTip;
}
}
@@ -0,0 +1,74 @@
/*
* 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.tile;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import appeng.api.storage.data.IAEItemStack;
import appeng.core.localization.WailaText;
import appeng.integration.modules.waila.BaseWailaDataProvider;
import appeng.tile.crafting.TileCraftingMonitorTile;
/**
* Crafting-monitor provider for WAILA
*
* @author thatsIch
* @version rv2
* @since rv2
*/
public final class CraftingMonitorWailaDataProvider extends BaseWailaDataProvider
{
/**
* Displays the item currently crafted by the CPU cluster
*
* @param itemStack stack of crafting monitor
* @param currentToolTip unmodified tooltip
* @param accessor information wrapper
* @param config config option
*
* @return modified tooltip
*/
@Override
public List<String> getWailaBody( ItemStack itemStack, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config )
{
final TileEntity te = accessor.getTileEntity();
if ( te instanceof TileCraftingMonitorTile )
{
final TileCraftingMonitorTile monitor = ( TileCraftingMonitorTile ) te;
final IAEItemStack displayStack = monitor.getJobProgress();
if ( displayStack != null )
{
final String currentCrafting = displayStack.getItemStack().getDisplayName();
currentToolTip.add( WailaText.Crafting.getLocal() + ": " + currentCrafting );
}
}
return currentToolTip;
}
}
@@ -0,0 +1,82 @@
/*
* 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.tile;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import appeng.api.implementations.IPowerChannelState;
import appeng.core.localization.WailaText;
import appeng.integration.modules.waila.BaseWailaDataProvider;
/**
* Power state provider for WAILA
*
* @author thatsIch
* @version rv2
* @since rv2
*/
public final class PowerStateWailaDataProvider extends BaseWailaDataProvider
{
/**
* Adds state to the tooltip
*
* @param itemStack stack of power state
* @param currentToolTip to be added to tooltip
* @param accessor wrapper for various information
* @param config config settings
*
* @return modified tooltip
*/
@Override
public List<String> getWailaBody( ItemStack itemStack, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config )
{
final TileEntity te = accessor.getTileEntity();
if ( te instanceof IPowerChannelState )
{
final IPowerChannelState state = ( IPowerChannelState ) te;
final boolean isActive = state.isActive();
final boolean isPowered = state.isPowered();
if ( isActive && isPowered )
{
currentToolTip.add( WailaText.DeviceOnline.getLocal() );
}
else if ( isPowered )
{
currentToolTip.add( WailaText.DeviceMissingChannel.getLocal() );
}
else
{
currentToolTip.add( WailaText.DeviceOffline.getLocal() );
}
}
return currentToolTip;
}
}
@@ -0,0 +1,169 @@
/*
* 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.tile;
import java.util.List;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import gnu.trove.map.TObjectLongMap;
import gnu.trove.map.hash.TObjectLongHashMap;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import appeng.api.networking.energy.IAEPowerStorage;
import appeng.core.localization.WailaText;
import appeng.integration.modules.waila.BaseWailaDataProvider;
import appeng.util.Platform;
/**
* Power storage provider for WAILA
*
* @author thatsIch
* @version rv2
* @since rv2
*/
public final class PowerStorageWailaDataProvider extends BaseWailaDataProvider
{
/**
* Power key used for the transferred {@link net.minecraft.nbt.NBTTagCompound}
*/
private static final String ID_CURRENT_POWER = "currentPower";
/**
* Used cache for power if the power was not transmitted through the server.
* <p/>
* This is useful, when a player just started to look at a tile
* and thus just requested the new information from the server.
* <p/>
* The cache will be updated from the server.
*/
private final TObjectLongMap<TileEntity> cache = new TObjectLongHashMap<TileEntity>();
/**
* Adds the current and max power to the tool tip
* Will ignore if the tile has an energy buffer ( &gt; 0 )
*
* @param itemStack stack of power storage
* @param currentToolTip current tool tip
* @param accessor wrapper for various world information
* @param config config to react to various settings
*
* @return modified tool tip
*/
@Override
public List<String> getWailaBody( ItemStack itemStack, List<String> currentToolTip, IWailaDataAccessor accessor, IWailaConfigHandler config )
{
final TileEntity te = accessor.getTileEntity();
if ( te instanceof IAEPowerStorage )
{
final IAEPowerStorage storage = ( IAEPowerStorage ) te;
final double maxPower = storage.getAEMaxPower();
if ( maxPower > 0 )
{
final NBTTagCompound tag = accessor.getNBTData();
final long internalCurrentPower = this.getInternalCurrentPower( tag, te );
final long internalMaxPower = ( long ) ( 100 * maxPower );
final String formatCurrentPower = Platform.formatPowerLong( internalCurrentPower, false );
final String formatMaxPower = Platform.formatPowerLong( internalMaxPower, false );
currentToolTip.add( WailaText.Contains + ": " + formatCurrentPower + " / " + formatMaxPower );
}
}
return currentToolTip;
}
/**
* Called on server to transfer information from server to client.
* <p/>
* If the {@link net.minecraft.tileentity.TileEntity} is a {@link appeng.api.networking.energy.IAEPowerStorage},
* it writes the power information to the {@code #tag}
* using the {@code #ID_CURRENT_POWER} key.
*
* @param player player looking at the power storage
* @param te power storage
* @param tag transferred tag which is send to the client
* @param world world of the power storage
* @param x x pos of the power storage
* @param y y pos of the power storage
* @param z z pos of the power storage
*
* @return tag send to the client
*/
@Override
public NBTTagCompound getNBTData( EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, int x, int y, int z )
{
if ( te instanceof IAEPowerStorage )
{
final IAEPowerStorage storage = ( IAEPowerStorage ) te;
if ( storage.getAEMaxPower() > 0 )
{
final long internalCurrentPower = ( long ) ( 100 * storage.getAECurrentPower() );
tag.setLong( ID_CURRENT_POWER, internalCurrentPower );
}
}
return tag;
}
/**
* Determines the current power.
* <p/>
* If the client received power information on the server, they are used,
* else if the cache contains a previous stored value, this will be used.
* Default value is 0.
*
* @param te te to be looked at
* @param tag tag maybe containing the channel information
*
* @return used channels on the cable
*/
private long getInternalCurrentPower( NBTTagCompound tag, TileEntity te )
{
final long internalCurrentPower;
if ( tag.hasKey( ID_CURRENT_POWER ) )
{
internalCurrentPower = tag.getLong( ID_CURRENT_POWER );
this.cache.put( te, internalCurrentPower );
}
else if ( this.cache.containsKey( te ) )
{
internalCurrentPower = this.cache.get( te );
}
else
{
internalCurrentPower = 0;
}
return internalCurrentPower;
}
}