Search in sources :

Example 1 with TileEntityReceiver

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

the class RailMonoMagnetDetector method setRailOutput.

public void setRailOutput(World world, int x, int y, int z, int meta) {
    boolean isPowered = (meta & 8) != 0;
    boolean hasCart = false;
    boolean isEnabled = false;
    float bBoxSize = 0.125F;
    List bBox = world.getEntitiesWithinAABB(EntityMinecart.class, AxisAlignedBB.getBoundingBox((double) ((float) x + bBoxSize), (double) y, (double) ((float) z + bBoxSize), (double) ((float) (x + 1) - bBoxSize), (double) ((float) (y + 1) - bBoxSize), (double) ((float) (z + 1) - bBoxSize)));
    if (!bBox.isEmpty()) {
        hasCart = true;
    }
    if (hasCart && !isPowered) {
        if (delaySecond != 0) {
            Point3D p = new Point3D(x, y, z);
            if (!tmpDelay.containsKey(p)) {
                tmpDelay.put(p, 0);
            }
            if (tmpDelay.get(p) < delaySecond * 20)
                tmpDelay.put(p, tmpDelay.get(p) + 1);
            else {
                if (getRailDirection(world, x, y, z) == RailDirection.NS) {
                    if (world.isBlockIndirectlyGettingPowered(x - 1, y, z) || world.isBlockIndirectlyGettingPowered(x + 1, y, z) || world.isBlockIndirectlyGettingPowered(x - 1, y - 1, z) || world.isBlockIndirectlyGettingPowered(x + 1, y - 1, z)) {
                        isEnabled = true;
                    }
                } else {
                    if (world.isBlockIndirectlyGettingPowered(x, y, z - 1) || world.isBlockIndirectlyGettingPowered(x, y, z + 1) || world.isBlockIndirectlyGettingPowered(x, y - 1, z - 1) || world.isBlockIndirectlyGettingPowered(x, y - 1, z + 1)) {
                        isEnabled = true;
                    }
                }
                if (world.getTileEntity(x, y, z) instanceof TileEntityReceiver) {
                    TileEntityReceiver railReceiver = (TileEntityReceiver) world.getTileEntity(x, y, z);
                    if (railReceiver.senderIsPowered())
                        isEnabled = true;
                }
                if (!isEnabled) {
                    world.setBlockMetadataWithNotify(x, y, z, meta | 8, 3);
                    world.notifyBlocksOfNeighborChange(x, y, z, this);
                    world.notifyBlocksOfNeighborChange(x, y - 1, z, this);
                    world.markBlockRangeForRenderUpdate(x, y, z, x, y, z);
                    tmpDelay.put(p, 0);
                }
            }
        } else {
            world.setBlockMetadataWithNotify(x, y, z, meta | 8, 3);
            world.notifyBlocksOfNeighborChange(x, y, z, this);
            world.notifyBlocksOfNeighborChange(x, y - 1, z, this);
            world.markBlockRangeForRenderUpdate(x, y, z, x, y, z);
        }
    } else if (!hasCart && !isPowered && delaySecond != 0) {
        if (tmpDelay.containsKey(new Point3D(x, y, z)))
            tmpDelay.put(new Point3D(x, y, z), 0);
    }
    if (!hasCart && isPowered) {
        world.setBlockMetadataWithNotify(x, y, z, meta & 7, 3);
        world.notifyBlocksOfNeighborChange(x, y, z, this);
        world.notifyBlocksOfNeighborChange(x, y - 1, z, this);
        world.markBlockRangeForRenderUpdate(x, y, z, x, y, z);
    }
    if (hasCart) {
        world.scheduleBlockUpdate(x, y, z, this, 20);
    }
    world.func_147453_f(x, y, z, this);
}
Also used : Point3D(org.thewdj.physics.Point3D) List(java.util.List) TileEntityReceiver(club.nsdn.nyasamatelecom.api.tileentity.TileEntityReceiver)

Example 2 with TileEntityReceiver

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

