Search in sources :

Example 1 with TileEntityActuator

use of club.nsdn.nyasamatelecom.api.tileentity.TileEntityActuator in project NyaSamaRailway by NSDN.

the class Item74HC04 method onConnectorUseLast.

@Override
public boolean onConnectorUseLast(EntityPlayer player, UUID uuid, TileEntity tileEntity) {
    if (Railcraft.getInstance() != null) {
        if (Railcraft.getInstance().verifySwitch(tileEntity)) {
            if (receiverRails.containsKey(uuid)) {
                if (receiverRails.get(uuid) instanceof TileEntityActuator) {
                    TileEntityActuator actuator = (TileEntityActuator) receiverRails.get(uuid);
                    if (actuator.getTarget() != tileEntity) {
                        actuator.setTarget(tileEntity);
                        if (player instanceof EntityPlayerMP)
                            player.addChatComponentMessage(new ChatComponentTranslation("info.signal.connected"));
                        updateTileEntity(actuator);
                        updateTileEntity(tileEntity);
                    } else {
                        actuator.setTarget(null);
                        if (player instanceof EntityPlayerMP)
                            player.addChatComponentMessage(new ChatComponentTranslation("info.signal.disconnected"));
                        updateTileEntity(actuator);
                        updateTileEntity(tileEntity);
                    }
                }
                receiverRails.remove(uuid);
            } else {
                if (player instanceof EntityPlayerMP)
                    player.addChatComponentMessage(new ChatComponentTranslation("info.signal.error"));
            }
            return true;
        }
    }
    return false;
}
Also used : TileEntityActuator(club.nsdn.nyasamatelecom.api.tileentity.TileEntityActuator) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 2 with TileEntityActuator

use of club.nsdn.nyasamatelecom.api.tileentity.TileEntityActuator in project NyaSamaRailway by NSDN.

the class Connector method onItemUseFirst.

