Fixes #861 Wireless Terminal notifies player, if it is unlinked
This commit is contained in:
parent
63a6037ad2
commit
dd1ca1e286
5 changed files with 62 additions and 20 deletions
|
@ -23,19 +23,31 @@
|
|||
|
||||
package appeng.api.features;
|
||||
|
||||
|
||||
/**
|
||||
* A Registry for locatable items, works based on serial numbers.
|
||||
*/
|
||||
public interface ILocatableRegistry
|
||||
{
|
||||
|
||||
/**
|
||||
* Attempts to find the object with the serial specified, if it can it
|
||||
* returns the object.
|
||||
*
|
||||
* @param serial serial
|
||||
*
|
||||
* @return requestedObject, or null
|
||||
*
|
||||
* @deprecated use {@link ILocatableRegistry#getLocatableBy(long)}
|
||||
*/
|
||||
public abstract Object findLocatableBySerial(long serial);
|
||||
@Deprecated
|
||||
Object findLocatableBySerial( long serial );
|
||||
|
||||
/**
|
||||
* Gets the {@link ILocatable} with the registered serial, if available
|
||||
*
|
||||
* @param serial serial
|
||||
*
|
||||
* @return requestedObject, or null, if the object does not exist anymore
|
||||
*/
|
||||
ILocatable getLocatableBy( long serial );
|
||||
}
|
|
@ -18,7 +18,9 @@
|
|||
|
||||
package appeng.core.features.registries;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
|
@ -30,13 +32,19 @@ import appeng.api.features.ILocatable;
|
|||
import appeng.api.features.ILocatableRegistry;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class LocatableRegistry implements ILocatableRegistry
|
||||
{
|
||||
|
||||
private final HashMap<Long, ILocatable> set;
|
||||
public final class LocatableRegistry implements ILocatableRegistry
|
||||
{
|
||||
private final Map<Long, ILocatable> set;
|
||||
|
||||
public LocatableRegistry()
|
||||
{
|
||||
this.set = new HashMap<Long, ILocatable>();
|
||||
MinecraftForge.EVENT_BUS.register( this );
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void updateLocatable(LocatableEventAnnounce e)
|
||||
public void updateLocatable( LocatableEventAnnounce e )
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return; // IGNORE!
|
||||
|
@ -51,18 +59,18 @@ public class LocatableRegistry implements ILocatableRegistry
|
|||
}
|
||||
}
|
||||
|
||||
public LocatableRegistry() {
|
||||
this.set = new HashMap<Long, ILocatable>();
|
||||
MinecraftForge.EVENT_BUS.register( this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a locate-able object by its serial.
|
||||
*/
|
||||
@Override
|
||||
public Object findLocatableBySerial(long ser)
|
||||
public Object findLocatableBySerial( long ser )
|
||||
{
|
||||
return this.set.get( ser );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILocatable getLocatableBy( long serial )
|
||||
{
|
||||
return this.set.get( serial );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,24 +18,25 @@
|
|||
|
||||
package appeng.core.features.registries;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.features.ILocatable;
|
||||
import appeng.api.features.IWirelessTermHandler;
|
||||
import appeng.api.features.IWirelessTermRegistry;
|
||||
import appeng.core.localization.PlayerMessages;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class WirelessRegistry implements IWirelessTermRegistry
|
||||
public final class WirelessRegistry implements IWirelessTermRegistry
|
||||
{
|
||||
|
||||
final List<IWirelessTermHandler> handlers;
|
||||
private final List<IWirelessTermHandler> handlers;
|
||||
|
||||
public WirelessRegistry() {
|
||||
this.handlers = new ArrayList<IWirelessTermHandler>();
|
||||
|
@ -76,10 +77,25 @@ public class WirelessRegistry implements IWirelessTermRegistry
|
|||
if ( Platform.isClient() )
|
||||
return;
|
||||
|
||||
IWirelessTermHandler handler = this.getWirelessTerminalHandler( item );
|
||||
if ( handler == null )
|
||||
if ( !this.isWirelessTerminal( item ) )
|
||||
{
|
||||
player.addChatMessage( new ChatComponentText( "Item is not a wireless terminal." ) );
|
||||
player.addChatMessage( PlayerMessages.DeviceNotWirelessTerminal.get() );
|
||||
return;
|
||||
}
|
||||
|
||||
final IWirelessTermHandler handler = this.getWirelessTerminalHandler( item );
|
||||
final String unparsedKey = handler.getEncryptionKey( item );
|
||||
if ( unparsedKey.length() == 0 )
|
||||
{
|
||||
player.addChatMessage( PlayerMessages.DeviceNotLinked.get() );
|
||||
return;
|
||||
}
|
||||
|
||||
final long parsedKey = Long.parseLong( unparsedKey );
|
||||
final ILocatable securityStation = AEApi.instance().registries().locatable().getLocatableBy( parsedKey );
|
||||
if ( securityStation == null )
|
||||
{
|
||||
player.addChatMessage( PlayerMessages.StationCanNotBeLocated.get() );
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,10 @@ public enum PlayerMessages
|
|||
{
|
||||
ChestCannotReadStorageCell, InvalidMachine, LoadedSettings, SavedSettings, MachineNotPowered,
|
||||
|
||||
isNowLocked, isNowUnlocked, AmmoDepleted, CommunicationError, OutOfRange, DeviceNotPowered, SettingCleared;
|
||||
isNowLocked, isNowUnlocked,
|
||||
AmmoDepleted,
|
||||
CommunicationError, OutOfRange, DeviceNotPowered, DeviceNotWirelessTerminal, DeviceNotLinked, StationCanNotBeLocated,
|
||||
SettingCleared,;
|
||||
|
||||
String getName()
|
||||
{
|
||||
|
|
|
@ -66,6 +66,9 @@ chat.appliedenergistics2.OutOfRange=Wireless Out Of Range.
|
|||
chat.appliedenergistics2.InvalidMachine=Invalid Machine.
|
||||
chat.appliedenergistics2.LoadedSettings=Successfully loaded settings.
|
||||
chat.appliedenergistics2.DeviceNotPowered=Device is low on power.
|
||||
chat.appliedenergistics2.DeviceNotWirelessTerminal=Device is not a wireless terminal.
|
||||
chat.appliedenergistics2.DeviceNotLinked=Device is not linked.
|
||||
chat.appliedenergistics2.StationCanNotBeLocated=Station can not be located.
|
||||
chat.appliedenergistics2.MachineNotPowered=Machine is not powered.
|
||||
chat.appliedenergistics2.CommunicationError=Error Communicating with Network.
|
||||
chat.appliedenergistics2.SavedSettings=Successfully saved settings.
|
||||
|
|
Loading…
Reference in a new issue