the class SignalBox method updateSignal.

public void updateSignal(World world, int x, int y, int z) {
    if (world.getTileEntity(x, y, z) == null)
        return;
    if (world.getTileEntity(x, y, z) instanceof TileEntitySignalBox) {
        TileEntitySignalBox signalBox = (TileEntitySignalBox) world.getTileEntity(x, y, z);
        int meta = world.getBlockMetadata(x, y, z);
        int old = meta;
        boolean isEnabled;
        if (signalBox.getSender() == null) {
            isEnabled = (meta & 0x8) != 0;
            meta &= 0x7;
        } else {
            isEnabled = signalBox.senderIsPowered();
            if (isEnabled)
                meta |= 0x8;
            else
                meta &= 0x7;
        }
        signalBox.isEnabled = isEnabled;
        if (signalBox.inverterEnabled)
            isEnabled = !isEnabled;
        if (!signalBox.tryControlFirst(isEnabled)) {
            if (!signalBox.tryControlSecond(isEnabled)) {
                if (!signalBox.setTargetSender(isEnabled)) {
                    if (!signalBox.setTargetGetter(isEnabled)) {
                        if (signalBox.getTarget() != null) {
                            TileEntity tileEntity = signalBox.getTarget();
                            if (tileEntity instanceof TileEntityReceiver) {
                                if (tileEntity instanceof IPassive) {
                                    signalBox.controlTarget(isEnabled);
                                }
                            } else {
                                signalBox.controlTarget(isEnabled);
                            }
                        }
                    }
                }
            }
        }
        if (old != meta || signalBox.prevInverterEnabled != signalBox.inverterEnabled) {
            signalBox.prevInverterEnabled = signalBox.inverterEnabled;
            world.markBlockForUpdate(x, y, z);
            world.setBlockMetadataWithNotify(x, y, z, meta, 3);
        }
        world.scheduleBlockUpdate(x, y, z, this, 1);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPassive(org.thewdj.telecom.IPassive) TileEntityReceiver(club.nsdn.nyasamatelecom.api.tileentity.TileEntityReceiver)

Example 3 with TileEntityReceiver

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

the class TriStateSignalBox method onBlockPreDestroy.

@Override
public void onBlockPreDestroy(World world, int x, int y, int z, int meta) {
    super.onBlockPreDestroy(world, x, y, z, meta);
    TileEntity tileEntity = world.getTileEntity(x, y, z);
    if (tileEntity != null) {
        if (tileEntity instanceof TileEntityReceiver) {
            ((TileEntityReceiver) tileEntity).onDestroy();
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityReceiver(club.nsdn.nyasamatelecom.api.tileentity.TileEntityReceiver)

Example 4 with TileEntityReceiver

use of club.nsdn.nyasamatelecom.api.tileentity.TileEntityReceiver 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 5 with TileEntityReceiver

use of club.nsdn.nyasamatelecom.api.tileentity.TileEntityReceiver 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

TileEntityReceiver (club.nsdn.nyasamatelecom.api.tileentity.TileEntityReceiver)14 TileEntity (net.minecraft.tileentity.TileEntity)9 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)6 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 ItemNTP32Bit (club.nsdn.nyasamarailway.item.tool.ItemNTP32Bit)4 ItemNTP8Bit (club.nsdn.nyasamarailway.item.tool.ItemNTP8Bit)4 EntityMinecart (net.minecraft.entity.item.EntityMinecart)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 ItemStack (net.minecraft.item.ItemStack)4 DamageSource (net.minecraft.util.DamageSource)4 TileEntityActuator (club.nsdn.nyasamatelecom.api.tileentity.TileEntityActuator)2 UUID (java.util.UUID)2 TileEntityTransceiver (club.nsdn.nyasamatelecom.api.tileentity.TileEntityTransceiver)1 List (java.util.List)1 Block (net.minecraft.block.Block)1 Point3D (org.thewdj.physics.Point3D)1 IPassive (org.thewdj.telecom.IPassive)1