@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    Block block = world.getBlock(x, y, z);
    if (block == null)
        return false;
    if (!world.isRemote) {
        if (player.isSneaking()) {
            UUID uuid = player.getUniqueID();
            TileEntity tileEntity = world.getTileEntity(x, y, z);
            if (tileEntity instanceof TileEntityTransceiver) {
                TileEntityTransceiver railSender = (TileEntityTransceiver) tileEntity;
                if (tmpRails.containsKey(uuid)) {
                    tmpRails.remove(uuid);
                    if (player instanceof EntityPlayerMP)
                        player.addChatComponentMessage(new ChatComponentTranslation("info.signal.abort"));
                } else {
                    tmpRails.put(uuid, railSender);
                    if (player instanceof EntityPlayerMP)
                        player.addChatComponentMessage(new ChatComponentTranslation("info.signal.begin"));
                }
                return true;
            } else if (tileEntity instanceof TileEntityReceiver) {
                TileEntityReceiver railReceiver = (TileEntityReceiver) tileEntity;
                if (tmpRails.containsKey(uuid)) {
                    if (railReceiver.getSender() != tmpRails.get(uuid)) {
                        if (tmpRails.get(uuid).getTransceiver() == null) {
                            if (player instanceof EntityPlayerMP)
                                player.addChatComponentMessage(new ChatComponentTranslation("info.signal.error"));
                        } else {
                            railReceiver.setSender(tmpRails.get(uuid));
                            if (player instanceof EntityPlayerMP)
                                player.addChatComponentMessage(new ChatComponentTranslation("info.signal.connected"));
                            updateTileEntity(tmpRails.get(uuid));
                            updateTileEntity(railReceiver);
                        }
                        tmpRails.remove(uuid);
                    } else {
                        if (railReceiver.getSender() == tmpRails.get(uuid)) {
                            railReceiver.setSender(null);
                            if (player instanceof EntityPlayerMP)
                                player.addChatComponentMessage(new ChatComponentTranslation("info.signal.disconnected"));
                            updateTileEntity(tmpRails.get(uuid));
                            updateTileEntity(railReceiver);
                            tmpRails.remove(uuid);
                        }
                    }
                } else {
                    if (player instanceof EntityPlayerMP)
                        player.addChatComponentMessage(new ChatComponentTranslation("info.signal.error"));
                }
                return true;
            }
        } else {
            UUID uuid = player.getUniqueID();
            TileEntity tileEntity = world.getTileEntity(x, y, z);
            if (tileEntity instanceof TileEntityMultiSender) {
                TileEntityMultiSender sender = (TileEntityMultiSender) tileEntity;
                if (senderRails.containsKey(uuid)) {
                    if (senderRails.get(uuid) instanceof TileEntityMultiSender) {
                        if (senderRails.get(uuid) == sender) {
                            if (player instanceof EntityPlayerMP)
                                player.addChatComponentMessage(new ChatComponentTranslation("info.signal.abort"));
                        } else {
                            if (player instanceof EntityPlayerMP)
                                player.addChatComponentMessage(new ChatComponentTranslation("info.signal.error"));
                        }
                    } else {
                        if (sender.getTransceiver() == senderRails.get(uuid)) {
                            sender.getTransceiver().setTransceiver(null);
                            sender.setTransceiver(null);
                            if (player instanceof EntityPlayerMP)
                                player.addChatComponentMessage(new ChatComponentTranslation("info.signal.disconnected"));
                            updateTileEntity(senderRails.get(uuid));
                            updateTileEntity(sender);
                        } else {
                            sender.setTransceiver(senderRails.get(uuid));
                            sender.getTransceiver().setTransceiver(sender);
                            if (player instanceof EntityPlayerMP)
                                player.addChatComponentMessage(new ChatComponentTranslation("info.signal.connected"));
                            updateTileEntity(senderRails.get(uuid));
                            updateTileEntity(sender);
                        }
                    }
                    senderRails.remove(uuid);
                } else {
                    if (receiverRails.containsKey(uuid)) {
                        // Here is actuator to transceiver, 1 to 1
                        if (receiverRails.get(uuid) instanceof TileEntityActuator) {
                            TileEntityActuator actuator = (TileEntityActuator) receiverRails.get(uuid);
                            if (actuator.getTarget() != sender) {
                                actuator.setTarget(sender);
                                if (player instanceof EntityPlayerMP)
                                    player.addChatComponentMessage(new ChatComponentTranslation("info.signal.connected"));
                                updateTileEntity(actuator);
                                updateTileEntity(sender);
                            } else {
                                actuator.setTarget(null);
                                if (player instanceof EntityPlayerMP)
                                    player.addChatComponentMessage(new ChatComponentTranslation("info.signal.disconnected"));
                                updateTileEntity(actuator);
                                updateTileEntity(sender);
                            }
                        } else {
                            if (player instanceof EntityPlayerMP)
                                player.addChatComponentMessage(new ChatComponentTranslation("info.signal.error"));
                        }
                        receiverRails.remove(uuid);
                    } else {
                        senderRails.put(uuid, sender);
                        if (player instanceof EntityPlayerMP)
                            player.addChatComponentMessage(new ChatComponentTranslation("info.signal.begin"));
                    }
                }
                return true;
            } else if (tileEntity instanceof TileEntityTransceiver) {
                TileEntityTransceiver transceiver = (TileEntityTransceiver) tileEntity;
                if (senderRails.containsKey(uuid)) {
                    if (senderRails.get(uuid) instanceof TileEntityMultiSender) {
                        if (transceiver.getTransceiver() == senderRails.get(uuid)) {
                            transceiver.getTransceiver().setTransceiver(null);
                            transceiver.setTransceiver(null);
                            if (player instanceof EntityPlayerMP)
                                player.addChatComponentMessage(new ChatComponentTranslation("info.signal.disconnected"));
                            updateTileEntity(senderRails.get(uuid));
                            updateTileEntity(transceiver);
                        } else {
                            if (player instanceof EntityPlayerMP)
                                player.addChatComponentMessage(new ChatComponentTranslation("info.signal.error"));
                        }
                    } else {
                        // Here is blocking rail, link with 1n4148 instead of this item, it may be dangerous
                        if (player instanceof EntityPlayerMP)
                            player.addChatComponentMessage(new ChatComponentTranslation("info.signal.abort"));
                    }
                    senderRails.remove(uuid);
                } else {
                    senderRails.put(uuid, transceiver);
                    if (player instanceof EntityPlayerMP)
                        player.addChatComponentMessage(new ChatComponentTranslation("info.signal.begin"));
                }
                return true;
            } else if (tileEntity instanceof TileEntityReceiver) {
                TileEntityReceiver receiver = (TileEntityReceiver) tileEntity;
                if (senderRails.containsKey(uuid)) {
                    if (receiver.getSender() != senderRails.get(uuid)) {
                        receiver.setSender(senderRails.get(uuid));
                        if (senderRails.get(uuid) instanceof TileEntityMultiSender) {
                            ((TileEntityMultiSender) senderRails.get(uuid)).incTarget();
                        }
                        if (player instanceof EntityPlayerMP)
                            player.addChatComponentMessage(new ChatComponentTranslation("info.signal.connected"));
                        updateTileEntity(senderRails.get(uuid));
                        updateTileEntity(receiver);
                    } else {
                        receiver.setSender(null);
                        if (senderRails.get(uuid) instanceof TileEntityMultiSender) {
                            ((TileEntityMultiSender) senderRails.get(uuid)).decTarget();
                        }
                        if (player instanceof EntityPlayerMP)
                            player.addChatComponentMessage(new ChatComponentTranslation("info.signal.disconnected"));
                        updateTileEntity(senderRails.get(uuid));
                        updateTileEntity(receiver);
                    }
                    senderRails.remove(uuid);
                } else {
                    if (receiverRails.containsKey(uuid)) {
                        if (receiverRails.get(uuid) instanceof TileEntityActuator) {
                            TileEntityActuator actuator = (TileEntityActuator) receiverRails.get(uuid);
                            if (actuator == receiver) {
                                if (player instanceof EntityPlayerMP)
                                    player.addChatComponentMessage(new ChatComponentTranslation("info.signal.abort"));
                            } else if (actuator.getTarget() != receiver) {
                                actuator.setTarget(receiver);
                                if (player instanceof EntityPlayerMP)
                                    player.addChatComponentMessage(new ChatComponentTranslation("info.signal.connected"));
                                updateTileEntity(actuator);
                                updateTileEntity(receiver);
                            } else {
                                actuator.setTarget(null);
                                if (player instanceof EntityPlayerMP)
                                    player.addChatComponentMessage(new ChatComponentTranslation("info.signal.disconnected"));
                                updateTileEntity(actuator);
                                updateTileEntity(receiver);
                            }
                        } else if (receiver instanceof TileEntityActuator) {
                            if (((TileEntityActuator) receiver).getTarget() != receiverRails.get(uuid)) {
                                ((TileEntityActuator) receiver).setTarget(receiverRails.get(uuid));
                                if (player instanceof EntityPlayerMP)
                                    player.addChatComponentMessage(new ChatComponentTranslation("info.signal.connected"));
                                updateTileEntity(receiverRails.get(uuid));
                                updateTileEntity(receiver);
                            } else {
                                ((TileEntityActuator) receiver).setTarget(null);
                                if (player instanceof EntityPlayerMP)
                                    player.addChatComponentMessage(new ChatComponentTranslation("info.signal.disconnected"));
                                updateTileEntity(receiverRails.get(uuid));
                                updateTileEntity(receiver);
                            }
                        }
                        receiverRails.remove(uuid);
                    } else {
                        if (receiver instanceof TileEntityPassiveReceiver) {
                            if (player instanceof EntityPlayerMP)
                                player.addChatComponentMessage(new ChatComponentTranslation("info.signal.error"));
                        } else {
                            receiverRails.put(uuid, receiver);
                            if (player instanceof EntityPlayerMP)
                                player.addChatComponentMessage(new ChatComponentTranslation("info.signal.begin"));
                        }
                    }
                }
                return true;
            } else {
                onConnectorUseLast(player, uuid, tileEntity);
            }
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityActuator(club.nsdn.nyasamatelecom.api.tileentity.TileEntityActuator) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) Block(net.minecraft.block.Block) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) TileEntityReceiver(club.nsdn.nyasamatelecom.api.tileentity.TileEntityReceiver) UUID(java.util.UUID) TileEntityTransceiver(club.nsdn.nyasamatelecom.api.tileentity.TileEntityTransceiver)

Example 3 with TileEntityActuator

use of club.nsdn.nyasamatelecom.api.tileentity.TileEntityActuator in project NyaSamaRailway by NSDN.

the class DevEditor method onItemUseFirst.

@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    TileEntity tileEntity = world.getTileEntity(x, y, z);
    UUID uuid = player.getUniqueID();
    if (!world.isRemote) {
        if (tileEntity == null) {
            if (sender.containsKey(uuid))
                sender.remove(uuid);
            if (target.containsKey(uuid))
                target.remove(uuid);
            player.addChatComponentMessage(new ChatComponentTranslation("info.editor.clear"));
            return true;
        }
        if (player.isSneaking()) {
            if (!target.containsKey(uuid)) {
                if (tileEntity instanceof TileEntityActuator) {
                    target.put(uuid, ((TileEntityActuator) tileEntity).getTarget());
                    player.addChatComponentMessage(new ChatComponentTranslation("info.editor.copy.target"));
                } else {
                    player.addChatComponentMessage(new ChatComponentTranslation("info.editor.error"));
                }
            } else {
                if (tileEntity instanceof TileEntityActuator) {
                    ((TileEntityActuator) tileEntity).setTarget(target.get(uuid));
                    world.markBlockForUpdate(x, y, z);
                    player.addChatComponentMessage(new ChatComponentTranslation("info.editor.paste.target"));
                } else {
                    player.addChatComponentMessage(new ChatComponentTranslation("info.editor.error"));
                }
            }
        } else {
            if (!sender.containsKey(uuid)) {
                if (tileEntity instanceof TileEntityReceiver) {
                    sender.put(uuid, ((TileEntityReceiver) tileEntity).getSender());
                    player.addChatComponentMessage(new ChatComponentTranslation("info.editor.copy.sender"));
                } else {
                    player.addChatComponentMessage(new ChatComponentTranslation("info.editor.error"));
                }
            } else {
                if (tileEntity instanceof TileEntityReceiver) {
                    ((TileEntityReceiver) tileEntity).setSender(sender.get(uuid));
                    world.markBlockForUpdate(x, y, z);
                    player.addChatComponentMessage(new ChatComponentTranslation("info.editor.paste.sender"));
                } else {
                    player.addChatComponentMessage(new ChatComponentTranslation("info.editor.error"));
                }
            }
        }
        return true;
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityActuator(club.nsdn.nyasamatelecom.api.tileentity.TileEntityActuator) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) TileEntityReceiver(club.nsdn.nyasamatelecom.api.tileentity.TileEntityReceiver) UUID(java.util.UUID)

Aggregations

TileEntityActuator (club.nsdn.nyasamatelecom.api.tileentity.TileEntityActuator)3 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)3 TileEntityReceiver (club.nsdn.nyasamatelecom.api.tileentity.TileEntityReceiver)2 UUID (java.util.UUID)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 TileEntity (net.minecraft.tileentity.TileEntity)2 TileEntityTransceiver (club.nsdn.nyasamatelecom.api.tileentity.TileEntityTransceiver)1 Block (net.minecraft.block.Block)1